@@ -16,41 +16,91 @@ typedef enum FFLogoSize
1616 FF_LOGO_SIZE_SMALL ,
1717} FFLogoSize ;
1818
19- static void ffLogoPrintCharsRaw (const char * data , size_t length )
19+ static bool ffLogoPrintCharsRaw (const char * data , size_t length , bool printError )
2020{
2121 FFOptionsLogo * options = & instance .config .logo ;
2222 FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate ();
2323
2424 if (!options -> width || !options -> height )
2525 {
26- ffStrbufAppendF (& buf , "\e[2J\e[3J\e[%u;%uH" ,
27- (unsigned ) options -> paddingTop ,
28- (unsigned ) options -> paddingLeft
29- );
26+ if (options -> position == FF_LOGO_POSITION_LEFT )
27+ {
28+ ffStrbufAppendF (& buf , "\e[2J\e[3J\e[%u;%uH" ,
29+ (unsigned ) options -> paddingTop + 1 ,
30+ (unsigned ) options -> paddingLeft + 1
31+ );
32+ }
33+ else if (options -> position == FF_LOGO_POSITION_TOP )
34+ {
35+ ffStrbufAppendNC (& buf , options -> paddingTop , '\n' );
36+ ffStrbufAppendNC (& buf , options -> paddingLeft , ' ' );
37+ }
38+ else if (options -> position == FF_LOGO_POSITION_RIGHT )
39+ {
40+ if (!options -> width )
41+ {
42+ if (printError )
43+ fputs ("Logo (iterm): Must set logo width when using position right\n" , stderr );
44+ return false;
45+ }
46+ ffStrbufAppendF (& buf , "\e[2J\e[3J\e[H\e[9999999C\e[%uD" , (unsigned ) options -> paddingRight + options -> width );
47+ }
3048 ffStrbufAppendNS (& buf , (uint32_t ) length , data );
3149 ffWriteFDBuffer (FFUnixFD2NativeFD (STDOUT_FILENO ), & buf );
3250
33- uint16_t X = 0 , Y = 0 ;
34- const char * error = ffGetTerminalResponse ("\e[6n" , "\e[%hu;%huR" , & Y , & X );
35- if (error )
51+ if (options -> position == FF_LOGO_POSITION_LEFT || options -> position == FF_LOGO_POSITION_RIGHT )
52+ {
53+ uint16_t X = 0 , Y = 0 ;
54+ const char * error = ffGetTerminalResponse ("\e[6n" , "\e[%hu;%huR" , & Y , & X );
55+ if (error )
56+ {
57+ if (printError )
58+ fprintf (stderr , "\nLogo (image-raw): fail to query cursor position: %s\n" , error );
59+ return true;
60+ }
61+ if (options -> position == FF_LOGO_POSITION_LEFT )
62+ instance .state .logoWidth = X + instance .config .logo .paddingRight - 1 ;
63+ instance .state .logoHeight = Y ;
64+ fputs ("\e[H" , stdout );
65+ }
66+ else if (options -> position == FF_LOGO_POSITION_TOP )
3667 {
37- fprintf ( stderr , "\nLogo (image-raw): fail to query cursor position: %s\n" , error ) ;
38- return ;
68+ instance . state . logoWidth = instance . state . logoHeight = 0 ;
69+ ffPrintCharTimes ( '\n' , options -> paddingRight ) ;
3970 }
40- instance .state .logoWidth = X + instance .config .logo .paddingRight ;
41- instance .state .logoHeight = Y ;
42- fputs ("\e[H" , stdout );
4371 }
4472 else
4573 {
4674 ffStrbufAppendNC (& buf , options -> paddingTop , '\n' );
47- ffStrbufAppendNC (& buf , options -> paddingLeft , ' ' );
75+
76+ if (options -> position == FF_LOGO_POSITION_RIGHT )
77+ ffStrbufAppendF (& buf , "\e[9999999C\e[%uD" , (unsigned ) options -> paddingRight + options -> width );
78+ else if (options -> paddingLeft )
79+ ffStrbufAppendF (& buf , "\e[%uC" , (unsigned ) options -> paddingLeft );
80+
4881 ffStrbufAppendNS (& buf , (uint32_t ) length , data );
49- instance .state .logoHeight = options -> paddingTop + options -> height ;
50- instance .state .logoWidth = options -> paddingLeft + options -> width + options -> paddingRight ;
51- ffStrbufAppendF (& buf , "\n\e[%uA" , instance .state .logoHeight );
82+ ffStrbufAppendC (& buf , '\n' );
83+
84+ if (options -> position == FF_LOGO_POSITION_LEFT )
85+ {
86+ instance .state .logoWidth = options -> width + options -> paddingLeft + options -> paddingRight ;
87+ instance .state .logoHeight = options -> paddingTop + options -> height ;
88+ ffStrbufAppendF (& buf , "\e[%uA" , (unsigned ) instance .state .logoHeight );
89+ }
90+ else if (options -> position == FF_LOGO_POSITION_TOP )
91+ {
92+ instance .state .logoWidth = instance .state .logoHeight = 0 ;
93+ ffStrbufAppendNC (& buf , options -> paddingRight , '\n' );
94+ }
95+ else if (options -> position == FF_LOGO_POSITION_RIGHT )
96+ {
97+ instance .state .logoWidth = instance .state .logoHeight = 0 ;
98+ ffStrbufAppendF (& buf , "\e[%uA" , (unsigned ) options -> height );
99+ }
52100 ffWriteFDBuffer (FFUnixFD2NativeFD (STDOUT_FILENO ), & buf );
53101 }
102+
103+ return true;
54104}
55105
56106// If result is NULL, calculate logo width
@@ -441,10 +491,9 @@ static bool logoPrintFileIfExists(bool doColorReplacement, bool raw)
441491
442492 logoApplyColors (logoGetBuiltinDetected (FF_LOGO_SIZE_NORMAL ), doColorReplacement );
443493 if (raw )
444- ffLogoPrintCharsRaw (content .chars , content .length );
445- else
446- ffLogoPrintChars (content .chars , doColorReplacement );
494+ return ffLogoPrintCharsRaw (content .chars , content .length , instance .config .display .showErrors );
447495
496+ ffLogoPrintChars (content .chars , doColorReplacement );
448497 return true;
449498}
450499
0 commit comments