Skip to content

Commit 135547f

Browse files
committed
Logo: don't accept chafa options when chafa is disabled
1 parent da05bed commit 135547f

3 files changed

Lines changed: 25 additions & 19 deletions

File tree

src/logo/image/image.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ FFLogoImageResult ffLogoPrintImageImpl(FFLogoRequestData* requestData, const FFI
727727

728728
bool printSuccessful = false;
729729
if (requestData->type == FF_LOGO_TYPE_IMAGE_CHAFA) {
730-
#ifdef FF_HAVE_CHAFA
730+
#if FF_HAVE_CHAFA
731731
printSuccessful = printImageChafa(requestData, &imageData);
732732
#endif
733733
} else if (requestData->type == FF_LOGO_TYPE_IMAGE_KITTY) {
@@ -782,12 +782,9 @@ static uint32_t readCachedUint32(FFLogoRequestData* requestData, const char* cac
782782
return result;
783783
}
784784

785-
static bool printCachedChars(FFLogoRequestData* requestData) {
786-
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreateA(32768);
787-
788-
if (requestData->type == FF_LOGO_TYPE_IMAGE_CHAFA) {
789-
readCachedStrbuf(requestData, &content, FF_CACHE_FILE_CHAFA);
790-
}
785+
static bool printCachedChars(FFLogoRequestData* requestData, const char* cacheFileName) {
786+
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
787+
readCachedStrbuf(requestData, &content, cacheFileName);
791788

792789
if (content.length == 0) {
793790
return false;
@@ -876,14 +873,6 @@ static bool printCachedPixel(FFLogoRequestData* requestData) {
876873
return true;
877874
}
878875

879-
static bool printCached(FFLogoRequestData* requestData) {
880-
if (requestData->type == FF_LOGO_TYPE_IMAGE_CHAFA) {
881-
return printCachedChars(requestData);
882-
} else {
883-
return printCachedPixel(requestData);
884-
}
885-
}
886-
887876
static bool getCharacterPixelDimensions(FFLogoRequestData* requestData) {
888877
#ifdef _WIN32
889878

@@ -947,9 +936,14 @@ static bool printImageIfExistsSlowPath(FFLogoType type, bool printError) {
947936
ffStrbufEnsureEndsWithC(&requestData.cacheDir, '/');
948937
ffStrbufAppendF(&requestData.cacheDir, "%u*%u/", requestData.logoPixelWidth, requestData.logoPixelHeight);
949938

950-
if (!instance.config.logo.recache && printCached(&requestData)) {
951-
ffStrbufDestroy(&requestData.cacheDir);
952-
return true;
939+
if (!instance.config.logo.recache) {
940+
bool cacheValid = requestData.type == FF_LOGO_TYPE_IMAGE_CHAFA
941+
? printCachedChars(&requestData, FF_CACHE_FILE_CHAFA)
942+
: printCachedPixel(&requestData);
943+
if (cacheValid) {
944+
ffStrbufDestroy(&requestData.cacheDir);
945+
return true;
946+
}
953947
}
954948

955949
FFLogoImageResult result = FF_LOGO_IMAGE_RESULT_INIT_ERROR;
@@ -1018,7 +1012,7 @@ bool ffLogoPrintImageIfExists(FFLogoType type, bool printError) {
10181012
return printImageKittyIcat(printError);
10191013
}
10201014

1021-
#if !defined(FF_HAVE_CHAFA)
1015+
#if !FF_HAVE_CHAFA
10221016
if (type == FF_LOGO_TYPE_IMAGE_CHAFA) {
10231017
if (printError) {
10241018
fputs("Logo: Chafa support is not compiled in\n", stderr);

src/options/logo.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ void ffOptionsInitLogo(FFOptionsLogo* options) {
2020
options->recache = false;
2121
options->position = FF_LOGO_POSITION_LEFT;
2222

23+
#if FF_HAVE_CHAFA
2324
options->chafaFgOnly = false;
2425
ffStrbufInitStatic(&options->chafaSymbols, "block+border+space-wide-inverted"); // Chafa default
2526
options->chafaCanvasMode = UINT32_MAX;
2627
options->chafaColorSpace = UINT32_MAX;
2728
options->chafaDitherMode = UINT32_MAX;
29+
#endif
2830
}
2931

3032
bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, const char* value) {
@@ -160,6 +162,7 @@ bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, cons
160162
if (subKey[0] == '\0') {
161163
ffOptionParseString(key, value, &options->source);
162164
options->type = FF_LOGO_TYPE_IMAGE_CHAFA;
165+
#if FF_HAVE_CHAFA
163166
} else if (ffStrEqualsIgnCase(subKey, "fg-only")) {
164167
options->chafaFgOnly = ffOptionParseBoolean(value);
165168
} else if (ffStrEqualsIgnCase(subKey, "symbols")) {
@@ -189,6 +192,7 @@ bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, cons
189192
{ "DIFFUSION", 2 },
190193
{},
191194
});
195+
#endif
192196
} else {
193197
return false;
194198
}
@@ -201,7 +205,9 @@ bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, cons
201205

202206
void ffOptionsDestroyLogo(FFOptionsLogo* options) {
203207
ffStrbufDestroy(&options->source);
208+
#if FF_HAVE_CHAFA
204209
ffStrbufDestroy(&options->chafaSymbols);
210+
#endif
205211
for (uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i) {
206212
ffStrbufDestroy(&options->colors[i]);
207213
}
@@ -342,6 +348,7 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
342348
}
343349
options->position = (FFLogoPosition) value;
344350
continue;
351+
#if FF_HAVE_CHAFA
345352
} else if (unsafe_yyjson_equals_str(key, "chafa")) {
346353
if (!yyjson_is_obj(val)) {
347354
return "Chafa config must be an object";
@@ -409,6 +416,7 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
409416
options->chafaDitherMode = (uint32_t) value;
410417
}
411418
continue;
419+
#endif
412420
} else {
413421
return "Unknown logo key";
414422
}
@@ -515,6 +523,7 @@ void ffOptionsGenerateLogoJsonConfig(FFdata* data, FFOptionsLogo* options) {
515523
"right",
516524
})[options->position]);
517525

526+
#if FF_HAVE_CHAFA
518527
{
519528
yyjson_mut_val* chafa = yyjson_mut_obj(doc);
520529
yyjson_mut_obj_add_bool(doc, chafa, "fgOnly", options->chafaFgOnly);
@@ -547,6 +556,7 @@ void ffOptionsGenerateLogoJsonConfig(FFdata* data, FFOptionsLogo* options) {
547556

548557
yyjson_mut_obj_add_val(doc, obj, "chafa", chafa);
549558
}
559+
#endif
550560

551561
yyjson_mut_obj_add_val(doc, doc->root, "logo", obj);
552562
}

src/options/logo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ typedef struct FFOptionsLogo {
4545
bool preserveAspectRatio;
4646
bool recache;
4747

48+
#if FF_HAVE_CHAFA
4849
bool chafaFgOnly;
4950
FFstrbuf chafaSymbols;
5051
uint32_t chafaCanvasMode;
5152
uint32_t chafaColorSpace;
5253
uint32_t chafaDitherMode;
54+
#endif
5355
} FFOptionsLogo;
5456

5557
void ffOptionsInitLogo(FFOptionsLogo* options);

0 commit comments

Comments
 (0)