Logo: support "type": "command-raw"

Fix #1780
This commit is contained in:
李通洲
2025-06-02 11:46:11 +08:00
parent d94a41cc1b
commit 08ed14b42a
4 changed files with 39 additions and 6 deletions
+1
View File
@@ -429,6 +429,7 @@
"file-raw",
"data",
"data-raw",
"command-raw",
"sixel",
"kitty",
"kitty-direct",
+32 -6
View File
@@ -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
+5
View File
@@ -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;
+1
View File
@@ -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)