diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a843e906..11d538134 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Features: * Support MATE Terminal version & terminal font detection * Add `--no-buffer` option for easier debugging. CMake option `ENABLE_BUFFER` is removed and always enabled. * Support `--*-key-color` option to change the key color of specified module +* Support `--colors-symbol` # 1.11.3 diff --git a/src/common/init.c b/src/common/init.c index 29a2933c2..2d18c828d 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -102,6 +102,7 @@ static void defaultConfig(FFinstance* instance) ffInitSoundOptions(&instance->config.sound); ffInitSeparatorOptions(&instance->config.separator); ffInitGamepadOptions(&instance->config.gamepad); + ffInitColorsOptions(&instance->config.colors); ffStrbufInit(&instance->config.libPCI); ffStrbufInit(&instance->config.libVulkan); @@ -306,6 +307,7 @@ static void destroyConfig(FFinstance* instance) ffDestroySeparatorOptions(&instance->config.separator); ffDestroySoundOptions(&instance->config.sound); ffDestroyGamepadOptions(&instance->config.gamepad); + ffDestroyColorsOptions(&instance->config.colors); ffStrbufDestroy(&instance->config.libPCI); ffStrbufDestroy(&instance->config.libVulkan); diff --git a/src/data/help.txt b/src/data/help.txt index bad9e1def..5feb254b6 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -136,6 +136,7 @@ Module specific options: --command-shell : Set the shell program to execute the command text. Default is cmd for Windows, csh for FreeBSD, bash for others --command-key : Set the module key to display --command-text : Set the command text to be executed + --colors-symbol : Set the symbol to be printed by Colors module. Default is block Parsing is not case sensitive. E.g. "--lib-PCI" is equal to "--Lib-Pci" If a value starts with a ?, it is optional. "true" will be used if not set. diff --git a/src/data/json_schema.jsonc b/src/data/json_schema.jsonc index 28463cf5c..19ec8ef4a 100644 --- a/src/data/json_schema.jsonc +++ b/src/data/json_schema.jsonc @@ -436,7 +436,7 @@ { "properties": { "type": { - "enum": ["Break", "Colors"] + "enum": ["Break"] } }, "additionalProperties": false @@ -547,6 +547,26 @@ }, "additionalProperties": false }, + { + "properties": { + "type": { + "enum": ["Colors"] + }, + "symbol": { + "title": "Set the symbol to use", + "type": "string", + "enum": [ + "block", + "circle", + "diamond", + "triangle", + "square", + "star" + ], + "default": "blocks" + } + } + }, { "properties": { "type": { diff --git a/src/fastfetch.c b/src/fastfetch.c index d4e7a1afd..758cee228 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1153,7 +1153,7 @@ static void parseStructureCommand(FFinstance* instance, const char* line) else if(strcasecmp(line, FF_DATETIME_MODULE_NAME) == 0) ffPrintDateTime(instance, &instance->config.dateTime); else if(strcasecmp(line, FF_COLORS_MODULE_NAME) == 0) - ffPrintColors(instance); + ffPrintColors(instance, &instance->config.colors); else if(strcasecmp(line, FF_VULKAN_MODULE_NAME) == 0) ffPrintVulkan(instance, &instance->config.vulkan); else if(strcasecmp(line, FF_OPENGL_MODULE_NAME) == 0) diff --git a/src/fastfetch.h b/src/fastfetch.h index 0ecbcd12a..f95d0fc36 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -104,6 +104,7 @@ typedef struct FFconfig FFSeparatorOptions separator; FFSoundOptions sound; FFGamepadOptions gamepad; + FFColorsOptions colors; FFstrbuf libPCI; FFstrbuf libVulkan; diff --git a/src/flashfetch.c b/src/flashfetch.c index d09a7c2f4..b7b18fc9f 100644 --- a/src/flashfetch.c +++ b/src/flashfetch.c @@ -69,7 +69,7 @@ int main(int argc, char** argv) //ffPrintSound(&instance, &instance.config.sound); //ffPrintGamepad(&instance); ffPrintBreak(&instance); - ffPrintColors(&instance); + ffPrintColors(&instance, &instance.config.colors); ffFinish(&instance); ffDestroyInstance(&instance); diff --git a/src/modules/colors/colors.c b/src/modules/colors/colors.c index 54b7a0d1d..07bcf6728 100644 --- a/src/modules/colors/colors.c +++ b/src/modules/colors/colors.c @@ -3,34 +3,120 @@ #include "util/textModifier.h" #include "modules/colors/colors.h" -void ffPrintColors(FFinstance* instance) +void ffPrintColors(FFinstance* instance, FFColorsOptions* options) { if(instance->config.pipe) return; ffLogoPrintLine(instance); - // 4%d: Set the background color - // 3%d: Set the foreground color - for(uint8_t i = 0; i < 8; i++) - printf("\033[4%d;3%dm███", i, i); + if (options->symbol == FF_COLORS_SYMBOL_BLOCK) + { + // 4%d: Set the background color + // 3%d: Set the foreground color + for(uint8_t i = 0; i < 8; i++) + printf("\033[4%d;3%dm███", i, i); - puts(FASTFETCH_TEXT_MODIFIER_RESET); + puts(FASTFETCH_TEXT_MODIFIER_RESET); - ffLogoPrintLine(instance); + ffLogoPrintLine(instance); - // 1: Set everything to bolt. This causes normal colors on some systems to be bright. - // 4%d: Set the backgound to the not bright color - // 3%d: Set the foreground to the not bright color - // 10%d: Set the background to the bright color - // 9%d: Set the foreground to the bright color - for(uint8_t i = 0; i < 8; i++) - printf("\033[1;4%d;3%d;10%d;9%dm███", i, i, i, i); + // 1: Set everything to bolt. This causes normal colors on some systems to be bright. + // 4%d: Set the backgound to the not bright color + // 3%d: Set the foreground to the not bright color + // 10%d: Set the background to the bright color + // 9%d: Set the foreground to the bright color + for(uint8_t i = 0; i < 8; i++) + printf("\033[1;4%d;3%d;10%d;9%dm███", i, i, i, i); + } + else + { + const char* symbol; + switch (options->symbol) + { + case FF_COLORS_SYMBOL_CIRCLE: symbol = "●"; break; + case FF_COLORS_SYMBOL_DIAMOND: symbol = "◆"; break; + case FF_COLORS_SYMBOL_TRIANGLE: symbol = "▲"; break; + case FF_COLORS_SYMBOL_SQUARE: symbol = "■"; break; + case FF_COLORS_SYMBOL_STAR: symbol = "★"; break; + default: symbol = "███"; break; + } + for (int i = 8; i >= 1; --i) + printf("\e[3%dm%s ", i, symbol); + } puts(FASTFETCH_TEXT_MODIFIER_RESET); } -void ffParseColorsJsonObject(FFinstance* instance, FF_MAYBE_UNUSED yyjson_val* module) +void ffInitColorsOptions(FFColorsOptions* options) { - return ffPrintColors(instance); + options->moduleName = FF_COLORS_MODULE_NAME; + options->symbol = FF_COLORS_SYMBOL_BLOCK; +} + +bool ffParseColorsCommandOptions(FFColorsOptions* options, const char* key, const char* value) +{ + const char* subKey = ffOptionTestPrefix(key, FF_COLORS_MODULE_NAME); + if (!subKey) return false; + + if (strcasecmp(subKey, "symbol") == 0) + { + options->symbol = (FFColorssymbol) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { + { "block", FF_COLORS_SYMBOL_BLOCK }, + { "circle", FF_COLORS_SYMBOL_CIRCLE }, + { "diamond", FF_COLORS_SYMBOL_DIAMOND }, + { "triangle", FF_COLORS_SYMBOL_TRIANGLE }, + { "square", FF_COLORS_SYMBOL_SQUARE }, + { "star", FF_COLORS_SYMBOL_STAR }, + {}, + }); + return true; + } + + return false; +} + +void ffDestroyColorsOptions(FF_MAYBE_UNUSED FFColorsOptions* options) +{ +} + +void ffParseColorsJsonObject(FFinstance* instance, yyjson_val* module) +{ + FFColorsOptions __attribute__((__cleanup__(ffDestroyColorsOptions))) options; + ffInitColorsOptions(&options); + + if (module) + { + yyjson_val *key_, *val; + size_t idx, max; + yyjson_obj_foreach(module, idx, max, key_, val) + { + const char* key = yyjson_get_str(key_); + if(strcasecmp(key, "type") == 0) + continue; + + if (strcasecmp(key, "symbol") == 0) + { + int value; + const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { + { "block", FF_COLORS_SYMBOL_BLOCK }, + { "circle", FF_COLORS_SYMBOL_CIRCLE }, + { "diamond", FF_COLORS_SYMBOL_DIAMOND }, + { "triangle", FF_COLORS_SYMBOL_TRIANGLE }, + { "square", FF_COLORS_SYMBOL_SQUARE }, + { "star", FF_COLORS_SYMBOL_STAR }, + {}, + }); + if (error) + ffPrintErrorString(instance, FF_COLORS_MODULE_NAME, 0, NULL, NULL, "Invalid %s value: %s", key, error); + else + options.symbol = (FFColorssymbol) value; + continue; + } + + ffPrintErrorString(instance, FF_COLORS_MODULE_NAME, 0, NULL, NULL, "Unknown JSON key %s", key); + } + } + + ffPrintColors(instance, &options); } diff --git a/src/modules/colors/colors.h b/src/modules/colors/colors.h index 990ae4348..7ab1a5efd 100644 --- a/src/modules/colors/colors.h +++ b/src/modules/colors/colors.h @@ -4,5 +4,7 @@ #define FF_COLORS_MODULE_NAME "Colors" -void ffPrintColors(FFinstance* instance); +void ffPrintColors(FFinstance* instance, FFColorsOptions* options); +void ffInitColorsOptions(FFColorsOptions* options); +void ffDestroyColorsOptions(FFColorsOptions* options); void ffParseColorsJsonObject(FFinstance* instance, yyjson_val* module); diff --git a/src/modules/colors/option.h b/src/modules/colors/option.h new file mode 100644 index 000000000..4e2e0b2d9 --- /dev/null +++ b/src/modules/colors/option.h @@ -0,0 +1,21 @@ +#pragma once + +// This file will be included in "fastfetch.h", do NOT put unnecessary things here + +#include "common/option.h" + +typedef enum FFColorssymbol +{ + FF_COLORS_SYMBOL_BLOCK, + FF_COLORS_SYMBOL_CIRCLE, + FF_COLORS_SYMBOL_DIAMOND, + FF_COLORS_SYMBOL_SQUARE, + FF_COLORS_SYMBOL_TRIANGLE, + FF_COLORS_SYMBOL_STAR, +} FFColorssymbol; + +typedef struct FFColorsOptions +{ + const char* moduleName; + FFColorssymbol symbol; +} FFColorsOptions; diff --git a/src/modules/display/display.c b/src/modules/display/display.c index e59435dab..c3bf888d7 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -157,6 +157,7 @@ void ffDestroyDisplayOptions(FFDisplayOptions* options) { ffOptionDestroyModuleArg(&options->moduleArgs); } + void ffParseDisplayJsonObject(FFinstance* instance, yyjson_val* module) { FFDisplayOptions __attribute__((__cleanup__(ffDestroyDisplayOptions))) options; diff --git a/src/modules/options.h b/src/modules/options.h index f9ae625b9..12aa53998 100644 --- a/src/modules/options.h +++ b/src/modules/options.h @@ -10,6 +10,7 @@ #include "modules/chassis/option.h" #include "modules/cpu/option.h" #include "modules/cpuusage/option.h" +#include "modules/colors/option.h" #include "modules/cursor/option.h" #include "modules/custom/option.h" #include "modules/command/option.h"