From a8ca2ce825d70c8507e9448378ebbcea3fe37410 Mon Sep 17 00:00:00 2001 From: Salonia Matteo Date: Sat, 20 Mar 2021 07:09:02 +0000 Subject: [PATCH 1/6] Sync from upstream --- completions/bash | 6 +----- src/common.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/fastfetch.c | 23 +++++++++++++++-------- src/fastfetch.h | 3 +++ src/flashfetch.c | 1 + src/logo.c | 9 +++++++++ 6 files changed, 71 insertions(+), 13 deletions(-) diff --git a/completions/bash b/completions/bash index c52e999f7..15df090a8 100644 --- a/completions/bash +++ b/completions/bash @@ -109,11 +109,7 @@ __fastfetch_completion() "--recache" "--show-errors" "--color-logo" - "--battery-manufacturer" - "--battery-model" - "--battery-technology" - "--battery-capacity" - "--battery-status" + "--print-remaining-logo" ) local FF_OPTIONS_STRING=( diff --git a/src/common.c b/src/common.c index 712203150..5d2a7f2c3 100644 --- a/src/common.c +++ b/src/common.c @@ -30,6 +30,7 @@ void ffDefaultConfig(FFconfig* config) config->showErrors = false; config->recache = false; config->cacheSave = true; + config->printRemainingLogo = true; ffStrbufInit(&config->osFormat); ffStrbufInit(&config->hostFormat); @@ -57,6 +58,47 @@ void ffDefaultConfig(FFconfig* config) ffStrbufInitA(&config->libXrandr, 256); } +static void ffCleanup(FFinstance* instance) +{ + ffStrbufDestroy(&instance->config.color); + ffStrbufDestroy(&instance->config.seperator); + + ffStrbufDestroy(&instance->config.osFormat); + ffStrbufDestroy(&instance->config.hostFormat); + ffStrbufDestroy(&instance->config.kernelFormat); + ffStrbufDestroy(&instance->config.uptimeFormat); + ffStrbufDestroy(&instance->config.packagesFormat); + ffStrbufDestroy(&instance->config.shellFormat); + ffStrbufDestroy(&instance->config.resolutionFormat); + ffStrbufDestroy(&instance->config.deFormat); + ffStrbufDestroy(&instance->config.wmFormat); + ffStrbufDestroy(&instance->config.themeFormat); + ffStrbufDestroy(&instance->config.iconsFormat); + ffStrbufDestroy(&instance->config.fontFormat); + ffStrbufDestroy(&instance->config.terminalFormat); + ffStrbufDestroy(&instance->config.termFontFormat); + ffStrbufDestroy(&instance->config.cpuFormat); + ffStrbufDestroy(&instance->config.gpuFormat); + ffStrbufDestroy(&instance->config.memoryFormat); + ffStrbufDestroy(&instance->config.diskFormat); + ffStrbufDestroy(&instance->config.batteryFormat); + ffStrbufDestroy(&instance->config.localeFormat); + + ffStrbufDestroy(&instance->config.libPCI); + ffStrbufDestroy(&instance->config.libX11); + ffStrbufDestroy(&instance->config.libXrandr); + + ffStrbufDestroy(&instance->state.terminal.value); +} + +void ffFinish(FFinstance* instance) +{ + if(instance->config.printRemainingLogo) + ffPrintRemainingLogo(instance); + + ffCleanup(instance); +} + void ffPrintKey(FFconfig* config, const char* key) { printf(FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"%s", config->color.chars, key, config->seperator.chars); diff --git a/src/fastfetch.c b/src/fastfetch.c index f0b8f98f8..18665b797 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -42,14 +42,15 @@ static inline void printHelp() " --print-default-config: prints the default config and exits\n" "\n" "General options:\n" - " --structure : sets the structure of the fetch. Must be a colon seperated list of keys\n" - " --set : hard set the value of an key\n" - " -c , --color : sets the color of the keys. Must be a linux console color code (+)\n" - " --spacer : sets the distance between logo and text\n" - " -s , --seperator : sets the seperator between key and value. Default is a colon with a space\n" - " -x , --offsetx : sets the x offset. Can be negative to cut the logo, but no more than logo width.\n" - " --show-errors : print occuring errors\n" - " -r --recache : if set to true, no cached values will be used\n" + " --structure : sets the structure of the fetch. Must be a colon seperated list of keys\n" + " --set : hard set the value of an key\n" + " -c , --color : sets the color of the keys. Must be a linux console color code (+)\n" + " --spacer : sets the distance between logo and text\n" + " -s , --seperator : sets the seperator between key and value. Default is a colon with a space\n" + " -x , --offsetx : sets the x offset. Can be negative to cut the logo, but no more than logo width.\n" + " --show-errors : print occuring errors\n" + " -r --recache : if set to true, no cached values will be used\n" + " --print-remaining-logo : print the remaining logo, if it is higher than the number of lines shown\n" "\n" "Logo options:\n" " -l , --logo : sets the shown logo. Also changes the main color accordingly\n" @@ -400,6 +401,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con instance->config.showErrors = optionParseBoolean(value); else if(strcasecmp(key, "--color-logo") == 0) instance->config.colorLogo = optionParseBoolean(value); + else if(strcasecmp(key, "--print-remaining-logo") == 0) + instance->config.printRemainingLogo = optionParseBoolean(value); else if(strcasecmp(key, "--structure") == 0) optionParseString(key, value, &data->structure); else if(strcasecmp(key, "-l") == 0 || strcasecmp(key, "--logo") == 0) @@ -691,5 +694,9 @@ int main(int argc, const char** argv) run(&instance, &data); + ffFinish(&instance); + + ffStrbufDestroy(&data.structure); + ffStrbufDestroy(&data.logoName); ffValuestoreDelete(&data.valuestore); } diff --git a/src/fastfetch.h b/src/fastfetch.h index 9b216dc2a..e6841207c 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -43,6 +43,7 @@ typedef struct FFconfig bool showErrors; bool recache; bool cacheSave; //This is only set to true when using arguments, because we dont want so save this values + bool printRemainingLogo; FFstrbuf osFormat; FFstrbuf hostFormat; @@ -125,11 +126,13 @@ 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, ...); +void ffFinish(FFinstance* instance); //Logo functions void ffLoadLogoSet(FFconfig* config, const char* logo); void ffLoadLogo(FFconfig* config); void ffPrintLogoLine(FFinstance* instance); +void ffPrintRemainingLogo(FFinstance* instance); #ifndef FLASHFETCH_BUILD_FLASHFATCH void ffListLogos(); diff --git a/src/flashfetch.c b/src/flashfetch.c index 8a8ec94a1..a0ce2a016 100644 --- a/src/flashfetch.c +++ b/src/flashfetch.c @@ -36,5 +36,6 @@ int main(int argc, char** argv) ffPrintBreak(&instance); ffPrintColors(&instance); + ffFinish(&instance); return 0; } \ No newline at end of file diff --git a/src/logo.c b/src/logo.c index 57a866301..d4dd4b9c6 100644 --- a/src/logo.c +++ b/src/logo.c @@ -230,6 +230,15 @@ void ffPrintLogoLine(FFinstance* instance) ++instance->state.current_row; } +void ffPrintRemainingLogo(FFinstance* instance) +{ + while(instance->state.current_row < instance->config.logo.height) + { + ffPrintLogoLine(instance); + putchar('\n'); + } +} + #ifndef FASTFETCH_BUILD_FLASHFETCH static FFlogo* getLogos(uint8_t* size, bool color) From e531278e626796bfbf8d04de4ad8dbdfa27f3b49 Mon Sep 17 00:00:00 2001 From: saloniamatteo Date: Sat, 20 Mar 2021 10:39:05 +0100 Subject: [PATCH 2/6] Experimental: use fallback for LANG --- src/modules/locale.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/modules/locale.c b/src/modules/locale.c index 5f1cfb936..cccc58cbc 100644 --- a/src/modules/locale.c +++ b/src/modules/locale.c @@ -1,3 +1,7 @@ +#include +#include +#include + #include "fastfetch.h" void ffPrintLocale(FFinstance* instance) @@ -5,13 +9,25 @@ void ffPrintLocale(FFinstance* instance) if(ffPrintCachedValue(instance, "Locale")) return; - char localeCode[256]; - ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", localeCode); + char localeCode[256]; + + FILE *fp; + fp = fopen("/etc/locale.conf", "r"); + + /* File does not exist */ + if (fp == NULL) { + strcpy(localeCode, getenv("LANG")); + } else { + 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; } + */ ffPrintLogoAndKey(instance, "Locale"); @@ -32,4 +48,4 @@ void ffPrintLocale(FFinstance* instance) ffPrintAndSaveCachedValue(instance, "Locale", locale.chars); ffStrbufDestroy(&locale); -} \ No newline at end of file +} From e2986b198fecfa43694b625667c43b78ea24d688 Mon Sep 17 00:00:00 2001 From: saloniamatteo Date: Sat, 20 Mar 2021 10:46:56 +0100 Subject: [PATCH 3/6] Free pointer to file --- src/modules/locale.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/modules/locale.c b/src/modules/locale.c index cccc58cbc..d9402b05a 100644 --- a/src/modules/locale.c +++ b/src/modules/locale.c @@ -12,6 +12,7 @@ void ffPrintLocale(FFinstance* instance) char localeCode[256]; FILE *fp; + /* Try to open /etc/locale.conf in read-only mode */ fp = fopen("/etc/locale.conf", "r"); /* File does not exist */ @@ -21,13 +22,8 @@ void ffPrintLocale(FFinstance* instance) 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; - } - */ + /* Free pointer to file */ + fclose(fp); ffPrintLogoAndKey(instance, "Locale"); From 3d27ecaba89738a47917d30e866c3ffd28eae070 Mon Sep 17 00:00:00 2001 From: saloniamatteo Date: Sat, 20 Mar 2021 10:47:49 +0100 Subject: [PATCH 4/6] Free pointer to file --- src/modules/locale.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/modules/locale.c b/src/modules/locale.c index d9402b05a..d82d3f933 100644 --- a/src/modules/locale.c +++ b/src/modules/locale.c @@ -1,7 +1,3 @@ -#include -#include -#include - #include "fastfetch.h" void ffPrintLocale(FFinstance* instance) From 05fe28114178e025c7d1ac6f57e0a41bff8a4781 Mon Sep 17 00:00:00 2001 From: saloniamatteo Date: Sat, 20 Mar 2021 11:20:37 +0100 Subject: [PATCH 5/6] Fully implement LANG fallbacks --- src/modules/locale.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/modules/locale.c b/src/modules/locale.c index d82d3f933..7a3fa04d8 100644 --- a/src/modules/locale.c +++ b/src/modules/locale.c @@ -7,15 +7,33 @@ void ffPrintLocale(FFinstance* instance) char localeCode[256]; - FILE *fp; /* Try to open /etc/locale.conf in read-only mode */ + FILE *fp; fp = fopen("/etc/locale.conf", "r"); /* File does not exist */ if (fp == NULL) { - strcpy(localeCode, getenv("LANG")); + /* Check if LANG exists */ + if (getenv("LANG") != NULL) + strcpy(localeCode, getenv("LANG")); + /* Check if LC_ALL exists */ + else if (getenv("LC_ALL") != NULL) + strcpy(localeCode, getenv("LC_ALL")); + /* Check if LC_CTYPE exists */ + else if (getenv("LC_CTYPE") != NULL) + strcpy(localeCode, getenv("LC_CTYPE")); + /* Check if LC_CTYPE exists */ + else if (getenv("LC_CTYPE") != NULL) + strcpy(localeCode, getenv("LC_CTYPE")); + /* Check if LC_MESSAGES exists */ + else if (getenv("LC_MESSAGES") != NULL) + strcpy(localeCode, getenv("LC_MESSAGES")); + /* User has broken system */ + else + ffPrintError(instance, "Locale", "Locale not found!"); + /* /etc/locale.conf exists */ } else { - ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", localeCode); + ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", localeCode); } /* Free pointer to file */ From 9d5481e83a2525766957479d9acdb12dc4626ea2 Mon Sep 17 00:00:00 2001 From: saloniamatteo Date: Sat, 20 Mar 2021 11:24:35 +0100 Subject: [PATCH 6/6] Sane indentation: use tabs instead of spaces --- src/modules/locale.c | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/modules/locale.c b/src/modules/locale.c index 7a3fa04d8..5ac34f6a2 100644 --- a/src/modules/locale.c +++ b/src/modules/locale.c @@ -2,17 +2,17 @@ void ffPrintLocale(FFinstance* instance) { - if(ffPrintCachedValue(instance, "Locale")) - return; + if(ffPrintCachedValue(instance, "Locale")) + return; - char localeCode[256]; + char localeCode[256]; - /* Try to open /etc/locale.conf in read-only mode */ - FILE *fp; - fp = fopen("/etc/locale.conf", "r"); + /* Try to open /etc/locale.conf in read-only mode */ + FILE *fp; + fp = fopen("/etc/locale.conf", "r"); - /* File does not exist */ - if (fp == NULL) { + /* File does not exist */ + if (fp == NULL) { /* Check if LANG exists */ if (getenv("LANG") != NULL) strcpy(localeCode, getenv("LANG")); @@ -31,31 +31,31 @@ void ffPrintLocale(FFinstance* instance) /* User has broken system */ else ffPrintError(instance, "Locale", "Locale not found!"); - /* /etc/locale.conf exists */ - } else { + /* /etc/locale.conf exists */ + } else { ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", localeCode); - } + } - /* Free pointer to file */ - fclose(fp); + /* Free pointer to file */ + fclose(fp); - ffPrintLogoAndKey(instance, "Locale"); + ffPrintLogoAndKey(instance, "Locale"); - FFstrbuf locale; - ffStrbufInit(&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} - ); - } + 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); + ffPrintAndSaveCachedValue(instance, "Locale", locale.chars); + ffStrbufDestroy(&locale); }