Support ANSI underline

This commit is contained in:
jesopo 2018-11-30 16:30:47 +00:00
parent af0fddf9ba
commit 4dfb2ffeaa
2 changed files with 15 additions and 5 deletions

View file

@ -49,3 +49,5 @@ ANSI_FOREGROUND_RESET = "\033[39m"
ANSI_BACKGROUND_RESET = "\033[49m"
ANSI_BOLD = "\033[1m"
ANSI_BOLD_RESET = "\033[22m"
ANSI_UNDERLINE = "\033[4m"
ANSI_UNDERLINE_RESET = "\033[24m"

View file

@ -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)