mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-03 11:44:18 +01:00
Colors: supports @<color-index>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user