Skip to content

Commit a9df048

Browse files
committed
Logo (Image): support --logo-position right for iterm and kitty-direct
1 parent 09782d6 commit a9df048

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/logo/image/image.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ static bool printImageIterm(bool printError)
8484
ffStrbufAppendNC(&buf, options->paddingTop, '\n');
8585
ffStrbufAppendNC(&buf, options->paddingLeft, ' ');
8686
}
87+
else if (options->position == FF_LOGO_POSITION_RIGHT)
88+
{
89+
if (printError)
90+
fputs("Logo (iterm): Must set logo width and height\n", stderr);
91+
return false;
92+
}
8793
if (options->width)
8894
ffStrbufAppendF(&buf, "\e]1337;File=inline=1;width=%u:%s\a", (unsigned) options->width, base64.chars);
8995
else
@@ -112,7 +118,10 @@ static bool printImageIterm(bool printError)
112118
else
113119
{
114120
ffStrbufAppendNC(&buf, options->paddingTop, '\n');
115-
ffStrbufAppendNC(&buf, options->paddingLeft, ' ');
121+
if (options->position == FF_LOGO_POSITION_RIGHT)
122+
ffStrbufAppendF(&buf, "\e[9999999C\e[%uD", (unsigned) options->paddingRight + options->width);
123+
else
124+
ffStrbufAppendF(&buf, "\e[%uC", (unsigned) options->paddingLeft);
116125
ffStrbufAppendF(&buf, "\e]1337;File=inline=1;width=%u;height=%u;preserveAspectRatio=%u:%s\a\n",
117126
(unsigned) options->width,
118127
(unsigned) options->height,
@@ -131,6 +140,11 @@ static bool printImageIterm(bool printError)
131140
instance.state.logoWidth = instance.state.logoHeight = 0;
132141
ffStrbufAppendNC(&buf, options->paddingRight, '\n');
133142
}
143+
else if (options->position == FF_LOGO_POSITION_RIGHT)
144+
{
145+
instance.state.logoWidth = instance.state.logoHeight = 0;
146+
ffStrbufAppendF(&buf, "\e[1G\e[%uA", (unsigned) options->height);
147+
}
134148
ffWriteFDBuffer(FFUnixFD2NativeFD(STDOUT_FILENO), &buf);
135149
}
136150

@@ -165,6 +179,12 @@ static bool printImageKittyDirect(bool printError)
165179
ffPrintCharTimes('\n', options->paddingTop);
166180
ffPrintCharTimes(' ', options->paddingLeft);
167181
}
182+
else if (options->position == FF_LOGO_POSITION_RIGHT)
183+
{
184+
if (printError)
185+
fputs("Logo (iterm): Must set logo width and height\n", stderr);
186+
return false;
187+
}
168188

169189
if (options->width)
170190
printf("\e_Ga=T,f=100,t=f,c=%u;%s\e\\", (unsigned) options->width, base64.chars);
@@ -193,7 +213,10 @@ static bool printImageKittyDirect(bool printError)
193213
else
194214
{
195215
ffPrintCharTimes('\n', options->paddingTop);
196-
ffPrintCharTimes(' ', options->paddingLeft);
216+
if (options->position == FF_LOGO_POSITION_RIGHT)
217+
printf("\e[9999999C\e[%uD", (unsigned) options->paddingRight + options->width);
218+
else
219+
printf("\e[%uC", (unsigned) options->paddingLeft);
197220

198221
printf("\e_Ga=T,f=100,t=f,c=%u,r=%u;%s\e\\\n",
199222
(unsigned) options->width,
@@ -211,6 +234,11 @@ static bool printImageKittyDirect(bool printError)
211234
instance.state.logoWidth = instance.state.logoHeight = 0;
212235
ffPrintCharTimes('\n', options->paddingRight);
213236
}
237+
else if (options->position == FF_LOGO_POSITION_RIGHT)
238+
{
239+
instance.state.logoWidth = instance.state.logoHeight = 0;
240+
printf("\e[1G\e[%uA", (unsigned) options->height);
241+
}
214242
}
215243

216244
return true;

src/options/logo.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,7 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
373373
});
374374

375375
if (error) return error;
376-
options->chafaCanvasMode = (uint32_t) value;
377-
376+
options->position = (FFLogoPosition) value;
378377
continue;
379378
}
380379
else if (ffStrEqualsIgnCase(key, "chafa"))

0 commit comments

Comments
 (0)