Merge pull request #7160 from mocompute/fix-7137-dumb-terminal

Respect TERM=dumb in test runner to prevent ANSI sequences, color
This commit is contained in:
Jeroen van Rijn
2026-07-30 12:18:56 +02:00
committed by GitHub
6 changed files with 24 additions and 7 deletions

View File

@@ -21,6 +21,15 @@ get_no_color :: proc() -> bool {
return false
}
get_is_dumb :: proc() -> bool {
buf: [128]u8
if term, err := os.lookup_env(buf[:], "TERM"); err == nil {
// "dumb" terminal overrides all other color and ansi capabilities logic
return term == "dumb"
}
return false
}
get_environment_color :: proc() -> Color_Depth {
buf: [128]u8
// `COLORTERM` is non-standard but widespread and unambiguous.
@@ -63,10 +72,10 @@ get_environment_color :: proc() -> Color_Depth {
@(init)
init_terminal :: proc "contextless" () {
_init_terminal()
context = runtime.default_context()
_init_terminal()
// We respect `NO_COLOR` specifically as a color-disabler but not as a
// blanket ban on any terminal manipulation codes, hence why this comes
// after `_init_terminal` which will allow Windows to enable Virtual

View File

@@ -23,6 +23,11 @@ is_terminal :: proc(f: $T) -> bool {
return _is_terminal(f)
}
/*
This is true if the terminal is dumb, i.e. cannot process ANSI control sequences.
*/
is_dumb: bool
/*
This is true if the terminal is accepting any form of colored text output.
*/

View File

@@ -8,6 +8,7 @@ _is_terminal :: proc "contextless" (handle: any) -> bool {
_init_terminal :: proc "contextless" () {
color_depth = .None
is_dumb = true
}
_fini_terminal :: proc "contextless" () { }

View File

@@ -12,6 +12,7 @@ _is_terminal :: proc "contextless" (f: ^os.File) -> bool {
_init_terminal :: proc "contextless" () {
context = runtime.default_context()
color_depth = get_environment_color()
is_dumb = get_is_dumb()
}
_fini_terminal :: proc "contextless" () { }

View File

@@ -18,6 +18,8 @@ old_modes: [2]struct{
}
_init_terminal :: proc "contextless" () {
context = runtime.default_context()
vtp_enabled: bool
for &v in old_modes {
@@ -41,11 +43,11 @@ _init_terminal :: proc "contextless" () {
// This color depth is available on Windows 10 since build 10586.
color_depth = .Four_Bit
} else {
context = runtime.default_context()
// The user may be on a non-default terminal emulator.
color_depth = get_environment_color()
}
is_dumb = get_is_dumb()
}
_fini_terminal :: proc "contextless" () {

View File

@@ -278,9 +278,8 @@ runner :: proc(internal_tests: []Internal_Test) -> bool {
// The animations are only ever shown through STDOUT;
// STDERR is used exclusively for logging regardless of error level.
global_log_colors_disabled = !terminal.color_enabled || !terminal.is_terminal(os.stderr)
global_ansi_disabled = !terminal.is_terminal(os.stdout)
global_log_colors_disabled = terminal.is_dumb || !terminal.color_enabled || !terminal.is_terminal(os.stderr)
global_ansi_disabled = terminal.is_dumb || !terminal.is_terminal(os.stdout)
should_show_animations := FANCY_OUTPUT && terminal.color_enabled && !global_ansi_disabled
// -- Parse CLI options