Skip to content

Commit 1bd6fce

Browse files
committed
Don't print bogus characters on windows terminals that don't support colors.
1 parent f042e30 commit 1bd6fce

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pre_commit/color.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import os
44
import sys
55

6+
terminal_supports_colors = True
67
if 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:
12+
terminal_supports_colors = False
1113
pass
1214

1315
RED = '\033[41m'
@@ -29,7 +31,7 @@ def format_color(text, color, use_color_setting):
2931
color - The color start string
3032
use_color_setting - Whether or not to color
3133
"""
32-
if not use_color_setting:
34+
if not use_color_setting or not terminal_supports_colors:
3335
return text
3436
else:
3537
return '{}{}{}'.format(color, text, NORMAL)

0 commit comments

Comments
 (0)