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-05-13 12:27:44 +02:00
static void printTerminalFontFromConfigFile ( FFinstance * instance , const char * configFile , const char * start )
2021-05-09 12:30:10 +02:00
{
2021-05-13 12:27:44 +02:00
FFstrbuf font ;
ffStrbufInit ( & font );
ffParsePropFileConfig ( instance , configFile , start , & font );
if ( font . length == 0 )
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "Couldn't find terminal font in \" $XDG_CONFIG_HOME/%s \" " , configFile );
else
printTerminalFont ( instance , font . chars );
2021-05-09 12:30:10 +02:00
2021-05-13 12:27:44 +02:00
ffStrbufDestroy ( & font );
2021-05-09 12:30:10 +02:00
}
2021-03-11 17:21:18 +01:00
static void printKonsole ( FFinstance * instance )
{
2021-05-13 12:27:44 +02:00
FFstrbuf profile ;
ffStrbufInit ( & profile );
2021-05-15 14:58:43 +02:00
ffParsePropFileConfig ( instance , "konsolerc" , "DefaultProfile =" , & profile );
2021-05-13 12:27:44 +02:00
if ( profile . length == 0 )
2021-03-11 17:21:18 +01:00
{
2021-05-13 12:27:44 +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 \" " );
ffStrbufDestroy ( & profile );
2021-03-11 17:21:18 +01:00
return ;
}
2021-05-13 12:27:44 +02:00
FFstrbuf profilePath ;
ffStrbufInitA ( & profilePath , 64 );
ffStrbufAppendS ( & profilePath , ".local/share/konsole/" );
ffStrbufAppend ( & profilePath , & profile );
2021-03-11 17:21:18 +01:00
2021-05-13 12:27:44 +02:00
FFstrbuf font ;
ffStrbufInit ( & font );
2021-05-15 14:58:43 +02:00
ffParsePropFileHome ( instance , profilePath . chars , "Font =" , & font );
2021-03-11 17:21:18 +01:00
2021-05-13 12:27:44 +02:00
if ( font . length == 0 )
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 . chars );
else
printTerminalFont ( instance , font . chars );
ffStrbufDestroy ( & font );
ffStrbufDestroy ( & profilePath );
ffStrbufDestroy ( & profile );
2021-03-11 17:21:18 +01:00
}
2021-05-17 23:02:27 +02:00
static void printGSTerminal ( FFinstance * instance , char * profilepath , char * profilelist , char * profile )
2021-05-17 14:21:55 +02:00
{
2021-05-17 23:02:27 +02:00
const char * defaultProfile = ffSettingsGetGsettings ( instance , profilelist , NULL , "default" , FF_VARIANT_TYPE_STRING ). strValue ;
2021-05-17 14:21:55 +02:00
if ( ! defaultProfile )
{
2021-05-17 23:02:27 +02:00
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "Couldn't get \" default \" profile from gsettings" );
2021-05-17 14:21:55 +02:00
return ;
}
FFstrbuf path ;
2021-05-17 23:02:27 +02:00
ffStrbufInitAS ( & path , 128 , profilepath );
2021-05-17 14:21:55 +02:00
ffStrbufAppendS ( & path , defaultProfile );
ffStrbufAppendC ( & path , '/' );
2021-05-17 23:02:27 +02:00
const char * fontName = NULL ;
2021-05-17 14:21:55 +02:00
2021-05-17 23:02:27 +02:00
FFvariant res = ffSettingsGetGsettings ( instance , profile , path . chars , "use-system-font" , FF_VARIANT_TYPE_BOOL );
2021-05-17 14:21:55 +02:00
if ( ! res . boolValue ) // custom font
2021-05-17 23:02:27 +02:00
fontName = ffSettingsGetGsettings ( instance , profile , path . chars , "font" , FF_VARIANT_TYPE_STRING ). strValue ;
2021-05-17 14:21:55 +02:00
else // system font
fontName = ffSettingsGetGsettings ( instance , "org.gnome.desktop.interface" , NULL , "monospace-font-name" , FF_VARIANT_TYPE_STRING ). strValue ;
2021-05-17 14:32:51 +02:00
ffStrbufDestroy ( & path );
2021-05-17 14:21:55 +02:00
if ( fontName == NULL )
2021-05-17 23:02:27 +02:00
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "Couldn't get terminal font from gsettings" );
else
printTerminalFont ( instance , fontName );
2021-05-17 14:21:55 +02:00
}
2021-05-11 22:28:10 +02:00
static void printXCFETerminal ( FFinstance * instance )
{
2021-05-13 12:27:44 +02:00
FFstrbuf useSysFont ;
ffStrbufInit ( & useSysFont );
2021-05-11 22:28:10 +02:00
2021-05-15 14:58:43 +02:00
if ( ! ffParsePropFileConfig ( instance , "xfce4/terminal/terminalrc" , "FontUseSystem =" , & useSysFont ))
2021-05-11 22:28:10 +02:00
{
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "Couldn't open \" $XDG_CONFIG_HOME/xfce4/terminal/terminalrc \" " );
2021-05-13 12:27:44 +02:00
ffStrbufDestroy ( & useSysFont );
2021-05-11 22:28:10 +02:00
return ;
}
2021-05-13 12:27:44 +02:00
if ( useSysFont . length == 0 || ffStrbufIgnCaseCompS ( & useSysFont , "FALSE" ) == 0 )
2021-05-11 22:28:10 +02:00
{
2021-05-15 14:58:43 +02:00
printTerminalFontFromConfigFile ( instance , "xfce4/terminal/terminalrc" , "FontName =" );
2021-05-13 12:27:44 +02:00
ffStrbufDestroy ( & useSysFont );
2021-05-11 22:28:10 +02:00
return ;
}
2021-05-12 20:13:56 +02:00
2021-05-13 12:27:44 +02:00
ffStrbufDestroy ( & useSysFont );
2021-05-12 20:13:56 +02:00
const char * fontName = ffSettingsGetXFConf ( instance , "xsettings" , "/Gtk/MonospaceFontName" , FF_VARIANT_TYPE_STRING ). strValue ;
2021-05-11 22:28:10 +02:00
if ( fontName == NULL )
ffPrintError ( instance , FF_TERMFONT_MODULE_NAME , 0 , & instance -> config . termFontKey , & instance -> config . termFontFormat , FF_TERMFONT_NUM_FORMAT_ARGS , "Couldn't find \" xsettings::/Gtk/MonospaceFontName \" in XFConf" );
2021-05-13 12:27:44 +02:00
else
printTerminalFont ( instance , fontName );
2021-05-11 22:28:10 +02:00
}
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-15 14:58:43 +02:00
ffParsePropFile ( "/etc/vconsole.conf" , "Font =" , & font );
2021-05-01 16:54:59 +02:00
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 )
2021-05-09 13:40:17 +02:00
printXCFETerminal ( instance );
2021-05-09 12:30:10 +02:00
else if ( ffStrbufIgnCaseCompS ( & result -> exeName , "lxterminal" ) == 0 )
2021-05-15 14:58:43 +02:00
printTerminalFontFromConfigFile ( instance , "lxterminal/lxterminal.conf" , "fontname =" );
2021-05-08 20:31:18 +02:00
else if ( ffStrbufIgnCaseCompS ( & result -> exeName , "tilix" ) == 0 )
2021-05-17 23:02:27 +02:00
printGSTerminal ( instance , "/com/gexperts/Tilix/profiles/" , "com.gexperts.Tilix.ProfilesList" , "com.gexperts.Tilix.Profile" );
2021-05-17 14:21:55 +02:00
else if ( ffStrbufIgnCaseCompS ( & result -> exeName , "gnome-terminal-server" ) == 0 )
2021-05-17 23:02:27 +02:00
printGSTerminal ( instance , "/org/gnome/terminal/legacy/profiles:/:" , "org.gnome.Terminal.ProfilesList" , "org.gnome.Terminal.Legacy.Profile" );
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
}