diff options
author | Eric Lin <anselor@gmail.com> | 2021-03-16 12:25:34 -0400 |
---|---|---|
committer | Eric Lin <anselor@gmail.com> | 2021-03-18 14:16:03 -0400 |
commit | 0cd626ebbef273aa78c2d1154ebdd5f9055028cf (patch) | |
tree | 9a822b245312b3b515b64a69d772fab75fce8121 /cmd2/ansi.py | |
parent | a649286b9468ebadbafeca1abf20a946351ceefe (diff) | |
download | cmd2-git-cmdset_settables.tar.gz |
Resolves comments from PRcmdset_settables
Diffstat (limited to 'cmd2/ansi.py')
-rw-r--r-- | cmd2/ansi.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/cmd2/ansi.py b/cmd2/ansi.py index 741d3b8b..5b086c45 100644 --- a/cmd2/ansi.py +++ b/cmd2/ansi.py @@ -230,7 +230,7 @@ def style_aware_write(fileobj: IO[str], msg: str) -> None: fileobj.write(msg) -def fg_lookup(fg_name: Union[str, fg]) -> Fore: +def fg_lookup(fg_name: Union[str, fg]) -> str: """ Look up ANSI escape codes based on foreground color name. @@ -239,16 +239,16 @@ def fg_lookup(fg_name: Union[str, fg]) -> Fore: :raises: ValueError: if the color cannot be found """ if isinstance(fg_name, fg): - return fg_name.value + return str(fg_name.value) try: ansi_escape = fg[fg_name.lower()].value except KeyError: raise ValueError('Foreground color {!r} does not exist; must be one of: {}'.format(fg_name, fg.colors())) - return ansi_escape + return str(ansi_escape) -def bg_lookup(bg_name: Union[str, bg]) -> Back: +def bg_lookup(bg_name: Union[str, bg]) -> str: """ Look up ANSI escape codes based on background color name. @@ -257,13 +257,13 @@ def bg_lookup(bg_name: Union[str, bg]) -> Back: :raises: ValueError: if the color cannot be found """ if isinstance(bg_name, bg): - return bg_name.value + return str(bg_name.value) try: ansi_escape = bg[bg_name.lower()].value except KeyError: raise ValueError('Background color {!r} does not exist; must be one of: {}'.format(bg_name, bg.colors())) - return ansi_escape + return str(ansi_escape) # noinspection PyShadowingNames @@ -292,13 +292,13 @@ def style( :return: the stylized string """ # List of strings that add style - additions = [] + additions: List[str] = [] # List of strings that remove style - removals = [] + removals: List[str] = [] # Convert the text object into a string if it isn't already one - text = "{}".format(text) + text_formatted = "{}".format(text) # Process the style settings if fg: @@ -322,7 +322,7 @@ def style( removals.append(UNDERLINE_DISABLE) # Combine the ANSI style sequences with the text - return cast(str, "".join(additions) + text + "".join(removals)) + return "".join(additions) + text_formatted + "".join(removals) # Default styles for printing strings of various types. |