Don't eat numbers after color formatting if they'd end up making the color code
`20` or more
This commit is contained in:
parent
8cd7393d17
commit
6d2c15ed2c
1 changed files with 13 additions and 6 deletions
|
@ -152,28 +152,35 @@ def _color_tokens(s: str) -> typing.List[str]:
|
||||||
is_color = False
|
is_color = False
|
||||||
foreground = ""
|
foreground = ""
|
||||||
background = ""
|
background = ""
|
||||||
|
is_background = False
|
||||||
matches = [] # type: typing.List[str]
|
matches = [] # type: typing.List[str]
|
||||||
|
|
||||||
for char in s:
|
for char in s:
|
||||||
if is_color:
|
if is_color:
|
||||||
if char.isdigit():
|
can_add = True
|
||||||
if background:
|
current_color = background if is_background else foreground
|
||||||
|
if current_color:
|
||||||
|
can_add = int(current_color) == 1
|
||||||
|
|
||||||
|
if char.isdigit() and can_add:
|
||||||
|
if is_background:
|
||||||
background += char
|
background += char
|
||||||
else:
|
else:
|
||||||
foreground += char
|
foreground += char
|
||||||
continue
|
continue
|
||||||
elif char == "," and not background:
|
elif char == "," and not is_background:
|
||||||
background += char
|
is_background = True
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
color = foreground
|
color = foreground
|
||||||
if len(background) > 1:
|
if background:
|
||||||
color += background
|
color += ","+background
|
||||||
|
|
||||||
matches.append("\x03%s" % color)
|
matches.append("\x03%s" % color)
|
||||||
is_color = False
|
is_color = False
|
||||||
foreground = ""
|
foreground = ""
|
||||||
background = ""
|
background = ""
|
||||||
|
is_background = False
|
||||||
|
|
||||||
if char == utils.consts.COLOR:
|
if char == utils.consts.COLOR:
|
||||||
if is_color:
|
if is_color:
|
||||||
|
|
Loading…
Reference in a new issue