MCPcopy Create free account
hub / github.com/bloomberg/pystack / colored

Function colored

src/pystack/colors.py:76–101  ·  view source on GitHub ↗

Colorize text, while stripping nested ANSI color sequences. Available text colors: red, green, yellow, blue, magenta, cyan, white. Available text highlights: on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white. Available attributes: bold, dark, und

(
    text: str,
    color: Optional[str] = None,
    highlight: Optional[str] = None,
    attrs: Optional[Iterable[str]] = None,
)

Source from the content-addressed store, hash-verified

74
75
76def colored(
77 text: str,
78 color: Optional[str] = None,
79 highlight: Optional[str] = None,
80 attrs: Optional[Iterable[str]] = None,
81) -> str:
82 """Colorize text, while stripping nested ANSI color sequences.
83 Available text colors:
84 red, green, yellow, blue, magenta, cyan, white.
85 Available text highlights:
86 on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white.
87 Available attributes:
88 bold, dark, underline, blink, reverse, concealed.
89 Example:
90 colored('Hello, World!', 'red', 'on_grey', ['blue', 'blink'])
91 colored('Hello, World!', 'green')
92 """
93
94 def terminal_supports_color() -> bool:
95 if os.getenv("NO_COLOR") is not None:
96 return False
97 return _is_stdout_a_tty()
98
99 if not terminal_supports_color():
100 return text
101 return format_colored(text, color, highlight, attrs)
102
103
104def format_colored(

Callers 9

produce_error_messageFunction · 0.85
as_green_strFunction · 0.85
as_yellow_strFunction · 0.85
format_frameFunction · 0.85
_format_merged_stacksFunction · 0.85

Calls 2

terminal_supports_colorFunction · 0.85
format_coloredFunction · 0.85