2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
2022-07-25 13:15:01 +02:00
|
|
|
#include "common/printing.h"
|
2022-09-25 18:21:08 +08:00
|
|
|
#include "detection/font/font.h"
|
2022-09-06 15:42:37 +02:00
|
|
|
#include "detection/displayserver/displayserver.h"
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-04-15 18:59:26 +02:00
|
|
|
#define FF_FONT_MODULE_NAME "Font"
|
2022-09-25 18:21:08 +08:00
|
|
|
#define FF_FONT_NUM_FORMAT_ARGS 2
|
2021-04-15 18:59:26 +02:00
|
|
|
|
2021-02-27 18:30:05 +01:00
|
|
|
void ffPrintFont(FFinstance* instance)
|
2021-02-18 22:25:36 +01:00
|
|
|
{
|
2022-01-02 16:55:26 +01:00
|
|
|
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);
|
2021-06-27 21:53:50 +02:00
|
|
|
|
|
|
|
|
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0)
|
|
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "Font isn't supported in TTY");
|
2021-06-27 21:53:50 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-25 18:21:08 +08:00
|
|
|
FFlist list;
|
|
|
|
|
ffListInit(&list, sizeof(FFFontResult));
|
|
|
|
|
const char* error = ffDetectFontImpl(instance, &list);
|
|
|
|
|
if(error)
|
2021-04-05 19:25:34 +02:00
|
|
|
{
|
2022-09-25 18:21:08 +08:00
|
|
|
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "%s", error);
|
2021-04-05 19:25:34 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2022-09-25 18:21:08 +08:00
|
|
|
for(uint32_t i = 0; i < list.length; ++i)
|
2021-02-18 22:25:36 +01:00
|
|
|
{
|
2022-09-25 18:21:08 +08:00
|
|
|
FFFontResult* font = (FFFontResult*)ffListGet(&list, i);
|
|
|
|
|
if(instance->config.font.outputFormat.length == 0)
|
2021-04-05 19:25:34 +02:00
|
|
|
{
|
2022-09-25 18:21:08 +08:00
|
|
|
FFstrbuf key;
|
|
|
|
|
ffStrbufInitF(&key, "%s (%s)", FF_FONT_MODULE_NAME, font->type);
|
|
|
|
|
ffPrintLogoAndKey(instance, key.chars, 0, &instance->config.font.key);
|
|
|
|
|
puts(font->fontPretty.chars);
|
|
|
|
|
ffStrbufDestroy(&key);
|
2021-04-05 19:25:34 +02:00
|
|
|
}
|
2022-09-25 18:21:08 +08:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ffPrintFormat(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]){
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRING, font->type},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fontPretty}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
ffStrbufDestroy(&font->fontPretty);
|
2021-02-18 22:25:36 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-25 18:21:08 +08:00
|
|
|
ffListDestroy(&list);
|
2021-03-27 18:14:19 +01:00
|
|
|
}
|