From 4ebfd53de03599b73838ee339e47652ac26c37c0 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 15 Sep 2023 17:24:26 -0600 Subject: Support the NO_COLOR environment variable I ran across this site: https://no-color.org/ ... which lobbies for tools to recognize the NO_COLOR environment variable and disable any terminal styling when it is seen. This patch implements this for gdb. Regression tested on x86-64 Fedora 38. Co-Authored-By: Andrew Burgess Reviewed-by: Kevin Buettner Reviewed-By: Eli Zaretskii Approved-By: Andrew Burgess --- gdb/testsuite/lib/gdb.exp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'gdb/testsuite/lib/gdb.exp') diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 1b91794..de22da8 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -6468,7 +6468,7 @@ proc default_gdb_init { test_file_name } { # This disables style output, which would interfere with many # tests. - setenv TERM "dumb" + setenv NO_COLOR sorry # This setting helps detect bugs in the Python code and doesn't # seem to have a significant downside for the tests. @@ -9238,6 +9238,25 @@ proc with_override { name override body } { return $result } +# Run BODY after setting the TERM environment variable to 'ansi', and +# unsetting the NO_COLOR environment variable. +proc with_ansi_styling_terminal { body } { + save_vars { ::env(TERM) ::env(NO_COLOR) } { + # Set environment variables to allow styling. + setenv TERM ansi + unset -nocomplain ::env(NO_COLOR) + + set code [catch {uplevel 1 $body} result] + } + + if {$code == 1} { + global errorInfo errorCode + return -code $code -errorinfo $errorInfo -errorcode $errorCode $result + } else { + return -code $code $result + } +} + # Setup tuiterm.exp environment. To be used in test-cases instead of # "load_lib tuiterm.exp". Calls initialization function and schedules # finalization function. -- cgit v1.1