Files
fastfetch/src/modules/terminalfont.c
T

82 lines
2.5 KiB
C
Raw Normal View History

2021-03-11 17:21:18 +01:00
#include "fastfetch.h"
2021-04-05 19:25:34 +02:00
static void printTerminalFont(FFinstance* instance, const char* font)
2021-03-19 20:57:07 +01:00
{
2021-04-05 19:25:34 +02:00
FF_STRBUF_CREATE(name);
double size;
ffParseFont(font, &name, &size);
FF_STRBUF_CREATE(pretty);
ffFontPretty(&pretty, &name, size);
2021-03-23 19:48:52 +01:00
if(instance->config.termFontFormat.length == 0)
2021-03-19 20:57:07 +01:00
{
2021-04-03 11:39:59 +02:00
ffPrintLogoAndKey(instance, &instance->config.termFontKey, "Terminal font");
2021-04-05 19:25:34 +02:00
ffStrbufPutTo(&pretty, stdout);
2021-03-19 20:57:07 +01:00
}
else
{
2021-04-05 19:25:34 +02:00
ffPrintFormatString(instance, &instance->config.termFontKey, "Terminal font", &instance->config.termFontFormat, 4,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, font},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &name},
(FFformatarg){FF_FORMAT_ARG_TYPE_DOUBLE, &size},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &pretty}
2021-03-19 20:57:07 +01:00
);
}
2021-04-05 19:25:34 +02:00
ffStrbufDestroy(&name);
ffStrbufDestroy(&pretty);
2021-03-19 20:57:07 +01:00
}
2021-03-11 17:21:18 +01:00
static void printKonsole(FFinstance* instance)
{
char profile[128];
ffParsePropFileHome(instance, ".config/konsolerc", "DefaultProfile=%[^\n]", profile);
if(profile[0] == '\0')
{
2021-04-03 11:39:59 +02:00
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Couldn't find \"DefaultProfile=%[^\n]\" in \".config/konsolerc\"");
2021-03-11 17:21:18 +01:00
return;
}
char profilePath[256];
sprintf(profilePath, ".local/share/konsole/%s", profile);
char font[128];
ffParsePropFileHome(instance, profilePath, "Font=%[^\n]", font);
if(font[0] == '\0')
{
2021-04-03 11:39:59 +02:00
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath);
2021-03-19 20:57:07 +01:00
return;
2021-03-11 17:21:18 +01:00
}
2021-04-05 19:25:34 +02:00
printTerminalFont(instance, font);
2021-03-11 17:21:18 +01:00
}
static void printTTY(FFinstance* instance)
{
char font[128];
ffParsePropFile("/etc/vconsole.conf", "Font=%[^\n]", font);
if(font[0] == '\0')
strcpy(font, "hardware-supplied VGA font");
2021-03-27 18:14:19 +01:00
2021-03-19 20:57:07 +01:00
printTerminalFont(instance, font);
2021-03-11 17:21:18 +01:00
}
void ffPrintTerminalFont(FFinstance* instance)
{
2021-04-03 23:10:14 +02:00
FFstrbuf* terminalExeName;
ffCalculateTerminal(instance, &terminalExeName, NULL, NULL);
2021-03-27 18:14:19 +01:00
2021-04-03 23:10:14 +02:00
if(terminalExeName->length == 0)
2021-03-11 17:21:18 +01:00
{
2021-04-03 23:10:14 +02:00
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Terminal font needs successfull terminal detection");
2021-03-19 20:57:07 +01:00
return;
2021-03-11 17:21:18 +01:00
}
2021-04-03 23:10:14 +02:00
if(ffStrbufIgnCaseCompS(terminalExeName, "konsole") == 0)
2021-03-11 17:21:18 +01:00
printKonsole(instance);
2021-04-03 23:10:14 +02:00
else if(ffStrbufIgnCaseCompS(terminalExeName, "login") == 0)
2021-03-11 17:21:18 +01:00
printTTY(instance);
else
2021-04-03 23:10:14 +02:00
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Unknown terminal: %s", terminalExeName->chars);
2021-03-27 18:14:19 +01:00
}