aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2018-11-25 13:21:15 +0000
committerGravatar jesopo2018-11-25 13:23:00 +0000
commit6d2c15ed2cbcfc05a31933840ab2e374fc843c4d (patch)
tree0aceb433e5f7f268c326c835d934134ca939a5c3
parentRegression: Don't connnect if a server's 'connect' setting is false (diff)
signature
Don't eat numbers after color formatting if they'd end up making the color code
`20` or more
-rw-r--r--src/utils/irc.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/utils/irc.py b/src/utils/irc.py
index f04abafc..47a425b7 100644
--- a/src/utils/irc.py
+++ b/src/utils/irc.py
@@ -152,28 +152,35 @@ def _color_tokens(s: str) -> typing.List[str]:
is_color = False
foreground = ""
background = ""
+ is_background = False
matches = [] # type: typing.List[str]
for char in s:
if is_color:
- if char.isdigit():
- if background:
+ can_add = True
+ 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
else:
foreground += char
continue
- elif char == "," and not background:
- background += char
+ elif char == "," and not is_background:
+ is_background = True
continue
else:
color = foreground
- if len(background) > 1:
- color += background
+ if background:
+ color += ","+background
matches.append("\x03%s" % color)
is_color = False
foreground = ""
background = ""
+ is_background = False
if char == utils.consts.COLOR:
if is_color: