diff --git a/CHANGELOG.md b/CHANGELOG.md index 3813e2555..b5a9915ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ Features: * Improves xterm font detection by checking `xterm.vt100.faceName` (TerminalFont, Linux) * Supports secure boot detection (Bootmgr, macOS) * Supports DPI scale factor detection on Windows 7 (Display, Windows) +* Supports xterm 256 color codes in color configuration + * In `display.color`: "@" (e.g., "@34" for color index 34) + * In `format` strings: "#@" (e.g., "#@34" for color index 34) * Improves uptime accuracy on Windows 10+ (Uptime, Windows) Bugfixes: diff --git a/src/common/impl/option.c b/src/common/impl/option.c index d5a5fabaf..63da17ef3 100644 --- a/src/common/impl/option.c +++ b/src/common/impl/option.c @@ -166,6 +166,22 @@ void ffOptionParseColorNoClear(const char* value, FFstrbuf* buffer) exit(479); } } + else if (value[0] == '@') + { + // Xterm 256 color + ++value; + char* pend = NULL; + uint32_t color = (uint32_t) strtoul(value, &pend, 10); + if (pend == value || color > 255) { + fprintf(stderr, "Error: invalid 256 color code found: %s\n", value); + exit(479); + } + + ffStrbufAppendS(buffer, FF_COLOR_FG_256); + ffStrbufAppendUInt(buffer, color); + value = pend; + continue; + } else if (value[0] == '#') { // RGB color diff --git a/tests/color.c b/tests/color.c index d000c2f53..45cdd51a0 100644 --- a/tests/color.c +++ b/tests/color.c @@ -44,6 +44,11 @@ int main(void) VERIFY("#123456", "38;2;18;52;86"); VERIFY("#abc", "38;2;170;187;204"); + // xterm 256 color codes + VERIFY("@0", "38;5;0"); + VERIFY("@1", "38;5;1"); + VERIFY("@255", "38;5;255"); + VERIFY("bold_#ff00ff", "1;38;2;255;0;255"); VERIFY("underline_#123", "4;38;2;17;34;51");