diff options
| author | 2019-01-13 21:56:36 +0000 | |
|---|---|---|
| committer | 2019-01-13 21:56:36 +0000 | |
| commit | 598fcb80b9d4a944b6bf4f63b916c939caca5692 (patch) | |
| tree | b10d25464bce700a5fd90e5c1bfdb5e4375706f5 /src/utils/irc.py | |
| parent | don't consume 3 digits for a colour code when the first char is 0 and the second (diff) | |
| signature | ||
'to_ansi_colors(' -> 'parse_format(' as it's become a lot more than just colors.
strip \x08 (in case hexchat users paste it) (print_activity.py, src.utils.irc)
Diffstat (limited to 'src/utils/irc.py')
| -rw-r--r-- | src/utils/irc.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/utils/irc.py b/src/utils/irc.py index 1cfe4fcc..57beffb1 100644 --- a/src/utils/irc.py +++ b/src/utils/irc.py @@ -150,7 +150,10 @@ FORMAT_TOKENS = [ utils.consts.RESET, utils.consts.UNDERLINE ] -def _color_tokens(s: str) -> typing.List[str]: +FORMAT_STRIP = [ + "\x08" # backspace +] +def _format_tokens(s: str) -> typing.List[str]: is_color = False foreground = "" background = "" @@ -195,6 +198,8 @@ def _color_tokens(s: str) -> typing.List[str]: is_color = True elif char in FORMAT_TOKENS: matches.append(char) + elif char in FORMAT_STRIP: + matches.append(char) return matches def _color_match(code: typing.Optional[str], foreground: bool) -> str: @@ -206,13 +211,13 @@ def _color_match(code: typing.Optional[str], foreground: bool) -> str: else: return str(color.ansi_background()) -def to_ansi_colors(s: str) -> str: +def parse_format(s: str) -> str: has_foreground = False has_background = False bold = False underline = False - for token in _color_tokens(s): + for token in _format_tokens(s): replace = "" type = token[0] @@ -250,6 +255,8 @@ def to_ansi_colors(s: str) -> str: else: replace += utils.consts.ANSI_UNDERLINE underline = not underline + elif type in FORMAT_STRIP: + replace = "" s = s.replace(token, replace, 1) |
