Files
fastfetch/src/modules/font.c
T

63 lines
2.2 KiB
C
Raw Normal View History

2021-02-18 22:25:36 +01:00
#include "fastfetch.h"
#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
if (instance->config.font.outputFormat.length == 0 && instance->config.fontInline)
2021-02-18 22:25:36 +01:00
{
ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font.key);
for(uint32_t i = 0; i < list.length; ++i)
2021-04-05 19:25:34 +02:00
{
FFFontResult* font = (FFFontResult*)ffListGet(&list, i);
printf("[%s] %*s%s", font->type, font->fontPretty.length, font->fontPretty.chars, i < list.length - 1 ? ", " : "");
ffStrbufDestroy(&font->fontPretty);
2021-04-05 19:25:34 +02:00
}
putchar('\n');
}
else
{
for(uint32_t i = 0; i < list.length; ++i)
2022-09-25 18:21:08 +08:00
{
FFFontResult* font = (FFFontResult*)ffListGet(&list, i);
if(instance->config.font.outputFormat.length == 0)
{
char keyChars[32];
snprintf(keyChars, sizeof(keyChars), "%s (%s)", FF_FONT_MODULE_NAME, font->type);
ffPrintLogoAndKey(instance, keyChars, 0, &instance->config.font.key);
puts(font->fontPretty.chars);
}
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);
2022-09-25 18:21:08 +08:00
}
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
}