From 7d878a0acd3c0fc68311c420e472865c647b19f2 Mon Sep 17 00:00:00 2001 From: Daniel Scharrer Date: Wed, 20 Feb 2019 02:45:01 +0100 Subject: [PATCH] console: Add support for the NO_COLOR environment variable --- doc/innoextract.1.in | 2 +- src/util/console.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/innoextract.1.in b/doc/innoextract.1.in index d396fc93..0e805ea4 100644 --- a/doc/innoextract.1.in +++ b/doc/innoextract.1.in @@ -116,7 +116,7 @@ With the "\fBrename\fP" action, steps 1 and 3 are only applied to files that wou \fB\-c\fP, \fB\-\-color\fP[=\fIENABLE\fP] By default .B innoextract -will try to detect if the terminal supports shell escape codes and enable or disable color output accordingly. Specifically, colors will be enabled if both \fBstdout\fP and \fBstderr\fP point to a TTY and the \fBTERM\fP environment variable is not set to "\fBdumb\fP". Pass \fB1\fP or \fBtrue\fP to \fB\-\-color\fP to force color output. Pass \fB0\fP or \fBfalse\fP to never output color codes. +will try to detect if the terminal supports shell escape codes and enable or disable color output accordingly. Specifically, colors will be enabled if both \fBstdout\fP and \fBstderr\fP point to a TTY, the \fBTERM\fP environment variable is not set to "\fBdumb\fP" and the \fBNO_COLOR\fP environment is unset. Pass \fB1\fP or \fBtrue\fP to \fB\-\-color\fP to force color output. Pass \fB0\fP or \fBfalse\fP to never output color codes. .TP \fB\-V\FP, \fB\-\-data\-version\fP Print the Inno Setup data version of the installer and exit immediately. diff --git a/src/util/console.cpp b/src/util/console.cpp index 0e3f507b..37e01c6d 100644 --- a/src/util/console.cpp +++ b/src/util/console.cpp @@ -130,7 +130,7 @@ void init(is_enabled color, is_enabled progress) { &dim_blue, &dim_magenta, &dim_cyan, &dim_white, }; - if(color == disable || (color == automatic && !is_tty)) { + if(color == disable || (color == automatic && (!is_tty || std::getenv("NO_COLOR") != NULL))) { BOOST_FOREACH(shell_command * color, all_colors) { color->command = "";