working center, screenshots, and new background support

This commit is contained in:
2018-10-02 13:20:57 +03:00
parent 3fc741b090
commit 4ea19e9942
2 changed files with 36 additions and 7 deletions

View File

@@ -20,7 +20,7 @@
'''Markslider: a slideshow engine based on markdown.''' '''Markslider: a slideshow engine based on markdown.'''
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>" __author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
__version__ = "1.0" __version__ = "1.1"
import sys,os,argparse,re,datetime import sys,os,argparse,re,datetime
from argparse import ArgumentParser from argparse import ArgumentParser
@@ -66,12 +66,14 @@ class slide_reader:
self.re_command = re.compile("(.*)`(.*)`>(.*)") self.re_command = re.compile("(.*)`(.*)`>(.*)")
#~ self.control_chars = ''.join(map(unichr, range(0,32) + range(127,160))) #~ self.control_chars = ''.join(map(unichr, range(0,32) + range(127,160)))
#~ self.control_char_re = re.compile('[%s]' % re.escape(self.control_chars)) #~ self.control_char_re = re.compile('[%s]' % re.escape(self.control_chars))
self.background = []
self.read() self.read()
def read(self): def read(self):
''' Read a file, set pages and data ''' ''' Read a file, set pages and data '''
self.pages = 0 self.pages = 0
self.background = []
self.data = [] self.data = []
self.file_start_page = [] self.file_start_page = []
first_slide_found = False first_slide_found = False
@@ -94,6 +96,7 @@ class slide_reader:
new_page=[] new_page=[]
# if first slide havent been found yet: # if first slide havent been found yet:
if not first_slide_found: if not first_slide_found:
self.background.append(row)
continue continue
new_page.extend(self.generate_content(row)) new_page.extend(self.generate_content(row))
if len(new_page)>0: if len(new_page)>0:
@@ -295,6 +298,8 @@ Keyboard shortcuts:
execution = parser.add_argument_group('execution') execution = parser.add_argument_group('execution')
control = parser.add_argument_group('controls') control = parser.add_argument_group('controls')
content.add_argument("--background",action="store_true",dest="background",default = False,
help="Use the rows before the first # header as slide background")
content.add_argument("--center",action="store_true",dest="center",default=False, content.add_argument("--center",action="store_true",dest="center",default=False,
help="Center slides on screen.") help="Center slides on screen.")
content.add_argument("--dc",action="store_true",dest="dark_colors",default=False, content.add_argument("--dc",action="store_true",dest="dark_colors",default=False,
@@ -318,6 +323,7 @@ Keyboard shortcuts:
help="Timer for slideshow. If set, starts automatic slide changing.") help="Timer for slideshow. If set, starts automatic slide changing.")
content.add_argument("-w",action="store_false",dest="wrap",default=True, content.add_argument("-w",action="store_false",dest="wrap",default=True,
help="Disable line wrapping. Cuts long lines.") help="Disable line wrapping. Cuts long lines.")
content.add_argument("--toc",action="store",dest="toc",default=False, content.add_argument("--toc",action="store",dest="toc",default=False,
const="Table of Contents", type=str, nargs='?', const="Table of Contents", type=str, nargs='?',
help="Insert table of contents. Define the header, or use default: %(const)s") help="Insert table of contents. Define the header, or use default: %(const)s")
@@ -345,9 +351,9 @@ def page_print(reader,opts,offset):
bc.clear() bc.clear()
if opts.center: # Placeholder for 80x25 center alignment if opts.center: # Placeholder for 80x25 center alignment
align_width = reader.get_max_width() align_width = reader.get_max_width()
align_x_offset = scrsize[1]/2-align_width/2 align_x_offset = int(scrsize[1]/2 - align_width/2)
align_pad = " " * align_x_offset align_pad = " " * align_x_offset
align_y_offset = scrsize[0]/2 - reader.get_max_height()/2 align_y_offset = int(scrsize[0]/2 - reader.get_max_height()/2)
bc.down_line(align_y_offset) bc.down_line(align_y_offset)
else: else:
align_pad = "" align_pad = ""
@@ -363,6 +369,13 @@ def page_print(reader,opts,offset):
opts) + opts) +
bc.Z bc.Z
) )
if opts.background:
bc.save()
if opts.color:
sys.stdout.write("\n".join([align_pad + bc.color_string(x) for x in reader.background]))
else:
sys.stdout.write("\n".join([align_pad + bc.nocolor_string(x) for x in reader.background]))
bc.restore()
if (sys.version_info < (3, 0)): if (sys.version_info < (3, 0)):
# python2 magic # python2 magic
page = [row.decode('utf-8') for row in page] page = [row.decode('utf-8') for row in page]
@@ -713,7 +726,10 @@ def take_screenshot(reader,opts):
if not os.path.exists(opts.screenshots): if not os.path.exists(opts.screenshots):
os.mkdir(opts.screenshots) os.mkdir(opts.screenshots)
subprocess.call( subprocess.call(
"sleep 0.5; import -window $WINDOWID '%s'"%(out_file,), "sleep 0.5; import -window %s '%s'"%(
opts.xwinid,
out_file
),
stdout = subprocess.PIPE, stdout = subprocess.PIPE,
stderr = subprocess.PIPE, stderr = subprocess.PIPE,
shell = True shell = True
@@ -732,7 +748,20 @@ def main():
bc = ansi.code() bc = ansi.code()
getch = getch() getch = getch()
opts = setup_options() opts = setup_options()
if opts.screenshots:
print("Click the terminal window to read window ID")
xwininfo = subprocess.check_output(
"xwininfo",
shell = True
)
if type(xwininfo) == bytes:
xwininfo = xwininfo.decode('utf-8')
xwininfo = re.search(r"Window id: (0x[0-9]+)", xwininfo)
if xwininfo:
opts.xwinid = xwininfo.group(1)
else:
print("Cannot parse window ID")
sys.exit(1)
browser( browser(
opts, opts,
opts.files opts.files

Binary file not shown.