format options for every output!

This commit is contained in:
Linus Dierheimer
2021-03-19 20:57:07 +01:00
parent 5c6bbbf677
commit 1ceb5c91ac
34 changed files with 1500 additions and 695 deletions
+2 -1
View File
@@ -33,6 +33,7 @@ include_directories(
set(SRCS
src/common.c
src/logo.c
src/util/FFstrbuf.c
src/modules/break.c
src/modules/custom.c
src/modules/title.c
@@ -44,7 +45,7 @@ set(SRCS
src/modules/packages.c
src/modules/shell.c
src/modules/resolution.c
src/modules/desktopenvironment.c
src/modules/de.c
src/modules/wm.c
src/modules/theme.c
src/modules/icons.c
+1 -1
View File
@@ -14,7 +14,7 @@ At the moment the performance difference is measurable, but too small to be huma
## Supported logos
Currently, `fastfetch` supports the `Arch` and the `Artix` logos only. Unknown/unsupported logos will be replaced with a question mark when running fastfetch. To add a new logo, edit [`src/logos.c`](src/logos.c).
Currently, `fastfetch` supports the `Arch` and the `Artix` logos only. Unknown/unsupported logos will be replaced with a question mark when running fastfetch. To add a new logo, edit [`src/logos.c`](src/logo.c).
## Dependencies
+36 -17
View File
@@ -6,8 +6,22 @@ __fastfetch_complete_help()
"color"
"os-format"
"host-format"
"kernel-format"
"packages-format"
"shell-format"
"resolution-format"
"de-format"
"wm-format"
"theme-format"
"icons-format"
"terminal-format"
"terminal-font-format"
"cpu-format"
"gpu-format"
"memory-format"
"disk-format"
"battery-format"
"locale-format"
)
COMPREPLY=($(compgen -W "${__ff_helps[*]}" -- "$CURRENT_WORD"))
}
@@ -95,16 +109,6 @@ __fastfetch_completion()
"--recache"
"--show-errors"
"--color-logo"
"--os-architecture"
"--host-version"
"--kernel-release"
"--kernel-version"
"--packages-combined"
"--packages-combined-names"
"--packages-pacman"
"--packages-flatpak"
"--shell-path"
"--resolution-refreshrate"
"--battery-manufacturer"
"--battery-model"
"--battery-technology"
@@ -120,18 +124,33 @@ __fastfetch_completion()
"--seperator"
"-x"
"--offsetx"
"--os-format"
"--host-format"
"--packages-format"
"--resolution-format"
"--battery-format"
"--structure"
"--set"
"--os-format"
"--host-format"
"--kernel-format"
"--uptime-format"
"--packages-format"
"--shell-format"
"--resolution-format"
"--de-format"
"--wm-format"
"--theme-format"
"--icons-format"
"--terminal-format"
"--terminal-font-format"
"--cpu-format"
"--gpu-format"
"--memory-format"
"--disk-format"
"--battery-format"
"--locale-format"
)
local FF_OPTIONS_PATH=(
"--resolution-libX11"
"--resolution-libXrandr"
"--lib-PCI"
"--lib-X11"
"--lib-Xrandr"
)
local FF_OPTIONS_LOGO=(
+169 -55
View File
@@ -5,6 +5,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdarg.h>
void ffInitState(FFstate* state)
{
@@ -12,15 +13,17 @@ void ffInitState(FFstate* state)
state->passwd = getpwuid(getuid());
uname(&state->utsname);
sysinfo(&state->sysinfo);
state->terminal.value = NULL;
ffStrbufInit(&state->terminal.value);
state->terminal.error = NULL;
state->terminal.calculated = false;
}
void ffDefaultConfig(FFconfig* config)
{
config->color[0] = '\0';
ffStrbufInit(&config->color);
config->logo_spacer = 4;
strcpy(config->seperator, ": ");
ffStrbufInitS(&config->seperator, ": ");
config->offsetx = 0;
config->titleLength = 20; // This is overwritten by ffPrintTitle
config->colorLogo = true;
@@ -28,39 +31,35 @@ void ffDefaultConfig(FFconfig* config)
config->recache = false;
config->cacheSave = true;
config->osShowArchitecture = true;
config->osFormat[0] = '\0';
ffStrbufInit(&config->osFormat);
ffStrbufInit(&config->hostFormat);
ffStrbufInit(&config->kernelFormat);
ffStrbufInit(&config->uptimeFormat);
ffStrbufInit(&config->packagesFormat);
ffStrbufInit(&config->shellFormat);
ffStrbufInit(&config->resolutionFormat);
ffStrbufInit(&config->deFormat);
ffStrbufInit(&config->wmFormat);
ffStrbufInit(&config->themeFormat);
ffStrbufInit(&config->iconsFormat);
ffStrbufInit(&config->fontFormat);
ffStrbufInit(&config->terminalFormat);
ffStrbufInit(&config->termFontFormat);
ffStrbufInit(&config->cpuFormat);
ffStrbufInit(&config->gpuFormat);
ffStrbufInit(&config->memoryFormat);
ffStrbufInit(&config->diskFormat);
ffStrbufInit(&config->batteryFormat);
ffStrbufInit(&config->localeFormat);
config->hostShowVersion = true;
config->hostFormat[0] = '\0';
config->kernelShowRelease = true;
config->kernelShowVersion = false;
config->packagesCombined = false;
config->packagesCombinedNames = true;
config->packagesShowPacman = true;
config->packagesShowFlatpak = true;
config->packagesFormat[0] = '\0';
config->shellShowPath = false;
config->resolutionShowRefreshRate = true;
config->resolutionLibX11[0] = '\0';
config->resolutionLibXrandr[0] = '\0';
config->resolutionFormat[0] = '\0';
config->batteryShowManufacturer = true;
config->batteryShowModel = true;
config->batteryShowTechnology = true;
config->batteryShowCapacity = true;
config->batteryShowStatus = true;
config->batteryFormat[0] = '\0';
ffStrbufInitA(&config->libPCI, 256);
ffStrbufInitA(&config->libX11, 256);
ffStrbufInitA(&config->libXrandr, 256);
}
void ffPrintKey(FFconfig* config, const char* key)
{
printf(FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"%s", config->color, key, config->seperator);
printf(FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"%s", config->color.chars, key, config->seperator.chars);
}
void ffPrintLogoAndKey(FFinstance* instance, const char* key)
@@ -105,44 +104,44 @@ static inline bool strSet(const char* str)
return str != NULL && str[0] != '\0';
}
void ffPrintGtkPretty(const char* gtk2, const char* gtk3, const char* gtk4)
void ffFormatGtkPretty(FFstrbuf* buffer, const char* gtk2, const char* gtk3, const char* gtk4)
{
if(strSet(gtk2) && strSet(gtk3) && strSet(gtk4))
{
if((strcmp(gtk2, gtk3) == 0) && (strcmp(gtk2, gtk4) == 0))
printf("%s [GTK2/3/4]", gtk2);
ffStrbufSetF(buffer, "%s [GTK2/3/4]", gtk2);
else if(strcmp(gtk2, gtk3) == 0)
printf("%s [GTK2/3], %s [GTK4]", gtk2, gtk4);
ffStrbufSetF(buffer, "%s [GTK2/3], %s [GTK4]", gtk2, gtk4);
else if(strcmp(gtk3, gtk4) == 0)
printf("%s [GTK2], %s [GTK3/4]", gtk2, gtk3);
ffStrbufSetF(buffer, "%s [GTK2], %s [GTK3/4]", gtk2, gtk3);
else
printf("%s [GTK2], %s [GTK3], %s [GTK4]", gtk2, gtk3, gtk4);
ffStrbufSetF(buffer, "%s [GTK2], %s [GTK3], %s [GTK4]", gtk2, gtk3, gtk4);
}
else if(strSet(gtk2) && strSet(gtk3))
{
if(strcmp(gtk2, gtk3) == 0)
printf("%s [GTK2/3]", gtk2);
ffStrbufSetF(buffer, "%s [GTK2/3]", gtk2);
else
printf("%s [GTK2], %s [GTK3]", gtk2, gtk3);
ffStrbufSetF(buffer, "%s [GTK2], %s [GTK3]", gtk2, gtk3);
}
else if(strSet(gtk3) && strSet(gtk4))
{
if(strcmp(gtk3, gtk4) == 0)
printf("%s [GTK3/4]", gtk3);
ffStrbufSetF(buffer, "%s [GTK3/4]", gtk3);
else
printf("%s [GTK3], %s [GTK4]", gtk3, gtk4);
ffStrbufSetF(buffer, "%s [GTK3], %s [GTK4]", gtk3, gtk4);
}
else if(strSet(gtk2))
{
printf("%s [GTK2]", gtk2);
ffStrbufSetF(buffer, "%s [GTK2]", gtk2);
}
else if(strSet(gtk3))
{
printf("%s [GTK3]", gtk3);
ffStrbufSetF(buffer, "%s [GTK3]", gtk3);
}
else if(strSet(gtk4))
{
printf("%s [GTK4]", gtk4);
ffStrbufSetF(buffer, "%s [GTK4]", gtk4);
}
}
@@ -160,13 +159,21 @@ void ffParseFont(char* font, char* buffer)
sprintf(buffer, "%s (%spt)", name, size);
}
void ffPrintError(FFinstance* instance, const char* key, const char* message)
void ffPrintError(FFinstance* instance, const char* key, const char* message, ...)
{
if(!instance->config.showErrors)
return;
ffPrintLogoAndKey(instance, key);
printf(FASTFETCH_TEXT_MODIFIER_ERROR"%s"FASTFETCH_TEXT_MODIFIER_RESET"\n", message);
va_list arguments;
va_start(arguments, message);
printf(FASTFETCH_TEXT_MODIFIER_ERROR);
vprintf(message, arguments);
puts(FASTFETCH_TEXT_MODIFIER_RESET);
va_end(arguments);
}
void ffTrimTrailingWhitespace(char* buffer)
@@ -237,12 +244,13 @@ bool ffPrintCachedValue(FFinstance* instance, const char* key)
if(instance->config.recache)
return false;
char fileName[256];
strcpy(fileName, getCacheDir(instance));
strcat(fileName, key);
FFstrbuf filename;
ffStrbufInitF(&filename, "%s%s", getCacheDir(instance), key);
char value[1024];
ffGetFileContent(fileName, value, sizeof(value));
ffGetFileContent(filename.chars, value, sizeof(value));
ffStrbufDestroy(&filename);
if(value[0] == '\0')
return false;
@@ -255,17 +263,15 @@ bool ffPrintCachedValue(FFinstance* instance, const char* key)
void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, const char* value)
{
ffPrintLogoAndKey(instance, key);
puts(value);
if(!instance->config.cacheSave)
return;
char fileName[256];
strcpy(fileName, getCacheDir(instance));
strcat(fileName, key);
FFstrbuf filename;
ffStrbufInitF(&filename, "%s%s", getCacheDir(instance), key);
int fd = open(fileName, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
int fd = open(filename.chars, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if(fd == -1)
return;
@@ -276,5 +282,113 @@ void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, const char
close(fd);
if(failed)
unlink(fileName);
unlink(filename.chars);
ffStrbufDestroy(&filename);
}
void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, ...)
{
va_list argp;
va_start(argp, numArgs);
FFformatarg arguments[numArgs];
for(uint32_t i = 0; i < numArgs; i++)
arguments[i] = (FFformatarg) va_arg(argp, FFformatarg);
va_end(argp);
uint32_t argCounter = 1; //First arg is 1 in fomat string
for(uint32_t i = 0; i < formatstr->length; ++i)
{
if(formatstr->chars[i] != '{')
{
ffStrbufAppendC(buffer, formatstr->chars[i]);
continue;
}
++i;
if(formatstr->chars[i] == '{')
{
ffStrbufAppendC(buffer, '{');
continue;
}
uint32_t argIndex;
if(formatstr->chars[i] == '}')
{
argIndex = argCounter++;
}
else
{
FFstrbuf argnumstr;
ffStrbufInit(&argnumstr);
while(true)
{
ffStrbufAppendC(&argnumstr, formatstr->chars[i++]);
if(formatstr->chars[i] == '}')
break;
if(formatstr->chars[i] == '\0')
{
fprintf(stderr, "Error: format string \"%s\" ends with an uncomplete placeholder %s\n", formatstr->chars, argnumstr.chars);
ffStrbufDestroy(buffer);
exit(802);
}
}
if(ffStrbufGetC(&argnumstr, 0) == '-')
{
fprintf(stderr, "Error: format string \"%s\" placeholder value \"%s\" is negative\n", formatstr->chars, argnumstr.chars);
ffStrbufDestroy(buffer);
exit(803);
}
if(sscanf(argnumstr.chars, "%u", &argIndex) != 1)
{
fprintf(stderr, "Error: format string \"%s\" placeholder value \"%s\" could not be parsed to uint32_t\n", formatstr->chars, argnumstr.chars);
ffStrbufDestroy(buffer);
exit(804);
}
ffStrbufDestroy(&argnumstr);
}
if(argIndex == 0)
argIndex = 1;
if(argIndex > numArgs)
{
fprintf(stderr, "Error: format string \"%s\" placeholder {%u} wants higher argument than number of arguments (%u)\n", formatstr->chars, argIndex, numArgs);
ffStrbufDestroy(buffer);
exit(805);
}
FFformatarg arg = arguments[argIndex - 1];
if(arg.type == FF_FORMAT_ARG_TYPE_INT)
ffStrbufAppendF(buffer, "%i", *(int*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_UINT)
ffStrbufAppendF(buffer, "%u", *(uint32_t*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_UINT8)
ffStrbufAppendF(buffer, "%u", *(uint8_t*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_STRING)
ffStrbufAppendF(buffer, "%s", (const char*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_STRBUF)
ffStrbufAppend(buffer, (FFstrbuf*)arg.value);
else if(arg.type == FF_FORMAT_ARG_TYPE_DOUBLE)
ffStrbufAppendF(buffer, "%.9g", *(double*)arg.value);
else
{
fprintf(stderr, "Error: format string \"%s\" argument is not implemented\n", formatstr->chars);
ffStrbufDestroy(buffer);
exit(806);
}
}
}
+299 -265
View File
@@ -11,63 +11,21 @@
#define FASTFETCH_DEFAULT_STRUCTURE "Title:Seperator:OS:Host:Kernel:Uptime:Packages:Shell:Resolution:DE:WM:Theme:Icons:Font:Terminal:TerminalFont:CPU:GPU:Memory:Disk:Battery:Locale:Break:Colors"
#define FASTFETCH_DEFAULT_CONFIG \
"## Fastfetch configuration\n" \
"## Put arguments here to make them permanently.\n" \
"## Direct arguments will overwrite the corresponding ones in this files\n" \
"## Each line is whitespace trimmed on beginn and end.\n" \
"## Empty lines or lines starting with # are ignored.\n" \
"## There are more arguments possible than listed here, take a look at fastfetch --help!\n" \
"## This version of the file was shipped with "FASTFETCH_PROJECT_VERSION".\n" \
"## Use fastfetch --print-default-config > ~/.config/fastfetch/config.conf to generate a new one with current defaults.\n" \
"\n" \
"## General options:\n" \
"# --structure "FASTFETCH_DEFAULT_STRUCTURE"\n" \
"# --spacer 4\n" \
"# --seperator \": \"\n" \
"# --offsetx 0\n" \
"# --recache false\n" \
"# --show-errors false\n" \
"\n" \
"## Logo options:\n" \
"# --color-logo true\n" \
"\n" \
"## OS options:\n" \
"# --os-architecture true\n" \
"\n" \
"## Host options:\n" \
"# --host-version true\n" \
"\n" \
"## Kernel options:\n" \
"# --kernel-release true\n" \
"# --kernel-version false\n" \
"\n" \
"## Packages options:\n" \
"# --packages-combined false\n" \
"# --packages-combined-names true\n" \
"# --packages-pacman true\n" \
"# --packages-flatpak true\n" \
"\n" \
"## Shell options:\n" \
"# --shell-path false\n" \
"\n" \
"## Resolution options:\n" \
"# --resolution-refreshrate true\n" \
"# --resolution-libX11 libX11.so\n"\
"# --resolution-libXrandr libXrandr.so\n" \
"\n" \
"## Battery options:\n" \
"# --battery-manufacturer true\n" \
"# --battery-model true\n" \
"# --battery-technology true\n" \
"# --battery-capacity true\n" \
"# --battery-status true\n"
"# Fastfetch configuration\n" \
"# Put arguments here to make them permanently (one per line). \n" \
"# Direct arguments will overwrite the corresponding ones in this files\n" \
"# Each line is whitespace trimmed on beginn and end.\n" \
"# Empty lines or lines starting with # are ignored.\n" \
"# There are more arguments possible than listed here, take a look at fastfetch --help!\n" \
"# This version of the file was shipped with "FASTFETCH_PROJECT_VERSION".\n" \
"# Use fastfetch --print-default-config > ~/.config/fastfetch/config.conf to generate a new one with current defaults.\n"
//Things only needed by fastfetch
typedef struct FFdata
{
FFvaluestore valuestore;
char structure[2048];
char logoName[32];
FFstrbuf structure;
FFstrbuf logoName;
} FFdata;
static inline void printHelp()
@@ -97,41 +55,32 @@ static inline void printHelp()
" -l <name>, --logo <name>: sets the shown logo. Also changes the main color accordingly\n"
" --color-logo <?value>: if set to false, the logo will be black / white\n"
"\n"
"OS options:\n"
" --os-architecture <?value>: Show the architecture of the os\n"
" --os-format <format>: Provide the printf format string for os output (+)\n"
"Format options: Provide the format string for custom output (+)\n"
" --os-format <format>\n"
" --host-format <format>\n"
" --kernel-format <format>\n"
" --uptime-format <format>\n"
" --packages-format <format>\n"
" --shell-format <format>\n"
" --resolution-format <format>\n"
" --de-format <format>\n"
" --wm-format <format>\n"
" --theme-format <format>\n"
" --icons-format <format>\n"
" --font-format <format>\n"
" --terminal-format <format>\n"
" --terminal-font-format <format>\n"
" --cpu-format <format>\n"
" --gpu-format <format>\n"
" --memory-format <format>\n"
" --disk-format <format>\n"
" --battery-format <format>\n"
" --locale-format <format>\n"
"\n"
"Host options:\n"
" --host-version <?value>: Show the version of the host platform, if possible. Most likely, this will be the BIOS version\n"
" --host-format <format>: Provide the printf format string for host output (+)\n"
"\n"
"Kernel options:\n"
" --kernel-release <?value>: Shows the release of the kernel\n"
" --kernel-version <?value>: Shows the build version of the kernel\n"
"\n"
"Packages options:\n"
" --packages-combined <?value>: Show the sum of all packages\n"
" --packages-combined-names <?value>: Show the names of the package managers after the sum if in packages-combined mode\n"
" --packages-pacman <?value>: Count pacman packages\n"
" --packages-flatpak <?value>: Count flatpak packages\n"
" --packages-format <format>: Provide the printf format string for packages output (+)\n"
"\n"
"Shell options:\n"
" --shell-path <?value>: Show the full path of the shell\n"
"\n"
"Resolution optins:\n"
" --resolution-refreshrate <?value>: Show the refresh rate of the monitor\n"
" --resolution-libX11 <path>: Set the path to the x11 library to load\n"
" --resolution-libXrandr <path>: Set the path to the xrandr library to load\n"
" --resolution-format <format>: Provide the printf format string for resolution output (+)\n"
"\n"
"Battery options:\n"
" --battery-manufacturer <?value>: Show the manufacturer of the battery, if possible\n"
" --battery-model <?value>: Show the model of the battery, if possible\n"
" --battery-technology <?value>: Show the technology of the battery, if possible\n"
" --battery-capacity <?value>: Show the capacity of the battery, if possible\n"
" --battery-status <?value>: Show the status of the battery, if possible\n"
" --battery-format <format>: Provide the printf format string for battery output (+)\n"
"Library optins: Set the path of a library to load\n"
" --lib-PCI <path>\n"
" --lib-X11 <path>:\n"
" --lib-Xrandr <path>:\n"
"\n"
"If an value starts with an ?, it is optional. \"true\" will be used if not set.\n"
"An (+) at the end indicates that more help can be printed with --help <option>\n"
@@ -157,65 +106,140 @@ static inline void printCommandHelpColor()
static inline void printCommandHelpOsFormat()
{
puts(
"usage fastfetch --os-format <format>\n"
"\n"
"<format> is a string of maximum length 32, which is passed to printf as the format string.\n"
"The arguments passed to printf are 2 strings in following order:\n"
"name, architecture\n"
"If an value could not be determined, it will be an zero length string.\n"
"The default value is something like \"%s %s\"."
"TBD"
);
}
static inline void printCommandHelpHostFormat()
{
puts(
"usage fastfetch --host-format <format>\n"
"\n"
"<format> is a string of maximum length 32, which is passed to printf as the format string.\n"
"The arguments passed to printf are 3 strings in following order:\n"
"family, name, version\n"
"If an value could not be determined, it will be an zero length string.\n"
"The default value is something like \"%s %s %s\"."
"TBD"
);
}
static inline void printCommandHelpBatteryFormat()
static inline void printCommandHelpKernelFormat()
{
puts(
"usage fastfetch --battery-format <format>\n"
"\n"
"<format> is a string of maximum length 32, which is passed to printf as the format string.\n"
"The arguments passed to printf are 5 strings in following order:\n"
"manufacturer, model, technology, capacity, status\n"
"If an value was disabled via battery-* argument, or could not be determined, it will be an zero length string.\n"
"The default value is something like \"%s %s (%s) [%s; %s]\"."
"TBD"
);
}
static inline void printCommandHelpUptimeFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpPackagesFormat()
{
puts(
"usage: fastfetch --packages-format <format>\n"
"\n"
"<format> is a string of maximum length 32, which is passed to printf as the format string.\n"
"if --packages-combined is set to false, the numbers of packages are passed to printf in following order as uint32_t:\n"
"all, pacman, flatpak, all\n"
"if an value is disabled via a packages-* argument, or could not be determined, zero is passed\n"
"The default value is something like \"%.0s%u (pacman), %u (flatpack)\""
"TBD"
);
}
static inline void printCommandHelpShellFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpResolutionFormat()
{
puts(
"usage: fastfetch --resolution-format <format>\n"
"\n"
"<format> is a string of maximum length 32, which is passed to printf as the format string.\n"
"the values passed to printf are in following order:\n"
"width (int), height (int), refreshRate (short)\n"
"if refresh rate is disabled, or could not be determined, zero is passed\n"
"The default value is something like \"%ix%i @ %dHz\""
"TBD"
);
}
static inline void printCommandHelpDEFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpWMFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpThemeFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpIconsFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpFontFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpTerminalFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpTerminalFontFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpCPUFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpGPUFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpMemoryFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpDiskFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpBatteryFormat()
{
puts(
"TBD"
);
}
static inline void printCommandHelpLocaleFormat()
{
puts(
"TBD"
);
}
@@ -227,12 +251,42 @@ static inline void printCommandHelp(const char* command)
printCommandHelpOsFormat();
else if(strcasecmp(command, "host-format") == 0)
printCommandHelpHostFormat();
else if(strcasecmp(command, "battery-format") == 0)
printCommandHelpBatteryFormat();
else if(strcasecmp(command, "kernel-format") == 0)
printCommandHelpKernelFormat();
else if(strcasecmp(command, "uptime-format") == 0)
printCommandHelpUptimeFormat();
else if(strcasecmp(command, "packages-format") == 0)
printCommandHelpPackagesFormat();
else if(strcasecmp(command, "shell-format") == 0)
printCommandHelpShellFormat();
else if(strcasecmp(command, "resolution-format") == 0)
printCommandHelpResolutionFormat();
else if(strcasecmp(command, "de-format") == 0)
printCommandHelpDEFormat();
else if(strcasecmp(command, "wm-format") == 0)
printCommandHelpWMFormat();
else if(strcasecmp(command, "theme-format") == 0)
printCommandHelpThemeFormat();
else if(strcasecmp(command, "icons-format") == 0)
printCommandHelpIconsFormat();
else if(strcasecmp(command, "font-format") == 0)
printCommandHelpFontFormat();
else if(strcasecmp(command, "terminal-format") == 0)
printCommandHelpTerminalFormat();
else if(strcasecmp(command, "terminal-font-format") == 0)
printCommandHelpTerminalFontFormat();
else if(strcasecmp(command, "cpu-format") == 0)
printCommandHelpCPUFormat();
else if(strcasecmp(command, "gpu-format") == 0)
printCommandHelpGPUFormat();
else if(strcasecmp(command, "memory-format") == 0)
printCommandHelpMemoryFormat();
else if(strcasecmp(command, "disk-format") == 0)
printCommandHelpDiskFormat();
else if(strcasecmp(command, "battery-format") == 0)
printCommandHelpBatteryFormat();
else if(strcasecmp(command, "locale-format") == 0)
printCommandHelpLocaleFormat();
else
printf("No specific help for command %s provided\n", command);
}
@@ -249,81 +303,14 @@ static inline bool optionParseBoolean(const char* str)
);
}
static inline void optionParseString(const char* key, const char* value, char* target, uint32_t capacity)
static inline void optionParseString(const char* key, const char* value, FFstrbuf* buffer)
{
if(value == NULL)
{
printf("Error: usage: %s <str>\n", key);
exit(477);
}
size_t len = strlen(value);
if(len > capacity)
{
printf("max string length for %s is %u, %zu given\n", key, capacity, len);
exit(478);
}
strcpy(target, value);
}
static void parseStructureCommand(FFinstance* instance, FFdata* data, const char* line)
{
const char* setValue = ffValuestoreGet(&data->valuestore, line);
if(setValue != NULL)
{
ffPrintCustom(instance, line, setValue);
return;
}
if(strcasecmp(line, "break") == 0)
ffPrintBreak(instance);
else if(strcasecmp(line, "title") == 0)
ffPrintTitle(instance);
else if(strcasecmp(line, "seperator") == 0)
ffPrintSeperator(instance);
else if(strcasecmp(line, "os") == 0)
ffPrintOS(instance);
else if(strcasecmp(line, "host") == 0)
ffPrintHost(instance);
else if(strcasecmp(line, "kernel") == 0)
ffPrintKernel(instance);
else if(strcasecmp(line, "uptime") == 0)
ffPrintUptime(instance);
else if(strcasecmp(line, "packages") == 0)
ffPrintPackages(instance);
else if(strcasecmp(line, "shell") == 0)
ffPrintShell(instance);
else if(strcasecmp(line, "resolution") == 0)
ffPrintResolution(instance);
else if(strcasecmp(line, "desktopenvironment") == 0 || strcasecmp(line, "de") == 0)
ffPrintDesktopEnvironment(instance);
else if(strcasecmp(line, "windowmanager") == 0 || strcasecmp(line, "wm") == 0)
ffPrintWM(instance);
else if(strcasecmp(line, "theme") == 0)
ffPrintTheme(instance);
else if(strcasecmp(line, "icons") == 0)
ffPrintIcons(instance);
else if(strcasecmp(line, "font") == 0)
ffPrintFont(instance);
else if(strcasecmp(line, "terminal") == 0)
ffPrintTerminal(instance);
else if(strcasecmp(line, "terminalfont") == 0)
ffPrintTerminalFont(instance);
else if(strcasecmp(line, "cpu") == 0)
ffPrintCPU(instance);
else if(strcasecmp(line, "gpu") == 0)
ffPrintGPU(instance);
else if(strcasecmp(line, "memory") == 0)
ffPrintMemory(instance);
else if(strcasecmp(line, "disk") == 0)
ffPrintDisk(instance);
else if(strcasecmp(line, "battery") == 0)
ffPrintBattery(instance);
else if(strcasecmp(line, "locale") == 0)
ffPrintLocale(instance);
else if(strcasecmp(line, "colors") == 0)
ffPrintColors(instance);
else
ffPrintError(instance, line, "<no implementaion provided>");
ffStrbufSetS(buffer, value);
}
static void parseOption(FFinstance* instance, FFdata* data, const char* key, const char* value)
@@ -357,21 +344,6 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
puts(FASTFETCH_DEFAULT_CONFIG);
exit(0);
}
else if(strcasecmp(key, "-c") == 0 || strcasecmp(key, "--color") == 0)
{
if(value == NULL)
{
printf("Error: usage: %s <color>\n", key);
exit(402);
}
size_t len = strlen(value);
if(len > 28)
{
printf("Error: max color string length is 28, %zu given\n", len);
exit(403);
}
sprintf(instance->config.color, "\033[%sm", value);
}
else if(strcasecmp(key, "--spacer") == 0)
{
if(value == NULL)
@@ -424,63 +396,64 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
instance->config.recache = optionParseBoolean(value);
instance->config.cacheSave = instance->config.recache;
}
else if(strcasecmp(key, "--structure") == 0)
optionParseString(key, value, data->structure, sizeof(data->structure));
else if(strcasecmp(key, "-l") == 0 || strcasecmp(key, "--logo") == 0)
optionParseString(key, value, data->logoName, sizeof(instance->config.logo));
else if(strcasecmp(key, "-s") == 0 || strcasecmp(key, "--seperator") == 0)
optionParseString(key, value, instance->config.seperator, sizeof(instance->config.seperator));
else if(strcasecmp(key, "--show-errors") == 0)
instance->config.showErrors = optionParseBoolean(value);
else if(strcasecmp(key, "--color-logo") == 0)
instance->config.colorLogo = optionParseBoolean(value);
else if(strcasecmp(key, "--os-architecture") == 0)
instance->config.osShowArchitecture = optionParseBoolean(value);
else if(strcasecmp(key, "--structure") == 0)
optionParseString(key, value, &data->structure);
else if(strcasecmp(key, "-l") == 0 || strcasecmp(key, "--logo") == 0)
optionParseString(key, value, &data->logoName);
else if(strcasecmp(key, "-s") == 0 || strcasecmp(key, "--seperator") == 0)
optionParseString(key, value, &instance->config.seperator);
else if(strcasecmp(key, "-c") == 0 || strcasecmp(key, "--color") == 0)
optionParseString(key, value, &instance->config.color);
else if(strcasecmp(key, "--os-format") == 0)
optionParseString(key, value, instance->config.osFormat, sizeof(instance->config.osFormat));
else if(strcasecmp(key, "--host-version") == 0)
instance->config.hostShowVersion = optionParseBoolean(value);
optionParseString(key, value, &instance->config.osFormat);
else if(strcasecmp(key, "--host-format") == 0)
optionParseString(key, value, instance->config.hostFormat, sizeof(instance->config.hostFormat));
else if(strcasecmp(key, "--kernel-release") == 0)
instance->config.kernelShowRelease = optionParseBoolean(value);
else if(strcasecmp(key, "--kernel-version") == 0)
instance->config.kernelShowVersion = optionParseBoolean(value);
else if(strcasecmp(key, "--packages-combined") == 0)
instance->config.packagesCombined = optionParseBoolean(value);
else if(strcasecmp(key, "--packages-combined-names") == 0)
{
instance->config.packagesCombined = true;
instance->config.packagesCombinedNames = optionParseBoolean(value);
}
else if(strcasecmp(key, "--packages-pacman") == 0)
instance->config.packagesShowPacman = optionParseBoolean(value);
else if(strcasecmp(key, "--packages-flatpak") == 0)
instance->config.packagesShowFlatpak = optionParseBoolean(value);
optionParseString(key, value, &instance->config.hostFormat);
else if(strcasecmp(key, "--kernel-format") == 0)
optionParseString(key, value, &instance->config.kernelFormat);
else if(strcasecmp(key, "--uptime-format") == 0)
optionParseString(key, value, &instance->config.uptimeFormat);
else if(strcasecmp(key, "--packages-format") == 0)
optionParseString(key, value, instance->config.packagesFormat, sizeof(instance->config.packagesFormat));
else if(strcasecmp(key, "--shell-path") == 0)
instance->config.shellShowPath = optionParseBoolean(value);
else if(strcasecmp(key, "--resolution-refreshrate") == 0)
instance->config.resolutionShowRefreshRate = optionParseBoolean(value);
else if(strcasecmp(key, "--resolution-libX11") == 0)
optionParseString(key, value, instance->config.resolutionLibX11, sizeof(instance->config.resolutionLibX11));
else if(strcasecmp(key, "--resolution-libXrandr") == 0)
optionParseString(key, value, instance->config.resolutionLibXrandr, sizeof(instance->config.resolutionLibXrandr));
optionParseString(key, value, &instance->config.packagesFormat);
else if(strcasecmp(key, "--shell-format") == 0)
optionParseString(key, value, &instance->config.shellFormat);
else if(strcasecmp(key, "--resolution-format") == 0)
optionParseString(key, value, instance->config.resolutionFormat, sizeof(instance->config.resolutionFormat));
else if(strcasecmp(key, "--battery-manufacturer") == 0)
instance->config.batteryShowManufacturer = optionParseBoolean(value);
else if(strcasecmp(key, "--battery-model") == 0)
instance->config.batteryShowModel = optionParseBoolean(value);
else if(strcasecmp(key, "--battery-technology") == 0)
instance->config.batteryShowTechnology = optionParseBoolean(value);
else if(strcasecmp(key, "--battery-capacity") == 0)
instance->config.batteryShowCapacity = optionParseBoolean(value);
else if(strcasecmp(key, "--battery-status") == 0)
instance->config.batteryShowStatus = optionParseBoolean(value);
optionParseString(key, value, &instance->config.resolutionFormat);
else if(strcasecmp(key, "--de-format") == 0)
optionParseString(key, value, &instance->config.deFormat);
else if(strcasecmp(key, "--wm-format") == 0)
optionParseString(key, value, &instance->config.wmFormat);
else if(strcasecmp(key, "--theme-format") == 0)
optionParseString(key, value, &instance->config.themeFormat);
else if(strcasecmp(key, "--icons-format") == 0)
optionParseString(key, value, &instance->config.iconsFormat);
else if(strcasecmp(key, "--font-format") == 0)
optionParseString(key, value, &instance->config.fontFormat);
else if(strcasecmp(key, "--terminal-format") == 0)
optionParseString(key, value, &instance->config.terminalFormat);
else if(strcasecmp(key, "--terminal-font-format") == 0)
optionParseString(key, value, &instance->config.termFontFormat);
else if(strcasecmp(key, "--cpu-format") == 0)
optionParseString(key, value, &instance->config.cpuFormat);
else if(strcasecmp(key, "--gpu-format") == 0)
optionParseString(key, value, &instance->config.gpuFormat);
else if(strcasecmp(key, "--memory-format") == 0)
optionParseString(key, value, &instance->config.memoryFormat);
else if(strcasecmp(key, "--disk-format") == 0)
optionParseString(key, value, &instance->config.diskFormat);
else if(strcasecmp(key, "--battery-format") == 0)
optionParseString(key, value, instance->config.batteryFormat, sizeof(instance->config.batteryFormat));
optionParseString(key, value, &instance->config.batteryFormat);
else if(strcasecmp(key, "--locale-format") == 0)
optionParseString(key, value, &instance->config.localeFormat);
else if(strcasecmp(key, "--lib-PCI") == 0)
optionParseString(key, value, &instance->config.libPCI);
else if(strcasecmp(key, "--lib-X11") == 0)
optionParseString(key, value, &instance->config.libX11);
else if(strcasecmp(key, "--lib-Xrandr") == 0)
optionParseString(key, value, &instance->config.libXrandr);
else
{
printf("Error: unknown option: %s\n", key);
@@ -606,22 +579,83 @@ static void parseArguments(FFinstance* instance, FFdata* data, int argc, const c
static void applyData(FFinstance* instance, FFdata* data)
{
//We must do this after parsing all options because of color options
if(data->logoName[0] == '\0')
if(ffStrbufIsEmpty(&data->logoName))
ffLoadLogo(&instance->config);
else
ffLoadLogoSet(&instance->config, data->logoName);
ffLoadLogoSet(&instance->config, data->logoName.chars);
//This must be done after loading the logo
if(instance->config.color[0] == '\0')
strcpy(instance->config.color, instance->config.logo.color);
if(ffStrbufIsEmpty(&instance->config.color))
ffStrbufSetS(&instance->config.color, instance->config.logo.color);
}
static void parseStructureCommand(FFinstance* instance, FFdata* data, const char* line)
{
const char* setValue = ffValuestoreGet(&data->valuestore, line);
if(setValue != NULL)
{
ffPrintCustom(instance, line, setValue);
return;
}
if(strcasecmp(line, "break") == 0)
ffPrintBreak(instance);
else if(strcasecmp(line, "title") == 0)
ffPrintTitle(instance);
else if(strcasecmp(line, "seperator") == 0)
ffPrintSeperator(instance);
else if(strcasecmp(line, "os") == 0)
ffPrintOS(instance);
else if(strcasecmp(line, "host") == 0)
ffPrintHost(instance);
else if(strcasecmp(line, "kernel") == 0)
ffPrintKernel(instance);
else if(strcasecmp(line, "uptime") == 0)
ffPrintUptime(instance);
else if(strcasecmp(line, "packages") == 0)
ffPrintPackages(instance);
else if(strcasecmp(line, "shell") == 0)
ffPrintShell(instance);
else if(strcasecmp(line, "resolution") == 0)
ffPrintResolution(instance);
else if(strcasecmp(line, "desktopenvironment") == 0 || strcasecmp(line, "de") == 0)
ffPrintDesktopEnvironment(instance);
else if(strcasecmp(line, "windowmanager") == 0 || strcasecmp(line, "wm") == 0)
ffPrintWM(instance);
else if(strcasecmp(line, "theme") == 0)
ffPrintTheme(instance);
else if(strcasecmp(line, "icons") == 0)
ffPrintIcons(instance);
else if(strcasecmp(line, "font") == 0)
ffPrintFont(instance);
else if(strcasecmp(line, "terminal") == 0)
ffPrintTerminal(instance);
else if(strcasecmp(line, "terminalfont") == 0)
ffPrintTerminalFont(instance);
else if(strcasecmp(line, "cpu") == 0)
ffPrintCPU(instance);
else if(strcasecmp(line, "gpu") == 0)
ffPrintGPU(instance);
else if(strcasecmp(line, "memory") == 0)
ffPrintMemory(instance);
else if(strcasecmp(line, "disk") == 0)
ffPrintDisk(instance);
else if(strcasecmp(line, "battery") == 0)
ffPrintBattery(instance);
else if(strcasecmp(line, "locale") == 0)
ffPrintLocale(instance);
else if(strcasecmp(line, "colors") == 0)
ffPrintColors(instance);
else
ffPrintError(instance, line, "<no implementaion provided>");
}
static void run(FFinstance* instance, FFdata* data)
{
if(data->structure[0] == '\0')
strcpy(data->structure, FASTFETCH_DEFAULT_STRUCTURE);
if(ffStrbufIsEmpty(&data->structure))
ffStrbufSetS(&data->structure, FASTFETCH_DEFAULT_STRUCTURE);
char* remaining = data->structure;
char* remaining = data->structure.chars;
char* colon = NULL;
while(true)
@@ -648,8 +682,8 @@ int main(int argc, const char** argv)
FFdata data;
ffValuestoreInit(&data.valuestore);
data.structure[0] = '\0'; //We use this in run to detect if a structure was set
data.logoName[0] = '\0'; //We use this in applyData to detect if a logo was set
ffStrbufInit(&data.structure);
ffStrbufInitA(&data.logoName, 2048);
parseConfigFile(&instance, &data);
parseArguments(&instance, &data, argc, argv);
+48 -40
View File
@@ -16,6 +16,8 @@
#include <sys/utsname.h>
#include <sys/sysinfo.h>
#include "util/FFstrbuf.h"
#define FASTFETCH_TEXT_MODIFIER_BOLT "\033[1m"
#define FASTFETCH_TEXT_MODIFIER_ERROR "\033[1;31m"
#define FASTFETCH_TEXT_MODIFIER_RESET "\033[0m"
@@ -31,60 +33,49 @@ typedef struct FFlogo
typedef struct FFconfig
{
//General
FFlogo logo;
uint16_t logo_spacer;
char seperator[16];
FFstrbuf seperator;
int16_t offsetx;
char color[32];
FFstrbuf color;
uint8_t titleLength;
bool colorLogo;
bool showErrors;
bool recache;
bool cacheSave; //This is only set to true when using arguments, because we dont want so save this values
//OS
bool osShowArchitecture;
char osFormat[32];
//Host
bool hostShowVersion;
char hostFormat[32];
//Kernel
bool kernelShowRelease;
bool kernelShowVersion;
//Packages
bool packagesCombined;
bool packagesCombinedNames;
bool packagesShowPacman;
bool packagesShowFlatpak;
char packagesFormat[32];
//Shell
bool shellShowPath;
FFstrbuf osFormat;
FFstrbuf hostFormat;
FFstrbuf kernelFormat;
FFstrbuf uptimeFormat;
FFstrbuf packagesFormat;
FFstrbuf shellFormat;
FFstrbuf resolutionFormat;
FFstrbuf deFormat;
FFstrbuf wmFormat;
FFstrbuf themeFormat;
FFstrbuf iconsFormat;
FFstrbuf fontFormat;
FFstrbuf terminalFormat;
FFstrbuf termFontFormat;
FFstrbuf cpuFormat;
FFstrbuf gpuFormat;
FFstrbuf memoryFormat;
FFstrbuf diskFormat;
FFstrbuf batteryFormat;
FFstrbuf localeFormat;
//Resolution
bool resolutionShowRefreshRate;
char resolutionLibX11[64];
char resolutionLibXrandr[64];
char resolutionFormat[32];
//Battery
bool batteryShowManufacturer;
bool batteryShowModel;
bool batteryShowTechnology;
bool batteryShowCapacity;
bool batteryShowStatus;
char batteryFormat[32];
FFstrbuf libPCI;
FFstrbuf libX11;
FFstrbuf libXrandr;
} FFconfig;
typedef struct FFvalue
{
char* value;
FFstrbuf value;
char* error;
bool calculated;
} FFvalue;
typedef struct FFstate
@@ -103,6 +94,22 @@ typedef struct FFinstance
FFstate state;
} FFinstance;
typedef enum FFformatargtype
{
FF_FORMAT_ARG_TYPE_UINT,
FF_FORMAT_ARG_TYPE_UINT8,
FF_FORMAT_ARG_TYPE_INT,
FF_FORMAT_ARG_TYPE_STRING,
FF_FORMAT_ARG_TYPE_STRBUF,
FF_FORMAT_ARG_TYPE_DOUBLE
} FFformatargtype;
typedef struct FFformatarg
{
FFformatargtype type;
void* value;
} FFformatarg;
//Util functions
void ffInitState(FFstate* state);
void ffDefaultConfig(FFconfig* config);
@@ -112,11 +119,12 @@ void ffGetFileContent(const char* fileName, char* buffer, uint32_t bufferSize);
void ffParsePropFile(const char* file, const char* regex, char* buffer);
void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const char* regex, char* buffer);
void ffParseFont(char* font, char* buffer);
void ffPrintGtkPretty(const char* gtk2, const char* gtk3, const char* gtk4);
void ffPrintError(FFinstance* instance, const char* key, const char* message);
void ffFormatGtkPretty(FFstrbuf* buffer, const char* gtk2, const char* gtk3, const char* gtk4);
void ffPrintError(FFinstance* instance, const char* key, const char* message, ...);
void ffTrimTrailingWhitespace(char* buffer);
bool ffPrintCachedValue(FFinstance* instance, const char* key);
void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, const char* value);
void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, ...);
//Logo functions
void ffLoadLogoSet(FFconfig* config, const char* logo);
+2 -4
View File
@@ -7,12 +7,10 @@ int main(int argc, char** argv)
ffDefaultConfig(&instance.config);
//Configuration
ffLoadLogoSet(&instance.config, "arch");
strcpy(instance.config.color, instance.config.logo.color); //Use the primary color of the logo as key color
ffStrbufSetS(&instance.config.color, instance.config.logo.color); //Use the primary color of the logo as key color
//Printing
ffPrintTitle(&instance);
ffPrintSeperator(&instance);
ffPrintOS(&instance);
+1 -1
View File
@@ -163,7 +163,7 @@ void ffPrintLogoLine(FFinstance* instance)
static FFlogo* getLogos(uint8_t* size, bool color)
{
#define FASTFETCH_LOGO_AMOUNT 3
#define FASTFETCH_LOGO_AMOUNT 4
*size = FASTFETCH_LOGO_AMOUNT;
static FFlogo logos[FASTFETCH_LOGO_AMOUNT];
+52 -64
View File
@@ -5,59 +5,34 @@
static void printBattery(FFinstance* instance, uint8_t index)
{
char manufactor[128];
if(instance->config.batteryShowManufacturer)
{
char manufactorPath[42];
sprintf(manufactorPath, "/sys/class/power_supply/BAT%i/manufacturer", index);
ffGetFileContent(manufactorPath, manufactor, sizeof(manufactor));
}
else
manufactor[0] = '\0';
char manufactorPath[42];
sprintf(manufactorPath, "/sys/class/power_supply/BAT%i/manufacturer", index);
ffGetFileContent(manufactorPath, manufactor, sizeof(manufactor));
char model[128];
if(instance->config.batteryShowModel)
{
char modelPath[40];
sprintf(modelPath, "/sys/class/power_supply/BAT%i/model_name", index);
ffGetFileContent(modelPath, model, sizeof(model));
}
else
model[0] = '\0';
char modelPath[40];
sprintf(modelPath, "/sys/class/power_supply/BAT%i/model_name", index);
ffGetFileContent(modelPath, model, sizeof(model));
char technology[32];
if(instance->config.batteryShowTechnology)
{
char technologyPath[40];
sprintf(technologyPath, "/sys/class/power_supply/BAT%i/technology", index);
ffGetFileContent(technologyPath, technology, sizeof(technology));
}
else
technology[0] = '\0';
char technologyPath[40];
sprintf(technologyPath, "/sys/class/power_supply/BAT%i/technology", index);
ffGetFileContent(technologyPath, technology, sizeof(technology));
char capacity[32];
if(instance->config.batteryShowCapacity)
{
char capacityPath[38];
sprintf(capacityPath, "/sys/class/power_supply/BAT%i/capacity", index);
ffGetFileContent(capacityPath, capacity, sizeof(capacity));
}
else
capacity[0] = '\0';
char capacityPath[38];
sprintf(capacityPath, "/sys/class/power_supply/BAT%i/capacity", index);
ffGetFileContent(capacityPath, capacity, sizeof(capacity));
char status[32];
if(instance->config.batteryShowStatus)
{
char statusPath[36];
sprintf(statusPath, "/sys/class/power_supply/BAT%i/status", index);
ffGetFileContent(statusPath, status, sizeof(status));
}
else
status[0] = '\0';
char statusPath[36];
sprintf(statusPath, "/sys/class/power_supply/BAT%i/status", index);
ffGetFileContent(statusPath, status, sizeof(status));
char key[10];
sprintf(key, "Battery %i", index);
if(manufactor[0] == '\0' && model[0] == '\0' && technology[0] == '\0' && capacity[0] == '\0' && status[0] == '\0')
if(manufactor[0] == '\0' && model[0] == '\0' && technology[0] == '\0' && capacity[0] == '\0' && status[0] == '\0' && ffStrbufIsEmpty(&instance->config.batteryFormat))
{
ffPrintError(instance, key, "No file in /sys/class/power_supply/BAT0/ could be read or all battery options are disabled");
return;
@@ -65,37 +40,50 @@ static void printBattery(FFinstance* instance, uint8_t index)
ffPrintLogoAndKey(instance, key);
if(instance->config.batteryFormat[0] != '\0')
if(ffStrbufIsEmpty(&instance->config.batteryFormat))
{
printf(instance->config.batteryFormat, manufactor, model, technology, capacity, status);
putchar('\n');
return;
}
if(manufactor[0] != '\0')
printf("%s ", manufactor);
if(manufactor[0] != '\0')
printf("%s ", manufactor);
if(model[0] != '\0')
printf("%s ", model);
if(model[0] != '\0')
printf("%s ", model);
if(technology[0] != '\0')
printf("(%s) ", technology);
if(technology[0] != '\0')
printf("(%s) ", technology);
if(capacity[0] != '\0')
{
printf("[%s%%", capacity);
if(status[0] == '\0')
puts("]");
if(capacity[0] != '\0')
{
printf("[%s%%", capacity);
if(status[0] == '\0')
puts("]");
else
printf("; %s]\n", status);
}
else
printf("; %s]\n", status);
{
if(status[0] != '\0')
printf("%s", status);
else
putchar('\n');
}
}
else
{
if(status[0] != '\0')
printf("%s", status);
else
putchar('\n');
FFstrbuf battery;
ffStrbufInit(&battery);
ffParseFormatString(&battery, &instance->config.batteryFormat, 5,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, manufactor},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, model},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, technology},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, capacity},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, status}
);
ffStrbufWriteTo(&battery, stdout);
putchar('\n');
ffStrbufDestroy(&battery);
}
}
+21 -3
View File
@@ -31,8 +31,26 @@ void ffPrintCPU(FFinstance* instance)
frequency /= 1000; //to MHz
double ghz = (double) frequency / 1000.0; //to GHz
char value[1024];
sprintf(value, "%s (%i) @ %.9gGHz", name, get_nprocs(), ghz);
int numProcs = get_nprocs();
ffPrintLogoAndKey(instance, "CPU");
FFstrbuf cpu;
ffStrbufInit(&cpu);
if(ffStrbufIsEmpty(&instance->config.cpuFormat))
{
ffStrbufSetF(&cpu, "%s (%i) @ %.9gGHz", name, numProcs, ghz);
}
else
{
ffParseFormatString(&cpu, &instance->config.cpuFormat, 3,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name},
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &numProcs},
(FFformatarg){FF_FORMAT_ARG_TYPE_DOUBLE, &ghz}
);
}
ffPrintAndSaveCachedValue(instance, "CPU", value);
ffPrintAndSaveCachedValue(instance, "CPU", cpu.chars);
ffStrbufDestroy(&cpu);
}
+92
View File
@@ -0,0 +1,92 @@
#include "fastfetch.h"
static void getKDE(FFstrbuf* name, FFstrbuf* version, FFstrbuf* type)
{
ffStrbufSetS(name, "KDE Plasma");
char versionBuf[256];
ffParsePropFile("/usr/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version=%[^\n]", versionBuf);
ffStrbufSetS(version, versionBuf);
}
void ffPrintDesktopEnvironment(FFinstance* instance)
{
FFstrbuf sessionDesktop;
ffStrbufInitS(&sessionDesktop, getenv("XDG_CURRENT_DESKTOP"));
if(ffStrbufIsEmpty(&sessionDesktop))
ffStrbufSetS(&sessionDesktop, getenv("XDG_SESSION_DESKTOP"));
FFstrbuf sessionVersion;
ffStrbufInit(&sessionVersion);
FFstrbuf sessionType;
ffStrbufInit(&sessionType);
if(ffStrbufIgnCaseCompS(&sessionDesktop, "KDE") == 0)
getKDE(&sessionDesktop, &sessionVersion, &sessionType);
if(ffStrbufIsEmpty(&sessionType))
{
const char* xdgSessionType = getenv("XDG_SESSION_TYPE");
if(strcasecmp(xdgSessionType, "wayland") == 0)
ffStrbufSetS(&sessionType, "Wayland");
else if(strcasecmp(xdgSessionType, "x11") == 0)
ffStrbufSetS(&sessionType, "X11");
else if(strcasecmp(xdgSessionType, "tty") == 0)
ffStrbufSetS(&sessionType, "TTY");
else if(strcasecmp(xdgSessionType, "mir") == 0)
ffStrbufSetS(&sessionType, "Mir");
else if(xdgSessionType != NULL)
ffStrbufSetS(&sessionType, xdgSessionType);
}
if(ffStrbufIsEmpty(&instance->config.deFormat))
{
if(ffStrbufIsEmpty(&sessionDesktop) && ffStrbufIsEmpty(&sessionType))
{
ffPrintError(instance, "DE", "Neither DE nor Display Server could be determined");
return;
}
ffPrintLogoAndKey(instance, "DE");
if(!ffStrbufIsEmpty(&sessionDesktop))
{
ffStrbufWriteTo(&sessionDesktop, stdout);
if(!ffStrbufIsEmpty(&sessionVersion))
{
putchar(' ');
ffStrbufWriteTo(&sessionVersion, stdout);
}
if(!ffStrbufIsEmpty(&sessionType))
putchar(' ');
}
if(!ffStrbufIsEmpty(&sessionType))
printf("(%s)", sessionType.chars);
}
else
{
ffPrintLogoAndKey(instance, "DE");
FFstrbuf de;
ffStrbufInit(&de);
ffParseFormatString(&de, &instance->config.deFormat, 3,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &sessionDesktop},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &sessionVersion},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &sessionType}
);
ffStrbufWriteTo(&de, stdout);
ffStrbufDestroy(&de);
}
putchar('\n');
ffStrbufDestroy(&sessionType);
ffStrbufDestroy(&sessionVersion);
ffStrbufDestroy(&sessionDesktop);
}
-45
View File
@@ -1,45 +0,0 @@
#include "fastfetch.h"
static void printKDE()
{
char version[256];
ffParsePropFile("/usr/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version=%[^\n]", version);
if(version[0] == '\0')
{
printf("KDE Plasma ");
return;
}
printf("KDE Plasma %s", version);
}
void ffPrintDesktopEnvironment(FFinstance* instance)
{
const char* currentDesktop = getenv("XDG_CURRENT_DESKTOP");
if(currentDesktop == NULL)
{
ffPrintError(instance, "DE", "getenv(\"XDG_CURRENT_DESKTOP\") == NULL");
return;
}
ffPrintLogoAndKey(instance, "DE");
if(strcasecmp(currentDesktop, "KDE") == 0)
printKDE();
else
printf("%s", currentDesktop);
const char* sessionType = getenv("XDG_SESSION_TYPE");
if(sessionType == NULL)
putchar('\n');
else if(strcasecmp(sessionType, "wayland") == 0)
puts(" (Wayland)");
else if(strcasecmp(sessionType, "x11") == 0)
puts(" (X11)");
else if(strcasecmp(sessionType, "tty") == 0)
puts(" TTY");
else if(strcasecmp(sessionType, "mir") == 0)
puts(" (Mir)");
else
printf(" (%s)\n", sessionType);
}
+25 -7
View File
@@ -12,14 +12,32 @@ void ffPrintDisk(FFinstance* instance)
return;
}
const uint32_t GB = (1024 * 1024) * 1024;
uint32_t GB = (1024 * 1024) * 1024;
const uint32_t total = (fs.f_blocks * fs.f_frsize) / GB;
const uint32_t available = (fs.f_bfree * fs.f_frsize) / GB;
const uint32_t used = total - available;
const uint32_t percentage = (used / (double) total) * 100.0;
uint32_t total = (fs.f_blocks * fs.f_frsize) / GB;
uint32_t available = (fs.f_bfree * fs.f_frsize) / GB;
uint32_t used = total - available;
uint8_t percentage = (used / (double) total) * 100.0;
ffPrintLogoAndKey(instance, "Disk (/)");
printf("%uGB / %uGB (%u%%)\n", used, total, percentage);
if(ffStrbufIsEmpty(&instance->config.diskFormat))
{
printf("%uGB / %uGB (%u%%)\n", used, total, percentage);
}
else
{
FFstrbuf disk;
ffStrbufInit(&disk);
ffParseFormatString(&disk, &instance->config.diskFormat, 3,
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &used},
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &total},
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT8, &percentage}
);
ffStrbufWriteTo(&disk, stdout);
putchar('\n');
ffStrbufDestroy(&disk);
}
}
+27 -6
View File
@@ -4,6 +4,12 @@ void ffPrintFont(FFinstance* instance)
{
char plasma[256];
ffParsePropFileHome(instance, ".config/kdeglobals", "font=%[^\n]", plasma);
char plasmaPretty[256];
if(plasma[0] == '\0')
strcpy(plasmaPretty, "Noto Sans (10pt)");
else
ffParseFont(plasma, plasmaPretty);
char gtk2[256];
ffParsePropFileHome(instance, ".gtkrc-2.0", "gtk-font-name=\"%[^\"]+", gtk2);
@@ -32,19 +38,34 @@ void ffPrintFont(FFinstance* instance)
else
ffParseFont(gtk4, gtk4Pretty);
FFstrbuf gtkPretty;
ffStrbufInit(&gtkPretty);
ffFormatGtkPretty(&gtkPretty, gtk2Pretty, gtk3Pretty, gtk4Pretty);
ffPrintLogoAndKey(instance, "Font");
if(plasma[0] == '\0')
if(ffStrbufIsEmpty(&instance->config.fontFormat))
{
printf("Noto Sans (10pt) [Plasma], ");
printf("%s [Plasma], ", plasmaPretty);
ffStrbufWriteTo(&gtkPretty, stdout);
}
else
{
char plasmaPretty[256];
ffParseFont(plasma, plasmaPretty);
printf("%s [Plasma], ", plasmaPretty);
FFstrbuf font;
ffStrbufInit(&font);
ffParseFormatString(&font, &instance->config.fontFormat, 5,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, plasmaPretty},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk2Pretty},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk3Pretty},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk4Pretty},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &gtkPretty}
);
ffStrbufWriteTo(&font, stdout);
ffStrbufDestroy(&font);
}
ffPrintGtkPretty(gtk2Pretty, gtk3Pretty, gtk4Pretty);
putchar('\n');
ffStrbufDestroy(&gtkPretty);
}
+23 -9
View File
@@ -11,32 +11,46 @@ static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_
if(ffPrintCachedValue(instance, key))
return;
char gpu[1024];
FFstrbuf gpu;
ffStrbufInit(&gpu);
char vendor[512];
ffpci_lookup_name(pacc, vendor, sizeof(vendor), PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id);
char vendorPretty[512];
if(strcasecmp(vendor, "Advanced Micro Devices, Inc. [AMD/ATI]") == 0)
strcpy(vendorPretty, "AMD ATI");
else
strcpy(vendorPretty, vendor);
char name[512];
ffpci_lookup_name(pacc, name, sizeof(name), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
if(strcasecmp(vendor, "Advanced Micro Devices, Inc. [AMD/ATI]") == 0)
ffPrintLogoAndKey(instance, "GPU");
if(ffStrbufIsEmpty(&instance->config.gpuFormat))
{
strcpy(gpu, "AMD ATI ");
ffStrbufSetF(&gpu, "%s %s", vendorPretty, name);
}
else
{
strcpy(gpu, vendor);
strcat(gpu, " ");
ffParseFormatString(&gpu, &instance->config.gpuFormat, 2,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, vendorPretty},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name}
);
}
strcat(gpu, name);
ffPrintAndSaveCachedValue(instance, key, gpu);
ffPrintAndSaveCachedValue(instance, key, gpu.chars);
ffStrbufDestroy(&gpu);
}
void ffPrintGPU(FFinstance* instance)
{
void* pci = dlopen("libpci.so", RTLD_LAZY);
void* pci;
if(ffStrbufIsEmpty(&instance->config.libPCI))
pci = dlopen("libpci.so", RTLD_LAZY);
else
pci = dlopen(instance->config.libPCI.chars, RTLD_LAZY);
if(pci == NULL)
{
ffPrintError(instance, "GPU", "dlopen(\"libpci.so\", RTLD_LAZY) == NULL");
+23 -16
View File
@@ -12,33 +12,40 @@ void ffPrintHost(FFinstance* instance)
ffGetFileContent("/sys/devices/virtual/dmi/id/product_name", name, sizeof(name));
char version[256];
if(instance->config.hostShowVersion || instance->config.hostFormat[0] != '\0')
ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", version, sizeof(version));
else
version[0] = '\0';
ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", version, sizeof(version));
char host[1024];
if(instance->config.hostFormat[0] != '\0')
{
snprintf(host, sizeof(host), instance->config.hostFormat, family, name, version);
}
else if(family[0] == '\0' && name[0] == '\0')
if(family[0] == '\0' && name[0] == '\0')
{
ffPrintError(instance, "Host", "neither family nor name could be determined");
return;
}else if(family[0] != '\0' && name[0] != '\0')
}
ffPrintLogoAndKey(instance, "Host");
FFstrbuf host;
ffStrbufInit(&host);
if(!ffStrbufIsEmpty(&instance->config.hostFormat))
{
snprintf(host, sizeof(host), "%s %s %s", family, name, instance->config.hostShowVersion ? version : "");
ffParseFormatString(&host, &instance->config.hostFormat, 3,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, family},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, version}
);
}
else if(family[0] != '\0' && name[0] != '\0')
{
ffStrbufSetF(&host, "%s %s %s", family, name, version);
}
else if(family[0] != '\0')
{
snprintf(host, sizeof(host), "%s %s", family, instance->config.hostShowVersion ? version : "");
ffStrbufSetF(&host, "%s %s", family, version);
}
else
{
snprintf(host, sizeof(host), "%s %s", name, instance->config.hostShowVersion ? version : "");
ffStrbufSetF(&host, "%s %s", name, version);
}
ffPrintAndSaveCachedValue(instance, "Host", host);
ffPrintAndSaveCachedValue(instance, "Host", host.chars);
ffStrbufDestroy(&host);
}
+32 -6
View File
@@ -19,14 +19,40 @@ void ffPrintIcons(FFinstance* instance)
ffParsePropFileHome(instance, ".config/gtk-4.0/settings.ini", "gtk-icon-theme-name=%[^\n]", gtk4);
if(gtk4[0] == '\0')
strcpy(gtk4, "Adwaita");
FFstrbuf gtkPretty;
ffStrbufInit(&gtkPretty);
ffFormatGtkPretty(&gtkPretty, gtk2, gtk3, gtk4);
ffPrintLogoAndKey(instance, "Icons");
if(plasma[0] == '\0')
printf("Breeze [Plasma], ");
else
printf("%s [Plasma], ", plasma);
if(ffStrbufIsEmpty(&instance->config.iconsFormat))
{
if(plasma[0] == '\0')
printf("Breeze [Plasma], ");
else
printf("%s [Plasma], ", plasma);
ffStrbufWriteTo(&gtkPretty, stdout);
}
else
{
FFstrbuf icons;
ffStrbufInit(&icons);
ffParseFormatString(&icons, &instance->config.iconsFormat, 5,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, plasma},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk2},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk3},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk4},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &gtkPretty}
);
ffStrbufWriteTo(&icons, stdout);
ffStrbufDestroy(&icons);
}
ffPrintGtkPretty(gtk2, gtk3, gtk4);
putchar('\n');
ffStrbufDestroy(&gtkPretty);
}
+18 -9
View File
@@ -2,14 +2,23 @@
void ffPrintKernel(FFinstance* instance)
{
ffPrintLogoAndKey(instance, "Kernel");
if(instance->config.kernelShowRelease && instance->config.kernelShowVersion)
printf("%s %s\n", instance->state.utsname.release, instance->state.utsname.version);
else if(instance->config.kernelShowRelease)
if(ffStrbufIsEmpty(&instance->config.kernelFormat))
{
ffPrintLogoAndKey(instance, "Kernel");
puts(instance->state.utsname.release);
else if(instance->config.kernelShowVersion)
puts(instance->state.utsname.version);
else
puts(instance->state.utsname.sysname);
return;
}
FFstrbuf kernel;
ffStrbufInit(&kernel);
ffParseFormatString(&kernel, &instance->config.kernelFormat, 3,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.sysname},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.release},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.version}
);
ffPrintLogoAndKey(instance, "Kernel");
ffStrbufWriteTo(&kernel, stdout);
ffStrbufDestroy(&kernel);
}
+22 -4
View File
@@ -5,13 +5,31 @@ void ffPrintLocale(FFinstance* instance)
if(ffPrintCachedValue(instance, "Locale"))
return;
char locale[256];
ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", locale);
if(locale[0] == '\0')
char localeCode[256];
ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", localeCode);
if(localeCode[0] == '\0' && ffStrbufIsEmpty(&instance->config.localeFormat))
{
ffPrintError(instance, "Locale", "\"LANG=%[^\\n]\" not found in \"/etc/locale.conf\"");
return;
}
ffPrintAndSaveCachedValue(instance, "Locale", locale);
ffPrintLogoAndKey(instance, "Locale");
FFstrbuf locale;
ffStrbufInit(&locale);
if(ffStrbufIsEmpty(&instance->config.localeFormat))
{
ffStrbufSetS(&locale, localeCode);
}
else
{
ffParseFormatString(&locale, &instance->config.localeFormat, 1,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, localeCode}
);
}
ffPrintAndSaveCachedValue(instance, "Locale", locale.chars);
ffStrbufDestroy(&locale);
}
+20 -1
View File
@@ -31,5 +31,24 @@ void ffPrintMemory(FFinstance* instance)
uint8_t percentage = (uint8_t) ((used_mem / (double) total_mem) * 100);
ffPrintLogoAndKey(instance, "Memory");
printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage);
if(ffStrbufIsEmpty(&instance->config.memoryFormat))
{
printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage);
}
else
{
FFstrbuf memory;
ffStrbufInit(&memory);
ffParseFormatString(&memory, &instance->config.memoryFormat, 3,
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &used_mem},
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &total_mem},
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT8, &percentage}
);
ffStrbufWriteTo(&memory, stdout);
putchar('\n');
ffStrbufDestroy(&memory);
}
}
+17 -8
View File
@@ -7,20 +7,29 @@ void ffPrintOS(FFinstance* instance)
char name[256];
ffParsePropFile("/etc/os-release", "NAME=\"%[^\"]+", name);
if(name[0] == '\0' && instance->config.osFormat[0] == '\0') //With custom format string we pass an empty string as name
if(name[0] == '\0' && ffStrbufIsEmpty(&instance->config.osFormat)) //With custom format string we pass an empty string as name
{
ffPrintError(instance, "OS", "\"NAME=\\\"%[^\\\"]+\" not found in \"/etc/os-release\"");
return;
}
char os[1024];
ffPrintLogoAndKey(instance, "OS");
if(instance->config.osFormat[0] != '\0')
sprintf(os, instance->config.osFormat, name, instance->state.utsname.machine);
else if(instance->config.osShowArchitecture)
sprintf(os, "%s %s", name, instance->state.utsname.machine);
FFstrbuf os;
ffStrbufInit(&os);
if(!ffStrbufIsEmpty(&instance->config.osFormat))
{
ffParseFormatString(&os, &instance->config.osFormat, 2,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.machine}
);
}
else
strcpy(os, name);
{
ffStrbufSetF(&os, "%s %s", name, instance->state.utsname.machine);
}
ffPrintAndSaveCachedValue(instance, "OS", os);
ffPrintAndSaveCachedValue(instance, "OS", os.chars);
ffStrbufDestroy(&os);
}
+24 -43
View File
@@ -25,8 +25,8 @@ static uint32_t get_num_dirs(const char* dirname) {
void ffPrintPackages(FFinstance* instance)
{
uint32_t pacman = instance->config.packagesShowPacman ? get_num_dirs("/var/lib/pacman/local") : 0;
uint32_t flatpak = instance->config.packagesShowFlatpak ? get_num_dirs("/var/lib/flatpak/app") : 0;
uint32_t pacman = get_num_dirs("/var/lib/pacman/local");
uint32_t flatpak = get_num_dirs("/var/lib/flatpak/app");
uint32_t all = pacman + flatpak;
@@ -36,50 +36,17 @@ void ffPrintPackages(FFinstance* instance)
return;
}
ffPrintLogoAndKey(instance, "Packages");
if(instance->config.packagesFormat[0] != '\0')
if(ffStrbufIsEmpty(&instance->config.packagesFormat))
{
printf(instance->config.packagesFormat, all, pacman, flatpak, all);
putchar('\n');
return;
}
ffPrintLogoAndKey(instance, "Packages");
if(instance->config.packagesCombined)
{
printf("%u", all);
if(instance->config.packagesCombinedNames)
{
printf(" (");
#define FF_PRINT_PACKAGE(name) \
if(name > 0) \
{ \
printf(#name); \
if((all = all - name) > 0) \
printf(", "); \
} \
FF_PRINT_PACKAGE(pacman)
FF_PRINT_PACKAGE(flatpak)
#undef FF_PRINT_PACKAGE
printf(")");
}
putchar('\n');
}
else
{
#define FF_PRINT_PACKAGE(name) \
if(name > 0) \
{ \
printf("%u ("#name")", name); \
if((all = all - name) > 0) \
printf(", "); \
};
if(name > 0) \
{ \
printf("%u ("#name")", name); \
if((all = all - name) > 0) \
printf(", "); \
};
FF_PRINT_PACKAGE(pacman)
FF_PRINT_PACKAGE(flatpak)
@@ -87,5 +54,19 @@ void ffPrintPackages(FFinstance* instance)
#undef FF_PRINT_PACKAGE
putchar('\n');
return;
}
FFstrbuf packages;
ffStrbufInit(&packages);
ffParseFormatString(&packages, &instance->config.packagesFormat, 3,
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &all},
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &pacman},
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &flatpak}
);
ffPrintLogoAndKey(instance, "Packages");
ffStrbufWriteTo(&packages, stdout);
ffStrbufDestroy(&packages);
}
+28 -14
View File
@@ -3,11 +3,11 @@
#include "X11/extensions/Xrandr.h"
#include "dlfcn.h"
static short getCurrentRate(FFinstance* instance, Display* display)
static int getCurrentRate(FFinstance* instance, Display* display)
{
void* xrandr;
if(instance->config.resolutionLibXrandr[0] != '\0')
xrandr = dlopen(instance->config.resolutionLibXrandr, RTLD_LAZY);
if(!ffStrbufIsEmpty(&instance->config.libXrandr))
xrandr = dlopen(instance->config.libXrandr.chars, RTLD_LAZY);
else
xrandr = dlopen("libXrandr.so", RTLD_LAZY);
if(xrandr == NULL)
@@ -35,7 +35,7 @@ static short getCurrentRate(FFinstance* instance, Display* display)
dlclose(xrandr);
return currentRate;
return (int) currentRate;
}
void ffPrintResolution(FFinstance* instance)
@@ -44,8 +44,8 @@ void ffPrintResolution(FFinstance* instance)
return;
void* x11;
if(instance->config.resolutionLibX11[0] != '\0')
x11 = dlopen(instance->config.resolutionLibX11, RTLD_LAZY);
if(!ffStrbufIsEmpty(&instance->config.libX11))
x11 = dlopen(instance->config.libX11.chars, RTLD_LAZY);
else
x11 = dlopen("libX11.so", RTLD_LAZY);
if(x11 == NULL)
@@ -70,18 +70,32 @@ void ffPrintResolution(FFinstance* instance)
Screen* screen = DefaultScreenOfDisplay(display);
short currentRate = instance->config.resolutionShowRefreshRate ? getCurrentRate(instance, display) : 0;
int currentRate = getCurrentRate(instance, display);
dlclose(x11);
char resolution[1024];
ffPrintLogoAndKey(instance, "Resolution");
if(instance->config.resolutionFormat[0] != '\0')
sprintf(resolution, instance->config.resolutionFormat, screen->width, screen->height, currentRate);
else if(currentRate == 0)
sprintf(resolution, "%ix%i", screen->width, screen->height);
FFstrbuf resolution;
ffStrbufInit(&resolution);
if(!ffStrbufIsEmpty(&instance->config.resolutionFormat))
{
ffParseFormatString(&resolution, &instance->config.resolutionFormat, 3,
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &screen->width},
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &screen->height},
(FFformatarg){FF_FORMAT_ARG_TYPE_INT, &currentRate}
);
}
else
sprintf(resolution, "%ix%i @ %dHz", screen->width, screen->height, currentRate);
{
ffStrbufAppendF(&resolution, "%ix%i", screen->width, screen->height);
ffPrintAndSaveCachedValue(instance, "Resolution", resolution);
if(currentRate > 0)
ffStrbufAppendF(&resolution, " @ %iHz", currentRate);
}
ffPrintAndSaveCachedValue(instance, "Resolution", resolution.chars);
ffStrbufDestroy(&resolution);
}
+27 -9
View File
@@ -12,20 +12,38 @@ void ffPrintShell(FFinstance* instance)
return;
}
char* value;
char empty[1];
empty[0] = '\0';
if(!instance->config.shellShowPath)
char* shellName = strrchr(shellPath, '/');
if(shellName == NULL)
{
char* shellName = strrchr(shellPath, '/');
if(shellName != NULL)
value = ++shellName;
else
value = shellPath;
shellName = shellPath;
shellPath = empty;
}
else
{
value = shellPath;
*shellName = '\0';
++shellName;
}
ffPrintAndSaveCachedValue(instance, "Shell", value);
ffPrintLogoAndKey(instance, "Shell");
FFstrbuf shell;
ffStrbufInit(&shell);
if(!ffStrbufIsEmpty(&instance->config.shellFormat))
{
ffParseFormatString(&shell, &instance->config.shellFormat, 2,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, shellPath},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, shellName}
);
}
else
{
ffStrbufSetS(&shell, shellName);
}
ffPrintAndSaveCachedValue(instance, "Shell", shell.chars);
ffStrbufDestroy(&shell);
}
+24 -10
View File
@@ -54,7 +54,7 @@ static void getTerminalName(FFinstance* instance, const char* pid, char* termina
void ffPopulateTerminal(FFinstance* instance)
{
if(instance->state.terminal.value != NULL || instance->state.terminal.error != NULL)
if(instance->state.terminal.calculated)
return;
static char terminal[256];
@@ -68,27 +68,41 @@ void ffPopulateTerminal(FFinstance* instance)
getTerminalName(instance, ppid, terminal, error);
if(terminal[0] != '\0')
instance->state.terminal.value = terminal;
ffStrbufSetS(&instance->state.terminal.value, terminal);
if(error[0] != '\0')
instance->state.terminal.error = error;
instance->state.terminal.calculated = true;
}
void ffPrintTerminal(FFinstance* instance)
{
ffPopulateTerminal(instance);
if(instance->state.terminal.value != NULL)
{
ffPrintLogoAndKey(instance, "Terminal");
puts(instance->state.terminal.value);
}
else if(instance->state.terminal.error != NULL)
if(instance->state.terminal.error != NULL)
{
ffPrintError(instance, "Terminal", instance->state.terminal.error);
return;
}
ffPrintLogoAndKey(instance, "Terminal");
if(ffStrbufIsEmpty(&instance->config.terminalFormat))
{
ffStrbufWriteTo(&instance->state.terminal.value, stdout);
}
else
{
ffPrintError(instance, "Terminal", "ffPopulateTerminal failed");
FFstrbuf terminal;
ffStrbufInit(&terminal);
ffParseFormatString(&terminal, &instance->config.terminalFormat, 1,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &instance->state.terminal.value}
);
ffStrbufWriteTo(&terminal, stdout);
}
putchar('\n');
}
+31 -19
View File
@@ -1,5 +1,28 @@
#include "fastfetch.h"
static void printTerminalFont(FFinstance* instance, char* font)
{
ffPrintLogoAndKey(instance, "Terminal font");
if(ffStrbufIsEmpty(&instance->config.termFontFormat))
{
puts(font);
}
else
{
FFstrbuf termfont;
ffStrbufInit(&termfont);
ffParseFormatString(&termfont, &instance->config.termFontFormat, 1,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, font}
);
ffStrbufWriteTo(&termfont, stdout);
putchar('\n');
ffStrbufDestroy(&termfont);
}
}
static void printKonsole(FFinstance* instance)
{
char profile[128];
@@ -17,16 +40,14 @@ static void printKonsole(FFinstance* instance)
ffParsePropFileHome(instance, profilePath, "Font=%[^\n]", font);
if(font[0] == '\0')
{
char error[289];
sprintf(error, "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath);
ffPrintError(instance, "Terminal Font", error);
ffPrintError(instance, "Terminal Font", "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath);
return;
}
char fontPretty[128];
ffParseFont(font, fontPretty);
ffPrintLogoAndKey(instance, "Terminal Font");
puts(fontPretty);
printTerminalFont(instance, fontPretty);
}
static void printTTY(FFinstance* instance)
@@ -36,8 +57,7 @@ static void printTTY(FFinstance* instance)
if(font[0] == '\0')
strcpy(font, "hardware-supplied VGA font");
ffPrintLogoAndKey(instance, "Terminal Font");
puts(font);
printTerminalFont(instance, font);
}
void ffPrintTerminalFont(FFinstance* instance)
@@ -47,21 +67,13 @@ void ffPrintTerminalFont(FFinstance* instance)
if(instance->state.terminal.error != NULL)
{
ffPrintError(instance, "Terminal Font", "Terminal Font needs successfull terminal detection");
}
else if(instance->state.terminal.value == NULL)
{
ffPrintError(instance, "Terminal Font", "ffPopulateTerminal failed");
return;
}
if(strcasecmp(instance->state.terminal.value, "konsole") == 0)
if(ffStrbufIgnCaseCompS(&instance->state.terminal.value, "konsole") == 0)
printKonsole(instance);
else if(strcasecmp(instance->state.terminal.value, "TTY") == 0)
else if(ffStrbufIgnCaseCompS(&instance->state.terminal.value, "TTY") == 0)
printTTY(instance);
else
{
char error[256];
sprintf(error, "Unknown terminal: %s", instance->state.terminal.value);
ffPrintError(instance, "Terminal Font", error);
}
ffPrintError(instance, "Terminal Font", "Unknown terminal: %s", instance->state.terminal.value);
}
+28 -6
View File
@@ -19,14 +19,36 @@ void ffPrintTheme(FFinstance* instance)
ffParsePropFileHome(instance, ".config/gtk-4.0/settings.ini", "gtk-theme-name=%[^\n]", gtk4);
if(gtk4[0] == '\0')
strcpy(gtk4, "Adwaita");
FFstrbuf gtkPretty;
ffStrbufInit(&gtkPretty);
ffFormatGtkPretty(&gtkPretty, gtk2, gtk3, gtk4);
ffPrintLogoAndKey(instance, "Theme");
if(plasma[0] == '\0')
printf("Breeze [Plasma], ");
else
printf("%s [Plasma], ", plasma);
if(ffStrbufIsEmpty(&instance->config.themeFormat))
{
if(plasma[0] != '\0')
printf("%s [Plasma], ", plasma);
ffPrintGtkPretty(gtk2, gtk3, gtk4);
ffStrbufWriteTo(&gtkPretty, stdout);
}
else
{
FFstrbuf theme;
ffStrbufInit(&theme);
ffParseFormatString(&theme, &instance->config.themeFormat, 5,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, plasma},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk2},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk3},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, gtk4},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &gtkPretty}
);
ffStrbufWriteTo(&theme, stdout);
}
putchar('\n');
}
+1 -1
View File
@@ -10,6 +10,6 @@ void ffPrintTitle(FFinstance* instance)
ffPrintLogoLine(instance);
printf(FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"@"FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"\n",
instance->config.color, instance->state.passwd->pw_name, instance->config.color, hostname
instance->config.color.chars, instance->state.passwd->pw_name, instance->config.color.chars, hostname
);
}
+36 -16
View File
@@ -2,26 +2,46 @@
void ffPrintUptime(FFinstance* instance)
{
ffPrintLogoAndKey(instance, "Uptime");
if(instance->state.sysinfo.uptime < 60)
uint32_t days = instance->state.sysinfo.uptime / 86400;
uint32_t hours = (instance->state.sysinfo.uptime - (days * 86400)) / 3600;
uint32_t minutes = (instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600)) / 60;
uint32_t seconds = instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600) - (minutes * 60);
if(ffStrbufIsEmpty(&instance->config.uptimeFormat))
{
printf("%ld seconds\n", instance->state.sysinfo.uptime);
return;
ffPrintLogoAndKey(instance, "Uptime");
if(days == 0 && hours == 0 && minutes == 0)
{
printf("%u seconds\n", seconds);
}
else
{
if(days > 0)
printf("%u day%s, ", days, days <= 1 ? "" : "s");
if(hours > 0)
printf("%u hour%s, ", hours, hours <= 1 ? "" : "s");
if(minutes > 0)
printf("%u min%s", minutes, minutes <= 1 ? "" : "s");
putchar('\n');
}
}
else
{
FFstrbuf uptime;
ffStrbufInit(&uptime);
int days = instance->state.sysinfo.uptime / 86400;
int hours = (instance->state.sysinfo.uptime - (days * 86400)) / 3600;
int minutes = (instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600)) / 60;
if(days > 0)
printf("%d day%s, ", days, days <= 1 ? "" : "s");
if(hours > 0)
printf("%d hour%s, ", hours, hours <= 1 ? "" : "s");
ffParseFormatString(&uptime, &instance->config.uptimeFormat, 4,
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &days},
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &hours},
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &minutes},
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &seconds}
);
if(minutes > 0)
printf("%d min%s", minutes, minutes <= 1 ? "" : "s");
putchar('\n');
ffPrintLogoAndKey(instance, "Uptime");
ffStrbufWriteTo(&uptime, stdout);
ffStrbufDestroy(&uptime);
}
}
+33 -14
View File
@@ -2,12 +2,14 @@
#include <dirent.h>
static void parseProcessName(const char* name, char* buffer)
static bool parseProcessName(FFstrbuf* name)
{
if(strcasecmp(name, "kwin_wayland") == 0)
strcpy(buffer, "KWin (Wayland)");
else if(strcasecmp(name, "kwin_x11") == 0)
strcpy(buffer, "KWin (X11)");
if(ffStrbufIgnCaseCompS(name, "kwin_wayland") == 0 || ffStrbufIgnCaseCompS(name, "kwin_x11") == 0)
ffStrbufSetS(name, "KWin");
else
return false;
return true;
}
void ffPrintWM(FFinstance* instance)
@@ -21,8 +23,10 @@ void ffPrintWM(FFinstance* instance)
struct dirent* dirent;
char name[32];
name[0] = '\0';
FFstrbuf name;
ffStrbufInit(&name);
bool found = false;
while((dirent = readdir(proc)) != NULL)
{
@@ -35,24 +39,39 @@ void ffPrintWM(FFinstance* instance)
char comm[17]; //MAX_COMM_LENGTH is 17 + null terminator
ffGetFileContent(path, comm, sizeof(comm));
if(comm[0] == '\0')
continue;
ffStrbufSetS(&name, comm);
parseProcessName(comm, name);
if(name[0] != '\0')
if((found = parseProcessName(&name)))
break;
}
closedir(proc);
if(name[0] == '\0')
if(!found)
{
ffPrintError(instance, "WM", "No process name matches the name of known display managers");
return;
}
if(ffStrbufIsEmpty(&instance->config.wmFormat))
{
ffPrintLogoAndKey(instance, "WM");
ffStrbufWriteTo(&name, stdout);
}
else
{
FFstrbuf wm;
ffStrbufInit(&wm);
ffParseFormatString(&wm, &instance->config.wmFormat, 1,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &name}
);
ffPrintLogoAndKey(instance, "WM");
puts(name);
ffStrbufWriteTo(&wm, stdout);
ffStrbufDestroy(&wm);
}
putchar('\n');
}
+271
View File
@@ -0,0 +1,271 @@
#include "FFstrbuf.h"
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
void ffStrbufInit(FFstrbuf* strbuf)
{
ffStrbufInitA(strbuf, FASTFETCH_STRBUF_DEFAULT_ALLOC);
}
void ffStrbufInitS(FFstrbuf* strbuf, const char* value)
{
ffStrbufInitAS(strbuf, FASTFETCH_STRBUF_DEFAULT_ALLOC, value);
}
void ffStrbufInitNS(FFstrbuf* strbuf, uint32_t length, const char* value)
{
ffStrbufInitANS(strbuf, FASTFETCH_STRBUF_DEFAULT_ALLOC, length, value);
}
void ffStrbufInitC(FFstrbuf* strbuf, const char c)
{
ffStrbufInitAC(strbuf, FASTFETCH_STRBUF_DEFAULT_ALLOC, c);
}
void ffStrbufInitA(FFstrbuf* strbuf, uint32_t allocate)
{
if(allocate == 0)
{
fprintf(stderr, "ffStrbufInitA(): allocation size == 0");
exit(701);
}
strbuf->allocated = allocate;
strbuf->chars = (char*) malloc(sizeof(char) * strbuf->allocated);
ffStrbufClear(strbuf);
}
void ffStrbufInitAS(FFstrbuf* strbuf, uint32_t allocate, const char* value)
{
ffStrbufInitA(strbuf, allocate);
ffStrbufAppendS(strbuf, value);
}
void ffStrbufInitANS(FFstrbuf* strbuf, uint32_t allocate, uint32_t length, const char* value)
{
ffStrbufInitA(strbuf, allocate);
ffStrbufAppendNS(strbuf, length, value);
}
void ffStrbufInitAC(FFstrbuf* strbuf, uint32_t allocate, const char c)
{
ffStrbufInitA(strbuf, allocate);
ffStrbufAppendC(strbuf, c);
}
void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...)
{
ffStrbufInitA(strbuf, FASTFETCH_STRBUF_DEFAULT_ALLOC);
va_list arguments;
va_start(arguments, format);
ffStrbufAppendVF(strbuf, format, arguments);
va_end(arguments);
}
void ffStrbufInitVF(FFstrbuf* strbuf, const char* format, va_list arguments)
{
ffStrbufInitA(strbuf, FASTFETCH_STRBUF_DEFAULT_ALLOC);
ffStrbufAppendVF(strbuf, format, arguments);
}
void ffStrbufEnsureCapacity(FFstrbuf* strbuf, uint32_t allocate)
{
if(strbuf->allocated >= allocate)
return;
strbuf->allocated = allocate;
strbuf->chars = realloc(strbuf->chars, sizeof(char) * strbuf->allocated);
}
void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free)
{
uint32_t allocate = strbuf->allocated;
while((strbuf->length + free) > allocate)
allocate *= 2;
ffStrbufEnsureCapacity(strbuf, allocate);
}
void ffStrbufClear(FFstrbuf* strbuf)
{
strbuf->chars[0] = '\0';
strbuf->length = 0;
}
bool ffStrbufIsEmpty(FFstrbuf* strbuf)
{
return strbuf->length == 0;
}
void ffStrbufSet(FFstrbuf* strbuf, FFstrbuf* value)
{
ffStrbufClear(strbuf);
ffStrbufAppendNS(strbuf, value->length, value->chars);
}
void ffStrbufSetS(FFstrbuf* strbuf, const char* value)
{
ffStrbufClear(strbuf);
ffStrbufAppendS(strbuf, value);
}
void ffStrbufSetNS(FFstrbuf* strbuf, uint32_t length, const char* value)
{
ffStrbufClear(strbuf);
ffStrbufAppendNS(strbuf, length, value);
}
void ffStrbufSetC(FFstrbuf* strbuf, const char c)
{
ffStrbufClear(strbuf);
ffStrbufAppendC(strbuf, c);
}
void ffStrbufSetF(FFstrbuf* strbuf, const char* format, ...)
{
ffStrbufClear(strbuf);
va_list arguments;
va_start(arguments, format);
ffStrbufAppendVF(strbuf, format, arguments);
va_end(arguments);
}
void ffStrbufSetVF(FFstrbuf* strbuf, const char* format, va_list arguments)
{
ffStrbufClear(strbuf);
ffStrbufAppendVF(strbuf, format, arguments);
}
void ffStrbufAppend(FFstrbuf* strbuf, FFstrbuf* value)
{
ffStrbufAppendNS(strbuf, value->length, value->chars);
}
void ffStrbufAppendS(FFstrbuf* strbuf, const char* value)
{
if(value == NULL)
return;
for(uint32_t i = 0; value[i] != '\0'; i++)
{
if(i % 16 == 0)
ffStrbufEnsureFree(strbuf, 16);
strbuf->chars[strbuf->length++] = value[i];
}
strbuf->chars[strbuf->length] = '\0';
}
void ffStrbufAppendNS(FFstrbuf* strbuf, uint32_t length, const char* value)
{
if(value == NULL)
return;
ffStrbufEnsureFree(strbuf, length);
for(uint32_t i = 0; i < length; i++)
{
if(value[i] == '\0')
break;
strbuf->chars[strbuf->length++] = value[i];
}
strbuf->chars[strbuf->length] = '\0';
}
void ffStrbufAppendC(FFstrbuf* strbuf, const char c)
{
ffStrbufEnsureFree(strbuf, 1);
strbuf->chars[strbuf->length++] = c;
strbuf->chars[strbuf->length] = '\0';
}
void ffStrbufAppendF(FFstrbuf* strbuf, const char* format, ...)
{
if(format == NULL)
return;
va_list arguments;
va_start(arguments, format);
ffStrbufAppendVF(strbuf, format, arguments);
va_end(arguments);
}
void ffStrbufAppendVF(FFstrbuf* strbuf, const char* format, va_list arguments)
{
if(format == NULL)
return;
va_list localArguments;
va_copy(localArguments, arguments);
ffStrbufEnsureFree(strbuf, 256);
int written = vsnprintf(strbuf->chars + strbuf->length, strbuf->allocated - strbuf->length, format, localArguments);
va_end(localArguments);
if(strbuf->length + written >= strbuf->allocated)
{
ffStrbufEnsureCapacity(strbuf, strbuf->allocated * 2);
ffStrbufAppendVF(strbuf, format, arguments); //Try again with larger buffer
}
else
{
strbuf->length += written;
strbuf->chars[strbuf->length] = '\0';
}
}
char ffStrbufGetC(FFstrbuf* strbuf, uint32_t index)
{
if(index >= strbuf->length)
{
fprintf(stderr, "ffStrbufGetC(): to high index");
exit(702);
}
return strbuf->chars[index];
}
void ffStrbufWriteTo(FFstrbuf* strbuf, FILE* file)
{
fwrite(strbuf->chars, sizeof(char), strbuf->length, file);
}
int ffStrbufComp(FFstrbuf* strbuf, FFstrbuf* comp)
{
return ffStrbufCompNS(strbuf, comp->length, comp->chars);
}
int ffStrbufCompS(FFstrbuf* strbuf, const char* comp)
{
return strcmp(strbuf->chars, comp);
}
int ffStrbufCompNS(FFstrbuf* strbuf, uint32_t length, const char* comp)
{
return strncasecmp(strbuf->chars, comp, length);
}
int ffStrbufIgnCaseComp(FFstrbuf* strbuf, FFstrbuf* comp)
{
return ffStrbufIgnCaseCompNS(strbuf, comp->length, comp->chars);
}
int ffStrbufIgnCaseCompS(FFstrbuf* strbuf, const char* comp)
{
return strcasecmp(strbuf->chars, comp);
}
int ffStrbufIgnCaseCompNS(FFstrbuf* strbuf, uint32_t length, const char* comp)
{
return strncasecmp(strbuf->chars, comp, length);
}
void ffStrbufDestroy(FFstrbuf* strbuf)
{
free(strbuf->chars);
strbuf->allocated = 0;
strbuf->chars = NULL;
strbuf->length = 0;
}
+64
View File
@@ -0,0 +1,64 @@
#pragma once
#ifndef FASTFETCH_INCLUDED_FFSTRBUF
#define FASTFETCH_INCLUDED_FFSTRBUF
#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#define FASTFETCH_STRBUF_DEFAULT_ALLOC 64
typedef struct FFstrbuf
{
uint32_t allocated;
uint32_t length;
char* chars;
} FFstrbuf;
void ffStrbufInit(FFstrbuf* strbuf);
void ffStrbufInitS(FFstrbuf* strbuf, const char* value);
void ffStrbufInitNS(FFstrbuf* strbuf, uint32_t length, const char* value);
void ffStrbufInitC(FFstrbuf* strbuf, const char c);
void ffStrbufInitA(FFstrbuf* strbuf, uint32_t allocate);
void ffStrbufInitAS(FFstrbuf* strbuf, uint32_t allocate, const char* value);
void ffStrbufInitANS(FFstrbuf* strbuf, uint32_t allocate, uint32_t length, const char* value);
void ffStrbufInitAC(FFstrbuf* strbuf, uint32_t allocate, const char c);
void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...);
void ffStrbufInitVF(FFstrbuf* strbuf, const char* format, va_list arguments);
void ffStrbufEnsureCapacity(FFstrbuf* strbuf, uint32_t allocate);
void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free);
void ffStrbufClear(FFstrbuf* strbuf);
bool ffStrbufIsEmpty(FFstrbuf* strbuf);
void ffStrbufSet(FFstrbuf* strbuf, FFstrbuf* value);
void ffStrbufSetS(FFstrbuf* strbuf, const char* value);
void ffStrbufSetNS(FFstrbuf* strbuf, uint32_t length, const char* value);
void ffStrbufSetC(FFstrbuf* strbuf, const char c);
void ffStrbufSetF(FFstrbuf* strbuf, const char* format, ...);
void ffStrbufSetVF(FFstrbuf* strbuf, const char* format, va_list arguments);
void ffStrbufAppend(FFstrbuf* strbuf, FFstrbuf* value);
void ffStrbufAppendS(FFstrbuf* strbuf, const char* value);
void ffStrbufAppendNS(FFstrbuf* strbuf, uint32_t length, const char* value);
void ffStrbufAppendC(FFstrbuf* strbuf, const char c);
void ffStrbufAppendF(FFstrbuf* strbuf, const char* format, ...);
void ffStrbufAppendVF(FFstrbuf* strbuf, const char* format, va_list arguments);
char ffStrbufGetC(FFstrbuf* strbuf, uint32_t index);
void ffStrbufWriteTo(FFstrbuf* strbuf, FILE* file);
int ffStrbufComp(FFstrbuf* strbuf, FFstrbuf* comp);
int ffStrbufCompS(FFstrbuf* strbuf, const char* comp);
int ffStrbufCompNS(FFstrbuf* strbuf, uint32_t length, const char* comp);
int ffStrbufIgnCaseComp(FFstrbuf* strbuf, FFstrbuf* comp);
int ffStrbufIgnCaseCompS(FFstrbuf* strbuf, const char* comp);
int ffStrbufIgnCaseCompNS(FFstrbuf* strbuf, uint32_t length, const char* comp);
void ffStrbufDestroy(FFstrbuf* strbuf);
#endif
+2
View File
@@ -1,3 +1,5 @@
#pragma once
#ifndef FASTFETCH_INCLUDED_FFVALUESTORE
#define FASTFETCH_INCLUDED_FFVALUESTORE
+1 -1
View File
@@ -27,7 +27,7 @@ int main(int argc, char** argv)
FASTFETCH_TEST_PERFORMANCE(
puts("Configuration");
ffLoadLogoSet(&instance.config, "arch");
strcpy(instance.config.color, instance.config.logo.color);
ffStrbufSetS(&instance.config.color, instance.config.logo.color);
)
FASTFETCH_TEST_PERFORMANCE(ffPrintTitle(&instance))