Files
fastfetch/src/modules/host.c
T

51 lines
1.4 KiB
C
Raw Normal View History

2021-02-18 22:25:36 +01:00
#include "fastfetch.h"
2021-02-27 18:30:05 +01:00
void ffPrintHost(FFinstance* instance)
2021-02-18 22:25:36 +01:00
{
2021-02-27 18:30:05 +01:00
if(ffPrintCachedValue(instance, "Host"))
2021-02-22 16:52:51 +01:00
return;
2021-03-12 12:16:41 +01:00
char family[256];
ffGetFileContent("/sys/devices/virtual/dmi/id/product_family", family, sizeof(family));
char name[256];
ffGetFileContent("/sys/devices/virtual/dmi/id/product_name", name, sizeof(name));
char version[256];
2021-03-19 20:57:07 +01:00
ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", version, sizeof(version));
2021-03-12 12:16:41 +01:00
2021-03-19 20:57:07 +01:00
if(family[0] == '\0' && name[0] == '\0')
2021-02-19 16:23:41 +01:00
{
2021-03-12 12:16:41 +01:00
ffPrintError(instance, "Host", "neither family nor name could be determined");
2021-02-19 16:23:41 +01:00
return;
2021-03-19 20:57:07 +01:00
}
ffPrintLogoAndKey(instance, "Host");
FFstrbuf host;
ffStrbufInit(&host);
if(!ffStrbufIsEmpty(&instance->config.hostFormat))
{
ffParseFormatString(&host, &instance->config.hostFormat, 3,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, family},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, version}
);
}
else if(family[0] != '\0' && name[0] != '\0')
2021-03-12 12:16:41 +01:00
{
2021-03-19 20:57:07 +01:00
ffStrbufSetF(&host, "%s %s %s", family, name, version);
2021-02-19 16:23:41 +01:00
}
2021-03-12 12:16:41 +01:00
else if(family[0] != '\0')
{
2021-03-19 20:57:07 +01:00
ffStrbufSetF(&host, "%s %s", family, version);
2021-03-12 12:16:41 +01:00
}
else
2021-02-19 16:23:41 +01:00
{
2021-03-19 20:57:07 +01:00
ffStrbufSetF(&host, "%s %s", name, version);
2021-02-19 16:23:41 +01:00
}
2021-02-22 16:52:51 +01:00
2021-03-19 20:57:07 +01:00
ffPrintAndSaveCachedValue(instance, "Host", host.chars);
ffStrbufDestroy(&host);
2021-02-18 22:25:36 +01:00
}