Global: improve support of --help *-format

Also fix some bugs found when refactoring
This commit is contained in:
李通洲
2023-10-07 13:40:40 +08:00
parent 23d2cc3fdc
commit 12208b2c7c
113 changed files with 746 additions and 557 deletions
+18 -495
View File
@@ -21,22 +21,23 @@
#include "modules/modules.h"
static void constructAndPrintCommandHelpFormat(const char* name, const char* def, uint32_t numArgs, ...)
static void printCommandFormatHelp(const char* command)
{
va_list argp;
va_start(argp, numArgs);
FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateNS((uint32_t) (strlen(command) - strlen("-format")), command);
for (FFModuleBaseInfo** modules = ffModuleInfos[toupper(command[0]) - 'A']; *modules; ++modules)
{
FFModuleBaseInfo* baseInfo = *modules;
if (ffStrbufIgnCaseEqualS(&type, baseInfo->name))
{
if (baseInfo->printHelpFormat)
baseInfo->printHelpFormat();
else
fprintf(stderr, "Error: Module '%s' doesn't support output formatting\n", baseInfo->name);
return;
}
}
printf("--%s-format:\n", name);
printf("Sets the format string for %s output.\n", name);
puts("To see how a format string is constructed, take a look at \"fastfetch --help format\".");
puts("The following values are passed:");
for(uint32_t i = 1; i <= numArgs; i++)
printf(" {%u}: %s\n", i, va_arg(argp, const char*));
printf("The default is something similar to \"%s\".\n", def);
va_end(argp);
fprintf(stderr, "Error: Module '%s' is not supported\n", type.chars);
}
static inline void printCommandHelp(const char* command)
@@ -49,488 +50,10 @@ static inline void printCommandHelp(const char* command)
puts(FASTFETCH_DATATEXT_HELP_FORMAT);
else if(ffStrEqualsIgnCase(command, "load-config") || ffStrEqualsIgnCase(command, "config"))
puts(FASTFETCH_DATATEXT_HELP_CONFIG);
else if(ffStrEqualsIgnCase(command, "title-format"))
{
constructAndPrintCommandHelpFormat("title", "{6}{7}{8}", 8,
"User name",
"Host name",
"Home directory",
"Executable path of current process",
"User's default shell",
"User name (colored)",
"@ symbol (colored)",
"Host name (colored)"
);
}
else if(ffStrEqualsIgnCase(command, "os-format"))
{
constructAndPrintCommandHelpFormat("os", "{3} {12}", 12,
"System name (typically just Linux)",
"Name of the OS",
"Pretty name of the OS",
"ID of the OS",
"ID like of the OS",
"Variant of the OS",
"Variant ID of the OS",
"Version of the OS",
"Version ID of the OS",
"Version codename of the OS",
"Build ID of the OS",
"Architecture of the OS"
);
}
else if(ffStrEqualsIgnCase(command, "host-format"))
{
constructAndPrintCommandHelpFormat("host", "{2} {3}", 8,
"product family",
"product name",
"product version",
"product sku",
"chassis type",
"chassis vendor",
"chassis version",
"sys vendor"
);
}
else if(ffStrEqualsIgnCase(command, "bios-format"))
{
constructAndPrintCommandHelpFormat("bios", "{4} ({2})", 4,
"bios date",
"bios release",
"bios vendor",
"bios version"
);
}
else if(ffStrEqualsIgnCase(command, "board-format"))
{
constructAndPrintCommandHelpFormat("board", "{1} ({3})", 3,
"board name",
"board vendor",
"board version"
);
}
else if(ffStrEqualsIgnCase(command, "chassis-format"))
{
constructAndPrintCommandHelpFormat("chassis", "{1}", 3,
"chassis type",
"chassis vendor",
"chassis version"
);
}
else if(ffStrEqualsIgnCase(command, "kernel-format"))
{
constructAndPrintCommandHelpFormat("kernel", "{2}", 3,
"Kernel sysname",
"Kernel release",
"Kernel version"
);
}
else if(ffStrEqualsIgnCase(command, "uptime-format"))
{
constructAndPrintCommandHelpFormat("uptime", "{1} days {2} hours {3} mins", 4,
"Days",
"Hours",
"Minutes",
"Seconds"
);
}
else if(ffStrEqualsIgnCase(command, "processes-format"))
{
constructAndPrintCommandHelpFormat("processes", "{1}", 1,
"Count"
);
}
else if(ffStrEqualsIgnCase(command, "packages-format"))
{
constructAndPrintCommandHelpFormat("packages", "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (emerge), {7} (eopkg), {8} (xbps), {9} (nix-system), {10} (nix-user), {11} (nix-default), {12} (apk), {13} (pkg), {14} (flatpak-system), {15} (flatpack-user), {16} (snap), {17} (brew), {18} (brew-cask), {19} (port), {20} (scoop), {21} (choco), {22} (pkgtool), {23} (paludis), {24} (winget)", 24,
"Number of all packages",
"Number of pacman packages",
"Pacman branch on manjaro",
"Number of dpkg packages",
"Number of rpm packages",
"Number of emerge packages",
"Number of eopkg packages",
"Number of xbps packages",
"Number of nix-system packages",
"Number of nix-user packages",
"Number of nix-default packages",
"Number of apk packages",
"Number of pkg packages",
"Number of flatpak-system packages",
"Number of flatpak-user packages",
"Number of snap packages",
"Number of brew packages",
"Number of brew-cask packages",
"Number of macports packages",
"Number of scoop packages",
"Number of choco packages",
"Number of pkgtool packages",
"Number of paludis packages"
"Number of winget packages"
);
}
else if(ffStrEqualsIgnCase(command, "shell-format"))
{
constructAndPrintCommandHelpFormat("shell", "{3} {4}", 6,
"Shell process name",
"Shell path with exe name",
"Shell exe name",
"Shell version",
"Shell pid",
"Shell pretty name"
);
}
else if(ffStrEqualsIgnCase(command, "display-format"))
{
constructAndPrintCommandHelpFormat("display", "{1}x{2} @ {3}Hz", 8,
"Screen width",
"Screen height",
"Screen refresh rate",
"Screen scaled width",
"Screen scaled height",
"Screen name",
"Screen type",
"Screen rotation"
);
}
else if(ffStrEqualsIgnCase(command, "brightness-format"))
{
constructAndPrintCommandHelpFormat("brightness", "{}", 2,
"Screen brightness",
"Screen name"
);
}
else if(ffStrEqualsIgnCase(command, "monitor-format"))
{
constructAndPrintCommandHelpFormat("monitor", "{2}x{3} px - {4}x{5} mm ({6} inches, {7} ppi)", 7,
"Display name",
"Display native resolution width in pixels",
"Display native resolution height in pixels",
"Display physical width in millimeters",
"Display physical height in millimeters",
"Display physical diagonal length in inches",
"Display physical pixels per inch (PPI)"
);
}
else if(ffStrEqualsIgnCase(command, "de-format"))
{
constructAndPrintCommandHelpFormat("de", "{2} {3}", 3,
"DE process name",
"DE pretty name",
"DE version"
);
}
else if(ffStrEqualsIgnCase(command, "wm-format"))
{
constructAndPrintCommandHelpFormat("wm", "{2} ({3})", 3,
"WM process name",
"WM pretty name",
"WM protocol name"
);
}
else if(ffStrEqualsIgnCase(command, "wmtheme-format"))
{
constructAndPrintCommandHelpFormat("wmtheme", "{1}", 1,
"WM theme name"
);
}
else if(ffStrEqualsIgnCase(command, "theme-format"))
{
constructAndPrintCommandHelpFormat("theme", "{1}", 1,
"Combined themes"
);
}
else if(ffStrEqualsIgnCase(command, "icons-format"))
{
constructAndPrintCommandHelpFormat("icons", "{1}", 1,
"Combined icons"
);
}
else if(ffStrEqualsIgnCase(command, "wallpaper-format"))
{
constructAndPrintCommandHelpFormat("wallpaper", "{1}", 1,
"Wallpaper image file"
);
}
else if(ffStrEqualsIgnCase(command, "font-format"))
{
constructAndPrintCommandHelpFormat("font", "{1} [QT], {2} [GTK2], {3} [GTK3], {4} [GTK4]", 4,
"Font 1",
"Font 2",
"Font 3",
"Font 4"
);
}
else if(ffStrEqualsIgnCase(command, "cursor-format"))
{
constructAndPrintCommandHelpFormat("cursor", "{1}", 2,
"Cursor theme",
"Cursor size"
);
}
else if(ffStrEqualsIgnCase(command, "terminal-format"))
{
constructAndPrintCommandHelpFormat("terminal", "{5} {6}", 6,
"Terminal process name",
"Terminal path with exe name",
"Terminal exe name",
"Terminal pid",
"Terminal pretty name",
"Terminal version"
);
}
else if(ffStrEqualsIgnCase(command, "terminalfont-format"))
{
constructAndPrintCommandHelpFormat("terminalfont", "{1}", 4,
"Terminal font",
"Terminal font name",
"Termianl font size",
"Terminal font styles"
);
}
else if(ffStrEqualsIgnCase(command, "cpu-format"))
{
constructAndPrintCommandHelpFormat("cpu", "{1} ({5}) @ {7} GHz", 8,
"Name",
"Vendor",
"Physical core count",
"Logical core count",
"Online core count",
"Min frequency",
"Max frequency",
"Temperature"
);
}
else if(ffStrEqualsIgnCase(command, "cpuusage-format"))
{
constructAndPrintCommandHelpFormat("cpuusage", "{1}", 1,
"CPU usage without percent mark"
);
}
else if(ffStrEqualsIgnCase(command, "gpu-format"))
{
constructAndPrintCommandHelpFormat("gpu", "{1} {2}", 6,
"GPU vendor",
"GPU name",
"GPU driver",
"GPU temperature",
"GPU core count",
"GPU type"
);
}
else if(ffStrEqualsIgnCase(command, "memory-format"))
{
constructAndPrintCommandHelpFormat("memory", "{1} / {2} ({3})", 3,
"Used size",
"Total size",
"Percentage used"
);
}
else if(ffStrEqualsIgnCase(command, "swap-format"))
{
constructAndPrintCommandHelpFormat("swap", "{1} / {2} ({3})", 3,
"Used size",
"Total size",
"Percentage used"
);
}
else if(ffStrEqualsIgnCase(command, "disk-format"))
{
constructAndPrintCommandHelpFormat("disk", "{1} / {2} ({3}) - {9}", 9,
"Size used",
"Size total",
"Size percentage",
"Files used",
"Files total",
"Files percentage",
"True if external volume",
"True if hidden volume",
"Filesystem"
);
}
else if(ffStrEqualsIgnCase(command, "battery-format"))
{
constructAndPrintCommandHelpFormat("battery", "{}%, {}", 5,
"Battery manufactor",
"Battery model",
"Battery technology",
"Battery capacity",
"Battery status"
);
}
else if(ffStrEqualsIgnCase(command, "poweradapter-format"))
{
constructAndPrintCommandHelpFormat("poweradapter", "{}%, {}", 5,
"PowerAdapter watts",
"PowerAdapter name",
"PowerAdapter manufacturer",
"PowerAdapter model",
"PowerAdapter description"
);
}
else if(ffStrEqualsIgnCase(command, "lm-format"))
{
constructAndPrintCommandHelpFormat("lm", "{1} {3} ({2})", 3,
"LM service",
"LM type",
"LM version"
);
}
else if(ffStrEqualsIgnCase(command, "locale-format"))
{
constructAndPrintCommandHelpFormat("locale", "{1}", 1,
"Locale code"
);
}
else if(ffStrEqualsIgnCase(command, "localip-format"))
{
constructAndPrintCommandHelpFormat("localip", "{1}{5}", 5,
"Local IPv4 address",
"Local IPv6 address",
"Physical (MAC) address",
"Interface name",
"Is default route"
);
}
else if(ffStrEqualsIgnCase(command, "publicip-format"))
{
constructAndPrintCommandHelpFormat("publicip", "{1} ({2})", 2,
"Public IP address",
"Location"
);
}
else if(ffStrEqualsIgnCase(command, "netio-format"))
{
constructAndPrintCommandHelpFormat("netio", "{1} (IN) - {2} (OUT){4}", 4,
"Size of data received per second (formatted)",
"Size of data sent per second (formatted)",
"Interface name",
"Is default route"
);
}
else if(ffStrEqualsIgnCase(command, "wifi-format"))
{
constructAndPrintCommandHelpFormat("wifi", "{4} - {10}", 10,
"Interface description",
"Interface status",
"Connection status",
"Connection SSID",
"Connection mac address",
"Connection protocol",
"Connection signal quality (percentage)",
"Connection RX rate",
"Connection TX rate",
"Connection Security algorithm"
);
}
else if(ffStrEqualsIgnCase(command, "player-format"))
{
constructAndPrintCommandHelpFormat("player", "{}", 4,
"Pretty player name",
"Player name",
"Player Identifier",
"URL name"
);
}
else if(ffStrEqualsIgnCase(command, "media-format"))
{
constructAndPrintCommandHelpFormat("media", "{3} - {1}", 4,
"Pretty media name",
"Media name",
"Artist name",
"Album name"
);
}
else if(ffStrEqualsIgnCase(command, "datetime-format"))
{
constructAndPrintCommandHelpFormat("[date][time]", "{1}-{4}-{11} {14}:{18}:{20}", 20,
"year",
"last two digits of year",
"month",
"month with leading zero",
"month name",
"month name short",
"week number on year",
"weekday",
"weekday short",
"day in year",
"day in month",
"day in Week",
"hour",
"hour with leading zero",
"hour 12h format",
"hour 12h format with leading zero",
"minute",
"minute with leading zero",
"second",
"second with leading zero"
);
}
else if(ffStrEqualsIgnCase(command, "version-format"))
{
constructAndPrintCommandHelpFormat("version", "{1} {2}{3} ({5})", 9,
"Project name",
"Version",
"Version tweak",
"Build type (debug or release)",
"Architecture",
"CMake build type (Debug, Release, RelWithDebInfo, MinSizeRel)",
"Date time when compiling",
"Compiler used"
);
}
else if(ffStrEqualsIgnCase(command, "vulkan-format"))
{
constructAndPrintCommandHelpFormat("vulkan", "{} (driver), {} (api version)", 3,
"Driver name",
"API version",
"Conformance version"
);
}
else if(ffStrEqualsIgnCase(command, "opengl-format"))
{
constructAndPrintCommandHelpFormat("opengl", "{1}", 4,
"version",
"renderer",
"vendor",
"shading language version"
);
}
else if(ffStrEqualsIgnCase(command, "opencl-format"))
{
constructAndPrintCommandHelpFormat("opencl", "{}", 3,
"version",
"device",
"vendor"
);
}
else if(ffStrEqualsIgnCase(command, "bluetooth-format"))
{
constructAndPrintCommandHelpFormat("bluetooth", "{1} (4%)", 4,
"Name",
"Address",
"Type",
"Battery percentage"
);
}
else if(ffStrEqualsIgnCase(command, "sound-format"))
{
constructAndPrintCommandHelpFormat("sound", "{2} ({3}%)", 4,
"Main",
"Name",
"Volume",
"Identifier"
);
}
else if(ffStrEqualsIgnCase(command, "gamepad-format"))
{
constructAndPrintCommandHelpFormat("gamepad", "{1}", 2,
"Name",
"Identifier"
);
}
else if(isalpha(command[0]) && ffStrEndsWithIgnCase(command, "-format")) // x-format
printCommandFormatHelp(command);
else
fprintf(stderr, "No specific help for command '%s' provided\n", command);
fprintf(stderr, "Error: No specific help for command '%s' provided\n", command);
}
static void listAvailablePresets(void)