From f8ba138b8d3dfc7af79df18a44c72d46e9ef5a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 16 Nov 2023 14:21:24 +0800 Subject: [PATCH] Completion: tidy --- completions/bash | 10 +++++----- completions/fish | 14 ++++++++------ src/data/help_color.txt | 2 +- src/fastfetch.c | 38 ++++++++++++++++++++++++++++---------- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/completions/bash b/completions/bash index 9a59d7116..c730d177d 100644 --- a/completions/bash +++ b/completions/bash @@ -5,7 +5,7 @@ __fastfetch_complete_help() local __ff_helps=( "color" "format" - "load-config" + "config" "os-format" "host-format" "kernel-format" @@ -66,7 +66,7 @@ __fastfetch_complete_path() __fastfetch_complete_logo() { - COMPREPLY=($(compgen -W "$(fastfetch --list-logos-autocompletion)" -- "$CURRENT_WORD")) + COMPREPLY=($(compgen -W "$(fastfetch --list-logos autocompletion)" -- "$CURRENT_WORD")) } __fastfetch_complete_logo_type() @@ -218,10 +218,9 @@ __fastfetch_completion() "--logo-color-6" "--logo-color-7" "--logo-color-8" + "--logo-color-9" "--logo-width" "--logo-height" - "--logo-color-9" - "-c" "--color" "--color-keys" "--color-title" @@ -360,7 +359,8 @@ __fastfetch_completion() ) local FF_OPTIONS_PATH=( - "--load-config" + "-c" + "--config" "--os-file" "--lib-pci" "--lib-vulkan" diff --git a/completions/fish b/completions/fish index 1515ff223..1edf0a38c 100755 --- a/completions/fish +++ b/completions/fish @@ -5,7 +5,7 @@ if not test -x fastfetch end set -l whole_text (fastfetch --pipe --help) -set -l modules (fastfetch --list-modules | string sub -s 5 | string lower) +set -l modules (fastfetch --list-modules autocompletion) complete -c fastfetch -f @@ -23,12 +23,13 @@ for line in (string match -- ' -*' $whole_text) switch (string match -r -- $regexp $args) case '<\?command>' - set -l modules_format $modules-format"\tModule_format" - set res $res -x -a "color\tSupported_colors format\tCustom_format config\tConfiguration $modules_format" + set -l temp (string lower $modules) + set -l temp $temp-format"\tModule\\ format" + set res $res -x -a "color\tSupported\\ colors format\tCustom\\ format config\tConfiguration $temp" case '<\?bool>' set res $res -x -a "true\tBool false\tBool" case '' - set -l presets (fastfetch --list-presets false)"\tPreset" + set -l presets (fastfetch --list-presets autocompletion)"\tPreset" set res $res -r -a "$presets" case '' set res $res -F -r @@ -40,8 +41,9 @@ for line in (string match -- ' -*' $whole_text) set temp $modules"\tModule" set res $res -x -a "$temp" case '' - set -l builtin_logos (fastfetch --list-logos-autocompletion) - set -l temp $builtin_logos"\tBuiltin" + set -l temp (fastfetch --list-logos autocompletion) + set -l temp (string replace -- ' ' '\\ ' $temp) + set -l temp $temp"\tBuiltin" set res $res -x -a "none\tNone small\tSmall $temp" case '' set res $res -x -a "black\tColor red\tColor green\tColor yellow\tColor blue\tColor magenta\tColor cyan\tColor white\tColor default\tColor" diff --git a/src/data/help_color.txt b/src/data/help_color.txt index defeab6d6..a28d89eb6 100644 --- a/src/data/help_color.txt +++ b/src/data/help_color.txt @@ -3,7 +3,7 @@ Usage: fastfetch --color must be a color encoding as ANSI escape sequences. It is inserted between "ESC[" and "m". Infos about them can be found here: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters. Examples: - --color 35: sets the color to pink + --color 35: sets the color to magenta. `--color magenta` is also supported --color 4;92: sets the color to bright Green with underline --color 5;104: blinking text on a blue background If no color is set, the main color of the logo will be used. diff --git a/src/fastfetch.c b/src/fastfetch.c index 837eae772..cd2972eaa 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -183,7 +183,7 @@ static void listDataPaths(void) } } -static void listModules() +static void listModules(bool pretty) { unsigned count = 0; for (int i = 0; i <= 'Z' - 'A'; ++i) @@ -191,7 +191,10 @@ static void listModules() for (FFModuleBaseInfo** modules = ffModuleInfos[i]; *modules; ++modules) { ++count; - printf("%d)%s%s\n", count, count > 9 ? " " : " ", (*modules)->name); + if (pretty) + printf("%d)%s%s\n", count, count > 9 ? " " : " ", (*modules)->name); + else + puts((*modules)->name); } } } @@ -450,9 +453,9 @@ static void parseCommand(FFdata* data, char* key, char* value) { const char* subkey = key + strlen("--list-"); if(ffStrEqualsIgnCase(subkey, "modules")) - listModules(); + listModules(!value || !ffStrEqualsIgnCase(value, "autocompletion")); else if(ffStrEqualsIgnCase(subkey, "presets")) - listAvailablePresets(ffOptionParseBoolean(value)); + listAvailablePresets(!value || !ffStrEqualsIgnCase(value, "autocompletion")); else if(ffStrEqualsIgnCase(subkey, "config-paths")) listConfigPaths(); else if(ffStrEqualsIgnCase(subkey, "data-paths")) @@ -461,13 +464,28 @@ static void parseCommand(FFdata* data, char* key, char* value) ffListFeatures(); else if(ffStrEqualsIgnCase(subkey, "logos")) { - puts("Builtin logos:"); - ffLogoBuiltinList(); - puts("\nCustom logos:"); - listAvailableLogos(); + if (value) + { + if (ffStrEqualsIgnCase(value, "autocompletion")) + ffLogoBuiltinListAutocompletion(); + else if (ffStrEqualsIgnCase(value, "builtin")) + ffLogoBuiltinList(); + else if (ffStrEqualsIgnCase(value, "custom")) + listAvailableLogos(); + else + { + fprintf(stderr, "Error: unsupported logo type: %s\n", value); + exit(415); + } + } + else + { + puts("Builtin logos:"); + ffLogoBuiltinList(); + puts("\nCustom logos:"); + listAvailableLogos(); + } } - else if(ffStrEqualsIgnCase(subkey, "logos-autocompletion")) - ffLogoBuiltinListAutocompletion(); else { fprintf(stderr, "Error: unsupported list option: %s\n", key);