Fixed color display of xterm256 with the xterm256 support turned off.
This commit is contained in:
parent
42b9ac40f3
commit
5f0ba55ce1
2 changed files with 10 additions and 9 deletions
|
|
@ -580,8 +580,8 @@ class CmdColorTest(MuxPlayerCommand):
|
||||||
ap = ansi.ANSI_PARSER
|
ap = ansi.ANSI_PARSER
|
||||||
# ansi colors
|
# ansi colors
|
||||||
# show all ansi color-related codes
|
# show all ansi color-related codes
|
||||||
col1 = ["%s%s|n" % (code, code.replace("|", "||")) for code, _ in ap.ext_ansi_map[6:14]]
|
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[14:22]]
|
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:]]
|
col3 = ["%s%s|n" % (code.replace("\\",""), code.replace("|", "||").replace("\\", "")) for code, _ in ap.ext_ansi_map[-8:]]
|
||||||
col2.extend(["" for i in range(len(col1)-len(col2))])
|
col2.extend(["" for i in range(len(col1)-len(col2))])
|
||||||
table = utils.format_table([col1, col2, col3])
|
table = utils.format_table([col1, col2, col3])
|
||||||
|
|
@ -601,8 +601,8 @@ class CmdColorTest(MuxPlayerCommand):
|
||||||
# foreground table
|
# foreground table
|
||||||
table[ir].append("|%i%i%i%s|n" % (ir, ig, ib, "||%i%i%i" % (ir, ig, ib)))
|
table[ir].append("|%i%i%i%s|n" % (ir, ig, ib, "||%i%i%i" % (ir, ig, ib)))
|
||||||
# background table
|
# background table
|
||||||
table[6+ir].append("|[%i%i%i|%i%i%i%s|n" % (ir, ig, ib,
|
table[6+ir].append("|%i%i%i|[%i%i%i%s|n" % (5 - ir, 5 - ig, 5 - ib,
|
||||||
5 - ir, 5 - ig, 5 - ib,
|
ir, ig, ib,
|
||||||
"||[%i%i%i" % (ir, ig, ib)))
|
"||[%i%i%i" % (ir, ig, ib)))
|
||||||
table = self.table_format(table)
|
table = self.table_format(table)
|
||||||
string = "Xterm256 colors (if not all hues show, your client might not report that it can handle xterm256):"
|
string = "Xterm256 colors (if not all hues show, your client might not report that it can handle xterm256):"
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class ANSIParser(object):
|
||||||
"""
|
"""
|
||||||
return self.ansi_bright_bgs.get(ansimatch.group(), "")
|
return self.ansi_bright_bgs.get(ansimatch.group(), "")
|
||||||
|
|
||||||
def sub_xterm256(self, rgbmatch, convert=False):
|
def sub_xterm256(self, rgbmatch, use_xterm256=False):
|
||||||
"""
|
"""
|
||||||
This is a replacer method called by `re.sub` with the matched
|
This is a replacer method called by `re.sub` with the matched
|
||||||
tag. It must return the correct ansi sequence.
|
tag. It must return the correct ansi sequence.
|
||||||
|
|
@ -117,7 +117,7 @@ class ANSIParser(object):
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
rgbmatch (re.matchobject): The match.
|
rgbmatch (re.matchobject): The match.
|
||||||
convert (bool, optional): Convert 256-colors to 16.
|
use_xterm256 (bool, optional): Don't convert 256-colors to 16.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
processed (str): The processed match string.
|
processed (str): The processed match string.
|
||||||
|
|
@ -135,19 +135,20 @@ class ANSIParser(object):
|
||||||
else:
|
else:
|
||||||
red, green, blue = int(rgbtag[0]), int(rgbtag[1]), int(rgbtag[2])
|
red, green, blue = int(rgbtag[0]), int(rgbtag[1]), int(rgbtag[2])
|
||||||
|
|
||||||
if convert:
|
if use_xterm256:
|
||||||
colval = 16 + (red * 36) + (green * 6) + blue
|
colval = 16 + (red * 36) + (green * 6) + blue
|
||||||
return "\033[%s8;5;%s%s%sm" % (3 + int(background), colval // 100, (colval % 100) // 10, colval%10)
|
return "\033[%s8;5;%s%s%sm" % (3 + int(background), colval // 100, (colval % 100) // 10, colval%10)
|
||||||
|
#return "\033[%s8;5;%sm" % (3 + int(background), colval)
|
||||||
else:
|
else:
|
||||||
# xterm256 not supported, convert the rgb value to ansi instead
|
# xterm256 not supported, convert the rgb value to ansi instead
|
||||||
if red == green and red == blue and red < 2:
|
if red == green == blue and red < 3:
|
||||||
if background:
|
if background:
|
||||||
return ANSI_BACK_BLACK
|
return ANSI_BACK_BLACK
|
||||||
elif red >= 1:
|
elif red >= 1:
|
||||||
return ANSI_HILITE + ANSI_BLACK
|
return ANSI_HILITE + ANSI_BLACK
|
||||||
else:
|
else:
|
||||||
return ANSI_NORMAL + ANSI_BLACK
|
return ANSI_NORMAL + ANSI_BLACK
|
||||||
elif red == green and red == blue:
|
elif red == green == blue:
|
||||||
if background:
|
if background:
|
||||||
return ANSI_BACK_WHITE
|
return ANSI_BACK_WHITE
|
||||||
elif red >= 4:
|
elif red >= 4:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue