Skip to content

Commit 6413656

Browse files
committed
Logo: rename --logo-separate to --logo-position
1 parent a334b80 commit 6413656

File tree

6 files changed

+69
-31
lines changed

6 files changed

+69
-31
lines changed

doc/json_schema.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,15 @@
219219
"description": "If true, regenerate image logo cache",
220220
"default": false
221221
},
222-
"separate": {
223-
"type": "boolean",
224-
"description": "If true, print modules at bottom of the logo",
225-
"default": false
222+
"position": {
223+
"type": "string",
224+
"description": "Set the position of the logo should be displayed",
225+
"enum": [
226+
"left",
227+
"top",
228+
"right"
229+
],
230+
"default": "left"
226231
},
227232
"chafa": {
228233
"type": "object",

src/data/help.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,15 @@
257257
}
258258
},
259259
{
260-
"long": "logo-separate",
261-
"desc": "If true, print modules at bottom of the logo",
260+
"long": "logo-position",
261+
"desc": "Set the position of the logo should be displayed",
262262
"arg": {
263-
"type": "bool",
264-
"optional": true,
265-
"default": false
263+
"type": "enum",
264+
"enum": {
265+
"left": "Left",
266+
"top": "Top",
267+
"right": "Right"
268+
}
266269
}
267270
},
268271
{

src/logo/image/image.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ static bool printImageIterm(bool printError)
7272

7373
if (!options->width || !options->height)
7474
{
75-
if (!options->separate)
75+
if (options->position == FF_LOGO_POSITION_LEFT)
7676
{
7777
ffStrbufAppendF(&buf, "\e[2J\e[3J\e[%u;%uH",
7878
(unsigned) options->paddingTop,
7979
(unsigned) options->paddingLeft
8080
);
8181
}
82-
else
82+
else if (options->position == FF_LOGO_POSITION_TOP)
8383
{
8484
ffStrbufAppendNC(&buf, options->paddingTop, '\n');
8585
ffStrbufAppendNC(&buf, options->paddingLeft, ' ');
@@ -90,7 +90,7 @@ static bool printImageIterm(bool printError)
9090
ffStrbufAppendF(&buf, "\e]1337;File=inline=1:%s\a", base64.chars);
9191
ffWriteFDBuffer(FFUnixFD2NativeFD(STDOUT_FILENO), &buf);
9292

93-
if (!options->separate)
93+
if (options->position == FF_LOGO_POSITION_LEFT)
9494
{
9595
uint16_t X = 0, Y = 0;
9696
const char* error = ffGetTerminalResponse("\e[6n", "\e[%hu;%huR", &Y, &X);
@@ -103,7 +103,7 @@ static bool printImageIterm(bool printError)
103103
instance.state.logoHeight = Y;
104104
fputs("\e[H", stdout);
105105
}
106-
else
106+
else if (options->position == FF_LOGO_POSITION_TOP)
107107
{
108108
instance.state.logoWidth = instance.state.logoHeight = 0;
109109
ffPrintCharTimes('\n', options->paddingRight);
@@ -120,13 +120,13 @@ static bool printImageIterm(bool printError)
120120
base64.chars
121121
);
122122

123-
if (!options->separate)
123+
if (options->position == FF_LOGO_POSITION_LEFT)
124124
{
125125
instance.state.logoWidth = options->width + options->paddingLeft + options->paddingRight;
126126
instance.state.logoHeight = options->paddingTop + options->height;
127127
ffStrbufAppendF(&buf, "\e[%uA", (unsigned) instance.state.logoHeight);
128128
}
129-
else
129+
else if (options->position == FF_LOGO_POSITION_TOP)
130130
{
131131
instance.state.logoWidth = instance.state.logoHeight = 0;
132132
ffStrbufAppendNC(&buf, options->paddingRight, '\n');
@@ -152,15 +152,15 @@ static bool printImageKittyDirect(bool printError)
152152

153153
if (!options->width || !options->height)
154154
{
155-
if (!options->separate)
155+
if (options->position == FF_LOGO_POSITION_LEFT)
156156
{
157157
// We must clear the entre screen to make sure that terminal buffer won't scroll up
158158
printf("\e[2J\e[3J\e[%u;%uH",
159159
(unsigned) options->paddingTop,
160160
(unsigned) options->paddingLeft
161161
);
162162
}
163-
else
163+
else if (options->position == FF_LOGO_POSITION_TOP)
164164
{
165165
ffPrintCharTimes('\n', options->paddingTop);
166166
ffPrintCharTimes(' ', options->paddingLeft);
@@ -171,7 +171,7 @@ static bool printImageKittyDirect(bool printError)
171171
else
172172
printf("\e_Ga=T,f=100,t=f;%s\e\\", base64.chars);
173173
fflush(stdout);
174-
if (!options->separate)
174+
if (options->position == FF_LOGO_POSITION_LEFT)
175175
{
176176
uint16_t X = 0, Y = 0;
177177
const char* error = ffGetTerminalResponse("\e[6n", "\e[%hu;%huR", &Y, &X);
@@ -184,7 +184,7 @@ static bool printImageKittyDirect(bool printError)
184184
instance.state.logoHeight = Y;
185185
fputs("\e[H", stdout);
186186
}
187-
else
187+
else if (options->position == FF_LOGO_POSITION_TOP)
188188
{
189189
instance.state.logoWidth = instance.state.logoHeight = 0;
190190
ffPrintCharTimes('\n', options->paddingRight);
@@ -200,13 +200,13 @@ static bool printImageKittyDirect(bool printError)
200200
(unsigned) options->height,
201201
base64.chars
202202
);
203-
if (!options->separate)
203+
if (options->position == FF_LOGO_POSITION_LEFT)
204204
{
205205
instance.state.logoWidth = options->width + options->paddingLeft + options->paddingRight;
206206
instance.state.logoHeight = options->paddingTop + options->height;
207207
printf("\e[%uA", (unsigned) instance.state.logoHeight);
208208
}
209-
else
209+
else if (options->position == FF_LOGO_POSITION_TOP)
210210
{
211211
instance.state.logoWidth = instance.state.logoHeight = 0;
212212
ffPrintCharTimes('\n', options->paddingRight);

src/logo/logo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
199199
if(!instance.config.display.pipe)
200200
ffStrbufAppendS(&result, FASTFETCH_TEXT_MODIFIER_RESET);
201201

202-
if(!options->separate)
202+
if(options->position == FF_LOGO_POSITION_LEFT)
203203
{
204204
//Happens if the last line is the longest
205205
if(currentlineLength > instance.state.logoWidth)
@@ -210,7 +210,7 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement)
210210
//Go to the leftmost position and go up the height
211211
ffStrbufAppendF(&result, "\e[1G\e[%uA", instance.state.logoHeight);
212212
}
213-
else
213+
else if (options->position == FF_LOGO_POSITION_TOP)
214214
{
215215
instance.state.logoWidth = instance.state.logoHeight = 0;
216216
ffStrbufAppendNC(&result, options->paddingRight, '\n');

src/options/logo.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void ffOptionsInitLogo(FFOptionsLogo* options)
1717
options->printRemaining = true;
1818
options->preserveAspectRatio = false;
1919
options->recache = false;
20-
options->separate = false;
20+
options->position = FF_LOGO_POSITION_LEFT;
2121

2222
options->chafaFgOnly = false;
2323
ffStrbufInitStatic(&options->chafaSymbols, "block+border+space-wide-inverted"); // Chafa default
@@ -110,8 +110,15 @@ bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, cons
110110
options->preserveAspectRatio = ffOptionParseBoolean(value);
111111
else if(ffStrEqualsIgnCase(subKey, "recache"))
112112
options->recache = ffOptionParseBoolean(value);
113-
else if(ffStrEqualsIgnCase(subKey, "separate"))
114-
options->separate = ffOptionParseBoolean(value);
113+
else if(ffStrEqualsIgnCase(subKey, "position"))
114+
{
115+
options->position = (FFLogoPosition) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
116+
{ "left", FF_LOGO_POSITION_LEFT },
117+
{ "right", FF_LOGO_POSITION_RIGHT },
118+
{ "top", FF_LOGO_POSITION_TOP },
119+
{},
120+
});
121+
}
115122
else
116123
return false;
117124
}
@@ -355,9 +362,19 @@ const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* roo
355362
options->recache = yyjson_get_bool(val);
356363
continue;
357364
}
358-
else if (ffStrEqualsIgnCase(key, "separate"))
365+
else if (ffStrEqualsIgnCase(key, "position"))
359366
{
360-
options->separate = yyjson_get_bool(val);
367+
int value;
368+
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
369+
{ "left", FF_LOGO_POSITION_LEFT },
370+
{ "top", FF_LOGO_POSITION_TOP },
371+
{ "right", FF_LOGO_POSITION_RIGHT },
372+
{},
373+
});
374+
375+
if (error) return error;
376+
options->chafaCanvasMode = (uint32_t) value;
377+
361378
continue;
362379
}
363380
else if (ffStrEqualsIgnCase(key, "chafa"))
@@ -528,8 +545,14 @@ void ffOptionsGenerateLogoJsonConfig(FFOptionsLogo* options, yyjson_mut_doc* doc
528545
if (options->recache != defaultOptions.recache)
529546
yyjson_mut_obj_add_bool(doc, obj, "recache", options->recache);
530547

531-
if (options->separate != defaultOptions.separate)
532-
yyjson_mut_obj_add_bool(doc, obj, "separate", options->separate);
548+
if (options->position != defaultOptions.position)
549+
{
550+
yyjson_mut_obj_add_str(doc, obj, "position", ((const char* []) {
551+
"left",
552+
"top",
553+
"right",
554+
})[options->position]);
555+
}
533556

534557
{
535558
yyjson_mut_val* chafa = yyjson_mut_obj(doc);

src/options/logo.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ typedef enum FFLogoType
2323
FF_LOGO_TYPE_NONE, //--logo none
2424
} FFLogoType;
2525

26+
typedef enum FFLogoPosition
27+
{
28+
FF_LOGO_POSITION_LEFT,
29+
FF_LOGO_POSITION_TOP,
30+
FF_LOGO_POSITION_RIGHT,
31+
} FFLogoPosition;
32+
2633
typedef struct FFOptionsLogo
2734
{
2835
FFstrbuf source;
2936
FFLogoType type;
37+
FFLogoPosition position;
3038
FFstrbuf colors[FASTFETCH_LOGO_MAX_COLORS];
3139
uint32_t width;
3240
uint32_t height;
@@ -36,7 +44,6 @@ typedef struct FFOptionsLogo
3644
bool printRemaining;
3745
bool preserveAspectRatio;
3846
bool recache;
39-
bool separate;
4047

4148
bool chafaFgOnly;
4249
FFstrbuf chafaSymbols;

0 commit comments

Comments
 (0)