mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
seperator is now always the width of the title
This commit is contained in:
@@ -102,7 +102,6 @@ static void defaultConfig(FFinstance* instance)
|
||||
instance->config.logoKeySpacing = 4;
|
||||
ffStrbufInitS(&instance->config.separator, ": ");
|
||||
instance->config.offsetx = 0;
|
||||
instance->config.titleLength = 20; // This is overwritten by ffPrintTitle
|
||||
instance->config.colorLogo = true;
|
||||
instance->config.showErrors = false;
|
||||
instance->config.recache = false;
|
||||
|
||||
+7
-1
@@ -38,7 +38,6 @@ typedef struct FFconfig
|
||||
FFstrbuf separator;
|
||||
int16_t offsetx;
|
||||
FFstrbuf color;
|
||||
uint32_t titleLength;
|
||||
bool colorLogo;
|
||||
bool showErrors;
|
||||
bool recache;
|
||||
@@ -104,6 +103,12 @@ typedef struct FFconfig
|
||||
|
||||
} FFconfig;
|
||||
|
||||
typedef struct FFTitleResult
|
||||
{
|
||||
FFstrbuf userName;
|
||||
FFstrbuf hostname;
|
||||
} FFTitleResult;
|
||||
|
||||
typedef struct FFOSResult
|
||||
{
|
||||
FFstrbuf systemName;
|
||||
@@ -324,6 +329,7 @@ const FFTerminalShellResult* ffDetectTerminalShell(FFinstance* instance);
|
||||
|
||||
//Common
|
||||
const FFOSResult* ffDetectOS(FFinstance* instance);
|
||||
const FFTitleResult* ffDetectTitle(FFinstance* instance);
|
||||
|
||||
//Printing
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
void ffPrintSeparator(FFinstance* instance)
|
||||
{
|
||||
const FFTitleResult* result = ffDetectTitle(instance);
|
||||
uint32_t titleLength = result->userName.length + 1 + result->hostname.length;
|
||||
|
||||
ffPrintLogoLine(instance);
|
||||
|
||||
for(uint32_t i = 0; i < instance->config.titleLength; i++)
|
||||
for(uint32_t i = 0; i < titleLength; i++)
|
||||
putchar('-');
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
+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