Logo (Image): only print error if --show-error is specified

This commit is contained in:
李通洲
2024-05-03 07:56:43 +08:00
parent 71cba2451a
commit 4c0ea7354d
2 changed files with 17 additions and 7 deletions
+14 -5
View File
@@ -54,13 +54,14 @@ static FFstrbuf base64Encode(const FFstrbuf* in)
return out;
}
static bool printImageIterm(void)
static bool printImageIterm(bool printError)
{
const FFOptionsLogo* options = &instance.config.logo;
FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate();
if(!ffAppendFileBuffer(options->source.chars, &buf))
{
fputs("Logo: Failed to load image file\n", stderr);
if (printError)
fputs("Logo (iterm): Failed to load image file\n", stderr);
return false;
}
@@ -135,9 +136,17 @@ static bool printImageIterm(void)
return true;
}
static bool printImageKittyDirect(void)
static bool printImageKittyDirect(bool printError)
{
const FFOptionsLogo* options = &instance.config.logo;
if (!ffPathExists(options->source.chars, FF_PATHTYPE_FILE))
{
if (printError)
fputs("Logo (kitty-direct): Failed to load image file\n", stderr);
return false;
}
FF_STRBUF_AUTO_DESTROY base64 = base64Encode(&options->source);
if (!options->width || !options->height)
@@ -857,10 +866,10 @@ bool ffLogoPrintImageIfExists(FFLogoType type, bool printError)
if(type == FF_LOGO_TYPE_IMAGE_ITERM)
return printImageIterm();
return printImageIterm(printError);
if(type == FF_LOGO_TYPE_IMAGE_KITTY_DIRECT)
return printImageKittyDirect();
return printImageKittyDirect(printError);
#if !defined(FF_HAVE_CHAFA)
if(type == FF_LOGO_TYPE_IMAGE_CHAFA)
+3 -2
View File
@@ -393,7 +393,8 @@ static bool logoPrintFileIfExists(bool doColorReplacement, bool raw)
: !ffAppendFileBuffer(options->source.chars, &content)
)
{
fprintf(stderr, "Logo: Failed to load file content from logo source: %s \n", options->source.chars);
if (instance.config.display.showErrors)
fprintf(stderr, "Logo: Failed to load file content from logo source: %s \n", options->source.chars);
return false;
}
@@ -448,7 +449,7 @@ static bool logoTryKnownType(void)
if(options->type == FF_LOGO_TYPE_IMAGE_RAW)
return logoPrintFileIfExists(false, true);
return logoPrintImageIfExists(options->type, true);
return logoPrintImageIfExists(options->type, instance.config.display.showErrors);
}
static void logoPrintKnownType(void)