MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / stylize

Function stylize

cmd2/string_utils.py:86–96  ·  view source on GitHub ↗

Apply an ANSI style to a string, preserving any existing styles. :param val: string to be styled :param style: style instance or style definition to apply. :return: the stylized string

(val: str, style: StyleType)

Source from the content-addressed store, hash-verified

84
85
86def stylize(val: str, style: StyleType) -> str:
87 """Apply an ANSI style to a string, preserving any existing styles.
88
89 :param val: string to be styled
90 :param style: style instance or style definition to apply.
91 :return: the stylized string
92 """
93 # Convert to a Rich Text object to parse and preserve existing ANSI styles.
94 text = Text.from_ansi(val)
95 text.stylize(style)
96 return ru.rich_text_to_string(text)
97
98
99def strip_style(val: str) -> str:

Callers 11

test_visible_promptFunction · 0.90
test_get_completionsMethod · 0.90
__init__Method · 0.90
__init__Method · 0.90
do_echoMethod · 0.90
_set_promptMethod · 0.90
errorMethod · 0.90
_build_colored_promptMethod · 0.90

Calls

no outgoing calls

Tested by 5

test_visible_promptFunction · 0.72
test_get_completionsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…