diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-26 17:44:25 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-06-26 17:44:25 -0400 |
commit | 2f9aab59acbbfc177a924afe7601b9021a4b1399 (patch) | |
tree | 11f2fde6c1e9d74956d6f287dcf221649d5233f1 /cmd2/ansi.py | |
parent | 92f8e3d616c836748638a19ad954c7e050059f21 (diff) | |
download | cmd2-git-2f9aab59acbbfc177a924afe7601b9021a4b1399.tar.gz |
Renamed colors setting to allow_ansi
Diffstat (limited to 'cmd2/ansi.py')
-rw-r--r-- | cmd2/ansi.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/cmd2/ansi.py b/cmd2/ansi.py index 8980b1d4..7ae9016e 100644 --- a/cmd2/ansi.py +++ b/cmd2/ansi.py @@ -1,5 +1,5 @@ # coding=utf-8 -"""Support for ANSI escape codes which are used for things like applying style to text""" +"""Support for ANSI escape sequences which are used for things like applying style to text""" import functools import re from typing import Any @@ -8,7 +8,7 @@ import colorama from colorama import Fore, Back, Style from wcwidth import wcswidth -# Regular expression to match ANSI escape codes +# Regular expression to match ANSI escape sequences ANSI_ESCAPE_RE = re.compile(r'\x1b[^m]*m') # Foreground color presets @@ -55,10 +55,10 @@ BG_COLORS = { def strip_ansi(text: str) -> str: - """Strip ANSI escape codes from a string. + """Strip ANSI escape sequences from a string. - :param text: string which may contain ANSI escape codes - :return: the same string with any ANSI escape codes removed + :param text: string which may contain ANSI escape sequences + :return: the same string with any ANSI escape sequences removed """ return ANSI_ESCAPE_RE.sub('', text) @@ -69,11 +69,11 @@ def ansi_safe_wcswidth(text: str) -> int: :param text: the string being measured """ - # Strip ANSI escape codes since they cause wcswidth to return -1 + # Strip ANSI escape sequences since they cause wcswidth to return -1 return wcswidth(strip_ansi(text)) -# ANSI escape strings not provided by colorama +# ANSI escape sequences not provided by colorama UNDERLINE_ENABLE = colorama.ansi.code_to_chars(4) UNDERLINE_DISABLE = colorama.ansi.code_to_chars(24) @@ -122,7 +122,7 @@ def style(text: Any, *, fg: str = '', bg: str = '', bold: bool = False, underlin additions.append(UNDERLINE_ENABLE) removals.append(UNDERLINE_DISABLE) - # Combine the ANSI escape strings with the text + # Combine the ANSI escape sequences with the text return "".join(additions) + text + "".join(removals) |