Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active November 16, 2019 06:47
Show Gist options
  • Select an option

  • Save gsscoder/ea38b07531a7253aa98072ede45329a8 to your computer and use it in GitHub Desktop.

Select an option

Save gsscoder/ea38b07531a7253aa98072ede45329a8 to your computer and use it in GitHub Desktop.
Checks if terminal supports colors
def supports_color():
# Ripped from: https://github.com/django/django/blob/master/django/core/management/color.py#L12
plat = sys.platform
supported_platform = plat != 'Pocket PC' and (plat != 'win32' or 'ANSICON' in os.environ)
# isatty is not always implemented, #6223.
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
return supported_platform and is_a_tty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment