|
6 | 6 |
|
7 | 7 | from collections import OrderedDict |
8 | 8 | from typing import ( |
| 9 | + Any, |
9 | 10 | List, # in case list doesn't support `[` in this Python version |
10 | 11 | Union, # in case `|` doesn't support 'type' in this Python version |
11 | 12 | ) |
@@ -173,3 +174,39 @@ def d_quote(value) -> str: |
173 | 174 | attribute debug messages or any other technical/literary use. |
174 | 175 | """ |
175 | 176 | return hr_repr(value, always_quote=True) |
| 177 | + |
| 178 | + |
| 179 | +def prBold(text: Any): |
| 180 | + """Print in bold |
| 181 | + (or if not available, more intense if available). |
| 182 | + See echoC for details""" |
| 183 | + # echoC(message, "1:37:40") |
| 184 | + ansiP(text, 1) |
| 185 | + |
| 186 | + |
| 187 | +def prDim(text: Any): |
| 188 | + """Show dim text in console. |
| 189 | + (resets to 00 [default colors] for text after prDim). |
| 190 | + Note: 0;30;40 is non-bold dim, but that's invisible in cmd.exe. |
| 191 | + """ |
| 192 | + ansiP(text, 2) |
| 193 | + |
| 194 | + |
| 195 | +def ansiP(text: Any, ansiColor: Union[int, str]): |
| 196 | + """Print color text to consoles that support ANSI color codes. |
| 197 | + Args: |
| 198 | + message (Any): Any message (will be cast to str). |
| 199 | + ansiColor: Numerical or multi-number (str) ansi |
| 200 | + color code (semi-colon separated--same codes but allows |
| 201 | + multiple codes in a row). See |
| 202 | + <https://en.wikipedia.org/wiki/ANSI_escape_code> for a full |
| 203 | + list. Examples: |
| 204 | + - "1;30;40" for dim (NOTE: 0;30;40 is gray, but is invisible |
| 205 | + in cmd.exe) |
| 206 | + - "96": Cyan |
| 207 | + """ |
| 208 | + # - `\033[` starts the ANSI escape sequence. |
| 209 | + # - 91m, 92m, ... etc., are color codes for different foreground colors. |
| 210 | + # - \033[00m resets the text style so the terminal returns to normal |
| 211 | + # formatting after each print. |
| 212 | + print(f"\033[{ansiColor}m {str(text)}\033[00m") |
0 commit comments