mirror of
https://github.com/systemd/systemd
synced 2026-03-16 01:54:45 +01:00
Compare commits
3 Commits
49f7149947
...
af718e0535
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af718e0535 | ||
|
|
fa41ce1142 | ||
|
|
236033fd48 |
6
NEWS
6
NEWS
@ -31,6 +31,12 @@ CHANGES WITH 260 in spe:
|
|||||||
rather than the first, to keep these options coherent with other
|
rather than the first, to keep these options coherent with other
|
||||||
unit settings.
|
unit settings.
|
||||||
|
|
||||||
|
Changes in other components:
|
||||||
|
|
||||||
|
* New options SYSTEMD_COLORS=auto-16 and SYSTEMD_COLORS=auto-256, which
|
||||||
|
are like SYSTEMD_COLORS=16 and SYSTEMD_COLORS=256 respectively when
|
||||||
|
output is to a non-dumb TTY, and like SYSTEMD_COLORS=no otherwise.
|
||||||
|
|
||||||
CHANGES WITH 259:
|
CHANGES WITH 259:
|
||||||
|
|
||||||
Announcements of Future Feature Removals and Incompatible Changes:
|
Announcements of Future Feature Removals and Incompatible Changes:
|
||||||
|
|||||||
@ -224,11 +224,40 @@
|
|||||||
<varlistentry id='colors'>
|
<varlistentry id='colors'>
|
||||||
<term><varname>$SYSTEMD_COLORS</varname></term>
|
<term><varname>$SYSTEMD_COLORS</varname></term>
|
||||||
|
|
||||||
<listitem><para>Takes a boolean argument. When true, <command>systemd</command> and related utilities
|
<listitem>
|
||||||
will use colors in their output, otherwise the output will be monochrome. Additionally, the variable can
|
<para>Takes a boolean argument, or a special value.</para>
|
||||||
take one of the following special values: <literal>16</literal>, <literal>256</literal> to restrict the use
|
|
||||||
of colors to the base 16 or 256 ANSI colors, respectively. This can be specified to override the automatic
|
<variablelist>
|
||||||
decision based on <varname>$TERM</varname> and what the console is connected to.</para></listitem>
|
<varlistentry>
|
||||||
|
<term><option>true</option></term>
|
||||||
|
<listitem><para>The default. <command>systemd</command> and related utilities will use colors in
|
||||||
|
their output if possible. Same as <literal>auto-24bit</literal> if <varname>$COLORTERM</varname>
|
||||||
|
is set to <literal>truecolor</literal> or <literal>24bit</literal>; same as
|
||||||
|
<literal>auto-256</literal> otherwise.</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>false</option></term>
|
||||||
|
<listitem><para>The output will be monochrome.</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><literal>16</literal></term>
|
||||||
|
<term><literal>256</literal></term>
|
||||||
|
<term><literal>24bit</literal></term>
|
||||||
|
<listitem><para>Always use the base 16 ANSI colors, 256 colors, or 24 bit color,
|
||||||
|
respectively.</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><literal>auto-16</literal></term>
|
||||||
|
<term><literal>auto-256</literal></term>
|
||||||
|
<term><literal>auto-24bit</literal></term>
|
||||||
|
<listitem><para>Use the given quantity of colours, subject to <varname>$TERM</varname>, and what
|
||||||
|
the console is connected to.</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
</variablelist>
|
||||||
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<!-- This is not documented on purpose, because it is not clear if $NO_COLOR will become supported
|
<!-- This is not documented on purpose, because it is not clear if $NO_COLOR will become supported
|
||||||
@ -236,7 +265,8 @@
|
|||||||
<varlistentry id='no-color'>
|
<varlistentry id='no-color'>
|
||||||
<term><varname>$NO_COLOR</varname></term>
|
<term><varname>$NO_COLOR</varname></term>
|
||||||
|
|
||||||
<listitem><para>If set (to any value), and <varname>$SYSTEMD_COLORS</varname> is not set, equivalent to
|
<listitem><para>If set (to any value), and <varname>$SYSTEMD_COLORS</varname> is not set to
|
||||||
|
<literal>16</literal>, <literal>256</literal>, or <literal>24bit</literal>, equivalent to
|
||||||
<option>SYSTEMD_COLORS=0</option>. See <ulink url="https://no-color.org/">no-color.org</ulink>.</para>
|
<option>SYSTEMD_COLORS=0</option>. See <ulink url="https://no-color.org/">no-color.org</ulink>.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|||||||
@ -85,8 +85,8 @@
|
|||||||
initrd. This accepts a device node path (usually <filename>/dev/disk/by-uuid/…</filename> or
|
initrd. This accepts a device node path (usually <filename>/dev/disk/by-uuid/…</filename> or
|
||||||
<filename>/dev/disk/by-label/…</filename> or similar), or the special values
|
<filename>/dev/disk/by-label/…</filename> or similar), or the special values
|
||||||
<literal>gpt-auto</literal>, <literal>gpt-auto-force</literal>, <literal>dissect</literal>,
|
<literal>gpt-auto</literal>, <literal>gpt-auto-force</literal>, <literal>dissect</literal>,
|
||||||
<literal>dissect-force</literal>, <literal>fstab</literal>, <literal>fstab</literal>, and
|
<literal>dissect-force</literal>, <literal>fstab</literal>, <literal>tmpfs</literal>,
|
||||||
<literal>off</literal>.</para>
|
<literal>bind:…</literal>, and <literal>off</literal>.</para>
|
||||||
|
|
||||||
<para>Set to <literal>gpt-auto</literal>, <literal>gpt-auto-force</literal>,
|
<para>Set to <literal>gpt-auto</literal>, <literal>gpt-auto-force</literal>,
|
||||||
<literal>dissect</literal>, <literal>dissect-force</literal> to explicitly request automatic root
|
<literal>dissect</literal>, <literal>dissect-force</literal> to explicitly request automatic root
|
||||||
|
|||||||
@ -55,7 +55,7 @@ static ColorMode get_color_mode_impl(void) {
|
|||||||
|
|
||||||
/* First, we check $SYSTEMD_COLORS, which is the explicit way to change the mode. */
|
/* First, we check $SYSTEMD_COLORS, which is the explicit way to change the mode. */
|
||||||
ColorMode m = parse_systemd_colors();
|
ColorMode m = parse_systemd_colors();
|
||||||
if (m >= 0)
|
if (IN_SET(m, COLOR_OFF, COLOR_16, COLOR_256, COLOR_24BIT))
|
||||||
return m;
|
return m;
|
||||||
|
|
||||||
/* Next, check for the presence of $NO_COLOR; value is ignored. */
|
/* Next, check for the presence of $NO_COLOR; value is ignored. */
|
||||||
@ -70,6 +70,13 @@ static ColorMode get_color_mode_impl(void) {
|
|||||||
return COLOR_OFF;
|
return COLOR_OFF;
|
||||||
|
|
||||||
/* We failed to figure out any reason to *disable* colors. Let's see how many colors we shall use. */
|
/* We failed to figure out any reason to *disable* colors. Let's see how many colors we shall use. */
|
||||||
|
if (m == COLOR_AUTO_16)
|
||||||
|
return COLOR_16;
|
||||||
|
if (m == COLOR_AUTO_256)
|
||||||
|
return COLOR_256;
|
||||||
|
if (m == COLOR_AUTO_24BIT)
|
||||||
|
return COLOR_24BIT;
|
||||||
|
|
||||||
if (STRPTR_IN_SET(getenv("COLORTERM"),
|
if (STRPTR_IN_SET(getenv("COLORTERM"),
|
||||||
"truecolor",
|
"truecolor",
|
||||||
"24bit"))
|
"24bit"))
|
||||||
@ -97,6 +104,9 @@ static const char* const color_mode_table[_COLOR_MODE_MAX] = {
|
|||||||
[COLOR_16] = "16",
|
[COLOR_16] = "16",
|
||||||
[COLOR_256] = "256",
|
[COLOR_256] = "256",
|
||||||
[COLOR_24BIT] = "24bit",
|
[COLOR_24BIT] = "24bit",
|
||||||
|
[COLOR_AUTO_16] = "auto-16",
|
||||||
|
[COLOR_AUTO_256] = "auto-256",
|
||||||
|
[COLOR_AUTO_24BIT] = "auto-24bit",
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(color_mode, ColorMode, COLOR_24BIT);
|
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(color_mode, ColorMode, COLOR_24BIT);
|
||||||
|
|||||||
@ -9,6 +9,9 @@ typedef enum ColorMode {
|
|||||||
COLOR_16, /* Only the base 16 colors. */
|
COLOR_16, /* Only the base 16 colors. */
|
||||||
COLOR_256, /* Only 256 colors. */
|
COLOR_256, /* Only 256 colors. */
|
||||||
COLOR_24BIT, /* For truecolor or 24bit color support, no restriction. */
|
COLOR_24BIT, /* For truecolor or 24bit color support, no restriction. */
|
||||||
|
COLOR_AUTO_16, /* The "AUTO" modes are as the above, but subject to suitable settings for */
|
||||||
|
COLOR_AUTO_256, /* the environment variables TERM and NO_COLOR. */
|
||||||
|
COLOR_AUTO_24BIT,
|
||||||
_COLOR_MODE_MAX,
|
_COLOR_MODE_MAX,
|
||||||
_COLOR_MODE_INVALID = -EINVAL,
|
_COLOR_MODE_INVALID = -EINVAL,
|
||||||
} ColorMode;
|
} ColorMode;
|
||||||
|
|||||||
@ -1422,6 +1422,9 @@ static int os_release_status(void) {
|
|||||||
if (l < 0) {
|
if (l < 0) {
|
||||||
log_debug_errno(l, "Failed to unescape FANCY_NAME=, ignoring: %m");
|
log_debug_errno(l, "Failed to unescape FANCY_NAME=, ignoring: %m");
|
||||||
fancy_name = mfree(fancy_name);
|
fancy_name = mfree(fancy_name);
|
||||||
|
} else if (!utf8_is_valid(fancy_name)) {
|
||||||
|
log_debug("Unescaped FANCY_NAME= contains invalid UTF-8, ignoring.");
|
||||||
|
fancy_name = mfree(fancy_name);
|
||||||
} else {
|
} else {
|
||||||
free_and_replace(fancy_name, unescaped);
|
free_and_replace(fancy_name, unescaped);
|
||||||
|
|
||||||
|
|||||||
@ -238,6 +238,9 @@ static void context_read_os_release(Context *c) {
|
|||||||
if (l < 0) {
|
if (l < 0) {
|
||||||
log_warning_errno(l, "Failed to unescape fancy OS name, ignoring: %m");
|
log_warning_errno(l, "Failed to unescape fancy OS name, ignoring: %m");
|
||||||
os_fancy_name = mfree(os_fancy_name);
|
os_fancy_name = mfree(os_fancy_name);
|
||||||
|
} else if (!utf8_is_valid(unescaped)) {
|
||||||
|
log_warning("Unescaped fancy OS name contains invalid UTF-8, ignoring.");
|
||||||
|
os_fancy_name = mfree(os_fancy_name);
|
||||||
} else
|
} else
|
||||||
free_and_replace(os_fancy_name, unescaped);
|
free_and_replace(os_fancy_name, unescaped);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -336,7 +336,17 @@ TEST(get_color_mode) {
|
|||||||
test_get_color_mode_with_env("SYSTEMD_COLORS", "yes", COLOR_24BIT);
|
test_get_color_mode_with_env("SYSTEMD_COLORS", "yes", COLOR_24BIT);
|
||||||
test_get_color_mode_with_env("SYSTEMD_COLORS", "24bit", COLOR_24BIT);
|
test_get_color_mode_with_env("SYSTEMD_COLORS", "24bit", COLOR_24BIT);
|
||||||
|
|
||||||
|
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-16", terminal_is_dumb() ? COLOR_OFF : COLOR_16);
|
||||||
|
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-256", terminal_is_dumb() ? COLOR_OFF : COLOR_256);
|
||||||
|
ASSERT_OK_ERRNO(setenv("COLORTERM", "truecolor", true));
|
||||||
|
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-24bit", terminal_is_dumb() ? COLOR_OFF : COLOR_24BIT);
|
||||||
|
ASSERT_OK_ERRNO(unsetenv("COLORTERM"));
|
||||||
|
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-24bit", terminal_is_dumb() ? COLOR_OFF : COLOR_256);
|
||||||
|
|
||||||
ASSERT_OK_ERRNO(setenv("NO_COLOR", "1", true));
|
ASSERT_OK_ERRNO(setenv("NO_COLOR", "1", true));
|
||||||
|
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-16", COLOR_OFF);
|
||||||
|
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-256", COLOR_OFF);
|
||||||
|
test_get_color_mode_with_env("SYSTEMD_COLORS", "auto-24bit", COLOR_OFF);
|
||||||
test_get_color_mode_with_env("SYSTEMD_COLORS", "42", COLOR_OFF);
|
test_get_color_mode_with_env("SYSTEMD_COLORS", "42", COLOR_OFF);
|
||||||
test_get_color_mode_with_env("SYSTEMD_COLORS", "invalid", COLOR_OFF);
|
test_get_color_mode_with_env("SYSTEMD_COLORS", "invalid", COLOR_OFF);
|
||||||
ASSERT_OK_ERRNO(unsetenv("NO_COLOR"));
|
ASSERT_OK_ERRNO(unsetenv("NO_COLOR"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user