mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 13:00:10 -06:00
Merge pull request #1103 from pre-commit/dumb_term
Disable color if TERM=dumb is detected
This commit is contained in:
@@ -49,6 +49,10 @@ def use_color(setting):
|
||||
raise InvalidColorSetting(setting)
|
||||
|
||||
return (
|
||||
setting == 'always' or
|
||||
(setting == 'auto' and sys.stdout.isatty() and terminal_supports_color)
|
||||
setting == 'always' or (
|
||||
setting == 'auto' and
|
||||
sys.stdout.isatty() and
|
||||
terminal_supports_color and
|
||||
os.getenv('TERM') != 'dumb'
|
||||
)
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ import sys
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from pre_commit import envcontext
|
||||
from pre_commit.color import format_color
|
||||
from pre_commit.color import GREEN
|
||||
from pre_commit.color import InvalidColorSetting
|
||||
@@ -38,13 +39,22 @@ def test_use_color_no_tty():
|
||||
def test_use_color_tty_with_color_support():
|
||||
with mock.patch.object(sys.stdout, 'isatty', return_value=True):
|
||||
with mock.patch('pre_commit.color.terminal_supports_color', True):
|
||||
assert use_color('auto') is True
|
||||
with envcontext.envcontext([('TERM', envcontext.UNSET)]):
|
||||
assert use_color('auto') is True
|
||||
|
||||
|
||||
def test_use_color_tty_without_color_support():
|
||||
with mock.patch.object(sys.stdout, 'isatty', return_value=True):
|
||||
with mock.patch('pre_commit.color.terminal_supports_color', False):
|
||||
assert use_color('auto') is False
|
||||
with envcontext.envcontext([('TERM', envcontext.UNSET)]):
|
||||
assert use_color('auto') is False
|
||||
|
||||
|
||||
def test_use_color_dumb_term():
|
||||
with mock.patch.object(sys.stdout, 'isatty', return_value=True):
|
||||
with mock.patch('pre_commit.color.terminal_supports_color', True):
|
||||
with envcontext.envcontext([('TERM', 'dumb')]):
|
||||
assert use_color('auto') is False
|
||||
|
||||
|
||||
def test_use_color_raises_if_given_shenanigans():
|
||||
|
||||
Reference in New Issue
Block a user