From bbbf00e834e04c07830e4d2dc34023ba561ce278 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 18 Nov 2021 18:25:24 +0100 Subject: [PATCH] Separator string option --- CMakeLists.txt | 2 +- src/common/init.c | 2 + src/data/config.txt | 6 ++ src/data/help.txt | 179 ++++++++++++++++++++-------------------- src/fastfetch.c | 9 +- src/fastfetch.h | 2 + src/modules/separator.c | 17 +++- tests/performance.c | 3 +- 8 files changed, 124 insertions(+), 96 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d7e5ccc63..8b6ce48fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wconversion") set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,-O3") if(BUILD_TESTS) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -mtune=native -pipe -fno-plt -Wconversion") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -mtune=native -pipe -fno-plt") endif(BUILD_TESTS) execute_process( diff --git a/src/common/init.c b/src/common/init.c index eda98d737..8d2d90a9a 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -180,6 +180,8 @@ static void defaultConfig(FFinstance* instance) ffStrbufInitA(&instance->config.batteryDir, 0); + ffStrbufInitA(&instance->config.separatorString, 0); + instance->config.localIpShowIpV4 = true; instance->config.localIpShowIpV6 = false; instance->config.localIpShowLoop = false; diff --git a/src/data/config.txt b/src/data/config.txt index c5ef512bc..0e4c4b972 100644 --- a/src/data/config.txt +++ b/src/data/config.txt @@ -97,6 +97,12 @@ # Default is true. #--color-logo true +# Separator string option: +# Sets the string printed by the "separator" module (usually between title and rest of output) +# Must be any string. It is repated / cut to fit perfectly. +# Default is "-" +#--separator-string - + # Key options: # Sets the displayed key of a module # Can be any string. Some of theme take an argument like a format string. See "fastfetch --help format" for help. diff --git a/src/data/help.txt b/src/data/help.txt index 9c624d78d..04abb7467 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -1,107 +1,108 @@ Usage: fastfetch Informative options: - -h, --help: shows this message and exits - -h , --help : shows help for a specific command and exits - -v --version: prints the version of fastfetch and exits - --list-logos: list available logos and exits - --list-modules: lists available modules and exits - --list-presets: list presets fastfetch knows about and exits. They can be loaded with --load-config. (+) - --list-features: list the supported features fastfetch was compiled with and exits. Mainly for development. - --print-logos: show available logos and exits - --print-config: prints the default config and exits - --print-structure: prints the default stucture and exits + -h, --help: shows this message and exits + -h , --help : shows help for a specific command and exits + -v --version: prints the version of fastfetch and exits + --list-logos: list available logos and exits + --list-modules: lists available modules and exits + --list-presets: list presets fastfetch knows about and exits. They can be loaded with --load-config. (+) + --list-features: list the supported features fastfetch was compiled with and exits. Mainly for development. + --print-logos: show available logos and exits + --print-config: prints the default config and exits + --print-structure: prints the default stucture and exits General options: - --structure : sets the structure of the fetch. Must be a colon separated list of keys. Use "fastfetch --list-modules" to see the ones available. - --set : hard set the value of a key - -c , --color : sets the color of the keys. Must be a linux console color code (+) - --spacing : sets the distance between logo and text - -s , --separator : sets the separator between key and value. Default is a colon with a space - -x , --offsetx : sets the x offset. Can be negative to cut the logo, but no more than logo width. - --show-errors : print occuring errors - -r --recache : generate new cached values - --nocache : don't use cached values, but also don't overwrite existing ones - --print-remaining-logo : print the remaining logo, if it is higher than the number of lines shown - --multithreading : use multiple threads to detect values - --load-config : load a config file (+) - --allow-slow-operations : Allow operations that are usually very slow for more detailed output - --disable-linewrap : Disable linewrap during the run - --hide-cursor : Hide the cursor during the run + --structure : sets the structure of the fetch. Must be a colon separated list of keys. Use "fastfetch --list-modules" to see the ones available. + --set : hard set the value of a key + -c , --color : sets the color of the keys. Must be a linux console color code (+) + --spacing : sets the distance between logo and text + -s , --separator : sets the separator between key and value. Default is a colon with a space + -x , --offsetx : sets the x offset. Can be negative to cut the logo, but no more than logo width. + --show-errors : print occuring errors + -r --recache : generate new cached values + --nocache : don't use cached values, but also don't overwrite existing ones + --print-remaining-logo : print the remaining logo, if it is higher than the number of lines shown + --multithreading : use multiple threads to detect values + --load-config : load a config file (+) + --allow-slow-operations : Allow operations that are usually very slow for more detailed output + --disable-linewrap : Disable linewrap during the run + --hide-cursor : Hide the cursor during the run Logo options: - -l , --logo : sets the shown logo. Also changes the main color accordingly. This will also load file contents as logo if the given argument is a valid path. - --color-logo : if set to false, the logo will be black / white + -l , --logo : sets the shown logo. Also changes the main color accordingly. This will also load file contents as logo if the given argument is a valid path. + --color-logo : if set to false, the logo will be black / white Format options: Provide the format string for custom output. Use fastfetch --help *-format for specific help. - --os-format - --host-format - --kernel-format - --uptime-format - --processes-format - --packages-format - --shell-format - --resolution-format - --de-format - --wm-format - --wm-theme-format - --theme-format - --icons-format - --font-format - --cursor-format - --terminal-format - --terminal-font-format - --cpu-format - --gpu-format - --memory-format - --disk-format - --battery-format - --locale-format - --local-ip-format + --os-format + --host-format + --kernel-format + --uptime-format + --processes-format + --packages-format + --shell-format + --resolution-format + --de-format + --wm-format + --wm-theme-format + --theme-format + --icons-format + --font-format + --cursor-format + --terminal-format + --terminal-font-format + --cpu-format + --gpu-format + --memory-format + --disk-format + --battery-format + --locale-format + --local-ip-format Key options: Provide a custom key for an output - --os-key - --host-key - --kernel-key - --uptime-key - --processes-key - --packages-key - --shell-key - --resolution-key : takes the resolution index as argument - --de-key - --wm-key - --wm-theme-key - --theme-key - --icons-key - --font-key - --cursor-key - --terminal-key - --terminal-font-key - --cpu-key - --gpu-key : takes the gpu index as format argument - --memory-key - --disk-key : takes the mount path as format argument - --battery-key : takes the battery index as format argument - --locale-key - --local-ip-key : takes the name of this network interface as format argument + --os-key + --host-key + --kernel-key + --uptime-key + --processes-key + --packages-key + --shell-key + --resolution-key : takes the resolution index as argument + --de-key + --wm-key + --wm-theme-key + --theme-key + --icons-key + --font-key + --cursor-key + --terminal-key + --terminal-font-key + --cpu-key + --gpu-key : takes the gpu index as format argument + --memory-key + --disk-key : takes the mount path as format argument + --battery-key : takes the battery index as format argument + --locale-key + --local-ip-key : takes the name of this network interface as format argument Library options: Set the path of a library to load - --lib-PCI - --lib-vulkan - --lib-X11 - --lib-Xrandr - --lib-gio - --lib-DConf - --lib-wayland - --lib-XFConf - --lib-RPM + --lib-PCI + --lib-vulkan + --lib-X11 + --lib-Xrandr + --lib-gio + --lib-DConf + --lib-wayland + --lib-XFConf + --lib-RPM Module specific options: - --disk-folders : A colon separated list of folder paths for the disk output. Default is "/:/home" - --battery-dir : The directory where the battery folders are. Standard: /sys/class/power_supply/ - --localip-show-ipv4 : Show ipv4 addresses in local ip module. Default is true - --localip-show-ipv6 : Show ipv6 addresses in local ip module. Default is false - --localip-show-loop : Show loop back addresses (127.0.0.1) in local ip module. Default is false + --separator-string : Set the string printed by the separator module + --disk-folders : A colon separated list of folder paths for the disk output. Default is "/:/home" + --battery-dir : The directory where the battery folders are. Standard: /sys/class/power_supply/ + --localip-show-ipv4 : Show ipv4 addresses in local ip module. Default is true + --localip-show-ipv6 : Show ipv6 addresses in local ip module. Default is false + --localip-show-loop : Show loop back addresses (127.0.0.1) in local ip module. Default is false 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/fastfetch.c b/src/fastfetch.c index ab8c5a52f..dfdb34ec1 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -761,6 +761,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con optionParseString(key, value, &instance->config.diskFolders); else if(strcasecmp(key, "--battery-dir") == 0) optionParseString(key, value, &instance->config.batteryDir); + else if(strcasecmp(key, "--separator-string") == 0) + optionParseString(key, value, &instance->config.separatorString); else if(strcasecmp(key, "--localip-show-ipv4") == 0) instance->config.localIpShowIpV4 = optionParseBoolean(value); else if(strcasecmp(key, "--localip-show-ipv6") == 0) @@ -812,8 +814,11 @@ static void parseArguments(FFinstance* instance, FFdata* data, int argc, const c { for(int i = 1; i < argc; i++) { - if(i == argc - 1 || (*argv[i + 1] == '-' && strcasecmp(argv[i], "--offsetx") != 0)) // --offsetx allows negative values - { + if(i == argc - 1 || ( + *argv[i + 1] == '-' && + strcasecmp(argv[i], "--offsetx") != 0 && // --offsetx allows negative values + strcasecmp(argv[i], "--separator-string") != 0 // Separator string can start with a - + )) { parseOption(instance, data, argv[i], NULL); } else diff --git a/src/fastfetch.h b/src/fastfetch.h index 0db3a63b4..4b226a743 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -114,6 +114,8 @@ typedef struct FFconfig FFstrbuf batteryDir; + FFstrbuf separatorString; + bool localIpShowLoop; bool localIpShowIpV4; bool localIpShowIpV6; diff --git a/src/modules/separator.c b/src/modules/separator.c index 6fd5f9178..c3c0f0973 100644 --- a/src/modules/separator.c +++ b/src/modules/separator.c @@ -7,7 +7,20 @@ void ffPrintSeparator(FFinstance* instance) ffPrintLogoLine(instance); - for(uint32_t i = 0; i < titleLength; i++) - putchar('-'); + if(instance->config.separatorString.length == 0) + { + for(uint32_t i = 0; i < titleLength; i++) + putchar('-'); + } + else + { + //Write the whole separator as often as it fits fully into titleLength + for(uint32_t i = 0; i < titleLength / instance->config.separatorString.length; i++) + ffStrbufWriteTo(&instance->config.separatorString, stdout); + + //Write as much of the separator as needed to fill titleLength + for(uint32_t i = 0; i < titleLength % instance->config.separatorString.length; i++) + putchar(instance->config.separatorString.chars[i]); + } putchar('\n'); } diff --git a/tests/performance.c b/tests/performance.c index c57e0ae24..96108599f 100644 --- a/tests/performance.c +++ b/tests/performance.c @@ -27,8 +27,7 @@ int main(int argc, char** argv) FASTFETCH_TEST_PERFORMANCE( puts("Configuration"); - ffLoadLogoSet(&instance, "arch"); - ffStrbufSetS(&instance.config.color, instance.config.logo.colors[0]); + ffStrbufSetS(&instance.config.color, instance.config.logo->colors[0]); instance.config.showErrors = true; instance.config.recache = argc == 1; instance.config.cacheSave = false;