Fix webclient ANSI background handling. Made bright ANSI backgrounds visible in color command. Resolves #1001.

This commit is contained in:
Griatch 2016-08-28 19:31:19 +02:00
parent 4e9c8aecec
commit 6fbdc88a27
3 changed files with 16 additions and 14 deletions

View file

@ -673,14 +673,16 @@ class CmdColorTest(COMMAND_DEFAULT_CLASS):
col1 = ["%s%s|n" % (code, code.replace("|", "||")) for code, _ in ap.ext_ansi_map[48:56]]
col2 = ["%s%s|n" % (code, code.replace("|", "||")) for code, _ in ap.ext_ansi_map[56:64]]
col3 = ["%s%s|n" % (code.replace("\\",""), code.replace("|", "||").replace("\\", "")) for code, _ in ap.ext_ansi_map[-8:]]
col4 = ["%s%s|n" % (code.replace("\\",""), code.replace("|", "||").replace("\\", "")) for code, _ in ap.ansi_bright_bgs[-8:]]
col2.extend(["" for i in range(len(col1)-len(col2))])
table = utils.format_table([col1, col2, col3])
table = utils.format_table([col1, col2, col4, col3])
string = "ANSI colors:"
for row in table:
string += "\n " + " ".join(row)
self.msg(string)
self.msg("||X : black. ||/ : return, ||- : tab, ||_ : space, ||* : invert, ||u : underline")
self.msg("To combine background and foreground, add background marker last, e.g. ||r||[B.")
self.msg("||X : black. ||/ : return, ||- : tab, ||_ : space, ||* : invert, ||u : underline\n"
"To combine background and foreground, add background marker last, e.g. ||r||[B.\n"
"Note: bright backgrounds like ||[r requires your client handling Xterm256 colors.")
elif self.args.startswith("x"):
# show xterm256 table

View file

@ -105,7 +105,7 @@ class ANSIParser(object):
processed (str): The processed match string.
"""
return self.ansi_bright_bgs.get(ansimatch.group(), "")
return self.ansi_bright_bgs_map.get(ansimatch.group(), "")
def sub_xterm256(self, rgbmatch, use_xterm256=False):
"""
@ -440,14 +440,14 @@ class ANSIParser(object):
mxp_re = r'\|lc(.*?)\|lt(.*?)\|le'
# prepare regex matching
brightbg_sub = re.compile(r"|".join([re.escape(tup[0]) for tup in ansi_bright_bgs]), re.DOTALL)
brightbg_sub = re.compile(r"|".join([r"(?<!\|)%s" % re.escape(tup[0]) for tup in ansi_bright_bgs]), re.DOTALL)
xterm256_sub = re.compile(r"|".join([tup[0] for tup in xterm256_map]), re.DOTALL)
ansi_sub = re.compile(r"|".join([re.escape(tup[0]) for tup in ext_ansi_map]), re.DOTALL)
mxp_sub = re.compile(mxp_re, re.DOTALL)
# used by regex replacer to correctly map ansi sequences
ansi_map = dict(ext_ansi_map)
ansi_bright_bgs = dict(ansi_bright_bgs)
ansi_bright_bgs_map = dict(ansi_bright_bgs)
# prepare matching ansi codes overall
ansi_re = r"\033\[[0-9;]+m"

View file

@ -55,14 +55,14 @@ class TextToHTMLparser(object):
] + [("color-%03i" % (i+16), XTERM256_FG % ("%i" % (i+16))) for i in xrange(240)]
colorback = [
('bgcolor-000', unhilite + ANSI_BACK_BLACK), # pure black
('bgcolor-001', unhilite + ANSI_BACK_RED),
('bgcolor-002', unhilite + ANSI_BACK_GREEN),
('bgcolor-003', unhilite + ANSI_BACK_YELLOW),
('bgcolor-004', unhilite + ANSI_BACK_BLUE),
('bgcolor-005', unhilite + ANSI_BACK_MAGENTA),
('bgcolor-006', unhilite + ANSI_BACK_CYAN),
('bgcolor-007', unhilite + ANSI_BACK_WHITE), # light grey
('bgcolor-000', ANSI_BACK_BLACK), # pure black
('bgcolor-001', ANSI_BACK_RED),
('bgcolor-002', ANSI_BACK_GREEN),
('bgcolor-003', ANSI_BACK_YELLOW),
('bgcolor-004', ANSI_BACK_BLUE),
('bgcolor-005', ANSI_BACK_MAGENTA),
('bgcolor-006', ANSI_BACK_CYAN),
('bgcolor-007', ANSI_BACK_WHITE), # light grey
('bgcolor-008', hilite + ANSI_BACK_BLACK), # dark grey
('bgcolor-009', hilite + ANSI_BACK_RED),
('bgcolor-010', hilite + ANSI_BACK_GREEN),