File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import os
44import sys
55
6+ terminal_supports_color = True
67if os .name == 'nt' : # pragma: no cover (windows)
78 from pre_commit .color_windows import enable_virtual_terminal_processing
89 try :
910 enable_virtual_terminal_processing ()
1011 except WindowsError :
11- pass
12+ terminal_supports_color = False
1213
1314RED = '\033 [41m'
1415GREEN = '\033 [42m'
@@ -47,4 +48,7 @@ def use_color(setting):
4748 if setting not in COLOR_CHOICES :
4849 raise InvalidColorSetting (setting )
4950
50- return setting == 'always' or (setting == 'auto' and sys .stdout .isatty ())
51+ return (
52+ setting == 'always' or
53+ (setting == 'auto' and sys .stdout .isatty () and terminal_supports_color )
54+ )
Original file line number Diff line number Diff line change @@ -35,9 +35,16 @@ def test_use_color_no_tty():
3535 assert use_color ('auto' ) is False
3636
3737
38- def test_use_color_tty ():
38+ def test_use_color_tty_with_color_support ():
3939 with mock .patch .object (sys .stdout , 'isatty' , return_value = True ):
40- assert use_color ('auto' ) is True
40+ with mock .patch ('pre_commit.color.terminal_supports_color' , True ):
41+ assert use_color ('auto' ) is True
42+
43+
44+ def test_use_color_tty_without_color_support ():
45+ with mock .patch .object (sys .stdout , 'isatty' , return_value = True ):
46+ with mock .patch ('pre_commit.color.terminal_supports_color' , False ):
47+ assert use_color ('auto' ) is False
4148
4249
4350def test_use_color_raises_if_given_shenanigans ():
You can’t perform that action at this time.
0 commit comments