mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 09:33:39 +01:00
Merge branch 'dev' of github.com:LinusDierheimer/fastfetch into dev
This commit is contained in:
@@ -6,8 +6,11 @@
|
||||
#include <sys/fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
const char* ffDetectBatteryImpl(FF_UNUSED_PARAM FFinstance* instance, FFlist* results)
|
||||
const char* ffDetectBatteryImpl(FF_MAYBE_UNUSED FFinstance* instance, FFlist* results)
|
||||
{
|
||||
//https://www.freebsd.org/cgi/man.cgi?acpi_battery(4)
|
||||
//https://gitlab.xfce.org/panel-plugins/xfce4-battery-plugin/-/blob/master/panel-plugin/libacpi.c
|
||||
|
||||
int acpifd = open("/dev/acpi", O_RDONLY);
|
||||
if(acpifd < 0)
|
||||
return "open(\"/dev/acpi\", O_RDONLY) failed";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
const char* ffDetectBrightness(FF_UNUSED_PARAM FFlist* result)
|
||||
const char* ffDetectBrightness(FF_MAYBE_UNUSED FFlist* result)
|
||||
{
|
||||
//https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-backlight
|
||||
const char* backlightDirPath = "/sys/class/backlight/";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "brightness.h"
|
||||
|
||||
const char* ffDetectBrightness(FF_UNUSED_PARAM FFlist* result)
|
||||
const char* ffDetectBrightness(FF_MAYBE_UNUSED FFlist* result)
|
||||
{
|
||||
return "Not supported on this platform";
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ static void detectAlacritty(const FFinstance* instance, FFTerminalFontResult* te
|
||||
ffStrbufDestroy(&fontSize);
|
||||
}
|
||||
|
||||
static void detectTTY(FFTerminalFontResult* terminalFont)
|
||||
FF_MAYBE_UNUSED static void detectTTY(FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FFstrbuf fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
@@ -291,7 +291,7 @@ static void detectFromWindowsTeriminal(const FFinstance* instance, const FFstrbu
|
||||
#endif
|
||||
#endif //defined(_WIN32) || defined(__linux__)
|
||||
|
||||
static bool detectKitty(const FFinstance* instance, FFTerminalFontResult* result)
|
||||
FF_MAYBE_UNUSED static bool detectKitty(const FFinstance* instance, FFTerminalFontResult* result)
|
||||
{
|
||||
FFstrbuf fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
@@ -320,21 +320,54 @@ static bool detectKitty(const FFinstance* instance, FFTerminalFontResult* result
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool detectWezterm(FF_MAYBE_UNUSED const FFinstance* instance, FFTerminalFontResult* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
|
||||
ffStrbufSetS(&result->error, ffProcessAppendStdOut(&fontName, (char* const[]){
|
||||
"wezterm",
|
||||
"ls-fonts",
|
||||
"--text",
|
||||
"a",
|
||||
NULL
|
||||
}));
|
||||
if(result->error.length)
|
||||
return false;
|
||||
|
||||
//LeftToRight
|
||||
// 0 a \u{61} x_adv=7 cells=1 glyph=a,180 wezterm.font("JetBrains Mono", {weight="Regular", stretch="Normal", style="Normal"})
|
||||
// <built-in>, BuiltIn
|
||||
ffStrbufSubstrAfterFirstC(&fontName, '"');
|
||||
ffStrbufSubstrBeforeFirstC(&fontName, '"');
|
||||
|
||||
if(!fontName.length)
|
||||
return false;
|
||||
|
||||
ffFontInitCopy(&result->font, fontName.chars);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffDetectTerminalFontPlatform(const FFinstance* instance, const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont);
|
||||
|
||||
static bool detectTerminalFontCommon(const FFinstance* instance, const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "alacritty") == 0)
|
||||
if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalProcessName, "alacritty"))
|
||||
detectAlacritty(instance, terminalFont);
|
||||
else if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "kitty") == 0)
|
||||
else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalProcessName, "wezterm-gui"))
|
||||
detectWezterm(instance, terminalFont);
|
||||
|
||||
#ifndef _WIN32
|
||||
else if(ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "kitty"))
|
||||
detectKitty(instance, terminalFont);
|
||||
else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalExe, "/dev/tty"))
|
||||
detectTTY(terminalFont);
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(__linux__)
|
||||
//Used by both Linux (WSL) and Windows
|
||||
else if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "Windows Terminal") == 0 ||
|
||||
ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "WindowsTerminal.exe") == 0)
|
||||
else if(ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "Windows Terminal") ||
|
||||
ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "WindowsTerminal.exe"))
|
||||
detectFromWindowsTeriminal(instance, &terminalShell->terminalExe, terminalFont);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/io.h"
|
||||
#include "common/processing.h"
|
||||
#include "common/properties.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -36,122 +38,252 @@ static bool getFileVersion(const char* exePath, FFstrbuf* version)
|
||||
|
||||
#endif
|
||||
|
||||
static void getShellVersionBash(FFstrbuf* exe, FFstrbuf* version)
|
||||
static bool getExeVersionRaw(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
return ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
}); // GNU bash, version 5.1.16(1)-release (x86_64-pc-msys)\nCopyright...
|
||||
}) == NULL;
|
||||
}
|
||||
|
||||
static bool getExeVersionGeneral(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
if(!getExeVersionRaw(exe, version))
|
||||
return false;
|
||||
|
||||
ffStrbufSubstrAfterFirstC(version, ' ');
|
||||
ffStrbufSubstrBeforeFirstC(version, ' ');
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool getShellVersionBash(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
if(!getExeVersionRaw(exe, version))
|
||||
return false;
|
||||
|
||||
// GNU bash, version 5.1.16(1)-release (x86_64-pc-msys)\nCopyright...
|
||||
ffStrbufSubstrBeforeFirstC(version, '\n'); // GNU bash, version 5.1.16(1)-release (x86_64-pc-msys)
|
||||
ffStrbufSubstrBeforeLastC(version, ' '); // GNU bash, version 5.1.16(1)-release
|
||||
ffStrbufSubstrAfterLastC(version, ' '); // 5.1.16(1)-release
|
||||
ffStrbufSubstrBeforeFirstC(version, '('); // 5.1.16
|
||||
return true;
|
||||
}
|
||||
|
||||
static void getShellVersionZsh(FFstrbuf* exe, FFstrbuf* version)
|
||||
static bool getShellVersionFish(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
});
|
||||
ffStrbufSubstrBeforeLastC(version, ' ');
|
||||
ffStrbufSubstrAfterFirstC(version, ' ');
|
||||
}
|
||||
if(!getExeVersionRaw(exe, version))
|
||||
return false;
|
||||
|
||||
static void getShellVersionFish(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
});
|
||||
//fish, version 3.6.0
|
||||
ffStrbufTrimRight(version, '\n');
|
||||
ffStrbufSubstrAfterLastC(version, ' ');
|
||||
return true;
|
||||
}
|
||||
|
||||
static void getShellVersionTcsh(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
}); // tcsh 6.24.01 (Astron) 2022-05-12 (aarch64-apple-darwin) options wide,nls,dl,al,kan,sm,rh,color,filec
|
||||
ffStrbufSubstrAfterFirstC(version, ' '); // 6.24.01 (Astron) 2022-05-12 (aarch64-apple-darwin) options wide,nls,dl,al,kan,sm,rh,color,filec
|
||||
ffStrbufSubstrBeforeFirstC(version, ' '); // 6.24.01
|
||||
}
|
||||
|
||||
static void getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version)
|
||||
static bool getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if(getFileVersion(exe->chars, version))
|
||||
return;
|
||||
{
|
||||
ffStrbufSubstrBeforeLastC(version, '.');
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
});
|
||||
if(!getExeVersionRaw(exe, version))
|
||||
return false;
|
||||
|
||||
ffStrbufTrimRight(version, '\n');
|
||||
ffStrbufSubstrAfterLastC(version, ' ');
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
static void getShellVersionWinPowerShell(FFstrbuf* exe, FFstrbuf* version)
|
||||
static bool getShellVersionWinPowerShell(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
if(ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"-NoLogo",
|
||||
"-NoProfile",
|
||||
"-Command",
|
||||
"$PSVersionTable.PSVersion.ToString()",
|
||||
NULL
|
||||
});
|
||||
})) return false;
|
||||
|
||||
ffStrbufTrimRight(version, '\n');
|
||||
ffStrbufSubstrAfterLastC(version, ' ');
|
||||
return true;
|
||||
}
|
||||
|
||||
static void getShellVersionCmd(FFstrbuf* exe, FFstrbuf* version)
|
||||
static bool getShellVersionCmd(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
getFileVersion(exe->chars, version);
|
||||
return getFileVersion(exe->chars, version);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void getShellVersionNu(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
});
|
||||
}
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version)
|
||||
{
|
||||
bool ok = true;
|
||||
if(strcasecmp(exeName, "bash") == 0 || strcasecmp(exeName, "sh") == 0)
|
||||
getShellVersionBash(exe, version);
|
||||
else if(strcasecmp(exeName, "zsh") == 0)
|
||||
getShellVersionZsh(exe, version);
|
||||
else if(strcasecmp(exeName, "fish") == 0)
|
||||
getShellVersionFish(exe, version);
|
||||
else if(strcasecmp(exeName, "pwsh") == 0)
|
||||
getShellVersionPwsh(exe, version);
|
||||
else if(strcasecmp(exeName, "csh") == 0 || strcasecmp(exeName, "tcsh") == 0)
|
||||
getShellVersionTcsh(exe, version);
|
||||
else if(strcasecmp(exeName, "nu") == 0)
|
||||
getShellVersionNu(exe, version);
|
||||
return getShellVersionBash(exe, version);
|
||||
if(strcasecmp(exeName, "zsh") == 0)
|
||||
return getExeVersionGeneral(exe, version); //zsh 5.9 (arm-apple-darwin21.3.0)
|
||||
if(strcasecmp(exeName, "fish") == 0)
|
||||
return getShellVersionFish(exe, version);
|
||||
if(strcasecmp(exeName, "pwsh") == 0)
|
||||
return getShellVersionPwsh(exe, version);
|
||||
if(strcasecmp(exeName, "csh") == 0 || strcasecmp(exeName, "tcsh") == 0)
|
||||
return getExeVersionGeneral(exe, version); //tcsh 6.24.07 (Astron) 2022-12-21 (aarch64-apple-darwin) options wide,nls,dl,al,kan,sm,rh,color,filec
|
||||
if(strcasecmp(exeName, "nu") == 0)
|
||||
return getExeVersionRaw(exe, version); //0.73.0
|
||||
|
||||
#ifdef _WIN32
|
||||
else if(strcasecmp(exeName, "powershell") == 0 || strcasecmp(exeName, "powershell_ise") == 0)
|
||||
getShellVersionWinPowerShell(exe, version);
|
||||
else if(strcasecmp(exeName, "cmd") == 0)
|
||||
getShellVersionCmd(exe, version);
|
||||
if(strcasecmp(exeName, "powershell") == 0 || strcasecmp(exeName, "powershell_ise") == 0)
|
||||
return getShellVersionWinPowerShell(exe, version);
|
||||
if(strcasecmp(exeName, "cmd") == 0)
|
||||
return getShellVersionCmd(exe, version);
|
||||
#endif
|
||||
|
||||
else
|
||||
ok = false;
|
||||
return ok;
|
||||
return false;
|
||||
}
|
||||
|
||||
FF_MAYBE_UNUSED static bool getTerminalVersionTermux(FFstrbuf* version)
|
||||
{
|
||||
ffStrbufSetS(version, getenv("TERMUX_VERSION"));
|
||||
return version->length > 0;
|
||||
}
|
||||
|
||||
FF_MAYBE_UNUSED static bool getTerminalVersionGnome(FFstrbuf* version)
|
||||
{
|
||||
if(ffProcessAppendStdOut(version, (char* const[]){
|
||||
"gnome-terminal",
|
||||
"--version",
|
||||
NULL
|
||||
})) return false;
|
||||
|
||||
//# GNOME Terminal 3.46.7 using VTE 0.70.2 +BIDI +GNUTLS +ICU +SYSTEMD
|
||||
ffStrbufSubstrAfterFirstS(version, "Terminal ");
|
||||
ffStrbufSubstrBeforeFirstC(version, ' ');
|
||||
return true;
|
||||
}
|
||||
|
||||
FF_MAYBE_UNUSED static bool getTerminalVersionKonsole(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
const char* konsoleVersion = getenv("KONSOLE_VERSION");
|
||||
if(konsoleVersion)
|
||||
{
|
||||
//221201
|
||||
long major = strtol(konsoleVersion, NULL, 10);
|
||||
if (major >= 0)
|
||||
{
|
||||
long patch = major % 100;
|
||||
major /= 100;
|
||||
long minor = major % 100;
|
||||
major /= 100;
|
||||
ffStrbufSetF(version, "%ld.%ld.%ld", major, minor, patch);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return getExeVersionGeneral(exe, version);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
static bool getTerminalVersionWindowsTerminal(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY buildInfoPath;
|
||||
ffStrbufInitNS(&buildInfoPath, ffStrbufLastIndexC(exe, '\\') + 1, exe->chars);
|
||||
ffStrbufAppendS(&buildInfoPath, "BuildInfo.xml");
|
||||
|
||||
if(ffParsePropFile(buildInfoPath.chars, "StoreVersion=\"", version))
|
||||
{
|
||||
ffStrbufTrimRight(version, '"');
|
||||
return true;
|
||||
}
|
||||
|
||||
return getFileVersion(exe->chars, version);
|
||||
}
|
||||
|
||||
static bool getTerminalVersionConEmu(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffStrbufSetS(version, getenv("ConEmuBuild"));
|
||||
|
||||
if(version->length)
|
||||
return true;
|
||||
|
||||
return getFileVersion(exe->chars, version);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
|
||||
if(ffStrbufEqualS(processName, "Termux"))
|
||||
return getTerminalVersionTermux(version);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(processName, "gnome-terminal-"))
|
||||
return getTerminalVersionGnome(version);
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(processName, "konsole"))
|
||||
return getTerminalVersionKonsole(exe, version);
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(processName, "xfce4-terminal"))
|
||||
return getExeVersionGeneral(exe, version);//xfce4-terminal 1.0.4 (Xfce 4.18)...
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(processName, "deepin-terminal"))
|
||||
return getExeVersionGeneral(exe, version);//deepin-terminal 5.4.36
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(processName, "WindowsTerminal.exe"))
|
||||
return getTerminalVersionWindowsTerminal(exe, version);
|
||||
|
||||
if(ffStrbufStartsWithIgnCaseS(processName, "ConEmuC"))
|
||||
return getTerminalVersionConEmu(exe, version);
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(processName, "kitty"))
|
||||
return getExeVersionGeneral(exe, version); //kitty 0.21.2 created by Kovid Goyal
|
||||
|
||||
#endif
|
||||
|
||||
if(ffStrbufStartsWithIgnCaseS(processName, "alacritty"))
|
||||
return getExeVersionGeneral(exe, 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);
|
||||
|
||||
#else
|
||||
|
||||
return false;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -350,12 +352,17 @@ const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
|
||||
|
||||
getTerminalFromEnv(&result);
|
||||
getUserShellFromEnv(instance, &result);
|
||||
getShellVersion(&result.shellExe, result.shellExeName, &result.shellVersion);
|
||||
|
||||
if(strcasecmp(result.shellExeName, result.userShellExeName) != 0)
|
||||
getShellVersion(&result.userShellExe, result.userShellExeName, &result.userShellVersion);
|
||||
else
|
||||
ffStrbufSet(&result.userShellVersion, &result.shellVersion);
|
||||
ffStrbufClear(&result.shellVersion);
|
||||
if(instance->config.shellVersion)
|
||||
{
|
||||
getShellVersion(&result.shellExe, result.shellExeName, &result.shellVersion);
|
||||
|
||||
if(strcasecmp(result.shellExeName, result.userShellExeName) != 0)
|
||||
getShellVersion(&result.userShellExe, result.userShellExeName, &result.userShellVersion);
|
||||
else
|
||||
ffStrbufSet(&result.userShellVersion, &result.shellVersion);
|
||||
}
|
||||
|
||||
if(ffStrbufEqualS(&result.shellProcessName, "pwsh"))
|
||||
ffStrbufInitS(&result.shellPrettyName, "PowerShell");
|
||||
@@ -373,11 +380,18 @@ const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
|
||||
ffStrbufInitS(&result.terminalPrettyName, "Apple Terminal");
|
||||
else if(ffStrbufEqualS(&result.terminalProcessName, "WarpTerminal"))
|
||||
ffStrbufInitS(&result.terminalPrettyName, "Warp");
|
||||
else if(ffStrbufEqualS(&result.terminalProcessName, "wezterm-gui"))
|
||||
ffStrbufInitS(&result.terminalPrettyName, "WezTerm");
|
||||
else if(strncmp(result.terminalExeName, result.terminalProcessName.chars, result.terminalProcessName.length) == 0) // if exeName starts with processName, print it. Otherwise print processName
|
||||
ffStrbufInitS(&result.terminalPrettyName, result.terminalExeName);
|
||||
else
|
||||
ffStrbufInitCopy(&result.terminalPrettyName, &result.terminalProcessName);
|
||||
|
||||
ffStrbufInit(&result.terminalVersion);
|
||||
|
||||
if(instance->config.terminalVersion)
|
||||
fftsGetTerminalVersion(&result.terminalProcessName, &result.terminalExe, &result.terminalVersion);
|
||||
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ static bool getProcessInfo(uint32_t pid, uint32_t* ppid, FFstrbuf* pname, FFstrb
|
||||
|
||||
extern "C" bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version);
|
||||
|
||||
static uint32_t getShellInfo(FFTerminalShellResult* result, uint32_t pid)
|
||||
static uint32_t getShellInfo(const FFinstance* instance, FFTerminalShellResult* result, uint32_t pid)
|
||||
{
|
||||
uint32_t ppid;
|
||||
|
||||
@@ -128,11 +128,12 @@ static uint32_t getShellInfo(FFTerminalShellResult* result, uint32_t pid)
|
||||
ffStrbufClear(&result->shellPrettyName);
|
||||
ffStrbufClear(&result->shellExe);
|
||||
result->shellExeName = nullptr;
|
||||
return getShellInfo(result, ppid);
|
||||
return getShellInfo(instance, result, ppid);
|
||||
}
|
||||
|
||||
ffStrbufClear(&result->shellVersion);
|
||||
fftsGetShellVersion(&result->shellExe, result->shellPrettyName.chars, &result->shellVersion);
|
||||
if(instance->config.shellVersion)
|
||||
fftsGetShellVersion(&result->shellExe, result->shellPrettyName.chars, &result->shellVersion);
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(&result->shellPrettyName, "pwsh"))
|
||||
ffStrbufSetS(&result->shellPrettyName, "PowerShell");
|
||||
@@ -175,7 +176,7 @@ static uint32_t getShellInfo(FFTerminalShellResult* result, uint32_t pid)
|
||||
return ppid;
|
||||
}
|
||||
|
||||
static uint32_t getTerminalInfo(FFTerminalShellResult* result, uint32_t pid)
|
||||
static uint32_t getTerminalInfo(const FFinstance* instance, FFTerminalShellResult* result, uint32_t pid)
|
||||
{
|
||||
uint32_t ppid;
|
||||
|
||||
@@ -201,7 +202,7 @@ static uint32_t getTerminalInfo(FFTerminalShellResult* result, uint32_t pid)
|
||||
ffStrbufClear(&result->terminalPrettyName);
|
||||
ffStrbufClear(&result->terminalExe);
|
||||
result->terminalExeName = "";
|
||||
return getTerminalInfo(result, ppid);
|
||||
return getTerminalInfo(instance, result, ppid);
|
||||
}
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "WindowsTerminal"))
|
||||
@@ -217,6 +218,8 @@ static uint32_t getTerminalInfo(FFTerminalShellResult* result, uint32_t pid)
|
||||
ffStrbufSetS(&result->terminalPrettyName, "Windows Explorer");
|
||||
else if(ffStrbufStartsWithIgnCaseS(&result->terminalPrettyName, "ConEmuC"))
|
||||
ffStrbufSetS(&result->terminalPrettyName, "ConEmu");
|
||||
else if(ffStrbufEqualS(&result->terminalPrettyName, "wezterm-gui"))
|
||||
ffStrbufInitS(&result->terminalPrettyName, "WezTerm");
|
||||
|
||||
return ppid;
|
||||
}
|
||||
@@ -263,6 +266,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);
|
||||
@@ -297,11 +302,15 @@ const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
|
||||
if(!getProcessInfo(0, &ppid, nullptr, nullptr, nullptr))
|
||||
goto exit;
|
||||
|
||||
ppid = getShellInfo(&result, ppid);
|
||||
getTerminalInfo(&result, ppid);
|
||||
ppid = getShellInfo(instance, &result, ppid);
|
||||
getTerminalInfo(instance, &result, ppid);
|
||||
if(result.terminalProcessName.length == 0)
|
||||
getTerminalFromEnv(&result);
|
||||
|
||||
ffStrbufInit(&result.terminalVersion);
|
||||
if(instance->config.terminalVersion)
|
||||
fftsGetTerminalVersion(&result.terminalProcessName, &result.terminalExe, &result.terminalVersion);
|
||||
|
||||
exit:
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
|
||||
@@ -40,7 +40,7 @@ static void convertIfStateToString(WLAN_INTERFACE_STATE state, FFstrbuf* result)
|
||||
}
|
||||
}
|
||||
|
||||
const char* ffDetectWifi(FF_UNUSED_PARAM const FFinstance* instance, FFlist* result)
|
||||
const char* ffDetectWifi(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* result)
|
||||
{
|
||||
FF_LIBRARY_LOAD(wlanapi, NULL, "dlopen wlanapi"FF_LIBRARY_EXTENSION" failed", "wlanapi"FF_LIBRARY_EXTENSION, 1)
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(wlanapi, WlanOpenHandle)
|
||||
|
||||
Reference in New Issue
Block a user