Skip to content

Commit 98abeb1

Browse files
committed
term: simplify can_show_color_on_stdout_cache and can_show_color_on_stderr_cache, in order to make term directly usable with the native backend
1 parent 78f3cf3 commit 98abeb1

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

vlib/term/term.v

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,32 @@ pub mut:
1414
y int
1515
}
1616

17-
__global can_show_color_on_stdout_cache = ?bool(none)
18-
__global can_show_color_on_stderr_cache = ?bool(none)
17+
__global can_show_color_on_stdout_cache = 0
18+
__global can_show_color_on_stderr_cache = 0
1919

2020
// can_show_color_on_stdout returns true, if colors are allowed in stdout.
2121
// It returns false otherwise.
2222
pub fn can_show_color_on_stdout() bool {
23-
if status := can_show_color_on_stdout_cache {
24-
return status
23+
match can_show_color_on_stdout_cache {
24+
1 { return true }
25+
-1 { return false }
26+
else {}
2527
}
2628
status := supports_escape_sequences(1)
27-
can_show_color_on_stdout_cache = status
29+
can_show_color_on_stdout_cache = if status { 1 } else { -1 }
2830
return status
2931
}
3032

3133
// can_show_color_on_stderr returns true, if colors are allowed in stderr.
3234
// It returns false otherwise.
3335
pub fn can_show_color_on_stderr() bool {
34-
if status := can_show_color_on_stderr_cache {
35-
return status
36+
match can_show_color_on_stderr_cache {
37+
1 { return true }
38+
-1 { return false }
39+
else {}
3640
}
3741
status := supports_escape_sequences(2)
38-
can_show_color_on_stderr_cache = status
42+
can_show_color_on_stderr_cache = if status { 1 } else { -1 }
3943
return status
4044
}
4145

0 commit comments

Comments
 (0)