Returns the currently set theme, potentially in a zero-color variant. In cases where colorizing is not possible (see `can_colorize`), the returned theme contains all empty strings in all color definitions. See `Theme.no_colors()` for more information. It is recommended not to cache
(
*,
tty_file: IO[str] | IO[bytes] | None = None,
force_color: bool = False,
force_no_color: bool = False,
)
| 320 | |
| 321 | |
| 322 | def get_theme( |
| 323 | *, |
| 324 | tty_file: IO[str] | IO[bytes] | None = None, |
| 325 | force_color: bool = False, |
| 326 | force_no_color: bool = False, |
| 327 | ) -> Theme: |
| 328 | """Returns the currently set theme, potentially in a zero-color variant. |
| 329 | |
| 330 | In cases where colorizing is not possible (see `can_colorize`), the returned |
| 331 | theme contains all empty strings in all color definitions. |
| 332 | See `Theme.no_colors()` for more information. |
| 333 | |
| 334 | It is recommended not to cache the result of this function for extended |
| 335 | periods of time because the user might influence theme selection by |
| 336 | the interactive shell, a debugger, or application-specific code. The |
| 337 | environment (including environment variable state and console configuration |
| 338 | on Windows) can also change in the course of the application life cycle. |
| 339 | """ |
| 340 | if force_color or (not force_no_color and |
| 341 | can_colorize(file=tty_file)): |
| 342 | return _theme |
| 343 | return theme_no_color |
| 344 | |
| 345 | |
| 346 | def set_theme(t: Theme) -> None: |