ansi-color: $SYSTEMD_COLORS=true should mean generic "auto", not 24bit

Follow-up for af718e0535

The commit changed the documentation, but the actual impl
was apparently not updated. And the documented behavior
feels a bit off. I think generally "auto"/true should
override $NO_COLOR.

Plus, the test for auto-24bit is at odds with the logic
we merged. I guess it was overlooked after applying
https://github.com/systemd/systemd/pull/40303#discussion_r2720450393
This commit is contained in:
Mike Yuan
2026-01-27 19:20:30 +01:00
parent 97be547c6f
commit cc7fe807c1
6 changed files with 27 additions and 17 deletions
+3 -2
View File
@@ -59,7 +59,7 @@ static ColorMode get_color_mode_impl(void) {
return m;
/* Next, check for the presence of $NO_COLOR; value is ignored. */
if (getenv("NO_COLOR"))
if (m != COLOR_TRUE && getenv("NO_COLOR"))
return COLOR_OFF;
/* If the above didn't work, we turn colors off unless we are on a TTY. And if we are on a TTY we
@@ -108,9 +108,10 @@ static const char* const color_mode_table[_COLOR_MODE_MAX] = {
[COLOR_AUTO_16] = "auto-16",
[COLOR_AUTO_256] = "auto-256",
[COLOR_AUTO_24BIT] = "auto-24bit",
[COLOR_TRUE] = "true",
};
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(color_mode, ColorMode, COLOR_24BIT);
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(color_mode, ColorMode, COLOR_TRUE);
/*
* Check that the string is formatted like an ANSI color code, i.e. that it consists of one or more
+3
View File
@@ -17,6 +17,9 @@ typedef enum ColorMode {
COLOR_AUTO_256,
COLOR_AUTO_24BIT,
/* Same as default (unset), except that $NO_COLOR is ignored/overridden */
COLOR_TRUE,
_COLOR_MODE_MAX,
_COLOR_MODE_INVALID = -EINVAL,
} ColorMode;