mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
Logo: don't accept chafa options when chafa is disabled
This commit is contained in:
+13
-19
@@ -727,7 +727,7 @@ FFLogoImageResult ffLogoPrintImageImpl(FFLogoRequestData* requestData, const FFI
|
||||
|
||||
bool printSuccessful = false;
|
||||
if (requestData->type == FF_LOGO_TYPE_IMAGE_CHAFA) {
|
||||
#ifdef FF_HAVE_CHAFA
|
||||
#if FF_HAVE_CHAFA
|
||||
printSuccessful = printImageChafa(requestData, &imageData);
|
||||
#endif
|
||||
} else if (requestData->type == FF_LOGO_TYPE_IMAGE_KITTY) {
|
||||
@@ -782,12 +782,9 @@ static uint32_t readCachedUint32(FFLogoRequestData* requestData, const char* cac
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool printCachedChars(FFLogoRequestData* requestData) {
|
||||
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreateA(32768);
|
||||
|
||||
if (requestData->type == FF_LOGO_TYPE_IMAGE_CHAFA) {
|
||||
readCachedStrbuf(requestData, &content, FF_CACHE_FILE_CHAFA);
|
||||
}
|
||||
static bool printCachedChars(FFLogoRequestData* requestData, const char* cacheFileName) {
|
||||
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
|
||||
readCachedStrbuf(requestData, &content, cacheFileName);
|
||||
|
||||
if (content.length == 0) {
|
||||
return false;
|
||||
@@ -876,14 +873,6 @@ static bool printCachedPixel(FFLogoRequestData* requestData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool printCached(FFLogoRequestData* requestData) {
|
||||
if (requestData->type == FF_LOGO_TYPE_IMAGE_CHAFA) {
|
||||
return printCachedChars(requestData);
|
||||
} else {
|
||||
return printCachedPixel(requestData);
|
||||
}
|
||||
}
|
||||
|
||||
static bool getCharacterPixelDimensions(FFLogoRequestData* requestData) {
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -947,9 +936,14 @@ static bool printImageIfExistsSlowPath(FFLogoType type, bool printError) {
|
||||
ffStrbufEnsureEndsWithC(&requestData.cacheDir, '/');
|
||||
ffStrbufAppendF(&requestData.cacheDir, "%u*%u/", requestData.logoPixelWidth, requestData.logoPixelHeight);
|
||||
|
||||
if (!instance.config.logo.recache && printCached(&requestData)) {
|
||||
ffStrbufDestroy(&requestData.cacheDir);
|
||||
return true;
|
||||
if (!instance.config.logo.recache) {
|
||||
bool cacheValid = requestData.type == FF_LOGO_TYPE_IMAGE_CHAFA
|
||||
? printCachedChars(&requestData, FF_CACHE_FILE_CHAFA)
|
||||
: printCachedPixel(&requestData);
|
||||
if (cacheValid) {
|
||||
ffStrbufDestroy(&requestData.cacheDir);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
FFLogoImageResult result = FF_LOGO_IMAGE_RESULT_INIT_ERROR;
|
||||
@@ -1018,7 +1012,7 @@ bool ffLogoPrintImageIfExists(FFLogoType type, bool printError) {
|
||||
return printImageKittyIcat(printError);
|
||||
}
|
||||
|
||||
#if !defined(FF_HAVE_CHAFA)
|
||||
#if !FF_HAVE_CHAFA
|
||||
if (type == FF_LOGO_TYPE_IMAGE_CHAFA) {
|
||||
if (printError) {
|
||||
fputs("Logo: Chafa support is not compiled in\n", stderr);
|
||||
|
||||
@@ -20,11 +20,13 @@ void ffOptionsInitLogo(FFOptionsLogo* options) {
|
||||
options->recache = false;
|
||||
options->position = FF_LOGO_POSITION_LEFT;
|
||||
|
||||
#if FF_HAVE_CHAFA
|
||||
options->chafaFgOnly = false;
|
||||
ffStrbufInitStatic(&options->chafaSymbols, "block+border+space-wide-inverted"); // Chafa default
|
||||
options->chafaCanvasMode = UINT32_MAX;
|
||||
options->chafaColorSpace = UINT32_MAX;
|
||||
options->chafaDitherMode = UINT32_MAX;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, const char* value) {
|
||||
@@ -160,6 +162,7 @@ bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, cons
|
||||
if (subKey[0] == '\0') {
|
||||
ffOptionParseString(key, value, &options->source);
|
||||
options->type = FF_LOGO_TYPE_IMAGE_CHAFA;
|
||||
#if FF_HAVE_CHAFA
|
||||
} else if (ffStrEqualsIgnCase(subKey, "fg-only")) {
|
||||
options->chafaFgOnly = ffOptionParseBoolean(value);
|
||||
} else if (ffStrEqualsIgnCase(subKey, "symbols")) {
|
||||
@@ -189,6 +192,7 @@ bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, cons
|
||||
{ "DIFFUSION", 2 },
|
||||
{},
|
||||
});
|
||||
#endif
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -201,7 +205,9 @@ bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, cons
|
||||
|
||||
void ffOptionsDestroyLogo(FFOptionsLogo* options) {
|
||||
ffStrbufDestroy(&options->source);
|
||||
#if FF_HAVE_CHAFA
|
||||
ffStrbufDestroy(&options->chafaSymbols);
|
||||
#endif
|
||||
for (uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i) {
|
||||
ffStrbufDestroy(&options->colors[i]);
|
||||
}
|
||||
@@ -342,6 +348,7 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
|
||||
}
|
||||
options->position = (FFLogoPosition) value;
|
||||
continue;
|
||||
#if FF_HAVE_CHAFA
|
||||
} else if (unsafe_yyjson_equals_str(key, "chafa")) {
|
||||
if (!yyjson_is_obj(val)) {
|
||||
return "Chafa config must be an object";
|
||||
@@ -409,6 +416,7 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
|
||||
options->chafaDitherMode = (uint32_t) value;
|
||||
}
|
||||
continue;
|
||||
#endif
|
||||
} else {
|
||||
return "Unknown logo key";
|
||||
}
|
||||
@@ -515,6 +523,7 @@ void ffOptionsGenerateLogoJsonConfig(FFdata* data, FFOptionsLogo* options) {
|
||||
"right",
|
||||
})[options->position]);
|
||||
|
||||
#if FF_HAVE_CHAFA
|
||||
{
|
||||
yyjson_mut_val* chafa = yyjson_mut_obj(doc);
|
||||
yyjson_mut_obj_add_bool(doc, chafa, "fgOnly", options->chafaFgOnly);
|
||||
@@ -547,6 +556,7 @@ void ffOptionsGenerateLogoJsonConfig(FFdata* data, FFOptionsLogo* options) {
|
||||
|
||||
yyjson_mut_obj_add_val(doc, obj, "chafa", chafa);
|
||||
}
|
||||
#endif
|
||||
|
||||
yyjson_mut_obj_add_val(doc, doc->root, "logo", obj);
|
||||
}
|
||||
|
||||
@@ -45,11 +45,13 @@ typedef struct FFOptionsLogo {
|
||||
bool preserveAspectRatio;
|
||||
bool recache;
|
||||
|
||||
#if FF_HAVE_CHAFA
|
||||
bool chafaFgOnly;
|
||||
FFstrbuf chafaSymbols;
|
||||
uint32_t chafaCanvasMode;
|
||||
uint32_t chafaColorSpace;
|
||||
uint32_t chafaDitherMode;
|
||||
#endif
|
||||
} FFOptionsLogo;
|
||||
|
||||
void ffOptionsInitLogo(FFOptionsLogo* options);
|
||||
|
||||
Reference in New Issue
Block a user