timer for markslider, more verbose whenfilech..

This commit is contained in:
Ville Rantanen
2015-10-12 13:13:42 +03:00
parent cd56c0663b
commit a6a049e8ee
2 changed files with 42 additions and 12 deletions

View File

@@ -185,13 +185,14 @@ function whenfilechanges() {
do ntime[$i]=$( stat -c %Z "${fname[$i]}" )
[ "${ntime[$i]}" -ne "${otime[$i]}" ] && {
echo "${fname[$i]} changed:"
eval "$@"
otime[$i]=$( stat -c %Z "${fname[$i]}" )
eval "$@"
echo -n "Waiting for file changes... "
date
}
done
read -t 2 forced
echo -ne Waiting.. $( date )\\r
[ $? -eq 0 ] && eval "$@"
done

View File

@@ -24,7 +24,7 @@ __version__ = "0.6"
import sys,os,argparse,re
from argparse import ArgumentParser
import traceback,tty,termios,subprocess
import traceback,tty,termios,subprocess,signal
HL=">"
EOS="# End of Slides"
@@ -158,12 +158,16 @@ class slide_reader:
def get_page_no(self):
return self.page
def inc_page_no(self,inc=1):
def inc_page_no(self,inc=1,loop=False):
self.page+=inc
if self.page<0:
self.page=0
if loop:
self.page=self.pages-1
if self.page>=self.pages:
self.page=self.pages-1
if loop:
self.page=0
self.width=max([len(x) for x in self.data[self.page]])
self.height=len(self.data[self.page])
def last_page(self):
@@ -224,9 +228,10 @@ class slide_reader:
def get_interactive_help_text():
return ''' left/right,page up/down,home,end
change page
s toggle status bar
q exit browser
r reload the file
s toggle status bar
t toggle timer (reqs. --timer switch)
,/. scroll page
up/down move highlight
h help'''
@@ -253,18 +258,20 @@ Keyboard shortcuts:
parser.add_argument("--dc",action="store_true",dest="dark_colors",default=False,
help="Use dark colorscheme, better for white background terminals.")
parser.add_argument("-e",action="store_true",dest="execute",default=False,
help="Execute commands in $! or $> tags at show time with Enter key. WARNING: Potentially very dangerous to run others' slides with this switch!")
parser.add_argument("-E",action="store_true",dest="execute_read",default=False,
help="Execute commands in $> tags at file read time. WARNING: Potentially very dangerous to run others' slides with this switch!")
parser.add_argument("-m",action="store_true",dest="autocolor",default=False,
help="Color by markdown structure.")
parser.add_argument("--no-color","-n",action="store_false",dest="color",default=True,
help="Disable color.")
parser.add_argument("-s",action="store_false",dest="menu",default=True,
help="Disable status bar.")
parser.add_argument("--timer",action="store",dest="slideTimer",default=False, type=int,
help="Timer for slideshow. If set, starts automatic slide changing.")
parser.add_argument("-w",action="store_false",dest="wrap",default=True,
help="Disable line wrapping. Cuts long lines.")
parser.add_argument("-e",action="store_true",dest="execute",default=False,
help="Execute commands in $! or $> tags at show time with Enter key. WARNING: Potentially very dangerous to run others' slides with this switch!")
parser.add_argument("-E",action="store_true",dest="execute_read",default=False,
help="Execute commands in $> tags at file read time. WARNING: Potentially very dangerous to run others' slides with this switch!")
parser.add_argument("--toc",action="store",dest="toc",default=False,
const="Table of Contents", type=str, nargs='?',
help="Insert table of contents. Define the header, or use default: %(const)s")
@@ -276,6 +283,7 @@ Keyboard shortcuts:
parser.add_argument("filename",type=str,
help="File to show")
opts=parser.parse_args()
opts.slideShow=not not opts.slideTimer
return opts
def page_print(reader,opts,offset):
@@ -315,10 +323,11 @@ def page_print(reader,opts,offset):
def menu_print(reader,opts):
bc.posprint( opts.size[0], 0,
colorify("${y}%d${Z}/%d %s|"%(
colorify("${y}%d${Z}/%d %s|%s"%(
1+reader.get_page_no(),
reader.get_pages(),
reader.get_filename()),
reader.get_filename(),
"slideshow" if opts.slideShow else ""),
opts))
def print_help(reader,opts):
@@ -326,7 +335,7 @@ def print_help(reader,opts):
helptext=get_interactive_help_text().split('\n')
maxlen=max([len(x) for x in helptext])
bc.posprint(3,6,"+"+"-"*maxlen+"+")
bc.posprint(4,6,("|{:^"+str(maxlen)+"}|").format("Help"))
bc.posprint(4,6,colorify("|${U}${Y}"+("{:^"+str(maxlen)+"}").format("Help")+"${Z}|",opts))
for y,row in enumerate(helptext):
bc.posprint(5+y,6,("|{:<"+str(maxlen)+"}|").format(row))
bc.posprint(6+y,6,"+"+"-"*maxlen+"+")
@@ -340,6 +349,16 @@ def offset_change(opts,reader,offset,new_offset):
offseth=min(reader.get_page_height(),new_offset[1])
return [max(0,o) for o in (offsety,offseth)]
def timeouthandler(sig,frame):
#~ print(sig,frame)
raise IOError("Input timeout")
def getkeypress():
try:
return ord(getch.get())
except:
return False
def browser(opts,filename):
''' Main function for printing '''
@@ -359,7 +378,15 @@ def browser(opts,filename):
menu_print(reader,opts)
sys.stdout.write(bc.pos(opts.size[0], opts.size[1]))
while 1:
inkey=ord(getch.get())
if opts.slideTimer and opts.slideShow:
signal.signal(signal.SIGALRM, timeouthandler)
signal.alarm(opts.slideTimer)
inkey=getkeypress()
signal.alarm(0)
if not inkey and opts.slideShow:
reader.inc_page_no(1,True)
offset=(0,0)
break
#~ print(inkey)
if inkey in [113,3,120]:
#print('Exited in: ')
@@ -380,6 +407,8 @@ def browser(opts,filename):
print_help(reader,opts)
if inkey==ord('s'):
opts.menu=not opts.menu
if inkey==ord('t'):
opts.slideShow=not opts.slideShow
if inkey==ord('r'):
reader.read()
offset=offset_change(opts,reader,offset,(0, 0))