2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
|
|
|
|
|
2021-04-09 14:07:05 +02:00
|
|
|
#include <unistd.h>
|
2021-06-15 11:04:44 +02:00
|
|
|
#include <pthread.h>
|
2021-04-09 14:07:05 +02:00
|
|
|
|
2021-06-15 11:04:44 +02:00
|
|
|
const FFTitleResult* ffDetectTitle(FFinstance* instance)
|
2021-02-18 22:25:36 +01:00
|
|
|
{
|
2021-06-15 11:04:44 +02:00
|
|
|
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
static bool init = false;
|
|
|
|
|
static FFTitleResult result;
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
|
if(init)
|
|
|
|
|
{
|
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
return &result;
|
|
|
|
|
}
|
|
|
|
|
init = true;
|
|
|
|
|
|
|
|
|
|
ffStrbufInit(&result.userName);
|
|
|
|
|
ffStrbufAppendS(&result.userName, instance->state.passwd->pw_name);
|
|
|
|
|
|
|
|
|
|
ffStrbufInitA(&result.hostname, 256);
|
|
|
|
|
gethostname(result.hostname.chars, result.hostname.allocated);
|
|
|
|
|
ffStrbufRecalculateLength(&result.hostname);
|
|
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
return &result;
|
|
|
|
|
}
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-06-15 11:04:44 +02:00
|
|
|
static inline void printTitlePart(FFinstance* instance, const FFstrbuf* content)
|
|
|
|
|
{
|
|
|
|
|
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
|
2022-04-02 14:35:43 +02:00
|
|
|
ffPrintColor(&instance->config.mainColor);
|
2021-06-15 11:04:44 +02:00
|
|
|
ffStrbufWriteTo(content, stdout);
|
|
|
|
|
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffPrintTitle(FFinstance* instance)
|
|
|
|
|
{
|
|
|
|
|
const FFTitleResult* result = ffDetectTitle(instance);
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-02-27 18:30:05 +01:00
|
|
|
ffPrintLogoLine(instance);
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-06-15 11:04:44 +02:00
|
|
|
printTitlePart(instance, &result->userName);
|
|
|
|
|
putchar('@');
|
|
|
|
|
printTitlePart(instance, &result->hostname);
|
|
|
|
|
putchar('\n');
|
2021-03-27 18:14:19 +01:00
|
|
|
}
|