2021-03-11 17:21:18 +01:00
#include "fastfetch.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 ];
2021-05-07 14:55:43 +02:00
ffParsePropFileConfig ( instance , "konsolerc" , "DefaultProfile=%[^ \n ]" , profile );
2021-03-11 17:21:18 +01:00
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
}
2021-04-24 13:12:40 +02:00
static void printXFCE4Terminal ( FFinstance * instance )
{
char font [ 128 ];
2021-05-07 14:55:43 +02:00
ffParsePropFileConfig ( instance , "xfce4/terminal/terminalrc" , "FontName=%[^ \n ]" , font );
2021-04-24 13:12:40 +02:00
if ( font [ 0 ] == '\0' )
{
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "Couldn't find \" FontName=%%[^ \\ n] \" in \" .config/xfce4/terminal/terminalrc \" " );
return ;
}
printTerminalFont ( instance , font );
}
2021-05-08 20:31:18 +02:00
static void printTilixTerminal ( FFinstance * instance )
{
static const char * fontName = NULL ;
static const char * defaultProfile = NULL ;
static FFstrbuf key ;
static FFvariant res ;
res . strValue = NULL ;
ffStrbufInitAS ( & key , 64 , "/com/gexperts/Tilix/profiles/" );
defaultProfile = ( ffSettingsGetGsettings ( instance , "com.gexperts.Tilix.ProfilesList" , NULL , "default" , FF_VARIANT_TYPE_STRING )). strValue ;
if ( ! defaultProfile )
{
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "Couldn't find \" Default \" profile in Tilix settings" );
ffStrbufDestroy ( & key );
return ;
}
else
{
ffStrbufAppendS ( & key , defaultProfile );
ffStrbufAppendS ( & key , "/use-system-font" );
res = ffSettingsGetDConf ( instance , key . chars , FF_VARIANT_TYPE_BOOL );
if ( res . boolValueSet && res . boolValue == 0 ) // custom font
{
ffStrbufRemoveStrings ( & key , 1 , "/use-system-font" );
ffStrbufAppendS ( & key , "/font" );
fontName = ( ffSettingsGetDConf ( instance , key . chars , FF_VARIANT_TYPE_STRING )). strValue ;
}
else if ( ! res . boolValueSet || res . boolValue == 1 ) // system font
fontName = ( ffSettingsGetDConf ( instance , "/org/gnome/desktop/interface/monospace-font-name" , FF_VARIANT_TYPE_STRING )). strValue ;
}
if ( ! fontName )
{
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "Couldn't find \" Terminal font \" in Tilix settings" );
ffStrbufDestroy ( & key );
return ;
}
printTerminalFont ( instance , fontName );
ffStrbufDestroy ( & key );
}
2021-03-11 17:21:18 +01:00
static void printTTY ( FFinstance * instance )
{
2021-05-01 16:54:59 +02:00
FFstrbuf font ;
ffStrbufInit ( & font );
2021-03-27 18:14:19 +01:00
2021-05-01 16:54:59 +02:00
ffParsePropFile ( "/etc/vconsole.conf" , "Font=%[^ \n ]" , font . chars );
ffStrbufRecalculateLength ( & font );
if ( font . length == 0 )
{
ffStrbufAppendS ( & font , "VGA default kernel font " );
ffProcessAppendStdOut ( & font , ( char * const []){
"showconsolefont" ,
"--info" ,
NULL
});
}
printTerminalFont ( instance , font . chars );
ffStrbufDestroy ( & font );
2021-03-11 17:21:18 +01:00
}
void ffPrintTerminalFont ( FFinstance * instance )
{
2021-04-28 19:53:30 +02:00
const FFTerminalResult * result = ffDetectTerminal ( 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-24 13:12:40 +02:00
else if ( ffStrbufIgnCaseCompS ( & result -> exeName , "xfce4-terminal" ) == 0 )
printXFCE4Terminal ( instance );
2021-05-08 20:31:18 +02:00
else if ( ffStrbufIgnCaseCompS ( & result -> exeName , "tilix" ) == 0 )
printTilixTerminal ( instance );
2021-05-01 16:54:59 +02:00
else if ( ffStrbufStartsWithIgnCaseS ( & result -> exeName , "/dev/tty" ))
2021-03-11 17:21:18 +01:00
printTTY ( instance );
else
2021-05-01 16:54:59 +02:00
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "Unknown terminal: %s" , result -> exeName . chars );
2021-03-27 18:14:19 +01:00
}