mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
seperator is now always the width of the title
This commit is contained in:
+39
-8
@@ -1,18 +1,49 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
const FFTitleResult* ffDetectTitle(FFinstance* instance)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static inline void printTitlePart(FFinstance* instance, const FFstrbuf* content)
|
||||
{
|
||||
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
|
||||
ffStrbufWriteTo(&instance->config.color, stdout);
|
||||
ffStrbufWriteTo(content, stdout);
|
||||
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
|
||||
}
|
||||
|
||||
void ffPrintTitle(FFinstance* instance)
|
||||
{
|
||||
char hostname[256];
|
||||
gethostname(hostname, 256);
|
||||
|
||||
instance->config.titleLength = (uint32_t) strlen(instance->state.passwd->pw_name) + 1 + strlen(hostname);
|
||||
const FFTitleResult* result = ffDetectTitle(instance);
|
||||
|
||||
ffPrintLogoLine(instance);
|
||||
|
||||
printf(FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"@"FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET"\n",
|
||||
instance->config.color.chars, instance->state.passwd->pw_name, instance->config.color.chars, hostname
|
||||
);
|
||||
printTitlePart(instance, &result->userName);
|
||||
putchar('@');
|
||||
printTitlePart(instance, &result->hostname);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user