diff options
| author | 2019-01-13 21:56:36 +0000 | |
|---|---|---|
| committer | 2019-01-13 21:56:36 +0000 | |
| commit | 598fcb80b9d4a944b6bf4f63b916c939caca5692 (patch) | |
| tree | b10d25464bce700a5fd90e5c1bfdb5e4375706f5 | |
| parent | don't consume 3 digits for a colour code when the first char is 0 and the second (diff) | |
'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)
| -rw-r--r-- | modules/print_activity.py | 3 | ||||
| -rw-r--r-- | src/utils/irc.py | 13 |
2 files changed, 12 insertions, 4 deletions
diff --git a/modules/print_activity.py b/modules/print_activity.py index 4014ab83..eb2683c2 100644 --- a/modules/print_activity.py +++ b/modules/print_activity.py @@ -9,7 +9,8 @@ class Module(ModuleManager.BaseModule): target = str(event["server"]) if not channel == None: target += channel - self.bot.log.info("%s | %s", [target, utils.irc.to_ansi_colors(line)]) + formatted_line = utils.irc.parse_format(line) + self.bot.log.info("%s | %s", [target, formatted_line]) def _mode_symbols(self, user, channel, server): modes = channel.get_user_status(user) 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) |
