Determine if terminal output should be colored, respecting NO_COLOR and CLICOLOR environment variables.
On Unix, ANSI colors are enabled if the output is isatty. On Windows, ANSI colors are assumed to be unsupported unless or colorama is installed and enabled.
import sys
from should_color import should_color, apply_ansi_style
should_color(sys.stdout)
should_color(sys.stderr)
should_color('stdout') # same as should_color(sys.stdout)
should_color('stderr') # same as should_color(sys.stdout)
print(
apply_ansi_style(
"ERROR:",
color="red",
bold=True,
# implicitly checks should_color('stdout'),
# both these options are the implicit defaults if unspecified
enabled='auto',
file='stdout',
),
"Fatal problem",
)Licensed under either the Apache 2.0 License or MIT License at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.