diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-10-19 12:34:11 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-10-19 14:37:45 -0400 |
commit | f4958c5bb081b0ea4b7aeb98fd1d996add1fc47d (patch) | |
tree | 3045ac805edb060dcb2951e4a7a6e0d05c17e5fc /cmd2/ansi.py | |
parent | f57b08672af97f9d973148b6c30d74fe4e712d14 (diff) | |
download | cmd2-git-colored_tables.tar.gz |
Added ability to colorize all aspects of BorderedTables and AlternatingTables.colored_tables
Refactored utils.align_text() to print less fill_char style characters.
Diffstat (limited to 'cmd2/ansi.py')
-rw-r--r-- | cmd2/ansi.py | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/cmd2/ansi.py b/cmd2/ansi.py index 91188a9c..5517ecf0 100644 --- a/cmd2/ansi.py +++ b/cmd2/ansi.py @@ -943,7 +943,7 @@ class RgbBg(BgColor): # TODO: Remove this PyShadowingNames usage when deprecated fg and bg classes are removed. # noinspection PyShadowingNames def style( - text: Any, + value: Any, *, fg: Optional[FgColor] = None, bg: Optional[BgColor] = None, @@ -959,7 +959,7 @@ def style( The styling is self contained which means that at the end of the string reset code(s) are issued to undo whatever styling was done at the beginning. - :param text: text to format (anything convertible to a str) + :param value: object whose text is to be styled :param fg: foreground color provided as any subclass of FgColor (e.g. Fg, EightBitFg, RgbFg) Defaults to no color. :param bg: foreground color provided as any subclass of BgColor (e.g. Bg, EightBitBg, RgbBg) @@ -978,9 +978,6 @@ def style( # List of strings that remove style removals: List[AnsiSequence] = [] - # Convert the text object into a string if it isn't already one - text_formatted = str(text) - # Process the style settings if fg is not None: additions.append(fg) @@ -1014,8 +1011,8 @@ def style( additions.append(TextStyle.UNDERLINE_ENABLE) removals.append(TextStyle.UNDERLINE_DISABLE) - # Combine the ANSI style sequences with the text - return "".join(map(str, additions)) + text_formatted + "".join(map(str, removals)) + # Combine the ANSI style sequences with the value's text + return "".join(map(str, additions)) + str(value) + "".join(map(str, removals)) # Default styles for printing strings of various types. |