Files
fastfetch/src/modules/host.c
T

62 lines
1.7 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;
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-12 12:16:41 +01:00
FF_STRBUF_CREATE(version);
ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", &version);
2021-03-12 12:16:41 +01:00
FF_STRBUF_CREATE(host);
2021-03-19 20:57:07 +01:00
2021-03-22 19:52:59 +01:00
if(ffStrbufIsEmpty(&instance->config.hostFormat))
2021-03-19 20:57:07 +01:00
{
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-03-19 20:57:07 +01:00
);
}
2021-03-12 12:16:41 +01:00
else
2021-02-19 16:23:41 +01:00
{
2021-03-22 19:52:59 +01:00
if(ffStrbufIsEmpty(&family) && ffStrbufIsEmpty(&name))
{
ffPrintError(instance, "Host", "neither family nor name could be determined");
return;
}
else if(ffStrbufIsEmpty(&name))
{
ffStrbufAppend(&host, &family);
}
else if(ffStrbufIsEmpty(&family))
{
ffStrbufAppend(&host, &name);
}
else
{
ffStrbufAppend(&host, &family);
ffStrbufAppendC(&host, ' ');
ffStrbufAppend(&host, &name);
}
if(!ffStrbufIsEmpty(&version) && ffStrbufIgnCaseCompS(&version, "None") != 0)
{
ffStrbufAppendC(&host, ' ');
ffStrbufAppend(&host, &version);
}
2021-02-19 16:23:41 +01:00
}
2021-02-22 16:52:51 +01:00
ffPrintAndSaveCachedValue(instance, "Host", &host);
2021-03-19 20:57:07 +01:00
ffStrbufDestroy(&host);
ffStrbufDestroy(&family);
ffStrbufDestroy(&name);
ffStrbufDestroy(&version);
2021-02-18 22:25:36 +01:00
}