-
-
Notifications
You must be signed in to change notification settings - Fork 34
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
Document in the README
the parameters, env vars and terminal detection checked here for overriding/using colours:
termcolor/src/termcolor/termcolor.py
Lines 102 to 134 in 825ad65
def _can_do_colour( | |
*, no_color: bool | None = None, force_color: bool | None = None | |
) -> bool: | |
"""Check env vars and for tty/dumb terminal""" | |
# First check overrides: | |
# "User-level configuration files and per-instance command-line arguments should | |
# override $NO_COLOR. A user should be able to export $NO_COLOR in their shell | |
# configuration file as a default, but configure a specific program in its | |
# configuration file to specifically enable color." | |
# https://no-color.org | |
if no_color is not None and no_color: | |
return False | |
if force_color is not None and force_color: | |
return True | |
# Then check env vars: | |
if "ANSI_COLORS_DISABLED" in os.environ: | |
return False | |
if "NO_COLOR" in os.environ: | |
return False | |
if "FORCE_COLOR" in os.environ: | |
return True | |
# Then check system: | |
if os.environ.get("TERM") == "dumb": | |
return False | |
if not hasattr(sys.stdout, "fileno"): | |
return False | |
try: | |
return os.isatty(sys.stdout.fileno()) | |
except io.UnsupportedOperation: | |
return sys.stdout.isatty() |
(Re: #33 (comment))
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation