diff --git a/doc/json_schema.json b/doc/json_schema.json index a1e66b3f9..6e0968667 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -2,11 +2,19 @@ "$schema": "https://json-schema.org/draft-07/schema", "$defs": { "colors": { - "type": "string", - "description": "https://github.com/fastfetch-cli/fastfetch/wiki/Color-Format-Specification", - "examples": [ - "reset_", "bright_", "dim_", "italic_", "underline_", "blink_", "inverse_", "hidden_", "strike_", "light_", - "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "default" + "oneOf": [ + { + "type": "string", + "$comment": "https://github.com/fastfetch-cli/fastfetch/wiki/Color-Format-Specification", + "examples": [ + "reset_", "bright_", "dim_", "italic_", "underline_", "blink_", "inverse_", "hidden_", "strike_", "light_", + "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "default" + ] + }, + { + "type": "null", + "$comment": "Disable default color" + } ] }, "key": { diff --git a/presets/examples/29.jsonc b/presets/examples/29.jsonc index 493350a43..25b25a4c2 100644 --- a/presets/examples/29.jsonc +++ b/presets/examples/29.jsonc @@ -15,9 +15,9 @@ "bar": { "border": { "left": "[", - "leftElapsed": "[─", + "leftElapsed": "[", "right": "]", - "rightElapsed": "─]" + "rightElapsed": "]" }, "char": { "elapsed": "─", @@ -27,7 +27,7 @@ "elapsed": "default", "total": "light_black" }, - "width": 14 + "width": 16 }, "color": { "separator": "default", diff --git a/src/common/percent.c b/src/common/percent.c index f609b1c19..ea41596d8 100644 --- a/src/common/percent.c +++ b/src/common/percent.c @@ -97,40 +97,38 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf bool autoColorElapsed = ffStrbufIgnCaseEqualS(&options->barColorElapsed, "auto"); + bool monochrome = (percentType & FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT) || !autoColorElapsed; + if (!options->pipe && options->barColorElapsed.length > 0 && monochrome) + { + const char* color = NULL; + if (!autoColorElapsed) + color = options->barColorElapsed.chars; + else if (green <= yellow) + { + if (percent < green) color = colorGreen; + else if (percent < yellow) color = colorYellow; + else color = colorRed; + } + else + { + if (percent < yellow) color = colorRed; + else if (percent < green) color = colorYellow; + else color = colorGreen; + } + ffStrbufAppendF(buffer, "\e[%sm", color); + } for (uint8_t i = 0; i < blocksPercent; ++i) { - if(!options->pipe && options->barColorElapsed.length > 0) + if (!options->pipe && options->barColorElapsed.length > 0 && !monochrome) { - if ((percentType & FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT) || !autoColorElapsed) - { - const char* color = NULL; - if (!autoColorElapsed) - color = options->barColorElapsed.chars; - else if (green <= yellow) - { - if (percent < green) color = colorGreen; - else if (percent < yellow) color = colorYellow; - else color = colorRed; - } - else - { - if (percent < yellow) color = colorRed; - else if (percent < green) color = colorYellow; - else color = colorGreen; - } - ffStrbufAppendF(buffer, "\e[%sm", color); - } - else - { - uint32_t section1Begin = (uint32_t) ((green <= yellow ? green : yellow) / 100.0 * options->barWidth + 0.5); - uint32_t section2Begin = (uint32_t) ((green > yellow ? green : yellow) / 100.0 * options->barWidth + 0.5); - if (i == section2Begin) - ffStrbufAppendF(buffer, "\e[%sm", (green > yellow ? colorGreen : colorRed)); - else if (i == section1Begin) - ffStrbufAppendF(buffer, "\e[%sm", colorYellow); - else if (i == 0) - ffStrbufAppendF(buffer, "\e[%sm", (green <= yellow ? colorGreen : colorRed)); - } + uint32_t section1Begin = (uint32_t) ((green <= yellow ? green : yellow) / 100.0 * options->barWidth + 0.5); + uint32_t section2Begin = (uint32_t) ((green > yellow ? green : yellow) / 100.0 * options->barWidth + 0.5); + if (i == section2Begin) + ffStrbufAppendF(buffer, "\e[%sm", (green > yellow ? colorGreen : colorRed)); + else if (i == section1Begin) + ffStrbufAppendF(buffer, "\e[%sm", colorYellow); + else if (i == 0) + ffStrbufAppendF(buffer, "\e[%sm", (green <= yellow ? colorGreen : colorRed)); } ffStrbufAppend(buffer, borderAsValue && i == 0 ? &options->barBorderLeftElapsed