Files
fastfetch/src/modules/terminalfont.c
T

71 lines
2.0 KiB
C
Raw Normal View History

2021-03-11 17:21:18 +01:00
#include "fastfetch.h"
2021-03-19 20:57:07 +01:00
static void printTerminalFont(FFinstance* instance, char* font)
{
2021-03-23 19:48:52 +01:00
if(instance->config.termFontFormat.length == 0)
2021-03-19 20:57:07 +01:00
{
ffPrintLogoAndKey(instance, "Terminal font");
2021-03-19 20:57:07 +01:00
puts(font);
}
else
{
ffPrintFormatString(instance, "Terminal font", &instance->config.termFontFormat, 1,
2021-03-19 20:57:07 +01:00
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, font}
);
}
}
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')
{
ffPrintError(instance, "Terminal Font", "Couldn't find \"DefaultProfile=%[^\n]\" in \".config/konsolerc\"");
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-03-19 20:57:07 +01:00
ffPrintError(instance, "Terminal Font", "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath);
return;
2021-03-11 17:21:18 +01:00
}
char fontPretty[128];
ffParseFont(font, fontPretty);
2021-03-19 20:57:07 +01:00
printTerminalFont(instance, fontPretty);
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-19 20:57:07 +01:00
printTerminalFont(instance, font);
2021-03-11 17:21:18 +01:00
}
void ffPrintTerminalFont(FFinstance* instance)
{
ffPopulateTerminal(instance);
if(instance->state.terminal.error != NULL)
{
ffPrintError(instance, "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-03-19 20:57:07 +01:00
if(ffStrbufIgnCaseCompS(&instance->state.terminal.value, "konsole") == 0)
2021-03-11 17:21:18 +01:00
printKonsole(instance);
2021-03-19 20:57:07 +01:00
else if(ffStrbufIgnCaseCompS(&instance->state.terminal.value, "TTY") == 0)
2021-03-11 17:21:18 +01:00
printTTY(instance);
else
2021-03-19 20:57:07 +01:00
ffPrintError(instance, "Terminal Font", "Unknown terminal: %s", instance->state.terminal.value);
2021-03-11 17:21:18 +01:00
}