Colors: supports @<color-index>

This commit is contained in:
李通洲
2026-01-08 10:42:58 +08:00
parent 546908fc29
commit c9c9a58f59
3 changed files with 24 additions and 0 deletions
+3
View File
@@ -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`: "@<color-index>" (e.g., "@34" for color index 34)
* In `format` strings: "#@<color-index>" (e.g., "#@34" for color index 34)
* Improves uptime accuracy on Windows 10+ (Uptime, Windows)
Bugfixes:
+16
View File
@@ -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
+5
View File
@@ -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");