Skip to main content

Determine if terminal output should be colored, respecting environment variables

Project description

should-color

github pypi types

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.

Example Usage

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)
should_color()          # 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",
)

License

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

should_color-0.1.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

should_color-0.1.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file should_color-0.1.0.tar.gz.

File metadata

  • Download URL: should_color-0.1.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for should_color-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1850cf72d8b094600e265825b335809eab2dfcf61d141ee191018adb7d6b2bf6
MD5 539fd04ad99df878ace846c1a8534d6c
BLAKE2b-256 02800e264d603ef92303e5829efe210368ad8e7cdc85e8063b4ef11458c30546

See more details on using hashes here.

File details

Details for the file should_color-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: should_color-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for should_color-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0c77306efc35eb82709b94497672eb3ed533626f97725b0e7d259f9d0de2ab2
MD5 609731f2b46fb0697182278c748b6f7f
BLAKE2b-256 2d7dfec8090ad5be94984516908e6492ab2227c1f1f5fddc1e0c50d0143011e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page