2021-02-18 22:25:36 +01:00
#include "fastfetch.h"
2021-04-28 19:53:30 +02:00
#include <string.h>
#include <unistd.h>
#include <pthread.h>
2021-04-15 18:59:26 +02:00
#define FF_TERMINAL_MODULE_NAME "Terminal"
#define FF_TERMINAL_NUM_FORMAT_ARGS 3
2021-03-11 17:21:18 +01:00
void ffPrintTerminal ( FFinstance * instance )
{
2021-06-14 23:22:14 +02:00
const FFTerminalShellResult * result = ffDetectTerminalShell ( instance );
2021-04-02 16:21:52 +02:00
2021-06-14 23:22:14 +02:00
if ( result -> terminalProcessName . length == 0 )
2021-04-03 21:51:50 +02:00
{
2021-06-14 23:22:14 +02:00
ffPrintError ( instance , FF_TERMINAL_MODULE_NAME , 0 , & instance -> config . terminalKey , & instance -> config . terminalFormat , FF_TERMINAL_NUM_FORMAT_ARGS , "Couldn't detect terminal" );
2021-04-03 21:51:50 +02:00
return ;
}
2021-03-23 19:48:52 +01:00
if ( instance -> config . terminalFormat . length == 0 )
2021-03-11 17:21:18 +01:00
{
2021-04-15 18:59:26 +02:00
ffPrintLogoAndKey ( instance , FF_TERMINAL_MODULE_NAME , 0 , & instance -> config . terminalKey );
2021-09-19 14:58:46 +02:00
uint32_t terminalExeNameLength = result -> terminalExe . chars + result -> terminalExe . length - result -> terminalExeName ;
if ( strncmp ( result -> terminalExeName , result -> terminalProcessName . chars , terminalExeNameLength ) == 0 ) // if exeName starts with processName, print it. Otherwise print processName
puts ( result -> terminalExeName );
else
ffStrbufPutTo ( & result -> terminalProcessName , stdout );
2021-03-11 17:21:18 +01:00
}
else
{
2021-04-15 18:59:26 +02:00
ffPrintFormatString ( instance , FF_TERMINAL_MODULE_NAME , 0 , & instance -> config . terminalKey , & instance -> config . terminalFormat , NULL , FF_TERMINAL_NUM_FORMAT_ARGS , ( FFformatarg []){
2021-06-14 23:22:14 +02:00
{ FF_FORMAT_ARG_TYPE_STRBUF , & result -> terminalProcessName },
{ FF_FORMAT_ARG_TYPE_STRBUF , & result -> terminalExe },
{ FF_FORMAT_ARG_TYPE_STRING , & result -> terminalExeName }
2021-04-15 18:59:26 +02:00
});
2021-03-11 17:21:18 +01:00
}
2021-02-18 22:25:36 +01:00
}