Move logic to handle terminal not supporting colors to use_color

This commit is contained in:
Jeffrey Rackauckas 2018-08-30 19:15:46 -07:00
parent a970d3b69b
commit 3d777bb386

View file

@ -3,13 +3,13 @@ from __future__ import unicode_literals
import os
import sys
terminal_supports_colors = True
terminal_supports_color = True
if os.name == 'nt': # pragma: no cover (windows)
from pre_commit.color_windows import enable_virtual_terminal_processing
try:
enable_virtual_terminal_processing()
except WindowsError:
terminal_supports_colors = False
terminal_supports_color = False
RED = '\033[41m'
GREEN = '\033[42m'
@ -30,7 +30,7 @@ def format_color(text, color, use_color_setting):
color - The color start string
use_color_setting - Whether or not to color
"""
if not use_color_setting or not terminal_supports_colors:
if not use_color_setting:
return text
else:
return '{}{}{}'.format(color, text, NORMAL)
@ -48,4 +48,7 @@ def use_color(setting):
if setting not in COLOR_CHOICES:
raise InvalidColorSetting(setting)
return setting == 'always' or (setting == 'auto' and sys.stdout.isatty())
return (
setting == 'always' or
(setting == 'auto' and sys.stdout.isatty() and terminal_supports_color)
)