/* First, we check $SYSTEMD_COLORS, which is the explicit way to change the mode. */
ColorMode m = parse_systemd_colors();
- if (IN_SET(m, COLOR_OFF, COLOR_16, COLOR_256, COLOR_24BIT))
+ if (m >= 0 && m < _COLOR_MODE_FIXED_MAX)
return m;
/* Next, check for the presence of $NO_COLOR; value is ignored. */
}
ColorMode get_color_mode(void) {
- if (cached_color_mode < 0)
+ if (cached_color_mode < 0) {
cached_color_mode = get_color_mode_impl();
+ assert(cached_color_mode >= 0 && cached_color_mode < _COLOR_MODE_FIXED_MAX);
+ }
return cached_color_mode;
}
-
static const char* const color_mode_table[_COLOR_MODE_MAX] = {
[COLOR_OFF] = "off",
[COLOR_16] = "16",
COLOR_16, /* Only the base 16 colors. */
COLOR_256, /* Only 256 colors. */
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_MODE_FIXED_MAX,
+
+ /* The "AUTO" modes are as the above, but subject to suitable settings for the environment variables
+ * TERM and NO_COLOR. */
+ COLOR_AUTO_16 = _COLOR_MODE_FIXED_MAX,
+ COLOR_AUTO_256,
COLOR_AUTO_24BIT,
+
_COLOR_MODE_MAX,
_COLOR_MODE_INVALID = -EINVAL,
} ColorMode;