diff --git a/CHANGELOG.md b/CHANGELOG.md index 041f0f97f..313eec725 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Changes: Features: * Add `--key-width` for aligning the left edge of values +* Add `--bar-char-elapsed`, `--bar-char-total` and `--bar-border` options Bugfixes: * Fix label detection (Disk, Linux) diff --git a/doc/json_schema.json b/doc/json_schema.json index 561213a08..7980a2837 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -352,6 +352,27 @@ "enum": ["CELSIUS", "C", "FAHRENHEIT", "F", "KELVIN", "K"], "default": "C" }, + "bar": { + "type": "object", + "title": "Set the bar configuration", + "properties": { + "charElapsed": { + "type": "string", + "title": "Set the character to use in elapsed part", + "default": "■" + }, + "charTotal": { + "type": "string", + "title": "Set the character to use in total part", + "default": "-" + }, + "border": { + "type": "boolean", + "title": "Whether to show a border around the bar", + "default": true + } + } + }, "percentType": { "type": "number", "title": "Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number", diff --git a/src/common/bar.c b/src/common/bar.c index e42a07c2a..f71326a17 100644 --- a/src/common/bar.c +++ b/src/common/bar.c @@ -1,5 +1,6 @@ +#include "common/bar.h" +#include "common/color.h" #include "util/textModifier.h" -#include "bar.h" // green, yellow, red: print the color on nth (0~9) block // set its value == 10 means the color will not be printed @@ -15,37 +16,46 @@ void ffAppendPercentBar(FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_ percent = (uint8_t)(percent + 5) / 10; assert(percent <= 10); - if(!instance.config.pipe) - ffStrbufAppendS(buffer, "\033[97m[ "); - else - ffStrbufAppendS(buffer, "[ "); + if(instance.config.barBorder) + { + if(!instance.config.pipe) + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m[ "); + else + ffStrbufAppendS(buffer, "[ "); + } for (uint8_t i = 0; i < percent; ++i) { if(!instance.config.pipe) { if (i == green) - ffStrbufAppendS(buffer, "\033[32m"); + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_GREEN "m"); else if (i == yellow) - ffStrbufAppendS(buffer, "\033[93m"); + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_YELLOW "m"); else if (i == red) - ffStrbufAppendS(buffer, "\033[91m"); + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_RED "m"); } - ffStrbufAppendS(buffer, "■"); + ffStrbufAppend(buffer, &instance.config.barCharElapsed); } if (percent < 10) { if(!instance.config.pipe) - ffStrbufAppendS(buffer, "\033[97m"); + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m"); for (uint8_t i = percent; i < 10; ++i) - ffStrbufAppendS(buffer, "-"); + ffStrbufAppend(buffer, &instance.config.barCharTotal); + } + + if(instance.config.barBorder) + { + if(!instance.config.pipe) + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m ]"); + else + ffStrbufAppendS(buffer, " ]"); } if(!instance.config.pipe) - ffStrbufAppendS(buffer, "\033[97m ]" FASTFETCH_TEXT_MODIFIER_RESET); - else - ffStrbufAppendS(buffer, " ]"); + ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); } // if (green < yellow) @@ -71,20 +81,20 @@ void ffAppendPercentNum(FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_ if(green < yellow) { if (percent <= green) - ffStrbufAppendS(buffer, "\033[32m"); + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_GREEN "m"); else if (percent <= yellow) - ffStrbufAppendS(buffer, "\033[93m"); + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_YELLOW "m"); else - ffStrbufAppendS(buffer, "\033[91m"); + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_RED "m"); } else { if (percent >= green) - ffStrbufAppendS(buffer, "\033[32m"); + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_GREEN "m"); else if (percent >= yellow) - ffStrbufAppendS(buffer, "\033[93m"); + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_YELLOW "m"); else - ffStrbufAppendS(buffer, "\033[91m"); + ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_RED "m"); } } ffStrbufAppendF(buffer, "%u%%", (unsigned) percent); diff --git a/src/common/init.c b/src/common/init.c index f102ef66a..61c6ad9c1 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -70,6 +70,11 @@ static void defaultConfig(void) instance.config.noBuffer = false; instance.config.keyWidth = 0; + ffStrbufInitStatic(&instance.config.barCharElapsed, "■"); + ffStrbufInitStatic(&instance.config.barCharTotal, "-"); + instance.config.barBorder = true; + instance.config.percentType = 1; + ffInitTitleOptions(&instance.config.title); ffInitOSOptions(&instance.config.os); ffInitHostOptions(&instance.config.host); @@ -146,8 +151,6 @@ static void defaultConfig(void) ffStrbufInit(&instance.config.libPulse); ffStrbufInit(&instance.config.libnm); ffStrbufInit(&instance.config.libDdcutil); - - instance.config.percentType = 1; } void ffInitInstance(void) @@ -273,6 +276,8 @@ static void destroyConfig(void) ffStrbufDestroy(&instance.config.colorKeys); ffStrbufDestroy(&instance.config.colorTitle); ffStrbufDestroy(&instance.config.keyValueSeparator); + ffStrbufDestroy(&instance.config.barCharElapsed); + ffStrbufDestroy(&instance.config.barCharTotal); #if defined(__linux__) || defined(__FreeBSD__) ffStrbufDestroy(&instance.config.playerName); diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 794b32405..b96ed5186 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -436,6 +436,23 @@ const char* ffParseDisplayJsonConfig(void) } else if (ffStrEqualsIgnCase(key, "percentType")) config->percentType = (uint32_t) yyjson_get_uint(val); + else if (ffStrEqualsIgnCase(key, "bar")) + { + if (yyjson_is_obj(val)) + { + const char* charElapsed = yyjson_get_str(yyjson_obj_get(val, "charElapsed")); + if (charElapsed) + ffStrbufSetS(&config->barCharElapsed, charElapsed); + const char* charTotal = yyjson_get_str(yyjson_obj_get(val, "charTotal")); + if (charTotal) + ffStrbufSetS(&config->barCharTotal, charTotal); + yyjson_val* border = yyjson_obj_get(val, "border"); + if (border) + config->barBorder = yyjson_get_bool(border); + } + else + return "display.bar must be an object"; + } else if (ffStrEqualsIgnCase(key, "noBuffer")) config->noBuffer = yyjson_get_bool(val); else if (ffStrEqualsIgnCase(key, "keyWidth")) diff --git a/src/data/help.txt b/src/data/help.txt index 4606bd48e..7f8642d37 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -69,6 +69,9 @@ Display options: --hide-cursor : Whether to hide the cursor during the run --binary-prefix : Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC --percent-type : Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number. Default is 1 + --bar-char-elapsed : Set the character to use in elapsed part. Default is '■' + --bar-char-total : Set the character to use in total part. Default is '-' + --bar-border : Whether to show a border around the bar. Default is true --no-buffer : Set if the stdout application buffer should be disabled. Default is false --size-ndigits : Set the number of digits to keep after the decimal point when formatting sizes --size-max-prefix : Set the largest binary prefix to use when formatting sizes. Default is YB diff --git a/src/fastfetch.c b/src/fastfetch.c index 45375573e..939e6895f 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1047,6 +1047,12 @@ static void parseOption(FFdata* data, const char* key, const char* value) } else if(ffStrEqualsIgnCase(key, "--percent-type")) instance.config.percentType = ffOptionParseUInt32(key, value); + else if(ffStrEqualsIgnCase(key, "--bar-char-elapsed")) + ffOptionParseString(key, value, &instance.config.barCharElapsed); + else if(ffStrEqualsIgnCase(key, "--bar-char-total")) + ffOptionParseString(key, value, &instance.config.barCharTotal); + else if(ffStrEqualsIgnCase(key, "--bar-border")) + instance.config.barBorder = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--no-buffer")) instance.config.noBuffer = ffOptionParseBoolean(value); diff --git a/src/fastfetch.h b/src/fastfetch.h index 3af517c7b..61b72be5b 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -54,6 +54,9 @@ typedef struct FFconfig uint8_t sizeNdigits; uint8_t sizeMaxPrefix; FFTemperatureUnit temperatureUnit; + FFstrbuf barCharElapsed; + FFstrbuf barCharTotal; + bool barBorder; uint32_t percentType; bool pipe; //disables logo and all escape sequences bool multithreading; diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index 744e4ed9c..844bfe896 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -32,12 +32,19 @@ void ffPrintSwap(FFSwapOptions* options) if(options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(FF_SWAP_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); if (storage.bytesTotal == 0) - puts("Disabled"); + { + if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) + { + ffAppendPercentBar(&str, 0, 0, 5, 8); + ffStrbufAppendC(&str, ' '); + } + if(!(instance.config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) + ffStrbufAppendS(&str, "Disabled"); + } else { - FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); - if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { ffAppendPercentBar(&str, percentage, 0, 5, 8); @@ -49,10 +56,10 @@ void ffPrintSwap(FFSwapOptions* options) if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) ffAppendPercentNum(&str, (uint8_t) percentage, 50, 80, str.length > 0); - - ffStrbufTrimRight(&str, ' '); - ffStrbufPutTo(&str, stdout); } + + ffStrbufTrimRight(&str, ' '); + ffStrbufPutTo(&str, stdout); } else {