aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2019-11-13 10:43:15 +0000
committerGravatar jesopo2019-11-13 10:43:15 +0000
commit5d2dd9178fb8ac3128ecf0779efda47fc32b74ae (patch)
tree22d0d51aa774fafd7854d1a8b3d6638f56537198
parentchange formatted NOTICEs to be denoted by "-nick-" (PRIVMSG as "<nick>") (diff)
signature
only set color_finished=True when is_background, otherwise next char sets it
-rw-r--r--src/utils/irc.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/utils/irc.py b/src/utils/irc.py
index 719d55b8..838d9d35 100644
--- a/src/utils/irc.py
+++ b/src/utils/irc.py
@@ -69,8 +69,8 @@ FORMAT_STRIP = [
]
def _format_tokens(s: str) -> typing.List[str]:
is_color = False
- foreground = ""
- background = ""
+ foreground = []
+ background = []
is_background = False
matches = [] # type: typing.List[str]
@@ -79,25 +79,24 @@ def _format_tokens(s: str) -> typing.List[str]:
if is_color:
current_color = background if is_background else foreground
color_finished = True
- if char.isdigit() and len(current_color) < 2:
- if is_background:
- background += char
- else:
- foreground += char
- color_finished = (len(current_color)+1) == 2
- elif char == "," and not is_background:
+
+ if char == "," and not is_background:
is_background = True
color_finished = False
+ elif char.isdigit() and len(current_color) < 2:
+ current_color.append(char)
+ color_finished = len(current_color) == 2 and is_background
+
if color_finished or last_char:
- color = foreground
+ color = "".join(foreground)
if background:
- color += ","+background
+ color += "".join([","]+background)
matches.append("\x03%s" % color)
is_color = False
- foreground = ""
- background = ""
+ foreground = []
+ background = []
is_background = False
if char == consts.COLOR: