basic/terminal-util: add support for $NO_COLOR
See inline comments. Fixes #13752.
This commit is contained in:
parent
78af8a798a
commit
c484315b01
|
@ -73,6 +73,17 @@
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</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'>
|
<varlistentry id='urlify'>
|
||||||
<term><varname>$SYSTEMD_URLIFY</varname></term>
|
<term><varname>$SYSTEMD_URLIFY</varname></term>
|
||||||
|
|
||||||
|
|
|
@ -1206,6 +1206,11 @@ bool colors_enabled(void) {
|
||||||
val = getenv_bool("SYSTEMD_COLORS");
|
val = getenv_bool("SYSTEMD_COLORS");
|
||||||
if (val >= 0)
|
if (val >= 0)
|
||||||
cached_colors_enabled = val;
|
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)
|
else if (getpid_cached() == 1)
|
||||||
/* PID1 outputs to the console without holding it open all the time */
|
/* PID1 outputs to the console without holding it open all the time */
|
||||||
cached_colors_enabled = !getenv_terminal_is_dumb();
|
cached_colors_enabled = !getenv_terminal_is_dumb();
|
||||||
|
@ -1231,6 +1236,9 @@ bool dev_console_colors_enabled(void) {
|
||||||
if (b >= 0)
|
if (b >= 0)
|
||||||
return b;
|
return b;
|
||||||
|
|
||||||
|
if (getenv("NO_COLOR"))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (getenv_for_pid(1, "TERM", &s) <= 0)
|
if (getenv_for_pid(1, "TERM", &s) <= 0)
|
||||||
(void) proc_cmdline_get_key("TERM", 0, &s);
|
(void) proc_cmdline_get_key("TERM", 0, &s);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue