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

Function format_colored

src/pystack/colors.py:104–121  ·  view source on GitHub ↗
(
    text: str,
    color: Optional[str] = None,
    highlight: Optional[str] = None,
    attrs: Optional[Iterable[str]] = None,
)

Source from the content-addressed store, hash-verified

102
103
104def format_colored(
105 text: str,
106 color: Optional[str] = None,
107 highlight: Optional[str] = None,
108 attrs: Optional[Iterable[str]] = None,
109) -> str:
110 fmt_str = "\033[%dm%s"
111 if color is not None:
112 text = re.sub(COLORS_RE + "(.*?)" + RESET_RE, r"\1", text)
113 text = fmt_str % (COLORS[color], text)
114 if highlight is not None:
115 text = re.sub(HIGHLIGHTS_RE + "(.*?)" + RESET_RE, r"\1", text)
116 text = fmt_str % (HIGHLIGHTS[highlight], text)
117 if attrs is not None:
118 text = re.sub(ATTRIBUTES_RE + "(.*?)" + RESET_RE, r"\1", text)
119 for attr in attrs:
120 text = fmt_str % (ATTRIBUTES[attr], text)
121 return text + RESET

Callers 5

test_basic_colorsFunction · 0.90
test_highlightsFunction · 0.90
test_attributesFunction · 0.90
test_mixed_parametersFunction · 0.90
coloredFunction · 0.85

Calls

no outgoing calls

Tested by 4

test_basic_colorsFunction · 0.72
test_highlightsFunction · 0.72
test_attributesFunction · 0.72
test_mixed_parametersFunction · 0.72