Disable colored output on a dumb terminal (#3552)

Enable colored output by default only when the TERM environment variable
is set to a value other than dumb, as git and grep do, so that users no
longer need to pass -M or set NO_COLOR on terminals that cannot display
escape sequences. Colored output is now disabled not only for TERM=dumb
but also when TERM is unset or empty. The -C option still enables colors
in all these cases. On Windows, colored output is still decided by
ANSICON and the console mode, and TERM is not checked.
This commit is contained in:
Dmitri Vereshchagin authored and GitHub committed 2026-10-16 21:50:47 +09:00
1 parent 6b53f80311
commit 633ae6058a
4 files changed
+44 -9

No files matched your search

+4 -1
View File
@@ -543,7 +543,10 @@ int main(int argc, char* argv[]) {
#ifdef USE_ISATTY
if (isatty(STDOUT_FILENO)) {
#ifndef WIN32
dumpopts |= JV_PRINT_ISATTY | JV_PRINT_COLOR;
dumpopts |= JV_PRINT_ISATTY;
char *term = getenv("TERM");
if (term != NULL && term[0] != '\0' && strcmp(term, "dumb"))
dumpopts |= JV_PRINT_COLOR;
#else
/* Verify we actually have the console, as the NUL device is also regarded as
tty. Windows can handle color if ANSICON (or ConEmu) is installed, or