Files
fastfetch/src/modules/host.c
T

67 lines
1.8 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-04-03 11:39:59 +02:00
if(ffPrintCachedValue(instance, &instance->config.hostKey, "Host"))
2021-02-22 16:52:51 +01:00
return;
FF_STRBUF_CREATE(family);
ffGetFileContent("/sys/devices/virtual/dmi/id/product_family", &family);
2021-03-12 12:16:41 +01:00
FF_STRBUF_CREATE(name);
ffGetFileContent("/sys/devices/virtual/dmi/id/product_name", &name);
2021-03-27 18:14:19 +01:00
FF_STRBUF_CREATE(version);
ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", &version);
2021-03-12 12:16:41 +01:00
2021-04-03 21:51:50 +02:00
if(family.length == 0 && name.length == 0)
{
ffPrintError(instance, &instance->config.hostKey, "Host", "neither family nor name could be determined");
return;
}
FF_STRBUF_CREATE(host);
2021-03-19 20:57:07 +01:00
2021-03-23 19:48:52 +01:00
if(instance->config.hostFormat.length == 0)
2021-03-19 20:57:07 +01:00
{
2021-04-03 21:51:50 +02:00
if(name.length == 0)
2021-03-22 19:52:59 +01:00
{
ffStrbufAppend(&host, &family);
}
2021-03-23 19:48:52 +01:00
else if(family.length == 0)
2021-03-22 19:52:59 +01:00
{
ffStrbufAppend(&host, &name);
}
else
{
ffStrbufAppend(&host, &family);
ffStrbufAppendC(&host, ' ');
ffStrbufAppend(&host, &name);
}
2021-03-23 19:48:52 +01:00
if(
version.length > 0 &&
ffStrbufIgnCaseCompS(&version, "None") != 0 &&
ffStrbufIgnCaseCompS(&version, "To be filled by O.E.M.") != 0
) {
2021-03-22 19:52:59 +01:00
ffStrbufAppendC(&host, ' ');
ffStrbufAppend(&host, &version);
}
2021-02-19 16:23:41 +01:00
}
2021-03-23 19:48:52 +01:00
else
{
ffParseFormatString(&host, &instance->config.hostFormat, 3,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &family},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &name},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &version}
);
}
2021-02-22 16:52:51 +01:00
2021-04-03 11:39:59 +02:00
ffPrintAndSaveCachedValue(instance, &instance->config.hostKey, "Host", &host);
2021-03-19 20:57:07 +01:00
ffStrbufDestroy(&host);
ffStrbufDestroy(&family);
ffStrbufDestroy(&name);
ffStrbufDestroy(&version);
2021-03-27 18:14:19 +01:00
}