FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pre-commit/pre_commit/color.py at wip_progress_dots · pre-commit/pre-commit · GitHub
pre-commit
pre-commit
Repository navigation
Code
Issues
17
(17)
Pull requests
8
(8)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
pre-commit
/
pre_commit
/
color.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (44 loc) · 1.33 KB
Breadcrumbs
pre-commit
/
pre_commit
/
color.py
Copy path
File metadata and controls
58 lines (44 loc) · 1.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from
__future__
import
unicode_literals
import
os
import
sys
terminal_supports_color
=
True
if
os
.
name
==
'nt'
:
# pragma: no cover (windows)
from
pre_commit
.
color_windows
import
enable_virtual_terminal_processing
try
:
enable_virtual_terminal_processing
()
except
WindowsError
:
terminal_supports_color
=
False
RED
=
'
\033
[41m'
GREEN
=
'
\033
[42m'
YELLOW
=
'
\033
[43;30m'
TURQUOISE
=
'
\033
[46;30m'
NORMAL
=
'
\033
[0m'
class
InvalidColorSetting
(
ValueError
):
pass
def
format_color
(
text
,
color
,
use_color_setting
):
"""Format text with color.
Args:
text - Text to be formatted with color if `use_color`
color - The color start string
use_color_setting - Whether or not to color
"""
if
not
use_color_setting
:
return
text
else
:
return
'{}{}{}'
.
format
(
color
,
text
,
NORMAL
)
COLOR_CHOICES
=
(
'auto'
,
'always'
,
'never'
)
def
use_color
(
setting
):
"""Choose whether to use color based on the command argument.
Args:
setting - Either `auto`, `always`, or `never`
"""
if
setting
not
in
COLOR_CHOICES
:
raise
InvalidColorSetting
(
setting
)
return
(
setting
==
'always'
or
(
setting
==
'auto'
and
sys
.
stdout
.
isatty
()
and
terminal_supports_color
and
os
.
getenv
(
'TERM'
)
!=
'dumb'
)
)
Back
|
FazBrowse Home
|
New Git URL