Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/fastfetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@
#include <ctype.h>
#include <string.h>

static void printWatchHeader(uint32_t iteration) {
const char* timeStr = ffTimeToShortStr(ffTimeGetNow());
uint32_t intervalSec = instance.state.dynamicInterval / 1000;
uint32_t intervalMs = instance.state.dynamicInterval % 1000;

// Print a reverse-video header bar
if (!instance.config.display.pipe) {
fputs("\e[7m", stdout); // Reverse video
}

if (intervalMs == 0) {
printf(" fastfetch --watch %s #%u (%us) Ctrl+C to exit ",
timeStr, iteration, intervalSec);
} else {
printf(" fastfetch --watch %s #%u (%.1fs) Ctrl+C to exit ",
timeStr, iteration, (double)instance.state.dynamicInterval / 1000.0);
}

if (!instance.config.display.pipe) {
fputs("\e[0m", stdout); // Reset
}
putchar('\n');
}

[[gnu::cold]]
static void printCommandFormatHelpJson(void) {
yyjson_mut_doc* doc = yyjson_mut_doc_new(nullptr);
Expand Down Expand Up @@ -670,6 +694,14 @@ static void parseCommand(FFdata* data, char* key, char* value) {
}
} else if (ffStrEqualsIgnCase(key, "--dynamic-interval")) {
instance.state.dynamicInterval = ffOptionParseUInt32(key, value); // seconds to milliseconds
} else if (ffStrEqualsIgnCase(key, "--watch") || ffStrEqualsIgnCase(key, "-w")) {
if (value == nullptr) {
instance.state.dynamicInterval = 2000; // Default 2 seconds
} else if (ffOptionParseBoolean(value)) {
instance.state.dynamicInterval = 2000;
} else {
instance.state.dynamicInterval = ffOptionParseUInt32(key, value);
}
} else {
return;
}
Expand Down Expand Up @@ -751,6 +783,7 @@ static void parseArguments(FFdata* data, int argc, char** argv, void (*parser)(F

static void run(FFdata* data) {
const bool useJsonConfig = data->structure.length == 0 && data->configDoc;
uint32_t watchIteration = 0;

if (useJsonConfig) {
ffPrintJsonConfig(data, true /* prepare */);
Expand Down Expand Up @@ -787,6 +820,8 @@ static void run(FFdata* data) {
fflush(stdout);
ffTimeSleep(instance.state.dynamicInterval);
fputs("\e[H", stdout); // Move cursor to the top left corner to overwrite the previous output
++watchIteration;
printWatchHeader(watchIteration);
instance.state.keysHeight = 0; // Reset keysHeight so `ffLogoPrintRemaining` will recalculate it
} else {
break;
Expand Down