(
text: str,
color: Optional[str] = None,
highlight: Optional[str] = None,
attrs: Optional[Iterable[str]] = None,
)
| 102 | |
| 103 | |
| 104 | def 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 |
no outgoing calls