CMake: adds option -DENABLE_IMAGE_LOGO=<BOOL>

This commit is contained in:
Carter Li
2026-09-17 13:50:07 +08:00
parent 9bac273165
commit e004c97ee0
7 changed files with 118 additions and 33 deletions
+1 -3
View File
@@ -46,6 +46,7 @@ const char* ffGpuDetectMetal(FFlist* gpus) {
continue;
}
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#ifndef MAC_OS_X_VERSION_10_15
if ([device supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily2_v1]) {
ffStrbufSetStatic(&gpu->platformApi, "Metal Feature Set 2");
@@ -53,14 +54,11 @@ const char* ffGpuDetectMetal(FFlist* gpus) {
ffStrbufSetStatic(&gpu->platformApi, "Metal Feature Set 1");
}
#else // MAC_OS_X_VERSION_10_15
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
if ([device supportsFamily:MTLGPUFamilyMetal4]) {
ffStrbufSetStatic(&gpu->platformApi, "Metal 4");
} else if ([device supportsFamily:MTLGPUFamilyMetal3]) {
ffStrbufSetStatic(&gpu->platformApi, "Metal 3");
}
#pragma clang diagnostic pop
else if ([device supportsFamily:MTLGPUFamilyCommon3]) {
ffStrbufSetStatic(&gpu->platformApi, "Metal Common 3");
} else if ([device supportsFamily:MTLGPUFamilyCommon2]) {
+20 -6
View File
@@ -518,6 +518,7 @@ static bool logoPrintFileIfExists(bool doColorReplacement, bool raw) {
return true;
}
#if FF_HAVE_IMAGE_LOGO
static bool logoPrintImageIfExists(FFLogoType logo, bool printError) {
if (!ffLogoPrintImageIfExists(logo, printError)) {
return false;
@@ -526,6 +527,7 @@ static bool logoPrintImageIfExists(FFLogoType logo, bool printError) {
logoApplyColors(logoGetBuiltinDetected(FF_LOGO_SIZE_NORMAL), false);
return true;
}
#endif
static bool logoTryKnownType(void) {
FFOptionsLogo* options = &instance.config.logo;
@@ -593,7 +595,16 @@ static bool logoTryKnownType(void) {
return logoPrintFileIfExists(false, true);
}
#if FF_HAVE_IMAGE_LOGO
return logoPrintImageIfExists(options->type, instance.config.display.showErrors);
#else
// No image logo type can be selected in this build (see ffOptionsParseLogoCommandLine), and
// FF_LOGO_TYPE_IMAGE_RAW was handled above, so nothing printable is left for this source.
if (instance.config.display.showErrors) {
fprintf(stderr, "Logo: Unsupported logo type for source: %s\n", options->source.chars);
}
return false;
#endif
}
void ffLogoPrint(void) {
@@ -638,8 +649,10 @@ void ffLogoPrint(void) {
}
}
#if FF_HAVE_IMAGE_LOGO
// Try to load the logo as an image.
if (!ffStrbufEndsWithIgnCaseS(&options->source, ".txt")) {
#if !FF_MODULE_DISABLE_TERMINAL
#if !FF_MODULE_DISABLE_TERMINAL
const FFTerminalResult* terminal = ffDetectTerminal();
bool supportsIterm2 = ffStrbufEqualS(&terminal->prettyName, "iTerm");
@@ -655,21 +668,22 @@ void ffLogoPrint(void) {
ffStrbufIgnCaseEqualS(&terminal->processName, "wezterm") ||
ffStrbufIgnCaseEqualS(&terminal->processName, "wayst") ||
ffStrbufIgnCaseEqualS(&terminal->processName, "ghostty") ||
#ifdef __APPLE__
#ifdef __APPLE__
ffStrbufIgnCaseEqualS(&terminal->processName, "WarpTerminal") ||
#else
#else
ffStrbufIgnCaseEqualS(&terminal->processName, "warp") ||
#endif
#endif
false;
#else
#else
bool supportsKitty = false;
#endif
#endif
// Try to load the logo as an image. If it succeeds, print it and return.
if (logoPrintImageIfExists(supportsKitty ? FF_LOGO_TYPE_IMAGE_KITTY : FF_LOGO_TYPE_IMAGE_CHAFA, false)) {
return;
}
}
#endif
// Try to load the logo as a file. If it succeeds, print it and return.
if (logoPrintFileIfExists(true, false)) {
+2
View File
@@ -39,5 +39,7 @@ const FFlogo* ffLogoGetBuiltinDetected(FFLogoSize size);
extern const FFlogo* ffLogoBuiltins[];
extern const FFlogo ffLogoUnknown;
#if FF_HAVE_IMAGE_LOGO
// image/image.c
bool ffLogoPrintImageIfExists(FFLogoType type, bool printError);
#endif
+54 -10
View File
@@ -3,6 +3,42 @@
#include "common/jsonconfig.h"
#include "common/strutil.h"
#if !FF_HAVE_IMAGE_LOGO
// The image logo types are still accepted by the parsers below in a build that can not render them,
// so that the user is told which type is unavailable instead of being told the type does not exist.
// The one that is deliberately left out is `raw`: it writes a pre-rendered byte stream through
// untouched and needs no decoder, so a build without image logos can still display one.
static bool logoTypeIsImage(FFLogoType type) {
switch (type) {
case FF_LOGO_TYPE_IMAGE_SIXEL:
case FF_LOGO_TYPE_IMAGE_KITTY:
case FF_LOGO_TYPE_IMAGE_KITTY_DIRECT:
case FF_LOGO_TYPE_IMAGE_KITTY_ICAT:
case FF_LOGO_TYPE_IMAGE_ITERM:
case FF_LOGO_TYPE_IMAGE_CHAFA:
return true;
default:
return false;
}
}
#endif
// --sixel, --kitty, --kitty-direct, --kitty-icat and --iterm. They keep a branch of their own in
// every build so that the error a build without image logos gives names the flag that was used,
// rather than it being rejected as an unknown option. --chafa is not among them: it is gated on
// FF_HAVE_CHAFA, which a build without image logos turns off as well, and it keeps the message it
// has always given in that case.
static void logoParseImageFlag(FFOptionsLogo* options, const char* key, const char* value, FFLogoType type) {
#if FF_HAVE_IMAGE_LOGO
ffOptionParseString(key, value, &options->source);
options->type = type;
#else
FF_UNUSED(options, key, value, type);
fputs("Error: Fastfetch was built without image logo support\n", stderr);
exit(477);
#endif
}
void ffOptionsInitLogo(FFOptionsLogo* options) {
ffStrbufInit(&options->source);
options->type = FF_LOGO_TYPE_AUTO;
@@ -71,6 +107,12 @@ bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, cons
{ "none", FF_LOGO_TYPE_NONE },
{},
});
#if !FF_HAVE_IMAGE_LOGO
if (logoTypeIsImage(options->type)) {
fputs("Error: Fastfetch was built without image logo support\n", stderr);
exit(477);
}
#endif
} else if (ffStrStartsWithIgnCase(subKey, "color-") && subKey[6] != '\0' && subKey[7] == '\0') // matches "--logo-color-*"
{
// Map the number to an array index, so that '1' -> 0, '2' -> 1, etc.
@@ -151,20 +193,15 @@ bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, cons
return false;
}
} else if (ffStrEqualsIgnCase(key, "--sixel")) {
ffOptionParseString(key, value, &options->source);
options->type = FF_LOGO_TYPE_IMAGE_SIXEL;
logoParseImageFlag(options, key, value, FF_LOGO_TYPE_IMAGE_SIXEL);
} else if (ffStrEqualsIgnCase(key, "--kitty")) {
ffOptionParseString(key, value, &options->source);
options->type = FF_LOGO_TYPE_IMAGE_KITTY;
logoParseImageFlag(options, key, value, FF_LOGO_TYPE_IMAGE_KITTY);
} else if (ffStrEqualsIgnCase(key, "--kitty-direct")) {
ffOptionParseString(key, value, &options->source);
options->type = FF_LOGO_TYPE_IMAGE_KITTY_DIRECT;
logoParseImageFlag(options, key, value, FF_LOGO_TYPE_IMAGE_KITTY_DIRECT);
} else if (ffStrEqualsIgnCase(key, "--kitty-icat")) {
ffOptionParseString(key, value, &options->source);
options->type = FF_LOGO_TYPE_IMAGE_KITTY_ICAT;
logoParseImageFlag(options, key, value, FF_LOGO_TYPE_IMAGE_KITTY_ICAT);
} else if (ffStrEqualsIgnCase(key, "--iterm")) {
ffOptionParseString(key, value, &options->source);
options->type = FF_LOGO_TYPE_IMAGE_ITERM;
logoParseImageFlag(options, key, value, FF_LOGO_TYPE_IMAGE_ITERM);
} else if (ffStrEqualsIgnCase(key, "--raw")) {
ffOptionParseString(key, value, &options->source);
options->type = FF_LOGO_TYPE_IMAGE_RAW;
@@ -278,6 +315,11 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
if (error) {
return error;
}
#if !FF_HAVE_IMAGE_LOGO
if (logoTypeIsImage((FFLogoType) value)) {
return "Image logo types are not supported because Fastfetch was built without image logo support";
}
#endif
options->type = (FFLogoType) value;
continue;
} else if (unsafe_yyjson_equals_str(key, "source")) {
@@ -482,6 +524,7 @@ void ffOptionsGenerateLogoJsonConfig(FFdata* data, FFOptionsLogo* options) {
case FF_LOGO_TYPE_COMMAND_RAW:
yyjson_mut_obj_add_str(doc, obj, "type", "command-raw");
break;
#if FF_HAVE_IMAGE_LOGO
case FF_LOGO_TYPE_IMAGE_SIXEL:
yyjson_mut_obj_add_str(doc, obj, "type", "sixel");
break;
@@ -500,6 +543,7 @@ void ffOptionsGenerateLogoJsonConfig(FFdata* data, FFOptionsLogo* options) {
case FF_LOGO_TYPE_IMAGE_CHAFA:
yyjson_mut_obj_add_str(doc, obj, "type", "chafa");
break;
#endif
case FF_LOGO_TYPE_IMAGE_RAW:
yyjson_mut_obj_add_str(doc, obj, "type", "raw");
break;