Files
fastfetch/src/modules/os.c
T

35 lines
1012 B
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 ffPrintOS(FFinstance* instance)
2021-02-18 22:25:36 +01:00
{
2021-02-27 18:30:05 +01:00
if(ffPrintCachedValue(instance, "OS"))
2021-02-22 16:52:51 +01:00
return;
2021-02-18 22:25:36 +01:00
char name[256];
2021-02-19 16:23:41 +01:00
ffParsePropFile("/etc/os-release", "NAME=\"%[^\"]+", name);
2021-03-19 20:57:07 +01:00
if(name[0] == '\0' && ffStrbufIsEmpty(&instance->config.osFormat)) //With custom format string we pass an empty string as name
2021-02-18 22:25:36 +01:00
{
2021-02-27 18:30:05 +01:00
ffPrintError(instance, "OS", "\"NAME=\\\"%[^\\\"]+\" not found in \"/etc/os-release\"");
2021-02-19 16:23:41 +01:00
return;
2021-02-18 22:25:36 +01:00
}
2021-03-19 20:57:07 +01:00
ffPrintLogoAndKey(instance, "OS");
2021-03-06 11:28:38 +01:00
2021-03-19 20:57:07 +01:00
FFstrbuf os;
ffStrbufInit(&os);
if(!ffStrbufIsEmpty(&instance->config.osFormat))
{
ffParseFormatString(&os, &instance->config.osFormat, 2,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.machine}
);
}
2021-03-06 11:28:38 +01:00
else
2021-03-19 20:57:07 +01:00
{
ffStrbufSetF(&os, "%s %s", name, instance->state.utsname.machine);
}
2021-02-22 16:52:51 +01:00
2021-03-19 20:57:07 +01:00
ffPrintAndSaveCachedValue(instance, "OS", os.chars);
ffStrbufDestroy(&os);
2021-02-18 22:25:36 +01:00
}