From 08ed14b42a1f9c82d71da87f7e9b08da445467de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 2 Jun 2025 11:46:11 +0800 Subject: [PATCH] Logo: support `"type": "command-raw"` Fix #1780 --- doc/json_schema.json | 1 + src/logo/logo.c | 38 ++++++++++++++++++++++++++++++++------ src/options/logo.c | 5 +++++ src/options/logo.h | 1 + 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/doc/json_schema.json b/doc/json_schema.json index bf09704df..66e471592 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -429,6 +429,7 @@ "file-raw", "data", "data-raw", + "command-raw", "sixel", "kitty", "kitty-direct", diff --git a/src/logo/logo.c b/src/logo/logo.c index 3757b949f..abf8be9e2 100644 --- a/src/logo/logo.c +++ b/src/logo/logo.c @@ -1,6 +1,7 @@ #include "logo/logo.h" #include "common/io/io.h" #include "common/printing.h" +#include "common/processing.h" #include "detection/os/os.h" #include "detection/terminalshell/terminalshell.h" #include "util/textModifier.h" @@ -455,14 +456,13 @@ static inline void logoPrintDetected(FFLogoSize size) logoPrintStruct(logoGetBuiltinDetected(size)); } -static bool logoPrintData(bool doColorReplacement) +static bool logoPrintData(bool doColorReplacement, FFstrbuf* source) { - FFOptionsLogo* options = &instance.config.logo; - if(options->source.length == 0) + if(source->length == 0) return false; logoApplyColors(logoGetBuiltinDetected(FF_LOGO_SIZE_NORMAL), doColorReplacement); - ffLogoPrintChars(options->source.chars, doColorReplacement); + ffLogoPrintChars(source->chars, doColorReplacement); return true; } @@ -548,10 +548,36 @@ static bool logoTryKnownType(void) return logoPrintBuiltinIfExists(&options->source, FF_LOGO_SIZE_SMALL); if(options->type == FF_LOGO_TYPE_DATA) - return logoPrintData(true); + return logoPrintData(true, &options->source); if(options->type == FF_LOGO_TYPE_DATA_RAW) - return logoPrintData(false); + return logoPrintData(false, &options->source); + + if(options->type == FF_LOGO_TYPE_COMMAND_RAW) + { + FF_STRBUF_AUTO_DESTROY source = ffStrbufCreate(); + + FFCommandOptions* commandOptions = &instance.config.modules.command; + const char* error = ffProcessAppendStdOut(&source, commandOptions->param.length ? (char* const[]){ + commandOptions->shell.chars, + commandOptions->param.chars, + options->source.chars, + NULL + } : (char* const[]){ + commandOptions->shell.chars, + options->source.chars, + NULL + }); + + if (error) + { + if (instance.config.display.showErrors) + fprintf(stderr, "Logo: failed to execute command `%s`: %s\n", options->source.chars, error); + return false; + } + + return logoPrintData(false, &source); + } updateLogoPath(); //We sure have a file, resolve relative paths diff --git a/src/options/logo.c b/src/options/logo.c index 66e652db3..5b3aed829 100644 --- a/src/options/logo.c +++ b/src/options/logo.c @@ -60,6 +60,7 @@ logoType: { "file-raw", FF_LOGO_TYPE_FILE_RAW }, { "data", FF_LOGO_TYPE_DATA }, { "data-raw", FF_LOGO_TYPE_DATA_RAW }, + { "command-raw", FF_LOGO_TYPE_COMMAND_RAW }, { "sixel", FF_LOGO_TYPE_IMAGE_SIXEL }, { "kitty", FF_LOGO_TYPE_IMAGE_KITTY }, { "kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT }, @@ -286,6 +287,7 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo { "file-raw", FF_LOGO_TYPE_FILE_RAW }, { "data", FF_LOGO_TYPE_DATA }, { "data-raw", FF_LOGO_TYPE_DATA_RAW }, + { "command-raw", FF_LOGO_TYPE_COMMAND_RAW }, { "sixel", FF_LOGO_TYPE_IMAGE_SIXEL }, { "kitty", FF_LOGO_TYPE_IMAGE_KITTY }, { "kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT }, @@ -492,6 +494,9 @@ void ffOptionsGenerateLogoJsonConfig(FFOptionsLogo* options, yyjson_mut_doc* doc case FF_LOGO_TYPE_DATA_RAW: yyjson_mut_obj_add_str(doc, obj, "type", "data-raw"); break; + case FF_LOGO_TYPE_COMMAND_RAW: + yyjson_mut_obj_add_str(doc, obj, "type", "command-raw"); + break; case FF_LOGO_TYPE_IMAGE_SIXEL: yyjson_mut_obj_add_str(doc, obj, "type", "sixel"); break; diff --git a/src/options/logo.h b/src/options/logo.h index c2a180b7b..94dd2a95b 100644 --- a/src/options/logo.h +++ b/src/options/logo.h @@ -14,6 +14,7 @@ typedef enum __attribute__((__packed__)) FFLogoType FF_LOGO_TYPE_FILE_RAW, //text file, printed as is FF_LOGO_TYPE_DATA, //text data, printed with color code replacement FF_LOGO_TYPE_DATA_RAW, //text data, printed as is + FF_LOGO_TYPE_COMMAND_RAW, //command to generate text data, printed as is FF_LOGO_TYPE_IMAGE_SIXEL, //image file, printed as sixel codes FF_LOGO_TYPE_IMAGE_KITTY, //image file, printed as kitty graphics protocol FF_LOGO_TYPE_IMAGE_KITTY_DIRECT, //image file, tell the terminal emulator to read image data from the specified file (Supported by kitty and wezterm)