mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Logo: refactor logo initial code
This commit is contained in:
@@ -96,7 +96,7 @@ Battery, Bios, Bluetooth, Board, Break, Brightness, Colors, Command, CPU, CPUUsa
|
||||
|
||||
##### Builtin logos
|
||||
|
||||
See files in <https://github.com/fastfetch-cli/fastfetch/tree/dev/src/logo/ascii>
|
||||
See files in <src/logo/ascii>
|
||||
|
||||
##### Package managers
|
||||
```
|
||||
|
||||
+1660
-2226
File diff suppressed because it is too large
Load Diff
+21
-35
@@ -187,8 +187,11 @@ static void logoApplyColors(const FFlogo* logo)
|
||||
|
||||
static bool logoHasName(const FFlogo* logo, const FFstrbuf* name, bool small)
|
||||
{
|
||||
for(const char** logoName = logo->names; *logoName != NULL; ++logoName)
|
||||
{
|
||||
for(
|
||||
const char* const* logoName = logo->names;
|
||||
*logoName != NULL && logoName <= &logo->names[FASTFETCH_LOGO_MAX_NAMES];
|
||||
++logoName
|
||||
) {
|
||||
if(small)
|
||||
{
|
||||
uint32_t logoNameLength = (uint32_t) (strlen(*logoName) - strlen("_small"));
|
||||
@@ -206,10 +209,8 @@ static const FFlogo* logoGetBuiltin(const FFstrbuf* name, FFLogoSize size)
|
||||
if (name->length == 0)
|
||||
return NULL;
|
||||
|
||||
for(GetLogoMethod* methods = ffLogoBuiltinGetAll(); *methods; ++methods)
|
||||
for(const FFlogo* logo = ffLogoBuiltins; logo < ffLogoBuiltins + ffLogoBuiltinLength; ++logo)
|
||||
{
|
||||
const FFlogo* logo = (*methods)();
|
||||
|
||||
switch (size)
|
||||
{
|
||||
case FF_LOGO_SIZE_NORMAL:
|
||||
@@ -253,7 +254,7 @@ static const FFlogo* logoGetBuiltinDetected(FFLogoSize size)
|
||||
if(logo != NULL)
|
||||
return logo;
|
||||
|
||||
return ffLogoBuiltinGetUnknown();
|
||||
return &ffLogoBuiltins[0]; // Unknown
|
||||
}
|
||||
|
||||
static inline void logoApplyColorsDetected(void)
|
||||
@@ -267,14 +268,14 @@ static void logoPrintStruct(const FFlogo* logo)
|
||||
|
||||
FFLogoOptions* options = &instance.config.logo;
|
||||
|
||||
const char** colors = logo->builtinColors;
|
||||
const char* const* colors = logo->colors;
|
||||
for(int i = 0; *colors != NULL && i < FASTFETCH_LOGO_MAX_COLORS; i++, colors++)
|
||||
{
|
||||
if(options->colors[i].length == 0)
|
||||
ffStrbufAppendS(&options->colors[i], *colors);
|
||||
}
|
||||
|
||||
ffLogoPrintChars(logo->data, true);
|
||||
ffLogoPrintChars(logo->lines, true);
|
||||
}
|
||||
|
||||
static void logoPrintNone(void)
|
||||
@@ -499,13 +500,11 @@ void ffLogoPrintRemaining(void)
|
||||
|
||||
void ffLogoBuiltinPrint(void)
|
||||
{
|
||||
GetLogoMethod* methods = ffLogoBuiltinGetAll();
|
||||
FFLogoOptions* options = &instance.config.logo;
|
||||
|
||||
while(*methods != NULL)
|
||||
for(const FFlogo* logo = ffLogoBuiltins; logo < ffLogoBuiltins + ffLogoBuiltinLength; ++logo)
|
||||
{
|
||||
const FFlogo* logo = (*methods)();
|
||||
printf("\033[%sm%s:\033[0m\n", logo->builtinColors[0], logo->names[0]);
|
||||
printf("\033[%sm%s:\033[0m\n", logo->colors[0], logo->names[0]);
|
||||
logoPrintStruct(logo);
|
||||
ffLogoPrintRemaining();
|
||||
|
||||
@@ -515,43 +514,30 @@ void ffLogoBuiltinPrint(void)
|
||||
for(uint8_t i = 0; i < FASTFETCH_LOGO_MAX_COLORS; i++)
|
||||
ffStrbufClear(&options->colors[i]);
|
||||
|
||||
puts("\n");
|
||||
++methods;
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
void ffLogoBuiltinList(void)
|
||||
{
|
||||
GetLogoMethod* methods = ffLogoBuiltinGetAll();
|
||||
|
||||
uint32_t counter = 0;
|
||||
|
||||
while(*methods != NULL)
|
||||
for(uint32_t counter = 0; counter < ffLogoBuiltinLength; ++counter)
|
||||
{
|
||||
const FFlogo* logo = (*methods)();
|
||||
const char** names = logo->names;
|
||||
|
||||
const FFlogo* logo = &ffLogoBuiltins[counter];
|
||||
printf("%u)%s ", counter, counter < 10 ? " " : "");
|
||||
++counter;
|
||||
|
||||
while(*names != NULL)
|
||||
{
|
||||
for(
|
||||
const char* const* names = logo->names;
|
||||
*names != NULL && names <= &logo->names[FASTFETCH_LOGO_MAX_NAMES];
|
||||
++names
|
||||
)
|
||||
printf("\"%s\" ", *names);
|
||||
++names;
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
++methods;
|
||||
}
|
||||
}
|
||||
|
||||
void ffLogoBuiltinListAutocompletion(void)
|
||||
{
|
||||
GetLogoMethod* methods = ffLogoBuiltinGetAll();
|
||||
|
||||
while(*methods != NULL)
|
||||
{
|
||||
printf("%s\n", (*methods)()->names[0]);
|
||||
++methods;
|
||||
}
|
||||
for(const FFlogo* logo = ffLogoBuiltins; logo < ffLogoBuiltins + ffLogoBuiltinLength; ++logo)
|
||||
printf("%s\n", logo->names[0]);
|
||||
}
|
||||
|
||||
+6
-8
@@ -7,22 +7,20 @@
|
||||
|
||||
typedef struct FFlogo
|
||||
{
|
||||
const char* data;
|
||||
const char** names; //Null terminated
|
||||
const char** builtinColors; //Null terminated
|
||||
const char* lines;
|
||||
const char* names[FASTFETCH_LOGO_MAX_NAMES];
|
||||
const char* colors[FASTFETCH_LOGO_MAX_COLORS];
|
||||
const char* colorKeys;
|
||||
const char* colorTitle;
|
||||
bool small;
|
||||
bool small; // The names of small logo must end with `_small` or `-small`
|
||||
} FFlogo;
|
||||
|
||||
typedef const FFlogo*(*GetLogoMethod)();
|
||||
|
||||
//logo.c
|
||||
void ffLogoPrintChars(const char* data, bool doColorReplacement);
|
||||
|
||||
//builtin.c
|
||||
const FFlogo* ffLogoBuiltinGetUnknown();
|
||||
GetLogoMethod* ffLogoBuiltinGetAll();
|
||||
extern const FFlogo ffLogoBuiltins[];
|
||||
extern const uint32_t ffLogoBuiltinLength;
|
||||
|
||||
//image/image.c
|
||||
bool ffLogoPrintImageIfExists(FFLogoType type, bool printError);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "util/FFstrbuf.h"
|
||||
|
||||
#define FASTFETCH_LOGO_MAX_NAMES 9
|
||||
#define FASTFETCH_LOGO_MAX_COLORS 9 //two digits would make parsing much more complicated (index 1 - 9)
|
||||
|
||||
typedef enum FFLogoType
|
||||
|
||||
Reference in New Issue
Block a user