Skip to content

Commit 3d7d02b

Browse files
committed
Logo (Image): support --logo-position right
1 parent 3f0ae13 commit 3d7d02b

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

src/logo/image/image.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,21 @@ static void printImagePixels(FFLogoRequestData* requestData, const FFstrbuf* res
373373

374374
//Write result to stdout
375375
ffPrintCharTimes('\n', options->paddingTop);
376-
ffPrintCharTimes(' ', options->paddingLeft);
376+
if (options->position == FF_LOGO_POSITION_RIGHT)
377+
printf("\e[9999999C\e[%uD", (unsigned) options->paddingRight + requestData->logoCharacterWidth);
378+
else
379+
printf("\e[%uC", (unsigned) options->paddingLeft);
377380
fflush(stdout);
378381
ffWriteFDBuffer(FFUnixFD2NativeFD(STDOUT_FILENO), result);
379382

380-
//Go to upper left corner
381-
printf("\e[1G\e[%uA", instance.state.logoHeight);
383+
if (options->position != FF_LOGO_POSITION_TOP)
384+
{
385+
//Go to upper left corner
386+
printf("\e[1G\e[%uA", instance.state.logoHeight);
387+
}
388+
389+
if (options->position != FF_LOGO_POSITION_LEFT)
390+
instance.state.logoWidth = instance.state.logoHeight = 0;
382391
}
383392

384393
static bool printImageSixel(FFLogoRequestData* requestData, const ImageData* imageData)
@@ -711,23 +720,25 @@ static bool printCachedChars(FFLogoRequestData* requestData)
711720

712721
static bool printCachedPixel(FFLogoRequestData* requestData)
713722
{
714-
requestData->logoCharacterWidth = instance.config.logo.width;
723+
FFOptionsLogo* options = &instance.config.logo;
724+
725+
requestData->logoCharacterWidth = options->width;
715726
if(requestData->logoCharacterWidth == 0)
716727
{
717728
requestData->logoCharacterWidth = readCachedUint32(requestData, FF_CACHE_FILE_WIDTH);
718729
if(requestData->logoCharacterWidth == 0)
719730
return false;
720731
}
721732

722-
requestData->logoCharacterHeight = instance.config.logo.height;
733+
requestData->logoCharacterHeight = options->height;
723734
if(requestData->logoCharacterHeight == 0)
724735
{
725736
requestData->logoCharacterHeight = readCachedUint32(requestData, FF_CACHE_FILE_HEIGHT);
726737
if(requestData->logoCharacterHeight == 0)
727738
return false;
728739
}
729740

730-
int fd = -1;
741+
FF_AUTO_CLOSE_FD int fd = -1;
731742
if(requestData->type == FF_LOGO_TYPE_IMAGE_KITTY)
732743
{
733744
fd = getCacheFD(requestData, FF_CACHE_FILE_KITTY_COMPRESSED);
@@ -740,22 +751,29 @@ static bool printCachedPixel(FFLogoRequestData* requestData)
740751
if(fd == -1)
741752
return false;
742753

743-
ffPrintCharTimes('\n', instance.config.logo.paddingTop);
744-
ffPrintCharTimes(' ', instance.config.logo.paddingLeft);
754+
ffPrintCharTimes('\n', options->paddingTop);
755+
if (options->position == FF_LOGO_POSITION_RIGHT)
756+
printf("\e[9999999C\e[%uD", (unsigned) options->paddingRight + requestData->logoCharacterWidth);
757+
else
758+
printf("\e[%uC", (unsigned) options->paddingLeft);
745759
fflush(stdout);
746760

747761
char buffer[32768];
748762
ssize_t readBytes;
749763
while((readBytes = ffReadFDData(FFUnixFD2NativeFD(fd), sizeof(buffer), buffer)) > 0)
750764
ffWriteFDData(FFUnixFD2NativeFD(STDOUT_FILENO), (size_t) readBytes, buffer);
751765

752-
close(fd);
766+
instance.state.logoWidth = requestData->logoCharacterWidth + options->paddingLeft + options->paddingRight;
767+
instance.state.logoHeight = requestData->logoCharacterHeight + options->paddingTop;
753768

754-
instance.state.logoWidth = requestData->logoCharacterWidth + instance.config.logo.paddingLeft + instance.config.logo.paddingRight;
755-
instance.state.logoHeight = requestData->logoCharacterHeight + instance.config.logo.paddingTop;
769+
if (options->position != FF_LOGO_POSITION_TOP)
770+
{
771+
//Go to upper left corner
772+
printf("\e[1G\e[%uA", instance.state.logoHeight);
773+
}
756774

757-
//Go to upper left corner
758-
printf("\e[1G\e[%uA", instance.state.logoHeight);
775+
if (options->position != FF_LOGO_POSITION_LEFT)
776+
instance.state.logoWidth = instance.state.logoHeight = 0;
759777
return true;
760778
}
761779

0 commit comments

Comments
 (0)