mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
TerminalShell: detect terminal version when available
This commit is contained in:
@@ -155,3 +155,29 @@ bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version)
|
||||
ok = false;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool fftsGetTerminalVersion(FFstrbuf* processName, FF_UNUSED_PARAM FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
const char* termProgramVersion = getenv("TERM_PROGRAM_VERSION");
|
||||
if(termProgramVersion)
|
||||
{
|
||||
const char* termProgram = getenv("TERM_PROGRAM");
|
||||
if(termProgram)
|
||||
{
|
||||
if(ffStrbufStartsWithIgnCaseS(processName, termProgram) || // processName ends with `.exe` on Windows
|
||||
(strcmp(termProgram, "vscode") == 0 && ffStrbufStartsWithIgnCaseS(processName, "code"))
|
||||
) {
|
||||
ffStrbufSetS(version, termProgramVersion);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
return getFileVersion(exe->chars, version);
|
||||
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ typedef struct FFTerminalShellResult
|
||||
FFstrbuf terminalExe;
|
||||
FFstrbuf terminalPrettyName;
|
||||
const char* terminalExeName; //pointer to a char in terminalExe
|
||||
FFstrbuf terminalVersion;
|
||||
|
||||
FFstrbuf userShellExe;
|
||||
const char* userShellExeName; //pointer to a char in userShellExe
|
||||
|
||||
@@ -310,6 +310,8 @@ static void getShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* versio
|
||||
getShellVersionGeneric(exe, exeName, version);
|
||||
}
|
||||
|
||||
bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* version);
|
||||
|
||||
const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
@@ -378,6 +380,9 @@ const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
|
||||
else
|
||||
ffStrbufInitCopy(&result.terminalPrettyName, &result.terminalProcessName);
|
||||
|
||||
ffStrbufInit(&result.terminalVersion);
|
||||
fftsGetTerminalVersion(&result.terminalProcessName, &result.terminalExe, &result.terminalVersion);
|
||||
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
|
||||
@@ -263,6 +263,8 @@ static void getTerminalFromEnv(FFTerminalShellResult* result)
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* version);
|
||||
|
||||
const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
@@ -302,6 +304,9 @@ const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
|
||||
if(result.terminalProcessName.length == 0)
|
||||
getTerminalFromEnv(&result);
|
||||
|
||||
ffStrbufInit(&result.terminalVersion);
|
||||
fftsGetTerminalVersion(&result.terminalProcessName, &result.terminalExe, &result.terminalVersion);
|
||||
|
||||
exit:
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
|
||||
@@ -20,7 +20,11 @@ void ffPrintTerminal(FFinstance* instance)
|
||||
if(instance->config.terminal.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminal.key);
|
||||
ffStrbufPutTo(&result->terminalPrettyName, stdout);
|
||||
|
||||
if(result->terminalVersion.length)
|
||||
printf("%s %s\n", result->terminalPrettyName.chars, result->terminalVersion.chars);
|
||||
else
|
||||
ffStrbufPutTo(&result->terminalPrettyName, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user