Ran black on text2html file for PEP8 cleanup

This commit is contained in:
Griatch 2022-06-04 13:14:37 +02:00
parent 5df72530c6
commit cd503cd9fd

View file

@ -51,7 +51,7 @@ class TextToHTMLparser(object):
ANSI_WHITE, ANSI_WHITE,
] ]
xterm_fg_codes = [ XTERM256_FG.format(i + 16) for i in range(240) ] xterm_fg_codes = [XTERM256_FG.format(i + 16) for i in range(240)]
ansi_bg_codes = [ ansi_bg_codes = [
# Background colors # Background colors
@ -65,13 +65,23 @@ class TextToHTMLparser(object):
ANSI_BACK_WHITE, ANSI_BACK_WHITE,
] ]
xterm_bg_codes = [ XTERM256_BG.format(i + 16) for i in range(240) ] xterm_bg_codes = [XTERM256_BG.format(i + 16) for i in range(240)]
re_style = re.compile(r"({})".format('|'.join(style_codes + ansi_color_codes + xterm_fg_codes + ansi_bg_codes + xterm_bg_codes).replace("[",r"\["))) re_style = re.compile(
r"({})".format(
"|".join(
style_codes + ansi_color_codes + xterm_fg_codes + ansi_bg_codes + xterm_bg_codes
).replace("[", r"\[")
)
)
colorlist = [ ANSI_UNHILITE + code for code in ansi_color_codes ] + [ ANSI_HILITE + code for code in ansi_color_codes ] + xterm_fg_codes colorlist = (
[ANSI_UNHILITE + code for code in ansi_color_codes]
+ [ANSI_HILITE + code for code in ansi_color_codes]
+ xterm_fg_codes
)
bglist = ansi_bg_codes + [ ANSI_HILITE + code for code in ansi_bg_codes ] + xterm_bg_codes bglist = ansi_bg_codes + [ANSI_HILITE + code for code in ansi_bg_codes] + xterm_bg_codes
re_string = re.compile( re_string = re.compile(
r"(?P<htmlchars>[<&>])|(?P<tab>[\t]+)|(?P<lineend>\r\n|\r|\n)", r"(?P<htmlchars>[<&>])|(?P<tab>[\t]+)|(?P<lineend>\r\n|\r|\n)",
@ -264,7 +274,10 @@ class TextToHTMLparser(object):
inverse = True inverse = True
# blink codes # blink codes
if substr in (ANSI_BLINK, ANSI_BLINK_HILITE, ANSI_INV_BLINK_HILITE) and "blink" not in classes: if (
substr in (ANSI_BLINK, ANSI_BLINK_HILITE, ANSI_INV_BLINK_HILITE)
and "blink" not in classes
):
classes.append("blink") classes.append("blink")
# underline # underline
@ -273,7 +286,7 @@ class TextToHTMLparser(object):
else: else:
# normal text, add text back to list # normal text, add text back to list
if not str_list[i-1]: if not str_list[i - 1]:
# prior entry was cleared, which means style change # prior entry was cleared, which means style change
# get indices for the fg and bg codes # get indices for the fg and bg codes
bg_index = self.bglist.index(bg) bg_index = self.bglist.index(bg)
@ -285,12 +298,12 @@ class TextToHTMLparser(object):
if inverse: if inverse:
# inverse means swap fg and bg indices # inverse means swap fg and bg indices
bg_class = "bgcolor-{}".format(str(color_index).rjust(3,"0")) bg_class = "bgcolor-{}".format(str(color_index).rjust(3, "0"))
color_class = "color-{}".format(str(bg_index).rjust(3,"0")) color_class = "color-{}".format(str(bg_index).rjust(3, "0"))
else: else:
# use fg and bg indices for classes # use fg and bg indices for classes
bg_class = "bgcolor-{}".format(str(bg_index).rjust(3,"0")) bg_class = "bgcolor-{}".format(str(bg_index).rjust(3, "0"))
color_class = "color-{}".format(str(color_index).rjust(3,"0")) color_class = "color-{}".format(str(color_index).rjust(3, "0"))
# black bg is the default, don't explicitly style # black bg is the default, don't explicitly style
if bg_class != "bgcolor-000": if bg_class != "bgcolor-000":
@ -302,9 +315,9 @@ class TextToHTMLparser(object):
prefix = '<span class="{}">'.format(" ".join(classes)) prefix = '<span class="{}">'.format(" ".join(classes))
# close any prior span # close any prior span
if not clean: if not clean:
prefix = '</span>' + prefix prefix = "</span>" + prefix
# add span to output # add span to output
str_list[i-1] = prefix str_list[i - 1] = prefix
# clean out color classes to easily update next time # clean out color classes to easily update next time
classes = [cls for cls in classes if "color" not in cls] classes = [cls for cls in classes if "color" not in cls]
@ -317,7 +330,6 @@ class TextToHTMLparser(object):
# recombine back into string # recombine back into string
return "".join(str_list) return "".join(str_list)
def parse(self, text, strip_ansi=False): def parse(self, text, strip_ansi=False):
""" """
Main access function, converts a text containing ANSI codes Main access function, converts a text containing ANSI codes