Logo: data source option

#345
This commit is contained in:
Linus Dierheimer
2022-12-12 13:43:10 +01:00
parent 68b98c1bd2
commit 3a5af1bbb3
6 changed files with 69 additions and 44 deletions
+1 -1
View File
@@ -67,7 +67,7 @@
# Logo type option:
# Sets the logo type to use.
# Must be auto, builtin, file, raw, sixel, kitty or chafa.
# Must be auto, builtin, file, file-raw, data, data-raw, sixel, kitty or chafa.
# Default is auto.
#--logo-type auto
+5 -3
View File
@@ -25,7 +25,7 @@ General options:
Logo options:
-l,--logo <logo>: set the logo to use. The type is specified by --logo-type. If default: the name of a builtin logo or a path to a file
--logo-type <type>: set the type of the logo given. Must be auto, builtin, file, raw, sixel, kitty or chafa.
--logo-type <type>: set the type of the logo given. Must be auto, builtin, file, file-raw, data, data-raw, sixel, kitty or chafa.
--logo-width <width>: set the width of the logo (in characters), if it is an image
--logo-height <height>: set the height of the logo (in characters), if it is an image
--logo-color-[1-9] <color>: overwrite a color in the logo
@@ -33,11 +33,13 @@ Logo options:
--logo-padding-left <padding>: set the padding on the left of the logo
--logo-padding-right <padding>: set the padding on the right of the logo
--logo-print-remaining <?value>: weather to print the remaining logo, if it has more lines than modules to display
--file <file>: short for --logo-type file --logo <file>
--file-raw <file>: short for --logo-type file-raw --logo <file>
--data <data>: short for --logo-type data --logo <data>
--data-raw <data>: short for --logo-type data-raw --logo <data>
--sixel <file>: short for --logo-type sixel --logo <file>
--kitty <file>: short for --logo-type kitty --logo <file>
--chafa <file>: short for --logo-type chafa --logo <file>
--file <file>: short for --logo-type file --logo <file>
--raw <file>: short for --logo-type raw --logo <file>
Display options:
-s,--structure <structure>: sets the structure of the fetch. Must be a colon separated list of keys. Use "fastfetch --list-modules" to see the ones available.
+33 -21
View File
@@ -50,13 +50,13 @@ static void constructAndPrintCommandHelpFormat(const char* name, const char* def
static inline void printCommandHelp(const char* command)
{
if(command == NULL)
fputs(FASTFETCH_DATATEXT_HELP, stdout);
puts(FASTFETCH_DATATEXT_HELP);
else if(strcasecmp(command, "c") == 0 || strcasecmp(command, "color") == 0)
fputs(FASTFETCH_DATATEXT_HELP_COLOR, stdout);
puts(FASTFETCH_DATATEXT_HELP_COLOR);
else if(strcasecmp(command, "format") == 0)
fputs(FASTFETCH_DATATEXT_HELP_FORMAT, stdout);
puts(FASTFETCH_DATATEXT_HELP_FORMAT);
else if(strcasecmp(command, "load-config") == 0 || strcasecmp(command, "loadconfig") == 0 || strcasecmp(command, "config") == 0)
fputs(FASTFETCH_DATATEXT_HELP_CONFIG, stdout);
puts(FASTFETCH_DATATEXT_HELP_CONFIG);
else if(strcasecmp(command, "os-format") == 0)
{
constructAndPrintCommandHelpFormat("os", "{3} {12}", 12,
@@ -945,10 +945,12 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
"auto", FF_LOGO_TYPE_AUTO,
"builtin", FF_LOGO_TYPE_BUILTIN,
"file", FF_LOGO_TYPE_FILE,
"raw", FF_LOGO_TYPE_RAW,
"sixel", FF_LOGO_TYPE_SIXEL,
"kitty", FF_LOGO_TYPE_KITTY,
"chafa", FF_LOGO_TYPE_CHAFA,
"file-raw", FF_LOGO_TYPE_FILE_RAW,
"data", FF_LOGO_TYPE_DATA,
"data-raw", FF_LOGO_TYPE_DATA_RAW,
"sixel", FF_LOGO_TYPE_IMAGE_SIXEL,
"kitty", FF_LOGO_TYPE_IMAGE_KITTY,
"chafa", FF_LOGO_TYPE_IMAGE_CHAFA,
NULL
);
}
@@ -985,30 +987,40 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
else
goto error;
}
else if(strcasecmp(key, "--sixel") == 0)
{
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_SIXEL;
}
else if(strcasecmp(key, "--kitty") == 0)
{
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_KITTY;
}
else if(strcasecmp(key, "--file") == 0)
{
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_FILE;
}
else if(strcasecmp(key, "--raw") == 0)
else if(strcasecmp(key, "--file-raw") == 0)
{
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_RAW;
instance->config.logo.type = FF_LOGO_TYPE_FILE_RAW;
}
else if(strcasecmp(key, "--data") == 0)
{
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_DATA;
}
else if(strcasecmp(key, "--data-raw") == 0)
{
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_DATA_RAW;
}
else if(strcasecmp(key, "--sixel") == 0)
{
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_IMAGE_SIXEL;
}
else if(strcasecmp(key, "--kitty") == 0)
{
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_IMAGE_KITTY;
}
else if(strcasecmp(key, "--chafa") == 0)
{
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_CHAFA;
instance->config.logo.type = FF_LOGO_TYPE_IMAGE_CHAFA;
}
///////////////////
+9 -7
View File
@@ -30,13 +30,15 @@ static inline void ffUnused(int dummy, ...) { (void) dummy; }
typedef enum FFLogoType
{
FF_LOGO_TYPE_AUTO, //If something is given, first try builtin, then file. Otherwise detect logo
FF_LOGO_TYPE_BUILTIN, //Builtin ascii art.
FF_LOGO_TYPE_FILE, //Raw text file, printed as is.
FF_LOGO_TYPE_RAW, //Raw text file, printed with color codes replacement.
FF_LOGO_TYPE_SIXEL, //Image file, printed as sixel codes.
FF_LOGO_TYPE_KITTY, //Image file, printed as kitty graphics protocol
FF_LOGO_TYPE_CHAFA //Image file, printed as ascii art using libchafa
FF_LOGO_TYPE_AUTO, //if something is given, first try builtin, then file. Otherwise detect logo
FF_LOGO_TYPE_BUILTIN, //builtin ascii art
FF_LOGO_TYPE_FILE, //text file, printed with color code replacement
FF_LOGO_TYPE_FILE_RAW, //text file, printed as is
FF_LOGO_TYPE_DATA, //text data, printed with color code replacement
FF_LOGO_TYPE_DATA_RAW, //text data, printed as is
FF_LOGO_TYPE_IMAGE_SIXEL, //image file, printed as sixel codes.
FF_LOGO_TYPE_IMAGE_KITTY, //image file, printed as kitty graphics protocol
FF_LOGO_TYPE_IMAGE_CHAFA, //image file, printed as ascii art using libchafa
} FFLogoType;
typedef enum FFBinaryPrefixType
+9 -9
View File
@@ -114,7 +114,7 @@ static void printImagePixels(FFinstance* instance, FFLogoRequestData* requestDat
instance->state.logoWidth = requestData->logoCharacterWidth + instance->config.logo.paddingLeft + instance->config.logo.paddingRight;
instance->state.logoHeight = requestData->logoCharacterHeight;
if(requestData->type == FF_LOGO_TYPE_KITTY)
if(requestData->type == FF_LOGO_TYPE_IMAGE_KITTY)
instance->state.logoHeight -= 1;
//Write cache files
@@ -346,15 +346,15 @@ FFLogoImageResult ffLogoPrintImageImpl(FFinstance* instance, FFLogoRequestData*
}
bool printSuccessful = false;
if(requestData->type == FF_LOGO_TYPE_CHAFA)
if(requestData->type == FF_LOGO_TYPE_IMAGE_CHAFA)
{
#ifdef FF_HAVE_CHAFA
printSuccessful = printImageChafa(instance, requestData, &imageData);
#endif
}
else if(requestData->type == FF_LOGO_TYPE_KITTY)
else if(requestData->type == FF_LOGO_TYPE_IMAGE_KITTY)
printSuccessful = printImageKitty(instance, requestData, &imageData);
else if(requestData->type == FF_LOGO_TYPE_SIXEL)
else if(requestData->type == FF_LOGO_TYPE_IMAGE_SIXEL)
printSuccessful = printImageSixel(instance, requestData, &imageData);
ffDestroyImageInfo(imageData.imageInfo);
@@ -407,7 +407,7 @@ static bool printCachedChars(FFinstance* instance, FFLogoRequestData* requestDat
FFstrbuf content;
ffStrbufInitA(&content, 32768);
if(requestData->type == FF_LOGO_TYPE_CHAFA)
if(requestData->type == FF_LOGO_TYPE_IMAGE_CHAFA)
readCachedStrbuf(requestData, &content, FF_CACHE_FILE_CHAFA);
if(content.length == 0)
@@ -440,13 +440,13 @@ static bool printCachedPixel(FFinstance* instance, FFLogoRequestData* requestDat
}
int fd = -1;
if(requestData->type == FF_LOGO_TYPE_KITTY)
if(requestData->type == FF_LOGO_TYPE_IMAGE_KITTY)
{
fd = getCacheFD(requestData, FF_CACHE_FILE_KITTY_COMPRESSED);
if(fd == -1)
fd = getCacheFD(requestData, FF_CACHE_FILE_KITTY_UNCOMPRESSED);
}
else if(requestData->type == FF_LOGO_TYPE_SIXEL)
else if(requestData->type == FF_LOGO_TYPE_IMAGE_SIXEL)
fd = getCacheFD(requestData, FF_CACHE_FILE_SIXEL);
if(fd == -1)
@@ -473,7 +473,7 @@ static bool printCachedPixel(FFinstance* instance, FFLogoRequestData* requestDat
static bool printCached(FFinstance* instance, FFLogoRequestData* requestData)
{
if(requestData->type == FF_LOGO_TYPE_CHAFA)
if(requestData->type == FF_LOGO_TYPE_IMAGE_CHAFA)
return printCachedChars(instance, requestData);
else
return printCachedPixel(instance, requestData);
@@ -517,7 +517,7 @@ bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type)
requestData.characterPixelHeight = 1;
if(
(type != FF_LOGO_TYPE_CHAFA || instance->config.logo.width == 0 || instance->config.logo.height == 0) &&
(type != FF_LOGO_TYPE_IMAGE_CHAFA || instance->config.logo.width == 0 || instance->config.logo.height == 0) &&
!getCharacterPixelDimensions(&requestData)
)
return false;
+12 -3
View File
@@ -266,6 +266,11 @@ static inline void logoPrintDetected(FFinstance* instance)
logoPrintStruct(instance, logoGetBuiltinDetected(instance));
}
static void logoPrintData(FFinstance* instance, bool doColorReplacement) {
ffLogoPrintChars(instance, instance->config.logo.source.chars, doColorReplacement);
logoApplyColorsDetected(instance);
}
static bool logoPrintFileIfExists(FFinstance* instance, bool doColorReplacement)
{
FFstrbuf content;
@@ -294,14 +299,18 @@ static bool logoPrintImageIfExists(FFinstance* instance, FFLogoType logo)
static void logoPrintKnownType(FFinstance* instance)
{
bool successfull;
bool successfull = true;
if(instance->config.logo.type == FF_LOGO_TYPE_BUILTIN)
successfull = logoPrintBuiltinIfExists(instance, instance->config.logo.source.chars);
else if(instance->config.logo.type == FF_LOGO_TYPE_FILE)
successfull = logoPrintFileIfExists(instance, true);
else if(instance->config.logo.type == FF_LOGO_TYPE_RAW)
else if(instance->config.logo.type == FF_LOGO_TYPE_FILE_RAW)
successfull = logoPrintFileIfExists(instance, false);
else if(instance->config.logo.type == FF_LOGO_TYPE_DATA)
logoPrintData(instance, true);
else if(instance->config.logo.type == FF_LOGO_TYPE_DATA_RAW)
logoPrintData(instance, false);
else //image
successfull = logoPrintImageIfExists(instance, instance->config.logo.type);
@@ -349,7 +358,7 @@ void ffLogoPrint(FFinstance* instance)
ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "wayst") == 0;
//Try to load the logo as an image. If it succeeds, print it and return.
if(logoPrintImageIfExists(instance, supportsKitty ? FF_LOGO_TYPE_KITTY : FF_LOGO_TYPE_CHAFA))
if(logoPrintImageIfExists(instance, supportsKitty ? FF_LOGO_TYPE_IMAGE_KITTY : FF_LOGO_TYPE_IMAGE_CHAFA))
return;
//Try to load the logo as a file. If it succeeds, print it and return.