Skip to content

Commit 1e3cabf

Browse files
--pipe option
1 parent 008cf3b commit 1e3cabf

File tree

8 files changed

+75
-38
lines changed

8 files changed

+75
-38
lines changed

src/common/caching.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ static void writeCacheFile(FFinstance* instance, const char* moduleName, const c
3535

3636
void ffCacheValidate(FFinstance* instance)
3737
{
38-
if(instance->config.recache)
39-
return;
40-
4138
FFstrbuf content;
4239
ffStrbufInit(&content);
4340
readCacheFile(instance, "cacheversion", "ffv", &content);

src/common/init.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static void defaultConfig(FFinstance* instance)
126126
instance->config.hideCursor = true;
127127
instance->config.escapeBedrock = true;
128128
instance->config.glType = FF_GL_TYPE_AUTO;
129+
instance->config.pipe = false;
129130

130131
ffStrbufInitA(&instance->config.osFormat, 0);
131132
ffStrbufInitA(&instance->config.osKey, 0);
@@ -240,29 +241,29 @@ void ffInitInstance(FFinstance* instance)
240241
defaultConfig(instance);
241242
}
242243

243-
static void resetConsole(bool disableLinewrap, bool hideCursor)
244+
static volatile bool ffDisableLinewrap = true;
245+
static volatile bool ffHideCursor = true;
246+
247+
static void resetConsole()
244248
{
245-
if(disableLinewrap)
249+
if(ffDisableLinewrap)
246250
fputs("\033[?7h", stdout);
247251

248-
if(hideCursor)
252+
if(ffHideCursor)
249253
fputs("\033[?25h", stdout);
250254
}
251255

252-
static volatile bool ffDisableLinewrap = true;
253-
static volatile bool ffHideCursor = true;
254-
255256
static void exitSignalHandler(int signal)
256257
{
257258
FF_UNUSED(signal);
258-
resetConsole(ffDisableLinewrap, ffHideCursor);
259+
resetConsole();
259260
exit(0);
260261
}
261262

262263
void ffStart(FFinstance* instance)
263264
{
264-
ffDisableLinewrap = instance->config.disableLinewrap;
265-
ffHideCursor = instance->config.hideCursor;
265+
ffDisableLinewrap = instance->config.disableLinewrap && !instance->config.pipe;
266+
ffHideCursor = instance->config.hideCursor && !instance->config.pipe;
266267

267268
struct sigaction action = {};
268269
action.sa_handler = exitSignalHandler;
@@ -272,24 +273,28 @@ void ffStart(FFinstance* instance)
272273
sigaction(SIGQUIT, &action, NULL);
273274

274275
//We do the cache validation here, so we can skip it if --recache is given
275-
ffCacheValidate(instance);
276+
if(!instance->config.recache)
277+
ffCacheValidate(instance);
276278

277279
//reset everything to default before we start printing
278-
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
280+
if(!instance->config.pipe)
281+
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
279282

280-
if(instance->config.hideCursor)
283+
if(ffHideCursor)
281284
fputs("\033[?25l", stdout);
282285

283-
if(instance->config.disableLinewrap)
286+
if(ffDisableLinewrap)
284287
fputs("\033[?7l", stdout);
285288

286289
ffPrintLogo(instance);
287290
}
288291

289292
void ffFinish(FFinstance* instance)
290293
{
291-
ffPrintRemainingLogo(instance);
292-
resetConsole(instance->config.disableLinewrap, instance->config.hideCursor);
294+
if(instance->config.logoPrintRemaining)
295+
ffPrintRemainingLogo(instance);
296+
297+
resetConsole();
293298
}
294299

295300
//Must be in a file compiled with the libfastfetch target, because the FF_HAVE* macros are not defined for the executable targets

src/data/help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ General options:
1919
--multithreading <?value>: use multiple threads to detect values
2020
--allow-slow-operations <?value>: allow operations that are usually very slow for more detailed output
2121
--escape-bedrock <?value>: on bedrock linux, sets if it should escape the bedrock jail or not
22+
--pipe <?value>: disable logo and all escape sequences
2223

2324
Logo options:
2425
-l,--logo <logo>: set the logo to use. The type is specified by --logo-type. If default: the name of a builtin logo or a path to a file

src/fastfetch.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,13 +737,24 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
737737
instance->config.allowSlowOperations = optionParseBoolean(value);
738738
else if(strcasecmp(key, "--escape-bedrock") == 0)
739739
instance->config.escapeBedrock = optionParseBoolean(value);
740+
else if(strcasecmp(key, "--pipe") == 0)
741+
instance->config.pipe = optionParseBoolean(value);
740742

741743
////////////////
742744
//Logo options//
743745
////////////////
744746

745747
else if(strcasecmp(key, "-l") == 0 || strcasecmp(key, "--logo") == 0)
748+
{
746749
optionParseString(key, value, &instance->config.logoSource);
750+
751+
//this is usally wanted when using the none logo
752+
if(strcasecmp(value, "none") == 0)
753+
{
754+
instance->config.logoPaddingRight = 0;
755+
instance->config.logoPaddingLeft = 0;
756+
}
757+
}
747758
else if(strcasecmp(key, "--logo-type") == 0)
748759
{
749760
if(value == NULL)

src/fastfetch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ typedef struct FFconfig
7272
bool hideCursor;
7373
bool escapeBedrock;
7474
FFGLType glType;
75+
bool pipe; //disables logo and all escape sequences
7576

7677
FFstrbuf osFormat;
7778
FFstrbuf osKey;

src/logo/logo.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ static void logoPrintDetected(FFinstance* instance)
199199

200200
void ffPrintLogo(FFinstance* instance)
201201
{
202+
if(instance->config.pipe)
203+
{
204+
instance->state.logoHeight = 0;
205+
instance->state.logoWidth = 0;
206+
return;
207+
}
208+
202209
if(instance->config.mainColor.length == 0)
203210
ffLogoSetMainColor(instance);
204211

@@ -225,37 +232,33 @@ void ffPrintLogo(FFinstance* instance)
225232
logoPrintDetected(instance);
226233
}
227234

228-
static inline void printLogoWidth(const FFinstance* instance)
235+
236+
void ffPrintLogoLine(FFinstance* instance)
229237
{
230238
if(instance->state.logoWidth > 0)
231239
printf("\033[%uC", instance->state.logoWidth);
240+
241+
++instance->state.keysHeight;
232242
}
233243

234244
void ffPrintRemainingLogo(FFinstance* instance)
235245
{
236-
if(!instance->config.logoPrintRemaining)
237-
return;
238-
239-
for(uint32_t i = instance->state.keysHeight; i <= instance->state.logoHeight; i++)
246+
while(instance->state.keysHeight < instance->state.logoHeight)
240247
{
241-
printLogoWidth(instance);
248+
ffPrintLogoLine(instance);
242249
putchar('\n');
243250
}
244251
}
245252

246-
void ffPrintLogoLine(FFinstance* instance)
247-
{
248-
printLogoWidth(instance);
249-
++instance->state.keysHeight;
250-
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
251-
}
252-
253253
void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat)
254254
{
255255
ffPrintLogoLine(instance);
256256

257-
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
258-
ffPrintColor(&instance->config.mainColor);
257+
if(!instance->config.pipe)
258+
{
259+
fputs(FASTFETCH_TEXT_MODIFIER_RESET FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
260+
ffPrintColor(&instance->config.mainColor);
261+
}
259262

260263
if(customKeyFormat == NULL || customKeyFormat->length == 0)
261264
{
@@ -275,7 +278,11 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
275278
ffStrbufDestroy(&key);
276279
}
277280

278-
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
281+
if(!instance->config.pipe)
282+
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
283+
279284
ffStrbufWriteTo(&instance->config.separator, stdout);
280-
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
285+
286+
if(!instance->config.pipe)
287+
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
281288
}

src/modules/colors.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
void ffPrintColors(FFinstance* instance)
44
{
5+
if(instance->config.pipe)
6+
{
7+
ffPrintLogoLine(instance);
8+
puts("████████████████████████");
9+
ffPrintLogoLine(instance);
10+
puts("████████████████████████");
11+
return;
12+
}
13+
514
ffPrintLogoLine(instance);
615

716
// 4%d: Set the background color

src/modules/title.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ const FFTitleResult* ffDetectTitle(FFinstance* instance)
3030

3131
static inline void printTitlePart(FFinstance* instance, const FFstrbuf* content)
3232
{
33-
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
34-
ffPrintColor(&instance->config.mainColor);
33+
if(!instance->config.pipe)
34+
{
35+
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
36+
ffPrintColor(&instance->config.mainColor);
37+
}
38+
3539
ffStrbufWriteTo(content, stdout);
36-
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
40+
41+
if(!instance->config.pipe)
42+
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
3743
}
3844

3945
void ffPrintTitle(FFinstance* instance)

0 commit comments

Comments
 (0)