working center, screenshots, and new background support
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
'''Markslider: a slideshow engine based on markdown.'''
|
||||
|
||||
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
||||
__version__ = "1.0"
|
||||
__version__ = "1.1"
|
||||
|
||||
import sys,os,argparse,re,datetime
|
||||
from argparse import ArgumentParser
|
||||
@@ -66,12 +66,14 @@ class slide_reader:
|
||||
self.re_command = re.compile("(.*)`(.*)`>(.*)")
|
||||
#~ 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.background = []
|
||||
self.read()
|
||||
|
||||
def read(self):
|
||||
''' Read a file, set pages and data '''
|
||||
|
||||
self.pages = 0
|
||||
self.background = []
|
||||
self.data = []
|
||||
self.file_start_page = []
|
||||
first_slide_found = False
|
||||
@@ -94,6 +96,7 @@ class slide_reader:
|
||||
new_page=[]
|
||||
# if first slide havent been found yet:
|
||||
if not first_slide_found:
|
||||
self.background.append(row)
|
||||
continue
|
||||
new_page.extend(self.generate_content(row))
|
||||
if len(new_page)>0:
|
||||
@@ -295,6 +298,8 @@ Keyboard shortcuts:
|
||||
execution = parser.add_argument_group('execution')
|
||||
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,
|
||||
help="Center slides on screen.")
|
||||
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.")
|
||||
content.add_argument("-w",action="store_false",dest="wrap",default=True,
|
||||
help="Disable line wrapping. Cuts long lines.")
|
||||
|
||||
content.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")
|
||||
@@ -345,9 +351,9 @@ def page_print(reader,opts,offset):
|
||||
bc.clear()
|
||||
if opts.center: # Placeholder for 80x25 center alignment
|
||||
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_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)
|
||||
else:
|
||||
align_pad = ""
|
||||
@@ -363,6 +369,13 @@ def page_print(reader,opts,offset):
|
||||
opts) +
|
||||
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)):
|
||||
# python2 magic
|
||||
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):
|
||||
os.mkdir(opts.screenshots)
|
||||
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,
|
||||
stderr = subprocess.PIPE,
|
||||
shell = True
|
||||
@@ -732,7 +748,20 @@ def main():
|
||||
bc = ansi.code()
|
||||
getch = getch()
|
||||
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(
|
||||
opts,
|
||||
opts.files
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user