summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2021-10-19 15:31:22 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2021-10-19 15:38:22 +0200
commit400a6895566b67d70bcde43dc8a1cc1c7121f87d (patch)
treec3c1439b0e5af8f956556eca7f64e2f3214e6e40
parentbdc8526819d288f6076e1d1854138f139f2df32f (diff)
Respect NO_COLOR environment variable
When color has not been turned on explictly in the configuration file or options, only turn it on if NO_COLOR is not set.
-rw-r--r--apt-private/private-cmndline.cc3
-rw-r--r--apt-private/private-output.cc2
2 files changed, 3 insertions, 2 deletions
diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc
index 2884dccba..9af241947 100644
--- a/apt-private/private-cmndline.cc
+++ b/apt-private/private-cmndline.cc
@@ -474,7 +474,8 @@ static void BinarySpecificConfiguration(char const * const Binary) /*{{{*/
std::string const binary = flNotDir(Binary);
if (binary == "apt" || binary == "apt-config")
{
- _config->CndSet("Binary::apt::APT::Color", true);
+ if (getenv("NO_COLOR") == nullptr)
+ _config->CndSet("Binary::apt::APT::Color", true);
_config->CndSet("Binary::apt::APT::Cache::Show::Version", 2);
_config->CndSet("Binary::apt::APT::Cache::AllVersions", false);
_config->CndSet("Binary::apt::APT::Cache::ShowVirtuals", true);
diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc
index d07ecc0ce..daa6c6aed 100644
--- a/apt-private/private-output.cc
+++ b/apt-private/private-output.cc
@@ -86,7 +86,7 @@ bool InitOutput(std::basic_streambuf<char> * const out) /*{{{*/
SigWinch(0);
}
- if(!isatty(1))
+ if(!isatty(1) || getenv("NO_COLOR") != nullptr)
{
_config->Set("APT::Color", "false");
_config->Set("APT::Color::Highlight", "");