Files
fastfetch/src/modules/font.c
T

98 lines
2.4 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-29 14:15:11 +02:00
#define FF_FONT_NUM_FORMAT_ARGS 4
#if defined(__linux__) || defined(__FreeBSD__)
#include "common/parsing.h"
static void printFont(const FFFontResult* font)
{
FFstrbuf gtk;
ffStrbufInit(&gtk);
ffParseGTK(&gtk, &font->fonts[1], &font->fonts[2], &font->fonts[3]);
if(font->fonts[0].length > 0)
{
printf("%s [QT]", font->fonts[0].chars);
if(gtk.length > 0)
fputs(", ", stdout);
}
ffStrbufWriteTo(&gtk, stdout);
}
#elif defined(__APPLE__)
static void printFont(const FFFontResult* font)
{
if(font->fonts[0].length > 0)
{
printf("%s [System]", font->fonts[0].chars);
if(font->fonts[1].length > 0)
fputs(", ", stdout);
}
if(font->fonts[1].length > 0)
printf("%s [User]", font->fonts[1].chars);
}
2022-10-08 16:07:59 +08:00
#elif defined(_WIN32) || defined(__MSYS__)
2022-10-07 22:04:41 +08:00
static void printFont(const FFFontResult* font)
{
if(font->fonts[0].length > 0)
{
printf("%s [Desktop]", font->fonts[0].chars);
}
}
2022-09-29 14:15:11 +02:00
#else
static void printFont(const FFFontResult* font)
{
FF_UNUSED(font);
}
#endif
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-09-29 14:15:11 +02:00
assert(FF_DETECT_FONT_NUM_FONTS == FF_FONT_NUM_FORMAT_ARGS);
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-29 14:15:11 +02:00
const FFFontResult* font = ffDetectFont(instance);
if(font->error.length > 0)
2021-04-05 19:25:34 +02:00
{
2022-09-29 14:15:11 +02:00
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "%s", font->error.chars);
2021-04-05 19:25:34 +02:00
return;
}
2021-02-18 22:25:36 +01:00
2022-09-29 14:15:11 +02:00
if(instance->config.font.outputFormat.length == 0)
2021-02-18 22:25:36 +01:00
{
ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font.key);
2022-09-29 14:15:11 +02:00
printFont(font);
putchar('\n');
}
else
{
2022-09-29 14:15:11 +02:00
ffPrintFormat(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[0]},
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[1]},
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[2]},
{FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[3]}
});
2021-02-18 22:25:36 +01:00
}
2021-03-27 18:14:19 +01:00
}