mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 09:33:39 +01:00
Introduce FFPlatform
This commit is contained in:
+10
-10
@@ -2,29 +2,29 @@
|
||||
#include "common/printing.h"
|
||||
|
||||
#define FF_KERNEL_MODULE_NAME "Kernel"
|
||||
#define FF_KERNEL_NUM_FORMAT_ARGS 3
|
||||
#define FF_KERNEL_NUM_FORMAT_ARGS 4
|
||||
|
||||
void ffPrintKernel(FFinstance* instance)
|
||||
{
|
||||
if(instance->config.kernel.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernel.key);
|
||||
ffStrbufWriteTo(&instance->state.platform.systemRelease, stdout);
|
||||
|
||||
#ifdef _WIN32
|
||||
if(instance->state.utsname.version[0] != '\0')
|
||||
printf("%s (%s)\n", instance->state.utsname.release, instance->state.utsname.version);
|
||||
else
|
||||
puts(instance->state.utsname.release);
|
||||
#else
|
||||
puts(instance->state.utsname.release);
|
||||
if(instance->state.platform.systemVersion.length > 0)
|
||||
printf(" (%s)", instance->state.platform.systemVersion.chars);
|
||||
#endif
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernel, FF_KERNEL_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.sysname},
|
||||
{FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.release},
|
||||
{FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.version}
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &instance->state.platform.systemName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &instance->state.platform.systemRelease},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &instance->state.platform.systemVersion},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &instance->state.platform.systemArchitecture}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -7,7 +7,7 @@
|
||||
#define FF_OS_MODULE_NAME "OS"
|
||||
#define FF_OS_NUM_FORMAT_ARGS 12
|
||||
|
||||
static void buildOutputDefault(const FFOSResult* os, FFstrbuf* result)
|
||||
static void buildOutputDefault(const FFinstance* instance, const FFOSResult* os, FFstrbuf* result)
|
||||
{
|
||||
//Create the basic output
|
||||
if(os->name.length > 0)
|
||||
@@ -17,7 +17,7 @@ static void buildOutputDefault(const FFOSResult* os, FFstrbuf* result)
|
||||
else if(os->id.length > 0)
|
||||
ffStrbufAppend(result, &os->id);
|
||||
else
|
||||
ffStrbufAppend(result, &os->systemName);
|
||||
ffStrbufAppend(result, &instance->state.platform.systemName);
|
||||
|
||||
#ifdef __APPLE__
|
||||
if(os->codename.length > 0)
|
||||
@@ -62,14 +62,14 @@ static void buildOutputDefault(const FFOSResult* os, FFstrbuf* result)
|
||||
}
|
||||
|
||||
//Append architecture if it is missing
|
||||
if(ffStrbufFirstIndex(result, &os->architecture) == result->length)
|
||||
if(ffStrbufFirstIndex(result, &instance->state.platform.systemArchitecture) == result->length)
|
||||
{
|
||||
ffStrbufAppendC(result, ' ');
|
||||
ffStrbufAppend(result, &os->architecture);
|
||||
ffStrbufAppend(result, &instance->state.platform.systemArchitecture);
|
||||
}
|
||||
}
|
||||
|
||||
static void buildOutputNixOS(const FFOSResult* os, FFstrbuf* result)
|
||||
static void buildOutputNixOS(const FFinstance* instance, const FFOSResult* os, FFstrbuf* result)
|
||||
{
|
||||
ffStrbufAppendS(result, "NixOS");
|
||||
|
||||
@@ -87,10 +87,10 @@ static void buildOutputNixOS(const FFOSResult* os, FFstrbuf* result)
|
||||
ffStrbufAppendC(result, ')');
|
||||
}
|
||||
|
||||
if(os->architecture.length > 0)
|
||||
if(instance->state.platform.systemArchitecture.length > 0)
|
||||
{
|
||||
ffStrbufAppendC(result, ' ');
|
||||
ffStrbufAppend(result, &os->architecture);
|
||||
ffStrbufAppend(result, &instance->state.platform.systemArchitecture);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ void ffPrintOS(FFinstance* instance)
|
||||
{
|
||||
const FFOSResult* os = ffDetectOS(instance);
|
||||
|
||||
if(os->name.length == 0 && os->prettyName.length == 0 && os->id.length == 0 && os->systemName.length == 0)
|
||||
if(os->name.length == 0 && os->prettyName.length == 0 && os->id.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_OS_MODULE_NAME, 0, &instance->config.os, "Could not detect OS");
|
||||
return;
|
||||
@@ -110,9 +110,9 @@ void ffPrintOS(FFinstance* instance)
|
||||
ffStrbufInit(&result);
|
||||
|
||||
if(ffStrbufIgnCaseCompS(&os->id, "nixos") == 0)
|
||||
buildOutputNixOS(os, &result);
|
||||
buildOutputNixOS(instance, os, &result);
|
||||
else
|
||||
buildOutputDefault(os, &result);
|
||||
buildOutputDefault(instance, os, &result);
|
||||
|
||||
ffPrintLogoAndKey(instance, FF_OS_MODULE_NAME, 0, &instance->config.os.key);
|
||||
ffStrbufPutTo(&result, stdout);
|
||||
@@ -121,7 +121,7 @@ void ffPrintOS(FFinstance* instance)
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_OS_MODULE_NAME, 0, &instance->config.os, FF_OS_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &os->systemName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &instance->state.platform.systemName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &os->name},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &os->prettyName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &os->id},
|
||||
@@ -132,7 +132,7 @@ void ffPrintOS(FFinstance* instance)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &os->versionID},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &os->codename},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &os->buildID},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &os->architecture}
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &instance->state.platform.systemArchitecture}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/title.h"
|
||||
|
||||
void ffPrintSeparator(FFinstance* instance)
|
||||
{
|
||||
const FFTitleResult* result = ffDetectTitle(instance);
|
||||
uint32_t titleLength = result->userName.length + 1 +
|
||||
(instance->config.titleFQDN ? result->fqdn.length : result->hostname.length);
|
||||
uint32_t titleLength = instance->state.platform.userName.length + 1 + (instance->config.titleFQDN ?
|
||||
instance->state.platform.domainName.length :
|
||||
instance->state.platform.hostName.length
|
||||
);
|
||||
|
||||
ffLogoPrintLine(instance);
|
||||
|
||||
|
||||
+5
-5
@@ -1,6 +1,5 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/title.h"
|
||||
#include "util/textModifier.h"
|
||||
|
||||
static inline void printTitlePart(FFinstance* instance, const FFstrbuf* content)
|
||||
@@ -19,12 +18,13 @@ static inline void printTitlePart(FFinstance* instance, const FFstrbuf* content)
|
||||
|
||||
void ffPrintTitle(FFinstance* instance)
|
||||
{
|
||||
const FFTitleResult* result = ffDetectTitle(instance);
|
||||
|
||||
ffLogoPrintLine(instance);
|
||||
|
||||
printTitlePart(instance, &result->userName);
|
||||
printTitlePart(instance, &instance->state.platform.userName);
|
||||
putchar('@');
|
||||
printTitlePart(instance, instance->config.titleFQDN ? &result->fqdn : &result->hostname);
|
||||
printTitlePart(instance, instance->config.titleFQDN ?
|
||||
&instance->state.platform.domainName :
|
||||
&instance->state.platform.hostName
|
||||
);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user