25
25
bright_cyan_start : Text = ansicolors ["BRIGHT_BOLD_CYAN" ]
26
26
reset : Text = ansicolors ["RESET" ]
27
27
28
+ if sys .stdout .isatty ():
29
+ IS_A_TTY = True
30
+ else :
31
+ IS_A_TTY = False
32
+
28
33
29
34
def bold_text (text : str , nocolor : bool = False ) -> str :
30
35
"""
31
36
Returns bold text ANSI escape code text string
32
37
"""
33
- if not nocolor and sys . stdout . isatty () :
38
+ if not nocolor and IS_A_TTY :
34
39
return f"{ bold_start } { text } { reset } "
35
40
else :
36
41
return text
@@ -40,7 +45,7 @@ def cyan_text(text: str, nocolor: bool = False) -> str:
40
45
"""
41
46
Returns cyan ANSI escape code colored text string
42
47
"""
43
- if not nocolor and sys . stdout . isatty () :
48
+ if not nocolor and IS_A_TTY :
44
49
return f"{ cyan_start } { text } { reset } "
45
50
else :
46
51
return text
@@ -51,7 +56,7 @@ def cyan_bright_text(text: str, nocolor: bool = False) -> str:
51
56
Returns cyan ANSI escape code colored text string
52
57
with bold weight
53
58
"""
54
- if not nocolor and sys . stdout . isatty () :
59
+ if not nocolor and IS_A_TTY :
55
60
return f"{ bright_cyan_start } { text } { reset } "
56
61
else :
57
62
return text
@@ -61,7 +66,7 @@ def green_text(text: str, nocolor: bool = False) -> str:
61
66
"""
62
67
Returns green ANSI escape code colored text string
63
68
"""
64
- if not nocolor and sys . stdout . isatty () :
69
+ if not nocolor and IS_A_TTY :
65
70
return f"{ green_start } { text } { reset } "
66
71
else :
67
72
return text
@@ -71,7 +76,7 @@ def red_text(text: str, nocolor: bool = False) -> str:
71
76
"""
72
77
Returns red ANSI escape code colored text string
73
78
"""
74
- if not nocolor and sys . stdout . isatty () :
79
+ if not nocolor and IS_A_TTY :
75
80
return f"{ red_start } { text } { reset } "
76
81
else :
77
82
return text
@@ -80,7 +85,7 @@ def red_text(text: str, nocolor: bool = False) -> str:
80
85
def report_header (header : str , nocolor : bool = False ) -> str :
81
86
header_len = len (header ) + 1
82
87
divider_char = "-"
83
- if not nocolor and sys . stdout . isatty () :
88
+ if not nocolor and IS_A_TTY :
84
89
header_string = (
85
90
f"{ divider_char * header_len } { os .linesep } "
86
91
f"{ bright_cyan_start } { header } { reset } { os .linesep } "
@@ -97,7 +102,7 @@ def report_header(header: str, nocolor: bool = False) -> str:
97
102
98
103
def overlap_result (glyphname : str , test_pass : bool , nocolor : bool = False ) -> str :
99
104
# color
100
- if not nocolor and sys . stdout . isatty () :
105
+ if not nocolor and IS_A_TTY :
101
106
if test_pass :
102
107
result_pre = f"[ { red_start } { glyphname } { reset } ]: "
103
108
else :
@@ -119,7 +124,7 @@ def direction_result(
119
124
components_with_transforms : Sequence [Tuple ] = [],
120
125
nocolor : bool = False ,
121
126
) -> str :
122
- if not nocolor and sys . stdout . isatty () :
127
+ if not nocolor and IS_A_TTY :
123
128
if contours == 0 :
124
129
return f"[ { bright_cyan_start } { glyphname } { reset } ]: no contours"
125
130
if direction_clockwise :
@@ -171,7 +176,7 @@ def _transformed_component(components_with_transforms: Sequence[Tuple]) -> str:
171
176
def segment_line (
172
177
coord1 : Coordinate , coord2 : Coordinate , distance : float , nocolor : bool
173
178
) -> str :
174
- if not nocolor and sys . stdout . isatty () :
179
+ if not nocolor and IS_A_TTY :
175
180
# color coord1 start and end points
176
181
if coord1 .startpoint :
177
182
coordinates1 = f"{ green_start } ({ coord1 .x } ,{ coord1 .y } ){ reset } "
@@ -204,7 +209,7 @@ def segment_quadratic_curve(
204
209
distance : float ,
205
210
nocolor : bool ,
206
211
) -> str :
207
- if not nocolor and sys . stdout . isatty () :
212
+ if not nocolor and IS_A_TTY :
208
213
if coord1 .startpoint :
209
214
coordinates1 = f"{ green_start } ({ coord1 .x } ,{ coord1 .y } ){ reset } "
210
215
elif coord1 .endpoint :
0 commit comments