mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Don't print bogus characters on windows terminals that don't support colors.
This commit is contained in:
parent
f042e302d8
commit
1bd6fce7dc
1 changed files with 3 additions and 1 deletions
|
|
@ -3,11 +3,13 @@ from __future__ import unicode_literals
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
terminal_supports_colors = True
|
||||||
if os.name == 'nt': # pragma: no cover (windows)
|
if os.name == 'nt': # pragma: no cover (windows)
|
||||||
from pre_commit.color_windows import enable_virtual_terminal_processing
|
from pre_commit.color_windows import enable_virtual_terminal_processing
|
||||||
try:
|
try:
|
||||||
enable_virtual_terminal_processing()
|
enable_virtual_terminal_processing()
|
||||||
except WindowsError:
|
except WindowsError:
|
||||||
|
terminal_supports_colors = False
|
||||||
pass
|
pass
|
||||||
|
|
||||||
RED = '\033[41m'
|
RED = '\033[41m'
|
||||||
|
|
@ -29,7 +31,7 @@ def format_color(text, color, use_color_setting):
|
||||||
color - The color start string
|
color - The color start string
|
||||||
use_color_setting - Whether or not to color
|
use_color_setting - Whether or not to color
|
||||||
"""
|
"""
|
||||||
if not use_color_setting:
|
if not use_color_setting or not terminal_supports_colors:
|
||||||
return text
|
return text
|
||||||
else:
|
else:
|
||||||
return '{}{}{}'.format(color, text, NORMAL)
|
return '{}{}{}'.format(color, text, NORMAL)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue