From f05d036023dd6ba00155ba9325c8d3ab22e0e2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 15 Oct 2022 01:02:16 +0800 Subject: [PATCH 1/3] README: update description on different platforms --- README.md | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b5282ea46..76e026e01 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Fastfetch -Fastfetch is a [neofetch](https://github.com/dylanaraps/neofetch)-like tool for fetching system information and displaying them in a pretty way. It is written in pure c, with performance and customizability in mind. Currently Linux, Android, BSD, MacOS and Windows on [MSYS2](https://www.msys2.org/) are supported. +Fastfetch is a [neofetch](https://github.com/dylanaraps/neofetch)-like tool for fetching system information and displaying them in a pretty way. It is written in pure c, with performance and customizability in mind. Currently Linux, Android, BSD, MacOS and Windows are supported. @@ -21,10 +21,13 @@ There are some premade config files in [`presets`](presets), including the ones ## Dependencies -Fastfetch dynamically loads needed libraries if they are available. Therefore its only hard dependencies are `libc` (any implementation of the c standard library), `libdl`. They are all shipped with [`glibc`](https://www.gnu.org/software/libc/), which is already installed on most linux distributions, so you probably don't have to worry about it. +Fastfetch dynamically loads needed libraries if they are available. On Linux, its only hard dependencies are `libc` (any implementation of the c standard library), `libdl` and [`libpthread`](https://man7.org/linux/man-pages/man7/pthreads.7.html) (if built with multithreading support). They are all shipped with [`glibc`](https://www.gnu.org/software/libc/), which is already installed on most linux distributions. + The following libraries are used if present at runtime: -* [`libpthread`](https://man7.org/linux/man-pages/man7/pthreads.7.html): For multithreading support, which may improve performance + +### Linux and BSD + * [`libpci`](https://github.com/pciutils/pciutils): GPU output. * [`libvulkan`](https://www.vulkan.org/): Vulkan module & fallback for GPU output. * [`libxcb-randr`](https://xcb.freedesktop.org/), @@ -46,7 +49,21 @@ The following libraries are used if present at runtime: * [`libsqlite3`](https://www.sqlite.org/index.html): Needed for pkg & rpm package count. * [`librpm`](http://rpm.org/): Slower fallback for rpm package count. Needed on openSUSE. * [`libcJSON`](https://github.com/DaveGamble/cJSON): Needed for Windows Terminal font ( Windows, WSL ). -* [`freetype`](https://www.freetype.org/): Needed for Termux font detection ( Android ). + +### macOS + +* [`MediaRemote`](https://iphonedev.wiki/index.php/MediaRemote.framework): Need for Media detection. It's a private framework provided by newer macOS system. +* [`libvulkan`](https://www.vulkan.org/): Vulkan module. To get it actually working, both loader (`vulkan-loader`) and driver (molten-vk) need to be installed. + +### Windows + +* [`libcJSON`](https://github.com/DaveGamble/cJSON): Used for Windows Terminal font detection. +* [`libvulkan`](https://www.vulkan.org/): Vulkan module. Usually has been provided by GPU drivers. +* [`libOpenCL`](https://www.khronos.org/opencl/): OpenCL module + +### Android + +* [`freetype`](https://www.freetype.org/): Used for Termux font detection. ## Support status All categories not listed here should work without needing a specific implementation. @@ -100,9 +117,7 @@ If pkg-config fails to find the headers for a library listed in [dependencies](# ### Building on Windows -Currently [MSYS2](https://www.msys2.org/) is required to build fastfetch. Running fastfetch requires msys2 runtime library (`msys-2.0.dll`) but not full MSYS2 environment. - -Full native Windows executable is planned. +Currently GCC or clang is required (MSVC is not supported). MSYS2 with CLANG64 sub system is suggested (and tested) to build fastfetch. ## Packaging From a99ca9a1a1c74b91c59cb8d6362b27a18eecff2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 15 Oct 2022 01:02:46 +0800 Subject: [PATCH 2/3] macOS: remove unneeded dependencies --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f4526855..1687f162c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -508,7 +508,6 @@ if(APPLE) target_link_libraries(libfastfetch PRIVATE "-framework CoreFoundation" PRIVATE "-framework IOKit" - PRIVATE "-framework CoreGraphics" PRIVATE "-framework OpenGL" PRIVATE "-framework OpenCL" PRIVATE "-framework Cocoa" From b042b90d9ba49c6feeded008d5c3141bb80567fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 15 Oct 2022 11:36:24 +0800 Subject: [PATCH 3/3] TerminalShell: improve shell detection on Windows --- .../terminalshell/terminalshell_windows.cpp | 78 ++++++++++++------- src/util/FFstrbuf.h | 14 +++- 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/src/detection/terminalshell/terminalshell_windows.cpp b/src/detection/terminalshell/terminalshell_windows.cpp index a6d02c612..cd904f97e 100644 --- a/src/detection/terminalshell/terminalshell_windows.cpp +++ b/src/detection/terminalshell/terminalshell_windows.cpp @@ -18,13 +18,16 @@ struct ProcessInfo static bool getProcessInfo(uint32_t pid, uint32_t* ppid, FFstrbuf* pname, FFstrbuf* exe) { wchar_t query[256] = {}; - swprintf(query, 256, L"SELECT Name, ParentProcessId, ExecutablePath FROM Win32_Process WHERE ProcessId = %" PRIu32, pid); + swprintf(query, 256, L"SELECT %ls %ls ParentProcessId FROM Win32_Process WHERE ProcessId = %" PRIu32, + pname ? L"Name," : L"", + pname ? L"ExecutablePath," : L"", + pid); IEnumWbemClassObject* pEnumerator = ffQueryWmi(query, nullptr); if(!pEnumerator) return false; - IWbemClassObject *pclsObj = NULL; + IWbemClassObject *pclsObj = nullptr; ULONG uReturn = 0; if(FAILED(pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn)) || uReturn == 0) @@ -65,20 +68,39 @@ static uint32_t getShellInfo(FFTerminalShellResult* result, uint32_t pid) if(ffStrbufEndsWithIgnCaseS(&result->shellPrettyName, ".exe")) ffStrbufSubstrBefore(&result->shellPrettyName, result->shellPrettyName.length - 4); + //Common programs that are between terminal and own process, but are not the shell + if( + ffStrbufIgnCaseEqualS(&result->shellPrettyName, "sudo") || + ffStrbufIgnCaseEqualS(&result->shellPrettyName, "su") || + ffStrbufIgnCaseEqualS(&result->shellPrettyName, "doas") || + ffStrbufIgnCaseEqualS(&result->shellPrettyName, "strace") || + ffStrbufIgnCaseEqualS(&result->shellPrettyName, "sshd") || + ffStrbufIgnCaseEqualS(&result->shellPrettyName, "gdb") || + ffStrbufIgnCaseEqualS(&result->shellPrettyName, "lldb") || + ffStrbufIgnCaseEqualS(&result->shellPrettyName, "guake-wrapped") || + ffStrbufContainIgnCaseS(&result->shellPrettyName, "debug") + ) { + ffStrbufClear(&result->shellProcessName); + ffStrbufClear(&result->shellPrettyName); + ffStrbufClear(&result->shellExe); + result->shellExeName = nullptr; + return getShellInfo(result, ppid); + } + ffStrbufClear(&result->shellVersion); fftsGetShellVersion(&result->shellExe, result->shellPrettyName.chars, &result->shellVersion); - if(ffStrbufIgnCaseCompS(&result->shellPrettyName, "pwsh") == 0) + if(ffStrbufIgnCaseEqualS(&result->shellPrettyName, "pwsh")) ffStrbufSetS(&result->shellPrettyName, "PowerShell"); - else if(ffStrbufIgnCaseCompS(&result->shellPrettyName, "powershell") == 0) + else if(ffStrbufIgnCaseEqualS(&result->shellPrettyName, "powershell")) ffStrbufSetS(&result->shellPrettyName, "Windows PowerShell"); - else if(ffStrbufIgnCaseCompS(&result->shellPrettyName, "powershell_ise") == 0) + else if(ffStrbufIgnCaseEqualS(&result->shellPrettyName, "powershell_ise")) ffStrbufSetS(&result->shellPrettyName, "Windows PowerShell ISE"); - else if(ffStrbufIgnCaseCompS(&result->shellPrettyName, "cmd") == 0) + else if(ffStrbufIgnCaseEqualS(&result->shellPrettyName, "cmd")) ffStrbufSetS(&result->shellPrettyName, "Command Prompt"); - else if(ffStrbufIgnCaseCompS(&result->shellPrettyName, "nu") == 0) + else if(ffStrbufIgnCaseEqualS(&result->shellPrettyName, "nu")) ffStrbufSetS(&result->shellPrettyName, "nushell"); - else if(ffStrbufIgnCaseCompS(&result->terminalPrettyName, "explorer") == 0) + else if(ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "explorer")) { ffStrbufSetS(&result->terminalPrettyName, "Windows Explorer"); // Started without shell return 0; @@ -100,28 +122,30 @@ static uint32_t getTerminalInfo(FFTerminalShellResult* result, uint32_t pid) ffStrbufSubstrBefore(&result->terminalPrettyName, result->terminalPrettyName.length - 4); if( - ffStrbufIgnCaseCompS(&result->terminalPrettyName, "pwsh") == 0 || - ffStrbufIgnCaseCompS(&result->terminalPrettyName, "cmd") == 0 || - ffStrbufIgnCaseCompS(&result->terminalPrettyName, "bash") == 0 || - ffStrbufIgnCaseCompS(&result->terminalPrettyName, "zsh") == 0 || - ffStrbufIgnCaseCompS(&result->terminalPrettyName, "fish") == 0 || - ffStrbufIgnCaseCompS(&result->terminalPrettyName, "nu") == 0 || - ffStrbufIgnCaseCompS(&result->terminalPrettyName, "powershell") == 0 || - ffStrbufIgnCaseCompS(&result->terminalPrettyName, "powershell_ise") == 0 + ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "pwsh") || + ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "cmd") || + ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "bash") || + ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "zsh") || + ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "fish") || + ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "nu") || + ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "powershell") || + ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "powershell_ise") ) { //We are nested shell ffStrbufClear(&result->terminalProcessName); ffStrbufClear(&result->terminalPrettyName); ffStrbufClear(&result->terminalExe); - result->terminalExeName = NULL; + result->terminalExeName = nullptr; return getTerminalInfo(result, ppid); } - if(ffStrbufIgnCaseCompS(&result->terminalPrettyName, "WindowsTerminal") == 0) + if(ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "WindowsTerminal")) ffStrbufSetS(&result->terminalPrettyName, "Windows Terminal"); - else if(ffStrbufIgnCaseCompS(&result->terminalPrettyName, "conhost") == 0) + else if(ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "conhost")) ffStrbufSetS(&result->terminalPrettyName, "Console Window Host"); - else if(ffStrbufIgnCaseCompS(&result->terminalPrettyName, "explorer") == 0) + else if(ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "Code")) + ffStrbufSetS(&result->terminalPrettyName, "Visual Studio Code"); + else if(ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "explorer")) ffStrbufSetS(&result->terminalPrettyName, "Windows Explorer"); return ppid; @@ -139,23 +163,23 @@ static void getTerminalFromEnv(FFTerminalShellResult* result) ffStrbufIgnCaseCompS(&result->terminalProcessName, "0") != 0 ) return; - const char* term = NULL; + const char* term = nullptr; //SSH - if(getenv("SSH_CONNECTION") != NULL) + if(getenv("SSH_CONNECTION") != nullptr) term = getenv("SSH_TTY"); //Windows Terminal if(!term && ( - getenv("WT_SESSION") != NULL || - getenv("WT_PROFILE_ID") != NULL + getenv("WT_SESSION") != nullptr || + getenv("WT_PROFILE_ID") != nullptr )) term = "Windows Terminal"; //Alacritty if(!term && ( - getenv("ALACRITTY_SOCKET") != NULL || - getenv("ALACRITTY_LOG") != NULL || - getenv("ALACRITTY_WINDOW_ID") != NULL + getenv("ALACRITTY_SOCKET") != nullptr || + getenv("ALACRITTY_LOG") != nullptr || + getenv("ALACRITTY_WINDOW_ID") != nullptr )) term = "Alacritty"; //Normal Terminal diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index cfe6449d4..11ce0518b 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -147,7 +147,7 @@ static inline int ffStrbufComp(const FFstrbuf* strbuf, const FFstrbuf* comp) return memcmp(strbuf->chars, comp->chars, length + 1); } -static inline FF_C_NODISCARD int ffStrbufEqual(const FFstrbuf* strbuf, const FFstrbuf* comp) +static inline FF_C_NODISCARD bool ffStrbufEqual(const FFstrbuf* strbuf, const FFstrbuf* comp) { return ffStrbufComp(strbuf, comp) == 0; } @@ -157,7 +157,7 @@ static inline FF_C_NODISCARD int ffStrbufCompS(const FFstrbuf* strbuf, const cha return strcmp(strbuf->chars, comp); } -static inline FF_C_NODISCARD int ffStrbufEqualS(const FFstrbuf* strbuf, const char* comp) +static inline FF_C_NODISCARD bool ffStrbufEqualS(const FFstrbuf* strbuf, const char* comp) { return ffStrbufCompS(strbuf, comp) == 0; } @@ -167,11 +167,21 @@ static inline FF_C_NODISCARD int ffStrbufIgnCaseCompS(const FFstrbuf* strbuf, co return strcasecmp(strbuf->chars, comp); } +static inline FF_C_NODISCARD bool ffStrbufIgnCaseEqualS(const FFstrbuf* strbuf, const char* comp) +{ + return ffStrbufIgnCaseCompS(strbuf, comp) == 0; +} + static inline FF_C_NODISCARD int ffStrbufIgnCaseComp(const FFstrbuf* strbuf, const FFstrbuf* comp) { return ffStrbufIgnCaseCompS(strbuf, comp->chars); } +static inline FF_C_NODISCARD bool ffStrbufIgnCaseEqual(const FFstrbuf* strbuf, const FFstrbuf* comp) +{ + return ffStrbufIgnCaseComp(strbuf, comp) == 0; +} + static inline FF_C_NODISCARD bool ffStrbufContainS(const FFstrbuf* strbuf, const char* str) { return strstr(strbuf->chars, str) != NULL;