]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/terminal-util: add support for $NO_COLOR
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 24 Nov 2019 12:59:22 +0000 (13:59 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 24 Nov 2019 12:59:22 +0000 (13:59 +0100)
See inline comments. Fixes #13752.

man/less-variables.xml
src/basic/terminal-util.c

index 03e4b353883c9d22e6b65d57b66b800fe0bc8f6b..08e513c99f8e9d52f5db5dfc0ec988bc0337f856 100644 (file)
       </listitem>
     </varlistentry>
 
+    <!-- This is not documented on purpose, because it is not clear if $NO_COLOR will become supported
+         widely enough. So let's provide support, but without advertising this.
+    <varlistentry id='no-color'>
+      <term><varname>$NO_COLOR</varname></term>
+
+      <listitem><para>If set (to any value), and <varname>$SYSTEMD_COLORS</varname> is not set, equivalent to
+      <option>SYSTEMD_COLORS=0</option>. See <ulink url="https://no-color.org/">no-color.org</ulink>.</para>
+      </listitem>
+    </varlistentry>
+    -->
+
     <varlistentry id='urlify'>
       <term><varname>$SYSTEMD_URLIFY</varname></term>
 
index 98c3ff04ef2bacc9d4e0c72e325918302942e4b5..511734cbbb8fd085c208b7b040be858d1c692edf 100644 (file)
@@ -1206,6 +1206,11 @@ bool colors_enabled(void) {
                 val = getenv_bool("SYSTEMD_COLORS");
                 if (val >= 0)
                         cached_colors_enabled = val;
+
+                else if (getenv("NO_COLOR"))
+                        /* We only check for the presence of the variable; value is ignored. */
+                        cached_colors_enabled = false;
+
                 else if (getpid_cached() == 1)
                         /* PID1 outputs to the console without holding it open all the time */
                         cached_colors_enabled = !getenv_terminal_is_dumb();
@@ -1231,6 +1236,9 @@ bool dev_console_colors_enabled(void) {
         if (b >= 0)
                 return b;
 
+        if (getenv("NO_COLOR"))
+                return false;
+
         if (getenv_for_pid(1, "TERM", &s) <= 0)
                 (void) proc_cmdline_get_key("TERM", 0, &s);