mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #1103 from pre-commit/dumb_term
Disable color if TERM=dumb is detected
This commit is contained in:
commit
7f1e9c1907
2 changed files with 18 additions and 4 deletions
|
|
@ -49,6 +49,10 @@ def use_color(setting):
|
||||||
raise InvalidColorSetting(setting)
|
raise InvalidColorSetting(setting)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
setting == 'always' or
|
setting == 'always' or (
|
||||||
(setting == 'auto' and sys.stdout.isatty() and terminal_supports_color)
|
setting == 'auto' and
|
||||||
|
sys.stdout.isatty() and
|
||||||
|
terminal_supports_color and
|
||||||
|
os.getenv('TERM') != 'dumb'
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import sys
|
||||||
import mock
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from pre_commit import envcontext
|
||||||
from pre_commit.color import format_color
|
from pre_commit.color import format_color
|
||||||
from pre_commit.color import GREEN
|
from pre_commit.color import GREEN
|
||||||
from pre_commit.color import InvalidColorSetting
|
from pre_commit.color import InvalidColorSetting
|
||||||
|
|
@ -38,13 +39,22 @@ def test_use_color_no_tty():
|
||||||
def test_use_color_tty_with_color_support():
|
def test_use_color_tty_with_color_support():
|
||||||
with mock.patch.object(sys.stdout, 'isatty', return_value=True):
|
with mock.patch.object(sys.stdout, 'isatty', return_value=True):
|
||||||
with mock.patch('pre_commit.color.terminal_supports_color', 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():
|
def test_use_color_tty_without_color_support():
|
||||||
with mock.patch.object(sys.stdout, 'isatty', return_value=True):
|
with mock.patch.object(sys.stdout, 'isatty', return_value=True):
|
||||||
with mock.patch('pre_commit.color.terminal_supports_color', False):
|
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():
|
def test_use_color_raises_if_given_shenanigans():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue