added formatting
This commit is contained in:
@@ -89,15 +89,15 @@ class code:
|
||||
custom_match = re.compile(r"(\${)([0-9;]*[ABCDEFGHJKSTfminsu]+)(})")
|
||||
|
||||
def pos(self, y, x):
|
||||
""" Go to absolute position """
|
||||
"""Go to absolute position"""
|
||||
return "\033[" + str(y) + ";" + str(x) + "H"
|
||||
|
||||
def column(self, x):
|
||||
""" Go to absolute column """
|
||||
"""Go to absolute column"""
|
||||
return "\033[" + str(x) + "G"
|
||||
|
||||
def posprint(self, y, x, s):
|
||||
""" Print string at a location """
|
||||
"""Print string at a location"""
|
||||
sys.stdout.write(self.pos(y, x) + str(s))
|
||||
self.flush()
|
||||
|
||||
@@ -129,11 +129,11 @@ class code:
|
||||
sys.stdout.write("\033[" + str(n) + "E")
|
||||
|
||||
def save(self):
|
||||
""" Save cursor position """
|
||||
"""Save cursor position"""
|
||||
sys.stdout.write("\033[s")
|
||||
|
||||
def restore(self):
|
||||
""" Restore cursor position """
|
||||
"""Restore cursor position"""
|
||||
sys.stdout.write("\033[u")
|
||||
|
||||
def color_string(self, s):
|
||||
@@ -160,7 +160,7 @@ class code:
|
||||
|
||||
|
||||
def demo():
|
||||
""" Print all control sequences """
|
||||
"""Print all control sequences"""
|
||||
c = code()
|
||||
unformatted = """${S}ANSI CODES
|
||||
==========${Z}
|
||||
|
||||
@@ -28,6 +28,7 @@ import traceback, tty, termios, subprocess, signal
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
||||
import ansicodes, md_color
|
||||
|
||||
try:
|
||||
import climage
|
||||
except ImportError:
|
||||
@@ -50,13 +51,13 @@ class getch:
|
||||
|
||||
|
||||
class EndProgram(Exception):
|
||||
""" Nice exit """
|
||||
"""Nice exit"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class slide_reader:
|
||||
""" Class for reading files. """
|
||||
"""Class for reading files."""
|
||||
|
||||
def __init__(self, files, opts):
|
||||
self.filename = files[0]
|
||||
@@ -86,7 +87,7 @@ class slide_reader:
|
||||
self.pygments = False
|
||||
|
||||
def read(self):
|
||||
""" Read a file, set pages and data """
|
||||
"""Read a file, set pages and data"""
|
||||
|
||||
self.pages = 0
|
||||
self.background = []
|
||||
@@ -234,7 +235,7 @@ class slide_reader:
|
||||
self.file_start_page = [1 + i for i in self.file_start_page]
|
||||
|
||||
def generate_content(self, s):
|
||||
""" Check for launchable items, or converted images """
|
||||
"""Check for launchable items, or converted images"""
|
||||
if self.opts.execute_read:
|
||||
if s.find("`>") > -1:
|
||||
command = self.re_command.match(s)
|
||||
@@ -278,7 +279,13 @@ class slide_reader:
|
||||
width = max(5, self.scrsize[1] - 10)
|
||||
output = climage.convert(
|
||||
image.group(3),
|
||||
is_unicode=True, is_truecolor=True, is_256color=False, is_16color=False, is_8color=False, width=width, palette="default"
|
||||
is_unicode=True,
|
||||
is_truecolor=True,
|
||||
is_256color=False,
|
||||
is_16color=False,
|
||||
is_8color=False,
|
||||
width=width,
|
||||
palette="default",
|
||||
)
|
||||
output = output.split("\n")
|
||||
while len(output[0].strip()) == 0:
|
||||
@@ -375,7 +382,7 @@ def get_interactive_help_text():
|
||||
|
||||
|
||||
def setup_options():
|
||||
""" Create command line options """
|
||||
"""Create command line options"""
|
||||
usage = (
|
||||
"""
|
||||
MarkSlider: a markdown based slideshow engine
|
||||
@@ -563,7 +570,7 @@ Keyboard shortcuts:
|
||||
|
||||
|
||||
def page_print(reader, opts, offset):
|
||||
""" Print a page """
|
||||
"""Print a page"""
|
||||
|
||||
page = reader.get_current_page()
|
||||
scrsize = opts.size
|
||||
@@ -678,7 +685,7 @@ def print_time(opts):
|
||||
|
||||
|
||||
def print_help(reader, opts):
|
||||
""" Create a window with help message """
|
||||
"""Create a window with help message"""
|
||||
helptext = get_interactive_help_text().split("\n")
|
||||
maxlen = max([len(x) for x in helptext])
|
||||
bc.posprint(3, 5, " +" + "-" * maxlen + "+ ")
|
||||
@@ -697,7 +704,7 @@ def print_help(reader, opts):
|
||||
|
||||
|
||||
def print_toc(reader, opts):
|
||||
""" Create a window with TOC """
|
||||
"""Create a window with TOC"""
|
||||
text = reader.get_toc(display_position=True)
|
||||
title = opts.toc if opts.toc else "Table of Contents"
|
||||
maxlen = max([len(x) for x in text])
|
||||
@@ -720,7 +727,7 @@ def print_toc(reader, opts):
|
||||
|
||||
|
||||
def offset_change(opts, reader, offset, new_offset):
|
||||
""" Change the display position of page """
|
||||
"""Change the display position of page"""
|
||||
new_offset = (offset[0] + new_offset[0], offset[1] + new_offset[1])
|
||||
offsety = min(reader.get_page_height() - 1, new_offset[0])
|
||||
offseth = min(reader.get_page_height(), new_offset[1])
|
||||
@@ -740,7 +747,7 @@ def getkeypress():
|
||||
|
||||
|
||||
def browser(opts, files):
|
||||
""" Main function for printing """
|
||||
"""Main function for printing"""
|
||||
|
||||
try:
|
||||
reader = slide_reader(files, opts)
|
||||
@@ -846,7 +853,7 @@ def get_console_size():
|
||||
|
||||
|
||||
def colorify(s, opts):
|
||||
""" Add colors to string """
|
||||
"""Add colors to string"""
|
||||
if not opts.color:
|
||||
return bc.nocolor_string(s)
|
||||
c = bc.color_string(s) # +bc.Z
|
||||
@@ -854,14 +861,14 @@ def colorify(s, opts):
|
||||
|
||||
|
||||
def cut_line(s, i):
|
||||
""" cut a color tagged string, and remove control chars """
|
||||
"""cut a color tagged string, and remove control chars"""
|
||||
s = s[:i]
|
||||
s = re.sub("\$$", "", re.sub("\$\{$", "", re.sub("\$\{.$", "", s)))
|
||||
return s
|
||||
|
||||
|
||||
def add_highlight(s, opts):
|
||||
""" Add cursor position highlight """
|
||||
"""Add cursor position highlight"""
|
||||
if len(s.strip()) == 0:
|
||||
cleaned = HL
|
||||
else:
|
||||
|
||||
@@ -157,7 +157,7 @@ def colorize(data, remove_colors=False, dark_colors=False, debug=False):
|
||||
|
||||
|
||||
def md_re_compile(d):
|
||||
""" Returns a re.compiled dict """
|
||||
"""Returns a re.compiled dict"""
|
||||
n = {}
|
||||
for t in d:
|
||||
n[t] = {}
|
||||
|
||||
Reference in New Issue
Block a user