TerminalShell: detect terminal version when available

This commit is contained in:
李通洲
2023-01-10 19:24:59 +08:00
parent 7f97725d7f
commit ef2a5110fe
6 changed files with 44 additions and 1 deletions
+2
View File
@@ -3,6 +3,7 @@
Notable Changes:
* fastfetch no longer creates a sample config file silently. Use `--gen-config` to generate one.
* fastfetch now search for user config file in the order of `fastfetch --list-config-paths`
* Unknown disks are hidden by default.
Features:
* `--logo-padding-top` option (@CarterLi, #372)
@@ -14,6 +15,7 @@ Features:
* Add `Brightness` module support
* Add `Battery` module support for FreeBSD
* Add `--disk-show-unknown` option for Disk module
* Detect terminal version when available
Logos:
* Raspbian (@IamNoRobot, #373)
@@ -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;
+5 -1
View File
@@ -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
{