mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Help: convert to parsable JSON format
This commit is contained in:
+10
-9
@@ -213,6 +213,16 @@ function(fastfetch_load_text FILENAME OUTVAR)
|
||||
set("${OUTVAR}" "${TEMP}" PARENT_SCOPE)
|
||||
endfunction(fastfetch_load_text)
|
||||
|
||||
function(fastfetch_load_raw_text FILENAME OUTVAR)
|
||||
file(READ "${FILENAME}" TEMP)
|
||||
string(REGEX REPLACE "\n$" "" TEMP "${TEMP}") # Remove trailing newline
|
||||
string(REPLACE "\\" "\\\\" TEMP "${TEMP}") # Escape backslashes
|
||||
string(REPLACE "\n" "\\n" TEMP "${TEMP}") # Replace newlines with \n
|
||||
string(REPLACE "\"" "\\\"" TEMP "${TEMP}") # Replace quotes with \"
|
||||
set(${OUTVAR} "\"${TEMP}\"" PARENT_SCOPE)
|
||||
endfunction(fastfetch_load_raw_text)
|
||||
|
||||
fastfetch_load_raw_text(src/data/help.json DATATEXT_JSON_HELP)
|
||||
fastfetch_load_text(src/data/structure.txt DATATEXT_STRUCTURE)
|
||||
fastfetch_load_text(src/data/help.txt DATATEXT_HELP)
|
||||
fastfetch_load_text(src/data/help_color.txt DATATEXT_HELP_COLOR)
|
||||
@@ -232,15 +242,6 @@ configure_file(doc/fastfetch.1.in fastfetch.1 @ONLY)
|
||||
# Ascii image data #
|
||||
####################
|
||||
|
||||
function(fastfetch_load_raw_text FILENAME OUTVAR)
|
||||
file(READ "${FILENAME}" TEMP)
|
||||
string(REGEX REPLACE "\n$" "" TEMP "${TEMP}") # Remove trailing newline
|
||||
string(REPLACE "\\" "\\\\" TEMP "${TEMP}") # Escape backslashes
|
||||
string(REPLACE "\n" "\\n" TEMP "${TEMP}") # Replace newlines with \n
|
||||
string(REPLACE "\"" "\\\"" TEMP "${TEMP}") # Replace quotes with \"
|
||||
set(${OUTVAR} "\"${TEMP}\"" PARENT_SCOPE)
|
||||
endfunction(fastfetch_load_raw_text)
|
||||
|
||||
file(GLOB LOGO_FILES "src/logo/ascii/*.txt")
|
||||
set(LOGO_BUILTIN_H "#pragma once\n\n")
|
||||
foreach(file ${LOGO_FILES})
|
||||
|
||||
+1343
File diff suppressed because it is too large
Load Diff
+4
-183
@@ -1,183 +1,4 @@
|
||||
Fastfetch is a neofetch-like tool for fetching system information and displaying them in a pretty way
|
||||
|
||||
Usage: fastfetch <?options>
|
||||
|
||||
Informative options:
|
||||
-h, --help <?command>: Show this message, or help for a specific command
|
||||
-v, --version: Show the version of fastfetch
|
||||
--list-config-paths: List search paths of config files
|
||||
--list-data-paths: List search paths of presets and logos
|
||||
--list-logos: List available logos
|
||||
--list-modules: List available modules
|
||||
--list-presets: List presets fastfetch knows about; they can be loaded with --config (+)
|
||||
--list-features: List the supported features fastfetch was compiled with (mainly for development)
|
||||
--print-logos: Print available logos
|
||||
--print-structure: Print the default structure
|
||||
|
||||
Config options:
|
||||
-c, --config <config>: Specify the config file or preset to be loaded. If "none", disable further config loading (+)
|
||||
--gen-config <?path>: Generate a config file (or print it if <path> is "-"), with options specified in the command line (if any)
|
||||
--gen-config-force <?path>: Generate a config file. Overwrite the existing one
|
||||
|
||||
General options:
|
||||
--thread <?bool>: Use separate threads to send HTTP requests
|
||||
--escape-bedrock <?bool>: On Bedrock Linux, whether to escape the bedrock jail
|
||||
--wmi-timeout <num>: Set the timeout (ms) for WMI queries. Windows only. Default is 5000
|
||||
--processing-timeout <num>: Set the timeout (ms) when waiting for child processes. Default is 1000
|
||||
--ds-force-drm <?bool>: Set if only DRM should be used to detect displays. Default is false. Linux only
|
||||
|
||||
Logo options:
|
||||
-l, --logo <logo>: Set the logo; if default, the name of a builtin logo or a path to a file
|
||||
--logo-type <str>: Set the type of the logo given; must be auto, builtin, file, file-raw, data, data-raw, raw, sixel, kitty, kitty-direct, iterm or chafa
|
||||
--logo-width <num>: Set the width of the logo (in characters), if it is an image. Required for iTerm image protocol
|
||||
--logo-height <num>: Set the height of the logo (in characters), if it is an image. Required for iTerm image protocol
|
||||
--logo-preserve-aspect-ratio <?bool>: Set if the logo should fill the specified width and height as much as possible without stretching. Supported by iTerm image protocol
|
||||
--logo-color-[1-9] <color>: Overwrite a color in the logo
|
||||
--logo-padding <num>: Set the padding on the left and the right of the logo
|
||||
--logo-padding-left <num>: Set the padding on the left of the logo
|
||||
--logo-padding-right <num>: Set the padding on the right of the logo
|
||||
--logo-padding-top <num>: Set the padding on the top of the logo
|
||||
--logo-print-remaining <?bool>: Whether to print the remaining logo, if it has more lines than modules to display
|
||||
--logo-separate <?bool>: If true, print modules at bottom of the logo
|
||||
--logo-recache <?bool>: If true, regenerate image logo cache
|
||||
--file <path>: Short for --logo-type file --logo <path>. Text file, printed with color code replacement
|
||||
--file-raw <path>: Short for --logo-type file-raw --logo <path>. Text file, printed as is (with escaped chars replacement)
|
||||
--data <data>: Short for --logo-type data --logo <data>. Text data, printed with color code replacement
|
||||
--data-raw <data>: Short for --logo-type data-raw --logo <data>. Text data, printed as is (with escaped chars replacement)
|
||||
--raw <path>: Short for --logo-type raw --logo <path>. Image file, printed as raw binary string
|
||||
--sixel <path>: Short for --logo-type sixel --logo <path>. Image file, printed as sixel codes
|
||||
--kitty <path>: Short for --logo-type kitty --logo <path>. Image file, printed as kitty graphics protocol
|
||||
--kitty-direct <path>: Short for --logo-type kitty-direct --logo <path>. Image file, tell the terminal emulator to read image data from the specified file
|
||||
--iterm <path>: Short for --logo-type iterm --logo <path>. Image file, printed as iterm graphics protocol
|
||||
--chafa <path>: Short for --logo-type chafa --logo <path>. Image file, printed as ascii art using libchafa
|
||||
--chafa-fg-only <?bool>: Produce character-cell output using foreground colors only. See chafa document for detail
|
||||
--chafa-symbols <str>: Specify character symbols to employ in final output. See chafa document for detail
|
||||
--chafa-canvas-mode <num>: Determine how colors are used in the output. This value maps the int value of enum ChafaCanvasMode. See chafa document for detail
|
||||
--chafa-color-space <num>: Set color space used for quantization. 0 for RGB; 1 for DIN99d. See chafa document for detail
|
||||
--chafa-dither-mode <num>: Set output dither mode (No effect with 24-bit color). This value maps the int value of enum ChafaDitherMode. See chafa document for detail
|
||||
|
||||
Display options:
|
||||
-s, --structure <structure>: Set the structure of the fetch. Must be a colon separated list of keys. Use "fastfetch --list-modules" to see the ones available.
|
||||
--stat <?bool>: Show time usage (in ms) for individual modules
|
||||
--pipe <?bool>: Disable logo and all escape sequences
|
||||
--color-keys <color>: Set the color of the keys
|
||||
--color-title <color>: Set the color of the title
|
||||
--color <color>: Set the color of both the keys and title
|
||||
--key-width <num>: Align the width of keys to <num> characters
|
||||
--bright-color <?bool>: Set if the keys, title and ASCII logo should be printed in bright color. Default is true
|
||||
--separator <str>: Set the separator between key and value. Default is a colon with a space
|
||||
--set <key=value>: Hard set the value of a key
|
||||
--set-keyless <key=value>: Hard set the value of a key, but don't print the key or the separator
|
||||
--show-errors <?bool>: Print occurring errors
|
||||
--disable-linewrap <?bool>: Whether to disable line wrap during the run
|
||||
--hide-cursor <?bool>: Whether to hide the cursor during the run
|
||||
--binary-prefix <str>: Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC
|
||||
--percent-type <num>: 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 9
|
||||
--percent-ndigits <num>: Set the number of digits to keep after the decimal point when formatting percentage numbers. Default is 0
|
||||
--bar-char-elapsed <str>: Set the character to use in elapsed part. Default is '■'
|
||||
--bar-char-total <str>: Set the character to use in total part. Default is '-'
|
||||
--bar-width <num>: Set the width of the bar, in number of characters. Default is 10
|
||||
--bar-border <?bool>: Whether to show a border around the bar. Default is true
|
||||
--no-buffer <?bool>: Set if the stdout application buffer should be disabled. Default is false
|
||||
--size-ndigits <num>: Set the number of digits to keep after the decimal point when formatting sizes
|
||||
--size-max-prefix <str>: Set the largest binary prefix to use when formatting sizes. Default is YB
|
||||
--temperature-unit <str>: Set the unit of the temperature. Must be one of C, F and K. Default is C
|
||||
|
||||
General module options:
|
||||
--<module>-format <format>: Set the format string to use for each specific module.
|
||||
To see how a format string works, use "fastfetch --help format".
|
||||
To see help about a specific format string, use "fastfetch --help <module>-format".
|
||||
|
||||
--<module>-key <key>: Set the key to use for each specific module.
|
||||
For modules which print multiple lines, the string is parsed as a format string with the index as first character.
|
||||
|
||||
--<module>-key-color <format>: Override the global "--color-keys" option for each specific module.
|
||||
--<module>-key-width <num>: Override the global "--key-width" option for each specific module.
|
||||
|
||||
Library path options:
|
||||
--lib-pci <path>: Pciutils. Used for GPU output
|
||||
--lib-vulkan <path>: Vulkan module & fallback for GPU output
|
||||
--lib-wayland <path>: Better display performance and output in wayland sessions
|
||||
--lib-xcb-randr <path>: X11 sessions for better display detection and faster WM detection
|
||||
--lib-xcb <path>: X11 sessions for better display detection and faster WM detection
|
||||
--lib-xrandr <path>: X11 sessions for better display detection and faster WM detection
|
||||
--lib-x11 <path>: X11 sessions for better display detection and faster WM detection
|
||||
--lib-gio <path>: Needed for values that are only stored GSettings
|
||||
--lib-dconf <path>: Needed for values that are only stored in DConf + Fallback for GSettings
|
||||
--lib-dbus <path>: Bluetooth, Player & Media detection
|
||||
--lib-xfconf <path>: Needed for XFWM theme and XFCE Terminal font
|
||||
--lib-sqlite3 <path>: Needed for pkg & rpm package count
|
||||
--lib-rpm <path>: Slower fallback for rpm package count
|
||||
--lib-imagemagick <path>: Images in terminal using sixel or kitty graphics protocol
|
||||
--lib-z <path>: Libz. Faster image output when using kitty graphics protocol
|
||||
--lib-chafa <path>: Image output as ascii art
|
||||
--lib-egl <path>: Needed by the OpenGL module for gl context creation
|
||||
--lib-glx <path>: Needed by the OpenGL module for gl context creation
|
||||
--lib-osmesa <path>: Needed by the OpenGL module for gl context creation
|
||||
--lib-opencl <path>: OpenCL module
|
||||
--lib-pulse <path>: Pulseaudio. Used for Sound detection
|
||||
--lib-nm <path>: NetworkManager. Used for Wifi detection
|
||||
--lib-freetype <path>: Used for Termux font detection
|
||||
--lib-ddcutil <path>: Used for brightness detection of external displays
|
||||
|
||||
Module specific options:
|
||||
--title-fqdn <?bool>: Set if the title should use fully qualified domain name. Default is false
|
||||
--title-color-user <color>: Set color of the user name (left part). Default is empty (use color of "--color-title").
|
||||
--title-color-at <color>: Set color of the @ symbol (middle part). Default is empty (use color of "--color-title")
|
||||
--title-color-host <color>: Set color of the host name (right part). Default is empty (use color of "--color-title")
|
||||
--chassis-use-wmi <?bool>: Set if WMI query should be used on Windows, which detects more information but slower. Default is false
|
||||
--separator-string <str>: Set the string printed by the separator module
|
||||
--os-file <path>: Set the file path which containing OS information. Linux only
|
||||
--disk-folders <path>: A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows)
|
||||
--disk-show-regular <?bool>: Set if regular volume should be printed. Default is true
|
||||
--disk-show-external <?bool>: Set if external volume should be printed. Default is true
|
||||
--disk-show-hidden <?bool>: Set if hidden volumes should be printed. Default is false
|
||||
--disk-show-subvolumes <?bool>: Set if subvolumes should be printed. Default is false
|
||||
--disk-show-readonly <?bool>: Set if read only volumes should be printed. Default is false
|
||||
--disk-show-unknown <?bool>: Set if unknown (unable to detect sizes) volumes should be printed. Default is false
|
||||
--disk-use-available <?bool>: Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false
|
||||
--diskio-name-prefix <str>: Show disks with given name prefix only. Default is empty
|
||||
--bluetooth-show-disconnected <?bool>: Set if disconnected bluetooth devices should be printed. Default is false
|
||||
--packages-winget <?bool>: Set if winget package count should be detected. Default is false
|
||||
--display-compact-type <str>: Set if all displays should be printed in one line. Must be one of "none", "original" and "scaled". Default is none
|
||||
--display-precise-refresh-rate <?bool>: Set if decimal refresh rates should not be rounded into integers when printing. Default is true
|
||||
--brightness-ddcci-sleep <num>: Set the sleep times (in ms) when sending DDC/CI requests. See <https://www.ddcutil.com/performance_options/#option-sleep-multiplier> for detail. Default is 10
|
||||
--sound-type <str>: Set what type of sound devices should be printed. Should be either main, active or all. Default is main
|
||||
--battery-dir <path>: The directory where the battery folders are. Standard: "/sys/class/power_supply/". Linux only
|
||||
--battery-use-setup-api <?bool>: Set if "SetupAPI" should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only
|
||||
--cpu-temp <?bool>: Detect and display CPU temperature if supported. Default is false
|
||||
--cpu-freq-ndigits <num>: Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2
|
||||
--cpuusage-separate <?bool>: Display CPU usage per CPU logical core, instead of an average result. Default is false
|
||||
--de-slow-version-detection <?bool>: Set if DE version should be detected with slow operations. Default is false
|
||||
--gpu-temp <?bool>: Detect and display GPU temperature if supported. Default is false
|
||||
--gpu-use-nvml <?bool>: Use nvml (NVIDIA Management Library) to detect more detailed GPU information (memory usage, CUDA core count, etc). Default is false
|
||||
--gpu-force-vulkan <?bool>: Force using vulkan to detect GPUs, which support video memory usage detection with "--allow-slow-operations". Default is false
|
||||
--gpu-hide-type <?bool>: Specify the type of GPUs should not be printed. Must be "integrated", "discrete" or "none". Default is none
|
||||
--battery-temp <?bool>: Detect and display Battery temperature if supported. Default is false
|
||||
--localip-show-ipv4 <?bool>: Show IPv4 addresses in local ip module. Default is true
|
||||
--localip-show-ipv6 <?bool>: Show IPv6 addresses in local ip module. Default is false
|
||||
--localip-show-mac <?bool>: Show mac addresses in local ip module. Default is false
|
||||
--localip-show-loop <?bool>: Show loop back addresses (127.0.0.1) in local ip module. Default is false
|
||||
--localip-name-prefix <str>: Show interfaces with given interface name prefix only. Default is empty
|
||||
--localip-default-route-only <?bool>: Show the interface that is used for default routing only. Default is true on non-android platforms
|
||||
--localip-compact <?bool>: Show all IPs in one line. Default is false
|
||||
--netio-name-prefix <str>: Show interfaces with given name prefix only. Default is empty
|
||||
--netio-default-route-only <?bool>: Show the interfac that is used for default routing only. Default is true on non-android platforms
|
||||
--publicip-timeout <num>: Time in milliseconds to wait for the public ip server to respond. Default is disabled (0)
|
||||
--publicip-url <str>: The URL of public IP detection server to be used.
|
||||
--weather-location <str>: Set the location to be used. It must be URI encoded (eg a whitespace must be encoded as "+").
|
||||
--weather-timeout <num>: Time in milliseconds to wait for the weather server to respond. Default is disabled (0)
|
||||
--weather-output-format <str>: The output weather format to be used. It must be URI encoded.
|
||||
--wm-detect-plugin <?bool>: Set if window manager plugin should be detected on supported platforms. Default is false
|
||||
--player-name <str>: The name of the player to use for module Media and Player. Linux only
|
||||
--opengl-library <str>: Set the OpenGL context creation library to use. Must be auto, egl, glx or osmesa. Default is auto
|
||||
--command-shell <str>: Set the shell program to execute the command text. Default is cmd for Windows, /bin/sh for *nix
|
||||
--command-key <str>: Set the module key to display
|
||||
--command-text <str>: Set the command text to be executed
|
||||
--colors-symbol <str>: Set the symbol to be printed by Colors module. Default is block
|
||||
--colors-padding-left <num>: Set the number of white spaces to print before the symbol. Default is 0
|
||||
|
||||
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.
|
||||
A (+) at the end indicates that more help can be printed with --help <option>
|
||||
All options can be made permanent with command "fastfetch <options> --gen-config"
|
||||
1. Parsing is not case sensitive. E.g. "--lib-PCI" is equal to "--Lib-Pci"
|
||||
2. If a value starts with a ?, it is optional. An optional boolean value defaults to true if not specified.
|
||||
3. More help can be printed with "-h <option>"
|
||||
4. All options can be made permanent with command "fastfetch <options> --gen-config"
|
||||
|
||||
+129
-88
@@ -1,4 +1,5 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/color.h"
|
||||
#include "common/commandoption.h"
|
||||
#include "common/printing.h"
|
||||
#include "common/parsing.h"
|
||||
@@ -38,102 +39,142 @@ static void printCommandFormatHelp(const char* command)
|
||||
fprintf(stderr, "Error: Module '%s' is not supported\n", type.chars);
|
||||
}
|
||||
|
||||
static void printFullHelp()
|
||||
{
|
||||
fputs("Fastfetch is a neofetch-like tool for fetching system information and displaying them in a pretty way\n\n", stdout);
|
||||
if (!instance.config.display.pipe)
|
||||
fputs("\e[" FF_COLOR_MODE_BOLD FF_COLOR_MODE_UNDERLINE "mUsage:\e[" FF_COLOR_MODE_RESET "m \e[" FF_COLOR_MODE_BOLD "mfastfetch\e[" FF_COLOR_MODE_RESET "m \e[" FF_COLOR_MODE_ITALIC "m<?options>\e[" FF_COLOR_MODE_RESET "m\n\n", stdout);
|
||||
else
|
||||
fputs("Usage: fastfetch <?options>\n\n", stdout);
|
||||
|
||||
yyjson_doc* doc = yyjson_read(FASTFETCH_DATATEXT_JSON_HELP, strlen(FASTFETCH_DATATEXT_JSON_HELP), YYJSON_READ_NOFLAG);
|
||||
assert(doc);
|
||||
yyjson_val *groupKey, *flagArr;
|
||||
size_t groupIdx, groupMax;
|
||||
yyjson_obj_foreach(yyjson_doc_get_root(doc), groupIdx, groupMax, groupKey, flagArr)
|
||||
{
|
||||
if (!instance.config.display.pipe)
|
||||
fputs("\e[" FF_COLOR_MODE_BOLD FF_COLOR_MODE_UNDERLINE "m", stdout);
|
||||
printf("%s options:", yyjson_get_str(groupKey));
|
||||
if (!instance.config.display.pipe)
|
||||
fputs("\e[" FF_COLOR_MODE_RESET "m", stdout);
|
||||
putchar('\n');
|
||||
|
||||
yyjson_val* flagObj;
|
||||
size_t flagIdx, flagMax;
|
||||
yyjson_arr_foreach(flagArr, flagIdx, flagMax, flagObj)
|
||||
{
|
||||
yyjson_val* shortKey = yyjson_obj_get(flagObj, "short");
|
||||
if (shortKey)
|
||||
{
|
||||
fputs(" ", stdout);
|
||||
if (!instance.config.display.pipe)
|
||||
fputs("\e[" FF_COLOR_MODE_BOLD "m", stdout);
|
||||
printf("-%s", yyjson_get_str(shortKey));
|
||||
if (!instance.config.display.pipe)
|
||||
fputs("\e[" FF_COLOR_MODE_RESET "m", stdout);
|
||||
fputs(", ", stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
yyjson_val* longKey = yyjson_obj_get(flagObj, "long");
|
||||
assert(longKey);
|
||||
if (!instance.config.display.pipe)
|
||||
fputs("\e[" FF_COLOR_MODE_BOLD "m", stdout);
|
||||
printf("--%s", yyjson_get_str(longKey));
|
||||
if (!instance.config.display.pipe)
|
||||
fputs("\e[" FF_COLOR_MODE_RESET "m", stdout);
|
||||
|
||||
yyjson_val* argObj = yyjson_obj_get(flagObj, "arg");
|
||||
if (argObj)
|
||||
{
|
||||
yyjson_val* typeKey = yyjson_obj_get(argObj, "type");
|
||||
assert(typeKey);
|
||||
yyjson_val* optionalKey = yyjson_obj_get(argObj, "optional");
|
||||
bool optional = optionalKey && yyjson_get_bool(optionalKey);
|
||||
putchar(' ');
|
||||
if (!instance.config.display.pipe)
|
||||
fputs("\e[" FF_COLOR_MODE_ITALIC "m", stdout);
|
||||
printf("<%s%s>", optional ? "?" : "", yyjson_get_str(typeKey));
|
||||
if (!instance.config.display.pipe)
|
||||
fputs("\e[" FF_COLOR_MODE_RESET "m", stdout);
|
||||
}
|
||||
|
||||
yyjson_val* descKey = yyjson_obj_get(flagObj, "desc");
|
||||
assert(descKey);
|
||||
if (yyjson_is_arr(descKey))
|
||||
{
|
||||
if (instance.config.display.pipe)
|
||||
putchar(':');
|
||||
|
||||
yyjson_val* descStr;
|
||||
size_t descIdx, descMax;
|
||||
yyjson_arr_foreach(descKey, descIdx, descMax, descStr)
|
||||
{
|
||||
if (!instance.config.display.pipe)
|
||||
printf("\e[46G%s\n", yyjson_get_str(descStr));
|
||||
else
|
||||
printf(" %s", yyjson_get_str(descStr));
|
||||
}
|
||||
if (instance.config.display.pipe)
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!instance.config.display.pipe)
|
||||
fputs("\e[46G", stdout);
|
||||
else
|
||||
fputs(": ", stdout);
|
||||
puts(yyjson_get_str(descKey));
|
||||
}
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
yyjson_doc_free(doc);
|
||||
}
|
||||
|
||||
static bool printSpecificCommandHelp(const char* command)
|
||||
{
|
||||
yyjson_doc* doc = yyjson_read(FASTFETCH_DATATEXT_JSON_HELP, strlen(FASTFETCH_DATATEXT_JSON_HELP), YYJSON_READ_NOFLAG);
|
||||
assert(doc);
|
||||
yyjson_val *groupKey, *flagArr;
|
||||
size_t groupIdx, groupMax;
|
||||
yyjson_obj_foreach(yyjson_doc_get_root(doc), groupIdx, groupMax, groupKey, flagArr)
|
||||
{
|
||||
yyjson_val* flagObj;
|
||||
size_t flagIdx, flagMax;
|
||||
yyjson_arr_foreach(flagArr, flagIdx, flagMax, flagObj)
|
||||
{
|
||||
yyjson_val* pseudo = yyjson_obj_get(flagObj, "pseudo");
|
||||
if (pseudo && yyjson_get_bool(pseudo))
|
||||
continue;
|
||||
|
||||
yyjson_val* longKey = yyjson_obj_get(flagObj, "long");
|
||||
assert(longKey);
|
||||
if (ffStrEqualsIgnCase(command, yyjson_get_str(longKey)))
|
||||
{
|
||||
printf("Usage: --%s\n", command);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void printCommandHelp(const char* command)
|
||||
{
|
||||
if(command == NULL)
|
||||
{
|
||||
static char input[] = FASTFETCH_DATATEXT_HELP;
|
||||
if (!instance.config.display.pipe)
|
||||
{
|
||||
char* token = strtok(input, "\n");
|
||||
puts(token);
|
||||
|
||||
while ((token = strtok(NULL, "\n")))
|
||||
{
|
||||
// handle empty lines
|
||||
char* back = token;
|
||||
while (*--back != '\0');
|
||||
ffPrintCharTimes('\n', (uint32_t) (token - back - 1));
|
||||
|
||||
if (isalpha(*token)) // highlight subjects
|
||||
{
|
||||
char* colon = strchr(token, ':');
|
||||
if (colon)
|
||||
{
|
||||
fputs("\e[1;4m", stdout); // Bold + Underline
|
||||
fwrite(token, 1, (uint32_t) (colon - token), stdout);
|
||||
fputs("\e[m", stdout);
|
||||
|
||||
if (colon - token == 5 && memcmp(token, "Usage", 5) == 0)
|
||||
{
|
||||
char* cmd = strstr(colon, "fastfetch ");
|
||||
if (cmd)
|
||||
{
|
||||
fwrite(colon, 1, (uint32_t) (cmd - colon), stdout);
|
||||
fputs("\e[1mfastfetch \e[m", stdout);
|
||||
cmd += strlen("fastfetch ");
|
||||
if (*cmd == '<')
|
||||
{
|
||||
char* gt = strchr(cmd, '>');
|
||||
if (gt)
|
||||
{
|
||||
fputs("\e[3m", stdout);
|
||||
fwrite(cmd, 1, (uint32_t) (gt - cmd + 1), stdout);
|
||||
fputs("\e[m", stdout);
|
||||
cmd = gt + 1;
|
||||
}
|
||||
}
|
||||
puts(cmd);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
puts(colon);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (*token == ' ') // highlight options. All options are indented
|
||||
{
|
||||
char* dash = strchr(token, '-'); // start of an option
|
||||
if (dash)
|
||||
{
|
||||
char* colon = strchr(dash, ':'); // end of an option
|
||||
if (colon)
|
||||
{
|
||||
*colon = '\0';
|
||||
char* lt = strrchr(dash, '<');
|
||||
*colon = ':';
|
||||
fputs("\e[1m", stdout); // Bold
|
||||
fwrite(token, 1, (uint32_t) ((lt ? lt : colon) - token), stdout);
|
||||
fputs("\e[m", stdout);
|
||||
if (lt)
|
||||
{
|
||||
fputs("\e[3m", stdout);
|
||||
fwrite(lt, 1, (uint32_t) (colon - lt), stdout);
|
||||
fputs("\e[m", stdout);
|
||||
}
|
||||
puts(colon);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
puts(token);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
puts(input);
|
||||
}
|
||||
}
|
||||
printFullHelp();
|
||||
else if(ffStrEqualsIgnCase(command, "color"))
|
||||
puts(FASTFETCH_DATATEXT_HELP_COLOR);
|
||||
else if(ffStrEqualsIgnCase(command, "format"))
|
||||
puts(FASTFETCH_DATATEXT_HELP_FORMAT);
|
||||
else if(ffStrEqualsIgnCase(command, "config"))
|
||||
puts(FASTFETCH_DATATEXT_HELP_CONFIG);
|
||||
else if(isalpha(command[0]) && ffStrEndsWithIgnCase(command, "-format")) // x-format
|
||||
else if(isalpha(command[0]) && ffStrEndsWithIgnCase(command, "-format")) // <module>-format
|
||||
printCommandFormatHelp(command);
|
||||
else
|
||||
else if(!printSpecificCommandHelp(command))
|
||||
fprintf(stderr, "Error: No specific help for command '%s' provided\n", command);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#ifndef FASTFETCH_INDLUDED_fastfetch_datatext_h_in
|
||||
#define FASTFETCH_INDLUDED_fastfetch_datatext_h_in
|
||||
|
||||
#define FASTFETCH_DATATEXT_JSON_HELP @DATATEXT_JSON_HELP@
|
||||
#define FASTFETCH_DATATEXT_STRUCTURE "@DATATEXT_STRUCTURE@"
|
||||
#define FASTFETCH_DATATEXT_HELP "@DATATEXT_HELP@"
|
||||
#define FASTFETCH_DATATEXT_HELP_COLOR "@DATATEXT_HELP_COLOR@"
|
||||
|
||||
Reference in New Issue
Block a user