2021-03-11 17:21:18 +01:00
#include "fastfetch.h"
2021-04-09 14:07:05 +02:00
#include <string.h>
2021-04-15 18:59:26 +02:00
#define FF_TERMFONT_MODULE_NAME "Terminal Font"
#define FF_TERMFONT_NUM_FORMAT_ARGS 4
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 ;
2021-04-09 14:07:05 +02:00
ffGetFont ( font , & name , & size );
2021-04-05 19:25:34 +02:00
FF_STRBUF_CREATE ( pretty );
2021-04-09 14:07:05 +02:00
ffGetFontPretty ( & pretty , & name , size );
2021-04-05 19:25:34 +02:00
2021-03-23 19:48:52 +01:00
if ( instance -> config . termFontFormat . length == 0 )
2021-03-19 20:57:07 +01:00
{
2021-04-15 18:59:26 +02:00
ffPrintLogoAndKey ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey );
2021-04-05 19:25:34 +02:00
ffStrbufPutTo ( & pretty , stdout );
2021-03-19 20:57:07 +01:00
}
else
{
2021-04-15 18:59:26 +02:00
ffPrintFormatString ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , NULL , FF_TERMFONT_NUM_FORMAT_ARGS , ( FFformatarg []){
{ FF_FORMAT_ARG_TYPE_STRING , font },
{ FF_FORMAT_ARG_TYPE_STRBUF , & name },
{ FF_FORMAT_ARG_TYPE_DOUBLE , & size },
{ 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-15 18:59:26 +02:00
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "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-15 18:59:26 +02:00
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "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-22 21:41:42 +02:00
const FFTerminalResult * result = ffCalculateTerminal ( instance );
2021-03-27 18:14:19 +01:00
2021-04-22 21:41:42 +02:00
if ( result -> exeName . length == 0 )
2021-03-11 17:21:18 +01:00
{
2021-04-15 18:59:26 +02:00
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "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-22 21:41:42 +02:00
if ( ffStrbufIgnCaseCompS ( & result -> exeName , "konsole" ) == 0 )
2021-03-11 17:21:18 +01:00
printKonsole ( instance );
2021-04-22 21:41:42 +02:00
else if ( ffStrbufStartsWithIgnCaseS ( & result -> exeName , "login" ))
2021-03-11 17:21:18 +01:00
printTTY ( instance );
else
2021-04-22 21:41:42 +02:00
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "Terminal Font" , "Unknown terminal: %s" , result -> exeName . chars );
2021-03-27 18:14:19 +01:00
}