Support ANSI underline
This commit is contained in:
parent
af0fddf9ba
commit
4dfb2ffeaa
2 changed files with 15 additions and 5 deletions
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue