From 4dfb2ffeaa6a0755d81937a2092c9b1cdf1df5e1 Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 30 Nov 2018 16:30:47 +0000 Subject: [PATCH] Support ANSI underline --- src/utils/consts.py | 10 ++++++---- src/utils/irc.py | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/utils/consts.py b/src/utils/consts.py index 221c327b..cfb09243 100644 --- a/src/utils/consts.py +++ b/src/utils/consts.py @@ -43,9 +43,11 @@ INVERT = "\x16" COLOR = "\x03" RESET = "\x0F" -ANSI_FORMAT = "\033[%sm" -ANSI_RESET = "\033[0m" +ANSI_FORMAT = "\033[%sm" +ANSI_RESET = "\033[0m" ANSI_FOREGROUND_RESET = "\033[39m" ANSI_BACKGROUND_RESET = "\033[49m" -ANSI_BOLD = "\033[1m" -ANSI_BOLD_RESET = "\033[22m" +ANSI_BOLD = "\033[1m" +ANSI_BOLD_RESET = "\033[22m" +ANSI_UNDERLINE = "\033[4m" +ANSI_UNDERLINE_RESET = "\033[24m" diff --git a/src/utils/irc.py b/src/utils/irc.py index d8609bf9..fa2f44d7 100644 --- a/src/utils/irc.py +++ b/src/utils/irc.py @@ -146,7 +146,8 @@ def strip_font(s: str) -> str: FORMAT_TOKENS = [ utils.consts.BOLD, - utils.consts.RESET + utils.consts.RESET, + utils.consts.UNDERLINE ] def _color_tokens(s: str) -> typing.List[str]: is_color = False @@ -205,6 +206,7 @@ def to_ansi_colors(s: str) -> str: has_foreground = False has_background = False bold = False + uderline = False for token in _color_tokens(s): replace = "" @@ -238,6 +240,12 @@ def to_ansi_colors(s: str) -> str: bold = not bold elif type == utils.consts.RESET: replace += utils.consts.ANSI_RESET + elif type == utils.consts.UNDERLINE: + if underline: + replace += utils.consts.ANSI_UNDERLINE_RESET + else: + replace += utils.consts.ANSI_UNDERLINE + underline = not underline s = s.replace(token, replace, 1)