Skip to content

Commit 08ed14b

Browse files
committed
Logo: support "type": "command-raw"
Fix #1780
1 parent d94a41c commit 08ed14b

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

doc/json_schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@
429429
"file-raw",
430430
"data",
431431
"data-raw",
432+
"command-raw",
432433
"sixel",
433434
"kitty",
434435
"kitty-direct",

src/logo/logo.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "logo/logo.h"
22
#include "common/io/io.h"
33
#include "common/printing.h"
4+
#include "common/processing.h"
45
#include "detection/os/os.h"
56
#include "detection/terminalshell/terminalshell.h"
67
#include "util/textModifier.h"
@@ -455,14 +456,13 @@ static inline void logoPrintDetected(FFLogoSize size)
455456
logoPrintStruct(logoGetBuiltinDetected(size));
456457
}
457458

458-
static bool logoPrintData(bool doColorReplacement)
459+
static bool logoPrintData(bool doColorReplacement, FFstrbuf* source)
459460
{
460-
FFOptionsLogo* options = &instance.config.logo;
461-
if(options->source.length == 0)
461+
if(source->length == 0)
462462
return false;
463463

464464
logoApplyColors(logoGetBuiltinDetected(FF_LOGO_SIZE_NORMAL), doColorReplacement);
465-
ffLogoPrintChars(options->source.chars, doColorReplacement);
465+
ffLogoPrintChars(source->chars, doColorReplacement);
466466
return true;
467467
}
468468

@@ -548,10 +548,36 @@ static bool logoTryKnownType(void)
548548
return logoPrintBuiltinIfExists(&options->source, FF_LOGO_SIZE_SMALL);
549549

550550
if(options->type == FF_LOGO_TYPE_DATA)
551-
return logoPrintData(true);
551+
return logoPrintData(true, &options->source);
552552

553553
if(options->type == FF_LOGO_TYPE_DATA_RAW)
554-
return logoPrintData(false);
554+
return logoPrintData(false, &options->source);
555+
556+
if(options->type == FF_LOGO_TYPE_COMMAND_RAW)
557+
{
558+
FF_STRBUF_AUTO_DESTROY source = ffStrbufCreate();
559+
560+
FFCommandOptions* commandOptions = &instance.config.modules.command;
561+
const char* error = ffProcessAppendStdOut(&source, commandOptions->param.length ? (char* const[]){
562+
commandOptions->shell.chars,
563+
commandOptions->param.chars,
564+
options->source.chars,
565+
NULL
566+
} : (char* const[]){
567+
commandOptions->shell.chars,
568+
options->source.chars,
569+
NULL
570+
});
571+
572+
if (error)
573+
{
574+
if (instance.config.display.showErrors)
575+
fprintf(stderr, "Logo: failed to execute command `%s`: %s\n", options->source.chars, error);
576+
return false;
577+
}
578+
579+
return logoPrintData(false, &source);
580+
}
555581

556582
updateLogoPath(); //We sure have a file, resolve relative paths
557583

src/options/logo.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, cons
6060
{ "file-raw", FF_LOGO_TYPE_FILE_RAW },
6161
{ "data", FF_LOGO_TYPE_DATA },
6262
{ "data-raw", FF_LOGO_TYPE_DATA_RAW },
63+
{ "command-raw", FF_LOGO_TYPE_COMMAND_RAW },
6364
{ "sixel", FF_LOGO_TYPE_IMAGE_SIXEL },
6465
{ "kitty", FF_LOGO_TYPE_IMAGE_KITTY },
6566
{ "kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT },
@@ -286,6 +287,7 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
286287
{ "file-raw", FF_LOGO_TYPE_FILE_RAW },
287288
{ "data", FF_LOGO_TYPE_DATA },
288289
{ "data-raw", FF_LOGO_TYPE_DATA_RAW },
290+
{ "command-raw", FF_LOGO_TYPE_COMMAND_RAW },
289291
{ "sixel", FF_LOGO_TYPE_IMAGE_SIXEL },
290292
{ "kitty", FF_LOGO_TYPE_IMAGE_KITTY },
291293
{ "kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT },
@@ -492,6 +494,9 @@ void ffOptionsGenerateLogoJsonConfig(FFOptionsLogo* options, yyjson_mut_doc* doc
492494
case FF_LOGO_TYPE_DATA_RAW:
493495
yyjson_mut_obj_add_str(doc, obj, "type", "data-raw");
494496
break;
497+
case FF_LOGO_TYPE_COMMAND_RAW:
498+
yyjson_mut_obj_add_str(doc, obj, "type", "command-raw");
499+
break;
495500
case FF_LOGO_TYPE_IMAGE_SIXEL:
496501
yyjson_mut_obj_add_str(doc, obj, "type", "sixel");
497502
break;

src/options/logo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ typedef enum __attribute__((__packed__)) FFLogoType
1414
FF_LOGO_TYPE_FILE_RAW, //text file, printed as is
1515
FF_LOGO_TYPE_DATA, //text data, printed with color code replacement
1616
FF_LOGO_TYPE_DATA_RAW, //text data, printed as is
17+
FF_LOGO_TYPE_COMMAND_RAW, //command to generate text data, printed as is
1718
FF_LOGO_TYPE_IMAGE_SIXEL, //image file, printed as sixel codes
1819
FF_LOGO_TYPE_IMAGE_KITTY, //image file, printed as kitty graphics protocol
1920
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)

0 commit comments

Comments
 (0)