mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
TerminalShell: code refactor
This commit is contained in:
@@ -235,10 +235,6 @@ static bool getShellVersionWinPowerShell(FFstrbuf* exe, FFstrbuf* version) {
|
||||
#endif
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version) {
|
||||
if (!instance.config.general.detectVersion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ffStrEqualsIgnCase(exeName, "sh")) { // #849
|
||||
return false;
|
||||
}
|
||||
@@ -727,10 +723,6 @@ static bool getTerminalVersionConEmu(FFstrbuf* exe, FFstrbuf* version) {
|
||||
#endif
|
||||
|
||||
bool fftsGetTerminalVersion(FFstrbuf* processName, FF_A_UNUSED FFstrbuf* exe, FFstrbuf* version) {
|
||||
if (!instance.config.general.detectVersion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
||||
if (ffStrbufEqualS(processName, "com.termux")) {
|
||||
|
||||
@@ -30,3 +30,6 @@ typedef struct FFTerminalResult {
|
||||
|
||||
const FFShellResult* ffDetectShell();
|
||||
const FFTerminalResult* ffDetectTerminal();
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version);
|
||||
bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* version);
|
||||
|
||||
@@ -280,14 +280,7 @@ static void getUserShellFromEnv(FFShellResult* result) {
|
||||
}
|
||||
}
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version);
|
||||
|
||||
bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* version);
|
||||
|
||||
static void setShellInfoDetails(FFShellResult* result) {
|
||||
ffStrbufClear(&result->version);
|
||||
fftsGetShellVersion(result->exePath.length > 0 ? &result->exePath : &result->exe, result->exeName, &result->version);
|
||||
|
||||
if (ffStrbufEqualS(&result->processName, "pwsh")) {
|
||||
ffStrbufInitStatic(&result->prettyName, "PowerShell");
|
||||
} else if (ffStrbufEqualS(&result->processName, "nu")) {
|
||||
@@ -369,8 +362,6 @@ static void setTerminalInfoDetails(FFTerminalResult* result) {
|
||||
} else {
|
||||
ffStrbufInitCopy(&result->prettyName, &result->processName);
|
||||
}
|
||||
|
||||
fftsGetTerminalVersion(&result->processName, result->exePath.length > 0 ? &result->exePath : &result->exe, &result->version);
|
||||
}
|
||||
|
||||
#if defined(MAXPATH)
|
||||
@@ -408,7 +399,13 @@ const FFShellResult* ffDetectShell() {
|
||||
|
||||
ppid = getShellInfo(&result, ppid);
|
||||
getUserShellFromEnv(&result);
|
||||
setShellInfoDetails(&result);
|
||||
|
||||
if (result.processName.length > 0) {
|
||||
setShellInfoDetails(&result);
|
||||
if (instance.config.general.detectVersion) {
|
||||
fftsGetShellVersion(result.exePath.length > 0 ? &result.exePath : &result.exe, result.exeName, &result.version);
|
||||
}
|
||||
}
|
||||
|
||||
return &result;
|
||||
}
|
||||
@@ -436,7 +433,13 @@ const FFTerminalResult* ffDetectTerminal() {
|
||||
ppid = getTerminalInfo(&result, ppid);
|
||||
}
|
||||
getTerminalFromEnv(&result);
|
||||
setTerminalInfoDetails(&result);
|
||||
|
||||
if (result.processName.length > 0) {
|
||||
setTerminalInfoDetails(&result);
|
||||
if (instance.config.general.detectVersion) {
|
||||
fftsGetTerminalVersion(&result.processName, result.exePath.length > 0 ? &result.exePath : &result.exe, &result.version);
|
||||
}
|
||||
}
|
||||
|
||||
return &result;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
#include <winternl.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version);
|
||||
|
||||
static uint32_t getShellInfo(FFShellResult* result, uint32_t pid) {
|
||||
uint32_t ppid = 0;
|
||||
bool gui = false;
|
||||
@@ -292,8 +290,6 @@ static void setTerminalInfoDetails(FFTerminalResult* result) {
|
||||
}
|
||||
}
|
||||
|
||||
bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* version);
|
||||
|
||||
const FFShellResult* ffDetectShell(void) {
|
||||
static FFShellResult result;
|
||||
static bool init = false;
|
||||
@@ -332,7 +328,9 @@ const FFShellResult* ffDetectShell(void) {
|
||||
if (ext) {
|
||||
*ext = '\0';
|
||||
}
|
||||
fftsGetShellVersion(result.exePath.length > 0 ? &result.exePath : &result.exe, tmp, &result.version);
|
||||
if (instance.config.general.detectVersion) {
|
||||
fftsGetShellVersion(result.exePath.length > 0 ? &result.exePath : &result.exe, tmp, &result.version);
|
||||
}
|
||||
}
|
||||
|
||||
return &result;
|
||||
@@ -370,7 +368,9 @@ const FFTerminalResult* ffDetectTerminal(void) {
|
||||
|
||||
if (result.processName.length > 0) {
|
||||
setTerminalInfoDetails(&result);
|
||||
fftsGetTerminalVersion(&result.processName, result.exePath.length > 0 ? &result.exePath : &result.exe, &result.version);
|
||||
if (instance.config.general.detectVersion) {
|
||||
fftsGetTerminalVersion(&result.processName, result.exePath.length > 0 ? &result.exePath : &result.exe, &result.version);
|
||||
}
|
||||
}
|
||||
|
||||
return &result;
|
||||
|
||||
Reference in New Issue
Block a user