Fastfetch: print non-colored logo in pipe mode

This commit is contained in:
李通洲
2024-05-05 20:01:12 +08:00
parent 865f57bd76
commit 5ea89ecba5
3 changed files with 30 additions and 14 deletions
+7
View File
@@ -842,6 +842,13 @@ static bool printImageIfExistsSlowPath(FFLogoType type, bool printError)
bool ffLogoPrintImageIfExists(FFLogoType type, bool printError)
{
if(instance.config.display.pipe)
{
if(printError)
fputs("Logo: Image logo is not supported in pipe mode\n", stderr);
return false;
}
if(!ffPathExists(instance.config.logo.source.chars, FF_PATHTYPE_FILE))
{
if(printError)
+22 -13
View File
@@ -70,7 +70,7 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
instance.state.logoHeight = options->paddingTop;
//Use logoColor[0] as the default color
if(doColorReplacement)
if(doColorReplacement && !instance.config.display.pipe)
ffStrbufAppendF(&result, "\e[%sm", options->colors[0].chars);
while(*data != '\0')
@@ -143,19 +143,27 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
continue;
}
//Map the number to an array index, so that '1' -> 0, '2' -> 1, etc.
int index = ((int) *data) - 49;
//If the index is valid, print the color. Otherwise continue as normal
if(index < 0 || index >= FASTFETCH_LOGO_MAX_COLORS)
if(!instance.config.display.pipe)
{
ffStrbufAppendC(&result, '$');
++currentlineLength;
//Don't continue here, we want to print the current char as unicode
//Map the number to an array index, so that '1' -> 0, '2' -> 1, etc.
int index = ((int) *data) - 49;
//If the index is valid, print the color. Otherwise continue as normal
if(index < 0 || index >= FASTFETCH_LOGO_MAX_COLORS)
{
ffStrbufAppendC(&result, '$');
++currentlineLength;
//Don't continue here, we want to print the current char as unicode
}
else
{
ffStrbufAppendF(&result, "\e[%sm", options->colors[index].chars);
++data;
continue;
}
}
else
{
ffStrbufAppendF(&result, "\e[%sm", options->colors[index].chars);
++data;
continue;
}
@@ -188,7 +196,8 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
}
}
ffStrbufAppendS(&result, FASTFETCH_TEXT_MODIFIER_RESET);
if(!instance.config.display.pipe)
ffStrbufAppendS(&result, FASTFETCH_TEXT_MODIFIER_RESET);
if(!options->separate)
{
@@ -460,10 +469,10 @@ static void logoPrintKnownType(void)
void ffLogoPrint(void)
{
//In pipe mode, we don't have a logo or padding.
//When generate JSON result, we don't have a logo or padding.
//We also don't need to set main color, because it won't be printed anyway.
//So we can return quickly here.
if(instance.config.display.pipe || instance.state.resultDoc)
if(instance.state.resultDoc)
{
instance.state.logoHeight = 0;
instance.state.logoWidth = 0;
+1 -1
View File
@@ -27,7 +27,7 @@ typedef struct FFOptionsDisplay
FFstrbuf keyValueSeparator;
bool stat;
bool pipe; //disables logo and all escape sequences
bool pipe; //disables all escape sequences
bool showErrors;
bool disableLinewrap;
bool hideCursor;