diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 2a1749ce77..4fe8f12f78 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -7,23 +7,7 @@ assignees: '' --- -## Before requesting a new feature - -* A lot of features are not enabled by default. Please try `fastfetch --list-modules` and `fastfetch -c all.jsonc` to see if it has been supported -* Fastfetch supports `Command` module, which can be used to grab output from a custom shell script. Please check if it fits your needs - -```jsonc -// ~/.config/fastfetch/fastfetch.jsonc -{ - "modules": [ - { - "type": "command", - "text": "/path/to/your/script", - "key": "Feature Title" - } - ] -} -``` +Be sure to read [FAQ](https://github.com/fastfetch-cli/fastfetch?tab=readme-ov-file#faq) before submitting a new issue. ## Wanted features: diff --git a/.gitignore b/.gitignore index 9af64d1cdf..2d69a508fc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ cscope.* tags fastfetch.kdev4 *.user +*.user.* diff --git a/CHANGELOG.md b/CHANGELOG.md index f47a7e7c87..14bb7df1cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,32 @@ +# 2.14.0 + +Features: +* Support monochrome bar type (#960) +* Support editor version detection on Windows (Editor, Windows) +* Apply default color palettes in `--file` and `--data` (Logo) +* Print all presets in `--list-presets` for better Windows support (Windows) +* Support for guix package manager detection (Packages, Linux) +* Support named variable placeholders in custom module formattion string (#796) + * `--title-format '{user-name-colored}{at-symbol-colored}{host-name-colored}'` is equivalent to `--title-format '{6}{7}{8}'` +* Support named color placeholders in custom module formattion string + * `---format '{#red}'` is equivalent to `---format '{#31}'` + * `'{#red}'` or `'{#31}'` is preferred over `\u001b[31m` because is more readable and `--pipe` aware (will be ignored in pipe mode) + * Supported in `Custom` module too + * See `fastfetch -h format` for detail +* Add option `--color-separator` to set the color of key-value separators +* Support Guix package manager count (#792, Packages, Linux) +* Improve python based shell detection (#977, Shell, macOS) +* Print error reason when vulkan init fails (Vulkan) + +Bugfixes: +* Don't detect `.conf` files in `--list-config-paths` +* Don't try to detect terminals in MSYS shell with process backtracing (Windows) +* Fix `outputColor` doesn't work if module keys are disabled + +Logos: +* Add Cereus Linux +* Re-add special handling of Loc-OS + # 2.13.2 Another hotfix release :( diff --git a/CMakeLists.txt b/CMakeLists.txt index f16be755aa..cea375dfe4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url project(fastfetch - VERSION 2.13.2 + VERSION 2.14.0 LANGUAGES C DESCRIPTION "Fast neofetch-like system information tool" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch" @@ -14,9 +14,9 @@ set(PROJECT_LICENSE "MIT license") ################### if(ANDROID) set(LINUX FALSE) -elseif("${CMAKE_SYSTEM_NAME}" MATCHES ".*[Ll]inux.*") +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") set(LINUX TRUE CACHE BOOL "..." FORCE) # LINUX means GNU/Linux, not just the kernel -elseif("${CMAKE_SYSTEM_NAME}" MATCHES ".*[Bb][Ss][Dd].*") +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") set(BSD TRUE CACHE BOOL "..." FORCE) elseif(NOT APPLE AND NOT WIN32) message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}") @@ -77,6 +77,13 @@ option(BUILD_TESTS "Build tests" OFF) # Also create test executables option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds option(IS_MUSL "Build with musl libc" OFF) # Used by Github Actions +set(BINARY_LINK_TYPE_OPTIONS dlopen dynamic static) +set(BINARY_LINK_TYPE dlopen CACHE STRING "How to link fastfetch") +set_property(CACHE BINARY_LINK_TYPE PROPERTY STRINGS ${BINARY_LINK_TYPE_OPTIONS}) +if(NOT BINARY_LINK_TYPE IN_LIST BINARY_LINK_TYPE_OPTIONS) + message(FATAL_ERROR "BINARY_LINK_TYPE must be one of ${BINARY_LINK_TYPE_OPTIONS}") +endif() + if (LINUX) set(CUSTOM_PCI_IDS_PATH "" CACHE STRING "Custom path to file pci.ids, defaults to `/usr/share/hwdata/pci.ids`") set(CUSTOM_AMDGPU_IDS_PATH "" CACHE STRING "Custom path to file amdgpu.ids, defaults to `/usr/share/libdrm/amdgpu.ids`") @@ -336,6 +343,7 @@ set(LIBFASTFETCH_SRC src/modules/gpu/gpu.c src/modules/host/host.c src/modules/icons/icons.c + src/modules/initsystem/initsystem.c src/modules/gamepad/gamepad.c src/modules/kernel/kernel.c src/modules/lm/lm.c @@ -424,6 +432,7 @@ if(LINUX) src/detection/gtk_qt/gtk.c src/detection/host/host_linux.c src/detection/icons/icons_linux.c + src/detection/initsystem/initsystem_linux.c src/detection/libc/libc_linux.c src/detection/lm/lm_linux.c src/detection/loadavg/loadavg_linux.c @@ -482,6 +491,7 @@ elseif(ANDROID) src/detection/gpu/gpu_nosupport.c src/detection/host/host_android.c src/detection/icons/icons_nosupport.c + src/detection/initsystem/initsystem_linux.c src/detection/libc/libc_android.c src/detection/lm/lm_nosupport.c src/detection/loadavg/loadavg_linux.c @@ -552,6 +562,7 @@ elseif(BSD) src/detection/host/host_bsd.c src/detection/lm/lm_linux.c src/detection/icons/icons_linux.c + src/detection/initsystem/initsystem_linux.c src/detection/libc/libc_bsd.c src/detection/loadavg/loadavg_bsd.c src/detection/locale/locale_linux.c @@ -611,6 +622,7 @@ elseif(APPLE) src/detection/gpu/gpu_apple.m src/detection/host/host_apple.c src/detection/icons/icons_nosupport.c + src/detection/initsystem/initsystem_linux.c src/detection/lm/lm_nosupport.c src/detection/loadavg/loadavg_bsd.c src/detection/libc/libc_apple.c @@ -669,6 +681,7 @@ elseif(WIN32) src/detection/gpu/gpu_windows.c src/detection/host/host_windows.c src/detection/icons/icons_windows.c + src/detection/initsystem/initsystem_nosupport.c src/detection/libc/libc_windows.cpp src/detection/lm/lm_nosupport.c src/detection/loadavg/loadavg_nosupport.c @@ -817,6 +830,11 @@ if(NOT "${CUSTOM_OS_RELEASE_PATH}" STREQUAL "") target_compile_definitions(libfastfetch PRIVATE FF_CUSTOM_OS_RELEASE_PATH=${CUSTOM_OS_RELEASE_PATH}) endif() +if(NOT BINARY_LINK_TYPE STREQUAL "dlopen") + message(STATUS "Enabling custom link type: ${BINARY_LINK_TYPE}") + target_compile_definitions(libfastfetch PRIVATE FF_DISABLE_DLOPEN=1) +endif() + function(ff_lib_enable VARNAME PKGCONFIG_NAMES CMAKE_NAME) if(NOT ENABLE_${VARNAME}) return() @@ -845,6 +863,11 @@ function(ff_lib_enable VARNAME PKGCONFIG_NAMES CMAKE_NAME) target_compile_definitions(libfastfetch PRIVATE FF_HAVE_${VARNAME}=1) target_include_directories(libfastfetch PRIVATE ${${VARNAME}_INCLUDE_DIRS}) + if(NOT BINARY_LINK_TYPE STREQUAL "dlopen") + target_link_directories(libfastfetch PUBLIC ${${VARNAME}_LIBRARY_DIRS}) + target_link_libraries(libfastfetch PRIVATE ${${VARNAME}_LIBRARIES}) + endif() + foreach(FLAG ${${VARNAME}_CFLAGS_OTHER}) if(FLAG MATCHES "-D.*") string(SUBSTRING ${FLAG} 2 -1 FLAG) @@ -1093,6 +1116,11 @@ elseif(APPLE) ) endif() +if(BINARY_LINK_TYPE STREQUAL "static") + target_link_options(fastfetch PRIVATE "-static") + target_link_options(flashfetch PRIVATE "-static") +endif() + ################### # Testing targets # ################### diff --git a/README.md b/README.md index 814084c892..d59f1f04d5 100644 --- a/README.md +++ b/README.md @@ -43,31 +43,28 @@ Replace sudo with doas depending on what you use. [See also if fastfetch has been packaged for your favorite Linux distro](#Packaging). -If fastfetch is not packaged for your distro or an outdated version is packaged, [linuxbrew](https://brew.sh/) is a good alternate: `brew install fastfetch` +If fastfetch is not packaged for your distro or an outdated version is packaged, [linuxbrew](https://brew.sh/) is a good alternative: `brew install fastfetch` ### macOS -...via [HomeBrew](https://brew.sh): - -`brew install fastfetch` - -...via [MacPorts](https://www.macports.org): - -`sudo port install fastfetch` +* [HomeBrew](https://formulae.brew.sh/formula/fastfetch#default): `brew install fastfetch` +* [MacPorts](https://ports.macports.org/port/fastfetch/): `sudo port install fastfetch` ### Windows -`scoop install fastfetch` +* [scoop](https://scoop.sh/#/apps?q=fastfetch): `scoop install fastfetch` +* [winget](https://github.com/microsoft/winget-pkgs/tree/master/manifests/f/Fastfetch-cli/Fastfetch): `winget install fastfetch` +* [MSYS2 MinGW](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-fastfetch): `pacman -S mingw-w64---fastfetch` You may also download it directly from [GitHub releases page](https://github.com/fastfetch-cli/fastfetch/releases/latest) and extract the archive. ### FreeBSD -`pkg install fastfetch` +* `pkg install fastfetch` ### Android (Termux) -`pkg install fastfetch` +* `pkg install fastfetch` ## Build from source @@ -155,6 +152,15 @@ See `fastfetch -h format` for basic usage. For module specific formattion, see ` Try `fastfetch -l /path/to/logo`. See [logo documentation](https://github.com/fastfetch-cli/fastfetch/wiki/Logo-options) for detail. +If you just want to display distro name in [FIGlet text](https://github.com/pwaller/pyfiglet) + +```bash +# install pyfiglet and jq first +pyfiglet -s -f small_slant $(fastfetch -s os --format json | jq -r '.[0].result.name') && fastfetch -l none +``` + +![image](https://github.com/fastfetch-cli/fastfetch/assets/6134068/6466524e-ab8c-484f-848d-eec7ddeb7df2) + ### Q: Fastfetch runs in white and black on shell startup. Why? This issue usually happens when using fastfetch with `p10k`. There are known incompatibility between fastfetch and p10k instant prompt. diff --git a/debian/changelog b/debian/changelog index ba25aafed8..e8a82b8f33 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,45 @@ +fastfetch (2.13.2) jammy; urgency=medium + + * Update to 2.13.2 + + -- Carter Li Fri, 24 May 2024 13:48:59 +0800 + +fastfetch (2.13.1) jammy; urgency=medium + + * Update to 2.13.1 + + -- Carter Li Tue, 21 May 2024 15:10:37 +0800 + +fastfetch (2.12.0) jammy; urgency=medium + + * Update to 2.12.0 + + -- Carter Li Tue, 14 May 2024 16:33:33 +0800 + +fastfetch (2.11.5) jammy; urgency=medium + + * Update to 2.11.5 + + -- Carter Li Tue, 07 May 2024 09:30:05 +0800 + +fastfetch (2.11.3) jammy; urgency=medium + + * Update to 2.11.3 + + -- Carter Li Mon, 06 May 2024 08:46:45 +0800 + +fastfetch (2.10.2) jammy; urgency=medium + + * Update to 2.10.2 + + -- Carter Li Tue, 23 Apr 2024 15:18:23 +0800 + +fastfetch (2.10.1) jammy; urgency=medium + + * Update to 2.10.1 + + -- Carter Li Tue, 23 Apr 2024 09:55:02 +0800 + fastfetch (2.9.2) jammy; urgency=medium * Update to 2.9.2 diff --git a/debian/files b/debian/files index be634b16a8..0372bb94a6 100644 --- a/debian/files +++ b/debian/files @@ -1 +1 @@ -fastfetch_2.9.2_source.buildinfo universe/utils optional +fastfetch_2.13.2_source.buildinfo universe/utils optional diff --git a/doc/json_schema.json b/doc/json_schema.json index 255873158c..2a954c1863 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -387,6 +387,10 @@ "output": { "description": "Set the color of the module output", "$ref": "#/$defs/colors" + }, + "separator": { + "description": "Set the color of the key-value separator", + "$ref": "#/$defs/colors" } } } @@ -515,7 +519,7 @@ "properties": { "type": { "type": "number", - "description": "Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number", + "description": "Set the percentage output type. 1 for percentage number, 2 for multi-color bar, 3 for both, 6 for bar only, 9 for colored number, 10 for monochrome bar", "minimum": 0, "maximum": 255, "default": 9 @@ -778,7 +782,7 @@ }, { "const": "board", - "description": "Print mather board name and other info" + "description": "Print motherboard name and other info" }, { "const": "bootmgr", diff --git a/presets/all.jsonc b/presets/all.jsonc index bd878beea9..ebe2517c62 100644 --- a/presets/all.jsonc +++ b/presets/all.jsonc @@ -10,6 +10,7 @@ "board", "chassis", "kernel", + "initsystem", "uptime", "loadavg", "processes", diff --git a/presets/archey.jsonc b/presets/archey.jsonc index ae5401d08f..4e2250c175 100644 --- a/presets/archey.jsonc +++ b/presets/archey.jsonc @@ -40,7 +40,7 @@ }, { "type": "terminal", - "format": "{5} {6} \u001b[37m█\u001b[97m█ \u001b[36m█\u001b[96m█ \u001b[35m█\u001b[95m█ \u001b[34m█\u001b[94m█ \u001b[33m█\u001b[93m█ \u001b[32m█\u001b[92m█ \u001b[31m█\u001b[91m█ \u001b[30m█\u001b[90m█" + "format": "{5} {6} {#37}█{#97}█ {#36}█{#96}█ {#35}█{#95}█ {#34}█{#94}█ {#33}█{#93}█ {#32}█{#92}█ {#31}█{#91}█ {#30}█{#90}█" }, { "type": "packages", diff --git a/presets/ci.jsonc b/presets/ci.jsonc index 4827788435..afaaa63956 100644 --- a/presets/ci.jsonc +++ b/presets/ci.jsonc @@ -17,6 +17,7 @@ "board", "chassis", "kernel", + "initsystem", "uptime", "loadavg", "processes", diff --git a/presets/examples/10.jsonc b/presets/examples/10.jsonc index 40af25fefc..50da238899 100644 --- a/presets/examples/10.jsonc +++ b/presets/examples/10.jsonc @@ -14,7 +14,8 @@ "modules": [ { "type": "custom", - "format": "\u001b[90m┌────────────────────────────────────────────────────────────┐" + "format": "┌────────────────────────────────────────────────────────────┐", + "outputColor": "90" }, { "type": "title", @@ -22,15 +23,17 @@ }, { "type": "custom", - "format": "\u001b[90m└────────────────────────────────────────────────────────────┘" + "format": "└────────────────────────────────────────────────────────────┘", + "outputColor": "90" }, { "type": "custom", - "format": " \u001b[90m \u001b[31m \u001b[32m \u001b[33m \u001b[34m \u001b[35m \u001b[36m \u001b[37m \u001b[38m \u001b[39m  \u001b[38m \u001b[37m \u001b[36m \u001b[35m \u001b[34m \u001b[33m \u001b[32m \u001b[31m \u001b[90m" + "format": " {#90} {#31} {#32} {#33} {#34} {#35} {#36} {#37} {#38} {#39}  {#38} {#37} {#36} {#35} {#34} {#33} {#32} {#31} {#90}" }, { "type": "custom", - "format": "\u001b[90m┌────────────────────────────────────────────────────────────┐" + "format": "┌────────────────────────────────────────────────────────────┐", + "outputColor": "90" }, { "type": "os", @@ -139,12 +142,13 @@ }, { "type": "custom", - "format": "\u001b[90m└────────────────────────────────────────────────────────────┘" + "format": "└────────────────────────────────────────────────────────────┘", + "outputColor": "90" }, "break", { "type": "custom", - "format": " \u001b[90m \u001b[31m \u001b[32m \u001b[33m \u001b[34m \u001b[35m \u001b[36m \u001b[37m \u001b[38m \u001b[39m  \u001b[38m \u001b[37m \u001b[36m \u001b[35m \u001b[34m \u001b[33m \u001b[32m \u001b[31m \u001b[90m" + "format": " {#90} {#31} {#32} {#33} {#34} {#35} {#36} {#37} {#38} {#39}  {#38} {#37} {#36} {#35} {#34} {#33} {#32} {#31} {#90}" } ] } diff --git a/presets/examples/11.jsonc b/presets/examples/11.jsonc index 1daee9b51b..50aceb0d61 100644 --- a/presets/examples/11.jsonc +++ b/presets/examples/11.jsonc @@ -4,7 +4,10 @@ "type": "small" }, "display": { - "separator": "\u001b[31m-> " + "separator": "-> ", + "color": { + "separator": "red" + } }, "modules": [ { diff --git a/presets/examples/12.jsonc b/presets/examples/12.jsonc index 86a66d1aa1..4851597318 100644 --- a/presets/examples/12.jsonc +++ b/presets/examples/12.jsonc @@ -4,7 +4,10 @@ "type": "none" }, "display": { - "separator": "-> " + "separator": "-> ", + "color": { + "separator": "1" + } }, "modules": [ { @@ -14,7 +17,7 @@ "break", { "type": "custom", - "format": "┌───────────────────────────── \u001b[1mSystem Information\u001b[0m ─────────────────────────────┐" // `\u001b` is `\033`, or `\e` + "format": "┌───────────────────────────── {#1}System Information{#} ─────────────────────────────┐" }, "break", { @@ -92,7 +95,7 @@ "break", { "type": "custom", - "format": "└──────────────────────────────────────────────────────────────────────────────┘" // `\u001b` is `\033`, or `\e` + "format": "└──────────────────────────────────────────────────────────────────────────────┘" }, "break", { diff --git a/presets/examples/13.jsonc b/presets/examples/13.jsonc index d4ff95a299..8b29ab4c1e 100644 --- a/presets/examples/13.jsonc +++ b/presets/examples/13.jsonc @@ -17,54 +17,55 @@ }, { // draw borders first to make colors of left and right border consistant - "key": "│ │\u001b[11D\u001b[31m user", + "key": "│ │\u001b[11D{#31} user", "type": "title", "format": "{1}" }, { - "key": "│ │\u001b[11D\u001b[32m󰇅 hname", + "key": "│ │\u001b[11D{#32}󰇅 hname", "type": "title", "format": "{2}" }, { - "key": "│ │\u001b[11D\u001b[33m󰅐 uptime", + "key": "│ │\u001b[11D{#33}󰅐 uptime", "type": "uptime" }, { - "key": "│ │\u001b[11D\u001b[34m󰟾 distro", + "key": "│ │\u001b[11D{#34}󰟾 distro", "type": "os" }, { - "key": "│ │\u001b[11D\u001b[35m kernel", + "key": "│ │\u001b[11D{#35} kernel", "type": "kernel" }, { - "key": "│ │\u001b[11D\u001b[36m󰇄 desktop", + "key": "│ │\u001b[11D{#36}󰇄 desktop", "type": "de" }, { - "key": "│ │\u001b[11D\u001b[31m term", + "key": "│ │\u001b[11D{#31} term", "type": "terminal" }, { - "key": "│ │\u001b[11D\u001b[32m shell", + "key": "│ │\u001b[11D{#32} shell", "type": "shell" }, { - "key": "│ │\u001b[11D\u001b[33m󰍛 cpu", - "type": "cpu" + "key": "│ │\u001b[11D{#33}󰍛 cpu", + "type": "cpu", + "showPeCoreCount": true }, { - "key": "│ │\u001b[11D\u001b[34m󰉉 disk", + "key": "│ │\u001b[11D{#34}󰉉 disk", "type": "disk", "folders": "/" }, { - "key": "│ │\u001b[11D\u001b[35m memory", + "key": "│ │\u001b[11D{#35} memory", "type": "memory" }, { - "key": "│ │\u001b[11D\u001b[36m󰩟 network", + "key": "│ │\u001b[11D{#36}󰩟 network", "type": "localip", "format": "{1} ({4})" }, @@ -73,7 +74,7 @@ "type": "custom" }, { - "key": "│ │\u001b[11D\u001b[m colors", + "key": "│ │\u001b[11D{#39} colors", "type": "colors", "symbol": "circle" }, diff --git a/presets/examples/2.jsonc b/presets/examples/2.jsonc index 8c1c4bfcf7..d118fcc7a3 100644 --- a/presets/examples/2.jsonc +++ b/presets/examples/2.jsonc @@ -15,7 +15,7 @@ "modules": [ { "type": "custom", // HardwareStart - "format": "┌─────────── \u001b[1mHardware Information\u001b[0m ───────────┐" // `\u001b` is `\033`, or `\e` + "format": "┌─────────── {#1}Hardware Information{#} ───────────┐" // {#1} is the same as `\u001b[1m`. {#} is `\u001b[m` }, { "type": "host", @@ -71,7 +71,7 @@ }, { "type": "custom", // SoftwareStart - "format": "├─────────── \u001b[1mSoftware Information\u001b[0m ───────────┤" + "format": "├─────────── {#1}Software Information{#} ───────────┤" }, { "type": "title", diff --git a/presets/examples/7.jsonc b/presets/examples/7.jsonc index 941703ce72..d1cff7870e 100644 --- a/presets/examples/7.jsonc +++ b/presets/examples/7.jsonc @@ -24,7 +24,7 @@ "type": "os", "key": "├", // Just get your distro's logo off nerdfonts.com "keyColor": "yellow", - "format": "{6}{?6} {?}{10} {8}" + "format": "{6}{?6} {?}{10}{?10} {?}{8}{?8} {?}{11}" }, { "type": "kernel", diff --git a/presets/examples/8.jsonc b/presets/examples/8.jsonc index 79d89e9db7..4993257c71 100644 --- a/presets/examples/8.jsonc +++ b/presets/examples/8.jsonc @@ -46,7 +46,7 @@ { "type": "custom", "key": "", - "format": "\u001b[31m███\u001b[32m███\u001b[33m███\u001b[34m███\u001b[35m███\u001b[36m███" + "format": "{#31}███{#32}███{#33}███{#34}███{#35}███{#36}███" } ] } diff --git a/screenshots/example1.png b/screenshots/example1.png index 3c32199d13..5b043b7483 100644 Binary files a/screenshots/example1.png and b/screenshots/example1.png differ diff --git a/screenshots/github-thumbnail.png b/screenshots/github-thumbnail.png deleted file mode 100644 index c2e092b3d0..0000000000 Binary files a/screenshots/github-thumbnail.png and /dev/null differ diff --git a/src/common/format.c b/src/common/format.c index 6c65ff473f..525b65788d 100644 --- a/src/common/format.c +++ b/src/common/format.c @@ -52,14 +52,29 @@ void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg) * @param placeholderValue the string to parse * @return uint32_t the parsed value */ -static inline uint32_t getArgumentIndex(const FFstrbuf* placeholderValue) +static uint32_t getArgumentIndex(const FFstrbuf* placeholderValue, uint32_t numArgs, const FFformatarg* arguments) { - uint32_t result = UINT32_MAX; + char firstChar = placeholderValue->chars[0]; - if(placeholderValue->chars[0] != '-') - sscanf(placeholderValue->chars, "%" PRIu32, &result); + if(firstChar >= '1' && firstChar <= '9') + { + char* pEnd = NULL; + unsigned long result = strtoul(placeholderValue->chars, &pEnd, 10); + if (pEnd != placeholderValue->chars + placeholderValue->length || result > numArgs) + return UINT32_MAX; + return (uint32_t) result; + } + else if (ffCharIsEnglishAlphabet(firstChar)) + { + for (uint32_t i = 0; i < numArgs; ++i) + { + const FFformatarg* arg = &arguments[i]; + if(arg->name && ffStrbufIgnCaseEqualS(placeholderValue, arg->name)) + return i + 1; + } + } - return result == 0 ? UINT32_MAX : result; + return UINT32_MAX; } static inline void appendInvalidPlaceholder(FFstrbuf* buffer, const char* start, const FFstrbuf* placeholderValue, uint32_t index, uint32_t formatStringLength) @@ -101,7 +116,8 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n uint32_t numOpenIfs = 0; uint32_t numOpenNotIfs = 0; - uint32_t numOpenColors = 0; + + FF_STRBUF_AUTO_DESTROY placeholderValue = ffStrbufCreate(); for(uint32_t i = 0; i < formatstr->length; ++i) { @@ -136,67 +152,70 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n continue; } - FF_STRBUF_AUTO_DESTROY placeholderValue = ffStrbufCreate(); - - while(i < formatstr->length && formatstr->chars[i] != '}') - ffStrbufAppendC(&placeholderValue, formatstr->chars[i++]); + ffStrbufClear(&placeholderValue); - // test if for stop, if so break the loop - if(placeholderValue.length == 1 && placeholderValue.chars[0] == '-') - break; - - // test for end of an if, if so do nothing - if(placeholderValue.length == 1 && placeholderValue.chars[0] == '?') { - if(numOpenIfs == 0) - appendInvalidPlaceholder(buffer, "{", &placeholderValue, i, formatstr->length); - else - --numOpenIfs; - - continue; + uint32_t iEnd = ffStrbufNextIndexC(formatstr, i, '}'); + ffStrbufAppendNS(&placeholderValue, iEnd - i, &formatstr->chars[i]); + i = iEnd; } - // test for end of a not if, if so do nothing - if(placeholderValue.length == 1 && placeholderValue.chars[0] == '/') + char firstChar = placeholderValue.chars[0]; + + if (placeholderValue.length == 1) { - if(numOpenNotIfs == 0) - appendInvalidPlaceholder(buffer, "{", &placeholderValue, i, formatstr->length); - else - --numOpenNotIfs; + // test if for stop, if so break the loop + if (firstChar == '-') + break; - continue; - } + // test for end of an if, if so do nothing + if (firstChar == '?') + { + if(numOpenIfs == 0) + appendInvalidPlaceholder(buffer, "{", &placeholderValue, i, formatstr->length); + else + --numOpenIfs; - // test for end of a color, if so do nothing - if(placeholderValue.length == 1 && placeholderValue.chars[0] == '#') - { - if(numOpenColors == 0) - appendInvalidPlaceholder(buffer, "{", &placeholderValue, i, formatstr->length); - else + continue; + } + + // test for end of a not if, if so do nothing + if (firstChar == '/') { - ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); - --numOpenColors; + if(numOpenNotIfs == 0) + appendInvalidPlaceholder(buffer, "{", &placeholderValue, i, formatstr->length); + else + --numOpenNotIfs; + + continue; } - continue; + // test for end of a color, if so do nothing + if (firstChar == '#') + { + if (!instance.config.display.pipe) + ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); + + continue; + } } // test for if, if so evaluate it - if(placeholderValue.chars[0] == '?') + if (firstChar == '?') { ffStrbufSubstrAfter(&placeholderValue, 0); - uint32_t index = getArgumentIndex(&placeholderValue); + uint32_t index = getArgumentIndex(&placeholderValue, numArgs, arguments); // testing for an invalid index - if(index > numArgs) + if (index > numArgs) { appendInvalidPlaceholder(buffer, "{?", &placeholderValue, i, formatstr->length); continue; } // continue normally if an format arg is set and the value is > 0 - if(formatArgSet(&arguments[index - 1])) + if (formatArgSet(&arguments[index - 1])) { ++numOpenIfs; continue; @@ -208,21 +227,21 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n } // test for not if, if so evaluate it - if(placeholderValue.chars[0] == '/') + if (firstChar == '/') { ffStrbufSubstrAfter(&placeholderValue, 0); - uint32_t index = getArgumentIndex(&placeholderValue); + uint32_t index = getArgumentIndex(&placeholderValue, numArgs, arguments); // testing for an invalid index - if(index > numArgs) + if (index > numArgs) { appendInvalidPlaceholder(buffer, "{/", &placeholderValue, i, formatstr->length); continue; } //continue normally if an format arg is not set or the value is 0 - if(!formatArgSet(&arguments[index - 1])) + if (!formatArgSet(&arguments[index - 1])) { ++numOpenNotIfs; continue; @@ -234,20 +253,21 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n } //test for color, if so evaluate it - if(placeholderValue.chars[0] == '#') + if (firstChar == '#') { - ++numOpenColors; - ffStrbufSubstrAfter(&placeholderValue, 0); - ffStrbufAppendS(buffer, "\033["); - ffStrbufAppend(buffer, &placeholderValue); - ffStrbufAppendC(buffer, 'm'); + if (!instance.config.display.pipe) + { + ffStrbufAppendS(buffer, "\e["); + ffOptionParseColorNoClear(placeholderValue.chars + 1, buffer); + ffStrbufAppendC(buffer, 'm'); + } continue; } - uint32_t index = getArgumentIndex(&placeholderValue); + uint32_t index = getArgumentIndex(&placeholderValue, numArgs, arguments); // test for invalid index - if(index > numArgs) + if (index > numArgs) { appendInvalidPlaceholder(buffer, "{", &placeholderValue, i, formatstr->length); continue; @@ -256,5 +276,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n ffFormatAppendFormatArg(buffer, &arguments[index - 1]); } - ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); + if (!instance.config.display.pipe) + ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); } diff --git a/src/common/format.h b/src/common/format.h index d05921d104..af1b7ff417 100644 --- a/src/common/format.h +++ b/src/common/format.h @@ -20,6 +20,7 @@ typedef struct FFformatarg { FFformatargtype type; const void* value; + const char* name; // argument name, must start with an alphabet } FFformatarg; void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg); diff --git a/src/common/library.c b/src/common/library.c index e776516b58..e8ade19da0 100644 --- a/src/common/library.c +++ b/src/common/library.c @@ -1,6 +1,8 @@ #include "fastfetch.h" #include "common/library.h" +#ifndef FF_DISABLE_DLOPEN + #include //Clang doesn't define __SANITIZE_ADDRESS__ but defines __has_feature(address_sanitizer) @@ -77,3 +79,5 @@ void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...) return result; } + +#endif diff --git a/src/common/library.h b/src/common/library.h index 5a283bc2e8..8a5e8b34e0 100644 --- a/src/common/library.h +++ b/src/common/library.h @@ -3,6 +3,8 @@ #include "fastfetch.h" #include "util/FFcheckmacros.h" +#ifndef FF_DISABLE_DLOPEN + #if defined(_WIN32) #include #define FF_DLOPEN_FLAGS 0 @@ -71,3 +73,45 @@ static inline void ffLibraryUnload(void** handle) FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName)->ff ## symbolName, symbolName, returnValue); void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...); + +#else + +#define FF_LIBRARY_EXTENSION "" + +#define FF_LIBRARY_SYMBOL(symbolName) \ + __typeof__(&symbolName) ff ## symbolName; + +#define FF_LIBRARY_LOAD(libraryObjectName, userLibraryName, returnValue, ...) \ + FF_MAYBE_UNUSED void* libraryObjectName = NULL; // Placeholder + +#define FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, symbolMapping, symbolName, returnValue) \ + symbolMapping = (__typeof__(&symbolName)) &symbolName + +#define FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, symbolMapping, symbolName, alternateName, returnValue) \ + symbolMapping = (__typeof__(&symbolName)) &symbolName + +#define FF_LIBRARY_LOAD_SYMBOL(library, symbolName, returnValue) \ + FF_MAYBE_UNUSED __typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff ## symbolName, symbolName, returnValue); + +#define FF_LIBRARY_LOAD_SYMBOL_LAZY(library, symbolName) \ + FF_MAYBE_UNUSED __typeof__(&symbolName) ff ## symbolName = (__typeof__(&symbolName)) &symbolName; + +#define FF_LIBRARY_LOAD_SYMBOL_MESSAGE(library, symbolName) \ + FF_MAYBE_UNUSED __typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff ## symbolName, symbolName, "dlsym " #symbolName " failed"); + +#define FF_LIBRARY_LOAD_SYMBOL_MESSAGE2(library, symbolName, alternateName) \ + FF_MAYBE_UNUSED __typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, ff ## symbolName, symbolName, alternateName, "dlsym " #symbolName " failed"); + +#define FF_LIBRARY_LOAD_SYMBOL_VAR(library, varName, symbolName, returnValue) \ + FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName).ff ## symbolName, symbolName, returnValue); + +#define FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(library, varName, symbolName) \ + FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName).ff ## symbolName, symbolName, "dlsym " #symbolName " failed"); + +#define FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE2(library, varName, symbolName, alternateName) \ + FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, (varName).ff ## symbolName, symbolName, alternateName, "dlsym " #symbolName " failed"); + +#define FF_LIBRARY_LOAD_SYMBOL_PTR(library, varName, symbolName, returnValue) \ + FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName)->ff ## symbolName, symbolName, returnValue); + +#endif diff --git a/src/common/modules.c b/src/common/modules.c index e7e2c20f83..9205cc0b52 100644 --- a/src/common/modules.c +++ b/src/common/modules.c @@ -59,6 +59,7 @@ static FFModuleBaseInfo* H[] = { static FFModuleBaseInfo* I[] = { (void*) &instance.config.modules.icons, + (void*) &instance.config.modules.initSystem, NULL, }; diff --git a/src/common/option.c b/src/common/option.c index a9fa3878fe..de2e487b41 100644 --- a/src/common/option.c +++ b/src/common/option.c @@ -145,47 +145,46 @@ bool ffOptionParseBoolean(const char* str) ); } -void ffOptionParseColor(const char* value, FFstrbuf* buffer) +void ffOptionParseColorNoClear(const char* value, FFstrbuf* buffer) { - ffStrbufClear(buffer); ffStrbufEnsureFree(buffer, 63); while(*value != '\0') { #define FF_APPEND_COLOR_CODE_COND(prefix, code) \ - if(ffStrStartsWithIgnCase(value, #prefix)) { ffStrbufAppendS(buffer, code); value += strlen(#prefix); } - - FF_APPEND_COLOR_CODE_COND(reset_, FF_COLOR_MODE_RESET) - else FF_APPEND_COLOR_CODE_COND(bright_, FF_COLOR_MODE_BOLD) - else FF_APPEND_COLOR_CODE_COND(dim_, FF_COLOR_MODE_DIM) - else FF_APPEND_COLOR_CODE_COND(italic_, FF_COLOR_MODE_ITALIC) - else FF_APPEND_COLOR_CODE_COND(underline_, FF_COLOR_MODE_UNDERLINE) - else FF_APPEND_COLOR_CODE_COND(blink_, FF_COLOR_MODE_BLINK) - else FF_APPEND_COLOR_CODE_COND(inverse_, FF_COLOR_MODE_INVERSE) - else FF_APPEND_COLOR_CODE_COND(hidden_, FF_COLOR_MODE_HIDDEN) - else FF_APPEND_COLOR_CODE_COND(strike_, FF_COLOR_MODE_STRIKETHROUGH) - else FF_APPEND_COLOR_CODE_COND(black, FF_COLOR_FG_BLACK) - else FF_APPEND_COLOR_CODE_COND(red, FF_COLOR_FG_RED) - else FF_APPEND_COLOR_CODE_COND(green, FF_COLOR_FG_GREEN) - else FF_APPEND_COLOR_CODE_COND(yellow, FF_COLOR_FG_YELLOW) - else FF_APPEND_COLOR_CODE_COND(blue, FF_COLOR_FG_BLUE) - else FF_APPEND_COLOR_CODE_COND(magenta, FF_COLOR_FG_MAGENTA) - else FF_APPEND_COLOR_CODE_COND(cyan, FF_COLOR_FG_CYAN) - else FF_APPEND_COLOR_CODE_COND(white, FF_COLOR_FG_WHITE) - else FF_APPEND_COLOR_CODE_COND(default, FF_COLOR_FG_DEFAULT) - else FF_APPEND_COLOR_CODE_COND(light_black, FF_COLOR_FG_LIGHT_BLACK) - else FF_APPEND_COLOR_CODE_COND(light_red, FF_COLOR_FG_LIGHT_RED) - else FF_APPEND_COLOR_CODE_COND(light_green, FF_COLOR_FG_LIGHT_GREEN) - else FF_APPEND_COLOR_CODE_COND(light_yellow, FF_COLOR_FG_LIGHT_YELLOW) - else FF_APPEND_COLOR_CODE_COND(light_blue, FF_COLOR_FG_LIGHT_BLUE) - else FF_APPEND_COLOR_CODE_COND(light_magenta, FF_COLOR_FG_LIGHT_MAGENTA) - else FF_APPEND_COLOR_CODE_COND(light_cyan, FF_COLOR_FG_LIGHT_CYAN) - else FF_APPEND_COLOR_CODE_COND(light_white, FF_COLOR_FG_LIGHT_WHITE) - else + if(ffStrStartsWithIgnCase(value, #prefix)) { ffStrbufAppendS(buffer, code); value += strlen(#prefix); continue; } + + if (ffCharIsEnglishAlphabet(value[0])) { - ffStrbufAppendC(buffer, *value); - ++value; + FF_APPEND_COLOR_CODE_COND(reset_, FF_COLOR_MODE_RESET) + else FF_APPEND_COLOR_CODE_COND(bright_, FF_COLOR_MODE_BOLD) + else FF_APPEND_COLOR_CODE_COND(dim_, FF_COLOR_MODE_DIM) + else FF_APPEND_COLOR_CODE_COND(italic_, FF_COLOR_MODE_ITALIC) + else FF_APPEND_COLOR_CODE_COND(underline_, FF_COLOR_MODE_UNDERLINE) + else FF_APPEND_COLOR_CODE_COND(blink_, FF_COLOR_MODE_BLINK) + else FF_APPEND_COLOR_CODE_COND(inverse_, FF_COLOR_MODE_INVERSE) + else FF_APPEND_COLOR_CODE_COND(hidden_, FF_COLOR_MODE_HIDDEN) + else FF_APPEND_COLOR_CODE_COND(strike_, FF_COLOR_MODE_STRIKETHROUGH) + else FF_APPEND_COLOR_CODE_COND(black, FF_COLOR_FG_BLACK) + else FF_APPEND_COLOR_CODE_COND(red, FF_COLOR_FG_RED) + else FF_APPEND_COLOR_CODE_COND(green, FF_COLOR_FG_GREEN) + else FF_APPEND_COLOR_CODE_COND(yellow, FF_COLOR_FG_YELLOW) + else FF_APPEND_COLOR_CODE_COND(blue, FF_COLOR_FG_BLUE) + else FF_APPEND_COLOR_CODE_COND(magenta, FF_COLOR_FG_MAGENTA) + else FF_APPEND_COLOR_CODE_COND(cyan, FF_COLOR_FG_CYAN) + else FF_APPEND_COLOR_CODE_COND(white, FF_COLOR_FG_WHITE) + else FF_APPEND_COLOR_CODE_COND(default, FF_COLOR_FG_DEFAULT) + else FF_APPEND_COLOR_CODE_COND(light_black, FF_COLOR_FG_LIGHT_BLACK) + else FF_APPEND_COLOR_CODE_COND(light_red, FF_COLOR_FG_LIGHT_RED) + else FF_APPEND_COLOR_CODE_COND(light_green, FF_COLOR_FG_LIGHT_GREEN) + else FF_APPEND_COLOR_CODE_COND(light_yellow, FF_COLOR_FG_LIGHT_YELLOW) + else FF_APPEND_COLOR_CODE_COND(light_blue, FF_COLOR_FG_LIGHT_BLUE) + else FF_APPEND_COLOR_CODE_COND(light_magenta, FF_COLOR_FG_LIGHT_MAGENTA) + else FF_APPEND_COLOR_CODE_COND(light_cyan, FF_COLOR_FG_LIGHT_CYAN) + else FF_APPEND_COLOR_CODE_COND(light_white, FF_COLOR_FG_LIGHT_WHITE) } + ffStrbufAppendC(buffer, *value); + ++value; #undef FF_APPEND_COLOR_CODE_COND } diff --git a/src/common/option.h b/src/common/option.h index e7dba9b226..8fce76c83d 100644 --- a/src/common/option.h +++ b/src/common/option.h @@ -67,6 +67,11 @@ FF_C_NODISCARD uint32_t ffOptionParseUInt32(const char* argumentKey, const char* FF_C_NODISCARD int32_t ffOptionParseInt32(const char* argumentKey, const char* value); FF_C_NODISCARD int ffOptionParseEnum(const char* argumentKey, const char* requestedKey, FFKeyValuePair pairs[]); FF_C_NODISCARD bool ffOptionParseBoolean(const char* str); -void ffOptionParseColor(const char* value, FFstrbuf* buffer); +void ffOptionParseColorNoClear(const char* value, FFstrbuf* buffer); +static inline void ffOptionParseColor(const char* value, FFstrbuf* buffer) +{ + ffStrbufClear(buffer); + ffOptionParseColorNoClear(value, buffer); +} void ffOptionInitModuleArg(FFModuleArgs* args); void ffOptionDestroyModuleArg(FFModuleArgs* args); diff --git a/src/common/percent.c b/src/common/percent.c index 14ab93f559..0570797ebc 100644 --- a/src/common/percent.c +++ b/src/common/percent.c @@ -50,14 +50,34 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig con { if(!options->pipe) { - uint32_t section1Begin = (uint32_t) ((green <= yellow ? green : yellow) / 100.0 * options->barWidth + 0.5); - uint32_t section2Begin = (uint32_t) ((green > yellow ? green : yellow) / 100.0 * options->barWidth + 0.5); - if (i == section2Begin) - ffStrbufAppendF(buffer, "\e[%sm", (green > yellow ? colorGreen : colorRed)); - else if (i == section1Begin) - ffStrbufAppendF(buffer, "\e[%sm", colorYellow); - else if (i == 0) - ffStrbufAppendF(buffer, "\e[%sm", (green <= yellow ? colorGreen : colorRed)); + if (options->percentType & FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT) + { + const char* color = NULL; + if (green <= yellow) + { + if (percent < green) color = colorGreen; + else if (percent < yellow) color = colorYellow; + else color = colorRed; + } + else + { + if (percent < yellow) color = colorRed; + else if (percent < green) color = colorYellow; + else color = colorGreen; + } + ffStrbufAppendF(buffer, "\e[%sm", color); + } + else + { + uint32_t section1Begin = (uint32_t) ((green <= yellow ? green : yellow) / 100.0 * options->barWidth + 0.5); + uint32_t section2Begin = (uint32_t) ((green > yellow ? green : yellow) / 100.0 * options->barWidth + 0.5); + if (i == section2Begin) + ffStrbufAppendF(buffer, "\e[%sm", (green > yellow ? colorGreen : colorRed)); + else if (i == section1Begin) + ffStrbufAppendF(buffer, "\e[%sm", colorYellow); + else if (i == 0) + ffStrbufAppendF(buffer, "\e[%sm", (green <= yellow ? colorGreen : colorRed)); + } } ffStrbufAppend(buffer, &options->barCharElapsed); } diff --git a/src/common/percent.h b/src/common/percent.h index 8ae87708cc..33921f6892 100644 --- a/src/common/percent.h +++ b/src/common/percent.h @@ -4,12 +4,13 @@ #include "common/parsing.h" #include "common/option.h" -enum +enum FFPercentageTypeFlags { FF_PERCENTAGE_TYPE_NUM_BIT = 1 << 0, FF_PERCENTAGE_TYPE_BAR_BIT = 1 << 1, FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT = 1 << 2, FF_PERCENTAGE_TYPE_NUM_COLOR_BIT = 1 << 3, + FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT = FF_PERCENTAGE_TYPE_NUM_COLOR_BIT, }; // if (green <= yellow) diff --git a/src/common/printing.c b/src/common/printing.c index 846d491224..a9888af3bd 100644 --- a/src/common/printing.c +++ b/src/common/printing.c @@ -11,43 +11,56 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu return; //This is used as a magic value for hiding keys - if(moduleArgs && ffStrbufEqualS(&moduleArgs->key, " ")) - return; - - if(!instance.config.display.pipe) + if (!(moduleArgs && ffStrbufEqualS(&moduleArgs->key, " "))) { - fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); - if (instance.config.display.brightColor) - fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout); - - if(moduleArgs && !(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_COLOR) && moduleArgs->keyColor.length > 0) - ffPrintColor(&moduleArgs->keyColor); + if(!instance.config.display.pipe) + { + fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); + if (instance.config.display.brightColor) + fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout); + + if(moduleArgs && !(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_COLOR) && moduleArgs->keyColor.length > 0) + ffPrintColor(&moduleArgs->keyColor); + else + ffPrintColor(&instance.config.display.colorKeys); + } + + //NULL check is required for modules with custom keys, e.g. disk with the folder path + if((printType & FF_PRINT_TYPE_NO_CUSTOM_KEY) || !moduleArgs || moduleArgs->key.length == 0) + { + fputs(moduleName, stdout); + + if(moduleIndex > 0) + printf(" %hhu", moduleIndex); + } else - ffPrintColor(&instance.config.display.colorKeys); - } - - //NULL check is required for modules with custom keys, e.g. disk with the folder path - if((printType & FF_PRINT_TYPE_NO_CUSTOM_KEY) || !moduleArgs || moduleArgs->key.length == 0) - { - fputs(moduleName, stdout); - - if(moduleIndex > 0) - printf(" %hhu", moduleIndex); - } - else - { - FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate(); - FF_PARSE_FORMAT_STRING_CHECKED(&key, &moduleArgs->key, 1, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex} - })); - ffStrbufWriteTo(&key, stdout); + { + FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate(); + FF_PARSE_FORMAT_STRING_CHECKED(&key, &moduleArgs->key, 1, ((FFformatarg[]){ + {FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex, "index"}, + })); + ffStrbufWriteTo(&key, stdout); + } + + if(!instance.config.display.pipe) + { + fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); + ffPrintColor(&instance.config.display.colorSeparator); + } + + ffStrbufWriteTo(&instance.config.display.keyValueSeparator, stdout); + + if(!instance.config.display.pipe && instance.config.display.colorSeparator.length) + fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); + + if (!(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_WIDTH)) + { + uint32_t keyWidth = moduleArgs && moduleArgs->keyWidth > 0 ? moduleArgs->keyWidth : instance.config.display.keyWidth; + if (keyWidth > 0) + printf("\e[%uG", (unsigned) (keyWidth + instance.state.logoWidth)); + } } - if(!instance.config.display.pipe) - fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); - - ffStrbufWriteTo(&instance.config.display.keyValueSeparator, stdout); - if(!instance.config.display.pipe) { fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); @@ -56,13 +69,6 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu else if (instance.config.display.colorOutput.length) ffPrintColor(&instance.config.display.colorOutput); } - - if (!instance.config.display.pipe && !(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_WIDTH)) - { - uint32_t keyWidth = moduleArgs && moduleArgs->keyWidth > 0 ? moduleArgs->keyWidth : instance.config.display.keyWidth; - if (keyWidth > 0) - printf("\e[%uG", (unsigned) (keyWidth + instance.state.logoWidth)); - } } void ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, uint32_t numArgs, const FFformatarg* arguments) @@ -73,11 +79,8 @@ void ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleAr else ffStrbufAppendS(&buffer, "unknown"); - if(buffer.length > 0) - { - ffPrintLogoAndKey(moduleName, moduleIndex, moduleArgs, printType); - ffStrbufPutTo(&buffer, stdout); - } + ffPrintLogoAndKey(moduleName, moduleIndex, moduleArgs, printType); + ffStrbufPutTo(&buffer, stdout); } static void printError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, va_list arguments) diff --git a/src/common/processing.h b/src/common/processing.h index ff2689a521..7208214dbb 100644 --- a/src/common/processing.h +++ b/src/common/processing.h @@ -2,6 +2,8 @@ #include "util/FFstrbuf.h" +#include + const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool useStdErr); static inline const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[]) @@ -19,3 +21,10 @@ static inline const char* ffProcessAppendStdErr(FFstrbuf* buffer, char* const ar ffStrbufTrimRightSpace(buffer); return error; } + +#ifdef _WIN32 +bool ffProcessGetInfoWindows(uint32_t pid, uint32_t* ppid, FFstrbuf* pname, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath, bool* gui); +#else +void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath); +const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, int32_t* tty); +#endif diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index 4401e3212b..ac4ee2b9f8 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -2,6 +2,8 @@ #include "common/processing.h" #include "common/io/io.h" #include "common/time.h" +#include "util/stringUtils.h" +#include "util/mallocHelper.h" #include #include @@ -11,6 +13,15 @@ #include #include +#if defined(__FreeBSD__) || defined(__APPLE__) + #include + #include + #include +#endif +#ifdef __APPLE__ + #include +#endif + enum { FF_PIPE_BUFSIZ = 8192 }; static inline int ffPipe2(int *fds, int flags) @@ -101,3 +112,234 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use return "read(childPipeFd, str, FF_PIPE_BUFSIZ) failed"; } + +void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath) +{ + assert(processName->length > 0); + ffStrbufClear(exe); + + #ifdef __linux__ + + char filePath[64]; + snprintf(filePath, sizeof(filePath), "/proc/%d/cmdline", (int)pid); + + if(ffReadFileBuffer(filePath, exe)) + { + ffStrbufRecalculateLength(exe); //Trim the arguments + ffStrbufTrimRightSpace(exe); + ffStrbufTrimLeft(exe, '-'); //Login shells start with a dash + } + + if (exePath) + { + snprintf(filePath, sizeof(filePath), "/proc/%d/exe", (int)pid); + ffStrbufEnsureFixedLengthFree(exePath, PATH_MAX); + ssize_t length = readlink(filePath, exePath->chars, exePath->allocated - 1); + if (length > 0) // doesn't contain trailing NUL + { + exePath->chars[length] = '\0'; + exePath->length = (uint32_t) length; + } + } + + #elif defined(__APPLE__) + + size_t len = 0; + int mibs[] = { CTL_KERN, KERN_PROCARGS2, pid }; + if (sysctl(mibs, sizeof(mibs) / sizeof(*mibs), NULL, &len, NULL, 0) == 0) + {// try get arg0 + #ifndef MAC_OS_X_VERSION_10_15 + //don't know why if don't let len longer, proArgs2 and len will change during the following sysctl() in old MacOS version. + len++; + #endif + FF_AUTO_FREE char* const procArgs2 = malloc(len); + if (sysctl(mibs, sizeof(mibs) / sizeof(*mibs), procArgs2, &len, NULL, 0) == 0) + { + // https://gist.github.com/nonowarn/770696#file-getargv-c-L46 + uint32_t argc = *(uint32_t*) procArgs2; + const char* realExePath = procArgs2 + sizeof(argc); + + const char* arg0 = memchr(realExePath, '\0', len - (size_t) (realExePath - procArgs2)); + if (exePath) + ffStrbufSetNS(exePath, (uint32_t) (arg0 - realExePath), realExePath); + + do arg0++; while (*arg0 == '\0'); + assert(arg0 < procArgs2 + len); + + if (argc > 1) + { + // #977 + const char* p = strrchr(arg0, '/'); + if (p) + p++; + else + p = arg0; + if (ffStrStartsWithIgnCase(p, "python")) // /opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python /Users/carter/.local/bin/xonsh + arg0 = p + strlen(p) + 1; + } + + if (*arg0 == '-') arg0++; // Login shells + + ffStrbufSetS(exe, arg0); + } + } + else + { + ffStrbufEnsureFixedLengthFree(exe, PATH_MAX); + int length = proc_pidpath(pid, exe->chars, exe->allocated); + if (length > 0) + { + exe->length = (uint32_t) length; + if (exePath) + ffStrbufSet(exePath, exe); + } + } + + #elif defined(__FreeBSD__) + + size_t size = ARG_MAX; + FF_AUTO_FREE char* args = malloc(size); + + static_assert(ARG_MAX > PATH_MAX, ""); + + if(exePath && sysctl( + (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid}, 4, + args, &size, + NULL, 0 + ) == 0) + ffStrbufSetNS(exePath, (uint32_t) (size - 1), args); + + size = ARG_MAX; + if(sysctl( + (int[]){CTL_KERN, KERN_PROC, KERN_PROC_ARGS, pid}, 4, + args, &size, + NULL, 0 + ) == 0) + { + char* arg0 = args; + size_t arg0Len = strlen(args); + if (size > arg0Len + 1) + { + char* p = (char*) memrchr(args, '/', arg0Len); + if (p) + p++; + else + p = arg0; + if (ffStrStartsWith(p, "python")) // /usr/local/bin/python3.9 /home/carter/.local/bin/xonsh + { + arg0 += arg0Len + 1; + } + } + if (arg0[0] == '-') arg0++; + ffStrbufSetS(exe, arg0); + } + + #endif + + if(exe->length == 0) + ffStrbufSet(exe, processName); + + assert(exe->length > 0); + uint32_t lastSlashIndex = ffStrbufLastIndexC(exe, '/'); + if(lastSlashIndex < exe->length) + *exeName = exe->chars + lastSlashIndex + 1; +} + +const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, int32_t* tty) +{ + if (pid <= 0) + return "Invalid pid"; + + #ifdef __linux__ + + char procFilePath[64]; + if (ppid) + { + snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/stat", (int)pid); + char buf[PROC_FILE_BUFFSIZ]; + ssize_t nRead = ffReadFileData(procFilePath, sizeof(buf) - 1, buf); + if(nRead <= 8) + return "ffReadFileData(/proc/pid/stat, PROC_FILE_BUFFSIZ-1, buf) failed"; + buf[nRead] = '\0'; + + *ppid = 0; + static_assert(sizeof(*ppid) == sizeof(int), ""); + + ffStrbufEnsureFixedLengthFree(name, 255); + int tty_; + if( + sscanf(buf, "%*s (%255[^)]) %*c %d %*d %*d %d", name->chars, ppid, &tty_) < 2 || //stat (comm) state ppid pgrp session tty + name->chars[0] == '\0' + ) + return "sscanf(stat) failed"; + + ffStrbufRecalculateLength(name); + if (tty) + *tty = tty_ & 0xFF; + } + else + { + snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/comm", (int)pid); + ssize_t nRead = ffReadFileBuffer(procFilePath, name); + if(nRead <= 0) + return "ffReadFileBuffer(/proc/pid/comm, name) failed"; + ffStrbufTrimRightSpace(name); + } + + #elif defined(__APPLE__) + + struct kinfo_proc proc; + size_t size = sizeof(proc); + if(sysctl( + (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PID, pid}, 4, + &proc, &size, + NULL, 0 + )) + return "sysctl(KERN_PROC_PID) failed"; + + ffStrbufSetS(name, proc.kp_proc.p_comm); //trancated to 16 chars + if (ppid) + *ppid = (pid_t)proc.kp_eproc.e_ppid; + if (tty) + { + *tty = ((proc.kp_eproc.e_tdev >> 24) & 0xFF) == 0x10 + ? proc.kp_eproc.e_tdev & 0xFFFFFF + : -1; + } + + #elif defined(__FreeBSD__) + + struct kinfo_proc proc; + size_t size = sizeof(proc); + if(sysctl( + (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PID, pid}, 4, + &proc, &size, + NULL, 0 + )) + return "sysctl(KERN_PROC_PID) failed"; + + ffStrbufSetS(name, proc.ki_comm); + if (ppid) + *ppid = (pid_t)proc.ki_ppid; + if (tty) + { + if (proc.ki_tdev != NODEV && proc.ki_flag & P_CONTROLT) + { + const char* ttyName = devname(proc.ki_tdev, S_IFCHR); + if (ffStrStartsWith(ttyName, "pts/")) + *tty = (int32_t) strtol(ttyName + strlen("pts/"), NULL, 10); + else + *tty = -1; + } + else + *tty = -1; + } + + #else + + return "Unsupported platform"; + + #endif + + return NULL; +} diff --git a/src/common/processing_windows.c b/src/common/processing_windows.c index 5cbd0819f5..03fb7cbfdb 100644 --- a/src/common/processing_windows.c +++ b/src/common/processing_windows.c @@ -3,6 +3,8 @@ #include "common/io/io.h" #include +#include +#include enum { FF_PIPE_BUFSIZ = 8192 }; @@ -124,3 +126,46 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use return NULL; } + +bool ffProcessGetInfoWindows(uint32_t pid, uint32_t* ppid, FFstrbuf* pname, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath, bool* gui) +{ + FF_AUTO_CLOSE_FD HANDLE hProcess = pid == 0 + ? GetCurrentProcess() + : OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid); + + if (gui) + *gui = GetGuiResources(hProcess, GR_GDIOBJECTS) > 0; + + if(ppid) + { + PROCESS_BASIC_INFORMATION info = {}; + ULONG size; + if(NT_SUCCESS(NtQueryInformationProcess(hProcess, ProcessBasicInformation, &info, sizeof(info), &size))) + { + assert(size == sizeof(info)); + *ppid = (uint32_t)info.InheritedFromUniqueProcessId; + } + else + return false; + } + if(exe) + { + DWORD bufSize = exe->allocated; + if(QueryFullProcessImageNameA(hProcess, 0, exe->chars, &bufSize)) + { + // We use full path here + // Querying command line of remote processes in Windows requires either WMI or ReadProcessMemory + exe->length = bufSize; + if (exePath) ffStrbufSet(exePath, exe); + } + else + return false; + } + if(pname && exeName) + { + *exeName = exe->chars + ffStrbufLastIndexC(exe, '\\') + 1; + ffStrbufSetS(pname, *exeName); + } + + return true; +} diff --git a/src/common/settings.c b/src/common/settings.c index a01d4e706e..8d6e6e47fd 100644 --- a/src/common/settings.c +++ b/src/common/settings.c @@ -6,45 +6,6 @@ #include -typedef enum FFInitState -{ - FF_INITSTATE_UNINITIALIZED = 0, - FF_INITSTATE_SUCCESSFUL = 1, - FF_INITSTATE_FAILED = 2 -} FFInitState; - -#define FF_LIBRARY_DATA_LOAD_INIT(dataObject, userLibraryName, ...) \ - static dataObject data; \ - static FFInitState initState = FF_INITSTATE_UNINITIALIZED; \ - if(initState != FF_INITSTATE_UNINITIALIZED) {\ - return initState == FF_INITSTATE_SUCCESSFUL ? &data : NULL; \ - } \ - initState = FF_INITSTATE_SUCCESSFUL; \ - void* libraryHandle = ffLibraryLoad(&userLibraryName, __VA_ARGS__, NULL); \ - if(libraryHandle == NULL) { \ - initState = FF_INITSTATE_FAILED; \ - return NULL; \ - } \ - -#define FF_LIBRARY_DATA_LOAD_SYMBOL(symbolName) \ - data.ff ## symbolName = dlsym(libraryHandle, #symbolName); \ - if(data.ff ## symbolName == NULL) { \ - dlclose(libraryHandle); \ - initState = FF_INITSTATE_FAILED; \ - return NULL; \ - } - -#define FF_LIBRARY_DATA_LOAD_RETURN \ - initState = FF_INITSTATE_SUCCESSFUL; \ - return &data; - -#define FF_LIBRARY_DATA_LOAD_ERROR \ - { \ - dlclose(libraryHandle); \ - initState = FF_INITSTATE_FAILED; \ - return NULL; \ - } - #ifdef FF_HAVE_GIO #include @@ -88,32 +49,39 @@ typedef struct GSettingsData FF_LIBRARY_SYMBOL(g_settings_schema_source_get_default) GSettingsSchemaSource* schemaSource; GVariantGetters variantGetters; + + bool inited; } GSettingsData; static const GSettingsData* getGSettingsData(void) { - FF_LIBRARY_DATA_LOAD_INIT(GSettingsData, instance.config.library.libGIO, "libgio-2.0" FF_LIBRARY_EXTENSION, 1); - - FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_schema_source_lookup) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_schema_has_key) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_new_full) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_get_value) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_get_user_value) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_get_default_value) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_schema_source_get_default) - - #define data data.variantGetters - FF_LIBRARY_DATA_LOAD_SYMBOL(g_variant_dup_string) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_variant_get_boolean) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_variant_get_int32) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_variant_unref); - #undef data - - data.schemaSource = data.ffg_settings_schema_source_get_default(); - if(data.schemaSource == NULL) - FF_LIBRARY_DATA_LOAD_ERROR - - FF_LIBRARY_DATA_LOAD_RETURN + static GSettingsData data; + + if (!data.inited) + { + data.inited = true; + FF_LIBRARY_LOAD(libgsettings, &instance.config.library.libGIO, NULL, "libgio-2.0" FF_LIBRARY_EXTENSION, 1); + FF_LIBRARY_LOAD_SYMBOL_VAR(libgsettings, data, g_settings_schema_source_lookup, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libgsettings, data, g_settings_schema_has_key, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libgsettings, data, g_settings_new_full, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libgsettings, data, g_settings_get_value, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libgsettings, data, g_settings_get_user_value, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libgsettings, data, g_settings_get_default_value, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libgsettings, data, g_settings_schema_source_get_default, NULL) + + FF_LIBRARY_LOAD_SYMBOL_VAR(libgsettings, data.variantGetters, g_variant_dup_string, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libgsettings, data.variantGetters, g_variant_get_boolean, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libgsettings, data.variantGetters, g_variant_get_int32, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libgsettings, data.variantGetters, g_variant_unref, NULL); + + data.schemaSource = data.ffg_settings_schema_source_get_default(); + if (data.schemaSource) + libgsettings = NULL; + } + if(!data.schemaSource) + return NULL; + + return &data; } FFvariant ffSettingsGetGSettings(const char* schemaName, const char* path, const char* key, FFvarianttype type) @@ -161,27 +129,34 @@ typedef struct DConfData FF_LIBRARY_SYMBOL(dconf_client_new) GVariantGetters variantGetters; DConfClient* client; + + bool inited; } DConfData; static const DConfData* getDConfData(void) { - FF_LIBRARY_DATA_LOAD_INIT(DConfData, instance.config.library.libDConf, "libdconf" FF_LIBRARY_EXTENSION, 2); - - FF_LIBRARY_DATA_LOAD_SYMBOL(dconf_client_read_full) - FF_LIBRARY_DATA_LOAD_SYMBOL(dconf_client_new) + static DConfData data; - #define data data.variantGetters - FF_LIBRARY_DATA_LOAD_SYMBOL(g_variant_dup_string) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_variant_get_boolean) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_variant_get_int32) - FF_LIBRARY_DATA_LOAD_SYMBOL(g_variant_unref) - #undef data - - data.client = data.ffdconf_client_new(); - if(data.client == NULL) - FF_LIBRARY_DATA_LOAD_ERROR + if (!data.inited) + { + data.inited = true; + + FF_LIBRARY_LOAD(libdconf, &instance.config.library.libDConf, NULL, "libdconf" FF_LIBRARY_EXTENSION, 2); + FF_LIBRARY_LOAD_SYMBOL_VAR(libdconf, data, dconf_client_read_full, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libdconf, data, dconf_client_new, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libdconf, data.variantGetters, g_variant_dup_string, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libdconf, data.variantGetters, g_variant_get_boolean, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libdconf, data.variantGetters, g_variant_get_int32, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libdconf, data.variantGetters, g_variant_unref, NULL) + + data.client = data.ffdconf_client_new(); + if (data.client) + libdconf = NULL; + } + if(!data.client) + return NULL; - FF_LIBRARY_DATA_LOAD_RETURN + return &data; } FFvariant ffSettingsGetDConf(const char* key, FFvarianttype type) @@ -232,23 +207,35 @@ typedef struct XFConfData FF_LIBRARY_SYMBOL(xfconf_channel_get_bool) FF_LIBRARY_SYMBOL(xfconf_channel_get_int) FF_LIBRARY_SYMBOL(xfconf_init) + + bool inited; } XFConfData; static const XFConfData* getXFConfData(void) { - FF_LIBRARY_DATA_LOAD_INIT(XFConfData, instance.config.library.libXFConf, "libxfconf-0" FF_LIBRARY_EXTENSION, 4); + static XFConfData data; - FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_channel_get) - FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_channel_has_property) - FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_channel_get_string) - FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_channel_get_bool) - FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_channel_get_int) - FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_init) + if (!data.inited) + { + data.inited = true; + FF_LIBRARY_LOAD(libxfconf, &instance.config.library.libXFConf, NULL, "libxfconf-0" FF_LIBRARY_EXTENSION, 4); + + FF_LIBRARY_LOAD_SYMBOL_VAR(libxfconf, data, xfconf_channel_get, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libxfconf, data, xfconf_channel_has_property, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libxfconf, data, xfconf_channel_get_string, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libxfconf, data, xfconf_channel_get_bool, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libxfconf, data, xfconf_channel_get_int, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libxfconf, data, xfconf_init, NULL) + if(!data.ffxfconf_init(NULL)) + data.ffxfconf_init = NULL; + else + libxfconf = NULL; + } - if(data.ffxfconf_init(NULL) == false) - FF_LIBRARY_DATA_LOAD_ERROR + if(!data.ffxfconf_init) + return NULL; - FF_LIBRARY_DATA_LOAD_RETURN + return &data; } FFvariant ffSettingsGetXFConf(const char* channelName, const char* propertyName, FFvarianttype type) @@ -294,22 +281,33 @@ typedef struct SQLiteData FF_LIBRARY_SYMBOL(sqlite3_column_text) FF_LIBRARY_SYMBOL(sqlite3_finalize) FF_LIBRARY_SYMBOL(sqlite3_close) + + bool inited; } SQLiteData; static const SQLiteData* getSQLiteData(void) { - FF_LIBRARY_DATA_LOAD_INIT(SQLiteData, instance.config.library.libSQLite3, "libsqlite3" FF_LIBRARY_EXTENSION, 1); - - FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_open_v2) - FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_prepare_v2) - FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_step) - FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_data_count) - FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_column_int) - FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_column_text) - FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_finalize) - FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_close) - - FF_LIBRARY_DATA_LOAD_RETURN + static SQLiteData data; + + if (!data.inited) + { + data.inited = true; + FF_LIBRARY_LOAD(libsqlite, &instance.config.library.libSQLite3, NULL, "libsqlite3" FF_LIBRARY_EXTENSION, 1); + FF_LIBRARY_LOAD_SYMBOL_VAR(libsqlite, data, sqlite3_open_v2, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libsqlite, data, sqlite3_prepare_v2, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libsqlite, data, sqlite3_step, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libsqlite, data, sqlite3_data_count, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libsqlite, data, sqlite3_column_int, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libsqlite, data, sqlite3_column_text, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libsqlite, data, sqlite3_finalize, NULL) + FF_LIBRARY_LOAD_SYMBOL_VAR(libsqlite, data, sqlite3_close, NULL) + libsqlite = NULL; + } + + if (!data.ffsqlite3_close) + return NULL; + + return &data; } int ffSettingsGetSQLite3Int(const char* dbPath, const char* query) diff --git a/src/data/help.json b/src/data/help.json index fa9670f517..348d426e35 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -457,6 +457,14 @@ "type": "color" } }, + { + "long": "color-separator", + "desc": "Set the color of the key-value separator", + "remark": "See `-h color` for the list of available colors", + "arg": { + "type": "color" + } + }, { "long": "color", "desc": "Set the color of both the keys and title", @@ -534,10 +542,11 @@ "desc": "Set the percentage output type", "remark": [ "1 for percentage number", - "2 for bar", + "2 for multi-color bar", "3 for both", "6 for bar only", - "9 for colored number" + "9 for colored number", + "10 for monochrome bar" ], "arg": { "type": "num", diff --git a/src/data/help_format.txt b/src/data/help_format.txt index 4d135eae28..2939abbdb1 100644 --- a/src/data/help_format.txt +++ b/src/data/help_format.txt @@ -4,6 +4,10 @@ For example the format string "Values: {1} ({2})", with the values "First" and " The format string can contain placeholders in any order and have multiple occurrences. To include spaces when setting from the command line, surround the whole string with double quotes ("). +In 2.14.0 or newer, the value indices can be meaningful named tags. +For example: "--title-format '{user-name-colored}{at-symbol-colored}{host-name-colored}'" is equivalent to "--title-format '{6}{7}{8}'" +See "fastfetch -h title-format" for all supported tags. + If the value index is missing, meaning the placeholder is "{}", an internal counter sets the value index. This means that the format string "Values: {1} ({2})" is equivalent to "Values: {} ({})". Note that this counter only counts empty placeholders, so the format string "{2} {} {}" will contain the second value, then the first, and then the second again. @@ -16,7 +20,7 @@ To only print something if a variable is set, use "{?} ... {?}". For example, to only print a second value if it is set, use "{?2} Second value: {2}{?}". If a "{?}" is found without an opener, it is printed as is. -To only print something if a variable is not set, do the same as with if, just replace every '?' with a '!'. +To only print something if a variable is not set, do the same as with if, just replace every '?' with a '/'. For example to print a fallback for a second value if it is not set, use "{?2}{2}{?}{/2}Second value fallback{/}". To stop formatting at any point in the format string, use "{-}". @@ -24,7 +28,7 @@ To stop formatting at any point in the format string, use "{-}". To print something with color, start a placeholder with a '#' and then the linux terminal color encoding. "\033[" at the start, and an 'm' at the end is automatically added, so don't do that. A "{#}" is equivalent to a "{#0}" and resets everything to normal. -For example to print something pink and underline, use "{#4;35}...{#}". +For example to print something pink and underline, use "{#4;35}...{#}". "{#underline_magenta}" is also supported. See `fastfetch -h color` for detail. Information about what the numbers mean can be found here: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters. Which escape codes are supported and how they look is defined by your terminal. diff --git a/src/detection/brightness/brightness_linux.c b/src/detection/brightness/brightness_linux.c index c1885260d4..de105504be 100644 --- a/src/detection/brightness/brightness_linux.c +++ b/src/detection/brightness/brightness_linux.c @@ -4,7 +4,6 @@ #include "util/stringUtils.h" #include -#include #include static const char* detectWithBacklight(FFlist* result) @@ -58,14 +57,14 @@ static const char* detectWithBacklight(FFlist* result) { ffStrbufSubstrBeforeLastC(&brightness->name, '/'); // remove "/edid" ffStrbufSubstrAfterLastC(&brightness->name, '/'); // try getting DRM connector name - if(isdigit(brightness->name.chars[0])) + if(ffCharIsDigit(brightness->name.chars[0])) { // PCI address or some unknown path, give up ffStrbufSetS(&brightness->name, entry->d_name); } else { - if(ffStrbufStartsWithS(&brightness->name, "card") && isdigit(brightness->name.chars[4])) + if(ffStrbufStartsWithS(&brightness->name, "card") && ffCharIsDigit(brightness->name.chars[4])) ffStrbufSubstrAfterFirstC(&brightness->name, '-'); } } @@ -109,14 +108,19 @@ static const char* detectWithDdcci(FFBrightnessOptions* options, FFlist* result) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libddcutil, ddca_free_any_vcp_value) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libddcutil, ddca_close_display) + #ifndef FF_DISABLE_DLOPEN __typeof__(&ddca_init) ffddca_init = dlsym(libddcutil, "ddca_init"); if (ffddca_init) + #else + __typeof__(&ddca_init) ffddca_init = ddca_init; + #endif { FF_SUPPRESS_IO(); // Ref: https://github.com/rockowitz/ddcutil/issues/344 if (ffddca_init(NULL, -1 /*DDCA_SYSLOG_NOT_SET*/, 1 /*DDCA_INIT_OPTIONS_DISABLE_CONFIG_FILE*/) < 0) return "ddca_init() failed"; } + #ifndef FF_DISABLE_DLOPEN else { __typeof__(&ddca_set_default_sleep_multiplier) ffddca_set_default_sleep_multiplier = dlsym(libddcutil, "ddca_set_default_sleep_multiplier"); @@ -125,6 +129,7 @@ static const char* detectWithDdcci(FFBrightnessOptions* options, FFlist* result) libddcutil = NULL; // Don't dlclose libddcutil. See https://github.com/rockowitz/ddcutil/issues/330 } + #endif FF_AUTO_FREE DDCA_Display_Info_List* infoList = NULL; if (ffddca_get_display_info_list2(false, &infoList) < 0) diff --git a/src/detection/cpu/cpu_linux.c b/src/detection/cpu/cpu_linux.c index ac5c895e48..53aa739f1d 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -9,7 +9,6 @@ #include #include #include -#include #ifdef __ANDROID__ #include "common/settings.h" @@ -139,7 +138,7 @@ static bool detectFrequency(FFCPUResult* cpu, const FFCPUOptions* options) struct dirent* entry; while ((entry = readdir(dir)) != NULL) { - if (ffStrStartsWith(entry->d_name, "policy") && isdigit(entry->d_name[strlen("policy")])) + if (ffStrStartsWith(entry->d_name, "policy") && ffCharIsDigit(entry->d_name[strlen("policy")])) { ffStrbufAppendS(&path, entry->d_name); uint32_t fbase = getFrequency(&path, "/base_frequency", NULL, &buffer); diff --git a/src/detection/de/de_linux.c b/src/detection/de/de_linux.c index 6c456495e2..ab6a93b7c6 100644 --- a/src/detection/de/de_linux.c +++ b/src/detection/de/de_linux.c @@ -106,11 +106,16 @@ static void getMate(FFstrbuf* result, FFDEOptions* options) static const char* getXfce4ByLib(FFstrbuf* result) { +#ifndef FF_DISABLE_DLOPEN const char* xfce_version_string(void); // from `xfce4/libxfce4util/xfce-misutils.h FF_LIBRARY_LOAD(xfce4util, NULL, "dlopen libxfce4util" FF_LIBRARY_EXTENSION "failed", "libxfce4util" FF_LIBRARY_EXTENSION, 7); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xfce4util, xfce_version_string); ffStrbufSetS(result, ffxfce_version_string()); return NULL; +#else + FF_UNUSED(result); + return "dlopen is disabled"; +#endif } static void getXFCE4(FFstrbuf* result, FFDEOptions* options) diff --git a/src/detection/displayserver/linux/drm.c b/src/detection/displayserver/linux/drm.c index 3710f1db27..3a2ed89e0d 100644 --- a/src/detection/displayserver/linux/drm.c +++ b/src/detection/displayserver/linux/drm.c @@ -194,7 +194,7 @@ static const char* drmGetNameByConnId(uint32_t connId, FFstrbuf* name) static const char* drmConnectLibdrm(FFDisplayServerResult* result) { - FF_LIBRARY_LOAD(libdrm, &instance.config.library.libdrm, "dlopen(libdrm)" FF_LIBRARY_EXTENSION " failed", "libdrm" FF_LIBRARY_EXTENSION, 2) + FF_LIBRARY_LOAD(libdrm, &instance.config.library.libdrm, "dlopen libdrm" FF_LIBRARY_EXTENSION " failed", "libdrm" FF_LIBRARY_EXTENSION, 2) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, drmGetDevices) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, drmModeGetResources) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libdrm, drmModeGetConnectorCurrent) diff --git a/src/detection/displayserver/linux/wmde.c b/src/detection/displayserver/linux/wmde.c index 64f16db031..4ee96cd489 100644 --- a/src/detection/displayserver/linux/wmde.c +++ b/src/detection/displayserver/linux/wmde.c @@ -4,7 +4,6 @@ #include "util/mallocHelper.h" #include -#include #include #include @@ -320,7 +319,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result) while((dirent = readdir(procdir)) != NULL) { //Match only folders starting with a number (the pid folders) - if(dirent->d_type != DT_DIR || !isdigit(dirent->d_name[0])) + if(dirent->d_type != DT_DIR || !ffCharIsDigit(dirent->d_name[0])) continue; ffStrbufAppendS(&procPath, dirent->d_name); diff --git a/src/detection/editor/editor.c b/src/detection/editor/editor.c index 00a30cbbd2..be6ee4a9cc 100644 --- a/src/detection/editor/editor.c +++ b/src/detection/editor/editor.c @@ -4,13 +4,27 @@ #include +#ifdef _WIN32 +#include +static inline char* realpath(const char* restrict file_name, char* restrict resolved_name) +{ + return _fullpath(resolved_name, file_name, _MAX_PATH); +} +#endif + const char* ffDetectEditor(FFEditorResult* result) { ffStrbufSetS(&result->name, getenv("VISUAL")); - if (result->name.length == 0) + if (result->name.length) + result->type = "Visual"; + else + { ffStrbufSetS(&result->name, getenv("EDITOR")); - if (result->name.length == 0) - return "$VISUAL or $EDITOR not set"; + if (result->name.length) + result->type = "Editor"; + else + return "$VISUAL or $EDITOR not set"; + } #ifndef _WIN32 if (result->name.chars[0] != '/') @@ -22,6 +36,21 @@ const char* ffDetectEditor(FFEditorResult* result) }) != NULL || result->path.length == 0) return NULL; } + #else + if (!(result->name.length > 3 && ffCharIsEnglishAlphabet(result->name.chars[0]) && result->name.chars[1] == ':' && result->name.chars[2] == '\\')) + { + char buf[32]; + uint32_t len = GetSystemDirectoryA(buf, sizeof(buf)); + if (len < strlen("C:\\WINDOWS\\system32")) return NULL; + strncpy(buf + len, "\\where.exe", sizeof(buf) - len); + if (ffProcessAppendStdOut(&result->path, (char* const[]){ + buf, + result->name.chars, + NULL, + }) != NULL || result->path.length == 0) + return NULL; + } + #endif else ffStrbufSet(&result->path, &result->name); @@ -30,29 +59,45 @@ const char* ffDetectEditor(FFEditorResult* result) return NULL; ffStrbufSetS(&result->path, buf); - const char* exe = &result->path.chars[ffStrbufLastIndexC(&result->path, '/')]; - if (!*exe) return NULL; - ++exe; - result->exe = exe; + + { + uint32_t index = ffStrbufLastIndexC(&result->path, + #ifndef _WIN32 + '/' + #else + '\\' + #endif + ); + if (index == result->path.length) + return NULL; + ffStrbufSetS(&result->exe, &result->path.chars[index + 1]); + if (!result->exe.length) + return NULL; + + #ifdef _WIN32 + if (ffStrbufEndsWithS(&result->exe, ".exe")) + ffStrbufSubstrBefore(&result->exe, result->exe.length - 4); + #endif + } const char* param = NULL; if ( - ffStrEquals(exe, "nano") || - ffStrEquals(exe, "vim") || - ffStrEquals(exe, "nvim") || - ffStrEquals(exe, "micro") || - ffStrEquals(exe, "emacs") || - ffStrStartsWith(exe, "emacs-") || // emacs-29.3 - ffStrEquals(exe, "hx") || - ffStrEquals(exe, "code") || - ffStrEquals(exe, "sublime_text") + ffStrbufEqualS(&result->exe, "nano") || + ffStrbufEqualS(&result->exe, "vim") || + ffStrbufEqualS(&result->exe, "nvim") || + ffStrbufEqualS(&result->exe, "micro") || + ffStrbufEqualS(&result->exe, "emacs") || + ffStrbufStartsWithS(&result->exe, "emacs-") || // emacs-29.3 + ffStrbufEqualS(&result->exe, "hx") || + ffStrbufEqualS(&result->exe, "code") || + ffStrbufEqualS(&result->exe, "sublime_text") ) param = "--version"; else if ( - ffStrEquals(exe, "kak") || - ffStrEquals(exe, "pico") + ffStrbufEqualS(&result->exe, "kak") || + ffStrbufEqualS(&result->exe, "pico") ) param = "-version"; else if ( - ffStrEquals(exe, "ne") + ffStrbufEqualS(&result->exe, "ne") ) param = "-h"; else return NULL; @@ -69,7 +114,7 @@ const char* ffDetectEditor(FFEditorResult* result) for (uint32_t iStart = 0; iStart < result->version.length; ++iStart) { char c = result->version.chars[iStart]; - if (c >= '0' && c <= '9') + if (ffCharIsDigit(c)) { for (uint32_t iEnd = iStart + 1; iEnd < result->version.length; ++iEnd) { @@ -85,7 +130,6 @@ const char* ffDetectEditor(FFEditorResult* result) break; } } - #endif return NULL; } diff --git a/src/detection/editor/editor.h b/src/detection/editor/editor.h index a90e5556a4..38d63aebe2 100644 --- a/src/detection/editor/editor.h +++ b/src/detection/editor/editor.h @@ -4,8 +4,9 @@ typedef struct FFEditorResult { + const char* type; FFstrbuf name; - const char* exe; + FFstrbuf exe; FFstrbuf path; FFstrbuf version; } FFEditorResult; diff --git a/src/detection/gamepad/gamepad_linux.c b/src/detection/gamepad/gamepad_linux.c index 791412a70d..50d04df5ef 100644 --- a/src/detection/gamepad/gamepad_linux.c +++ b/src/detection/gamepad/gamepad_linux.c @@ -2,9 +2,6 @@ #include "common/io/io.h" #include "util/stringUtils.h" -#include -#include - static void detectGamepad(FFlist* devices, FFstrbuf* name, FFstrbuf* path) { uint32_t baseLen = path->length; @@ -71,7 +68,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) { if (!ffStrStartsWith(entry->d_name, "js")) continue; - if (!isdigit(entry->d_name[2])) + if (!ffCharIsDigit(entry->d_name[2])) continue; ffStrbufAppendS(&path, entry->d_name); diff --git a/src/detection/gpu/gpu_nvidia.c b/src/detection/gpu/gpu_nvidia.c index 42b1cf977b..84a7938004 100644 --- a/src/detection/gpu/gpu_nvidia.c +++ b/src/detection/gpu/gpu_nvidia.c @@ -19,6 +19,8 @@ struct FFNvmlData { const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName) { +#ifndef FF_DISABLE_DLOPEN + if (!nvmlData.inited) { nvmlData.inited = true; @@ -127,4 +129,11 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR } return NULL; + +#else + + FF_UNUSED(cond, result, soName); + return "dlopen is disabled"; + +#endif } diff --git a/src/detection/gpu/gpu_wsl.cpp b/src/detection/gpu/gpu_wsl.cpp index 22bab850b3..eb7ed5b17c 100644 --- a/src/detection/gpu/gpu_wsl.cpp +++ b/src/detection/gpu/gpu_wsl.cpp @@ -31,8 +31,13 @@ const char* ffGPUDetectByDirectX(FF_MAYBE_UNUSED const FFGPUOptions* options, FF FF_LIBRARY_LOAD(libdxcore, nullptr, "dlopen libdxcore.so failed. Make sure WSLg is enabled", "/usr/lib/wsl/lib/libdxcore" FF_LIBRARY_EXTENSION, 4) // DXCoreCreateAdapterFactory is a reloaded function, so we can't use FF_LIBRARY_LOAD_SYMBOL_MESSAGE here typedef HRESULT (*DXCoreCreateAdapterFactory_t)(REFIID riid, void** ppvFactory); + +#ifndef FF_DISABLE_DLOPEN auto ffDXCoreCreateAdapterFactory = (DXCoreCreateAdapterFactory_t) dlsym(libdxcore, "DXCoreCreateAdapterFactory"); if(ffDXCoreCreateAdapterFactory == nullptr) return "dlsym DXCoreCreateAdapterFactory failed"; +#else + auto ffDXCoreCreateAdapterFactory = (DXCoreCreateAdapterFactory_t) DXCoreCreateAdapterFactory; +#endif IDXCoreAdapterFactory *factory = nullptr; diff --git a/src/detection/initsystem/initsystem.h b/src/detection/initsystem/initsystem.h new file mode 100644 index 0000000000..07f79ff742 --- /dev/null +++ b/src/detection/initsystem/initsystem.h @@ -0,0 +1,13 @@ +#pragma once + +#include "fastfetch.h" + +typedef struct FFInitSystemResult +{ + FFstrbuf name; + FFstrbuf exe; + FFstrbuf version; + uint32_t pid; +} FFInitSystemResult; + +const char* ffDetectInitSystem(FFInitSystemResult* result); diff --git a/src/detection/initsystem/initsystem_linux.c b/src/detection/initsystem/initsystem_linux.c new file mode 100644 index 0000000000..b518db21d4 --- /dev/null +++ b/src/detection/initsystem/initsystem_linux.c @@ -0,0 +1,57 @@ +#include "initsystem.h" +#include "common/processing.h" + +const char* ffDetectInitSystem(FFInitSystemResult* result) +{ + const char* error = ffProcessGetBasicInfoLinux((int) result->pid, &result->name, NULL, NULL); + if (error) return error; + + const char* _; + // In linux /proc/1/exe is not readable + ffProcessGetInfoLinux((int) result->pid, &result->name, &result->exe, &_, NULL); + if (result->exe.chars[0] == '/') + { + // In some old system, /sbin/init is a symlink + char buf[PATH_MAX]; + if (realpath(result->exe.chars, buf)) + ffStrbufSetS(&result->exe, buf); + } + + if (ffStrbufEqualS(&result->name, "systemd")) + { + if (ffProcessAppendStdOut(&result->version, (char* const[]) { + ffStrbufEndsWithS(&result->exe, "/systemd") ? result->exe.chars : "systemctl", // use exe path in case users have another systemd installed + "--version", + NULL, + }) == NULL && result->version.length) + { + uint32_t iStart = ffStrbufFirstIndexC(&result->version, '('); + if (iStart < result->version.length) + { + uint32_t iEnd = ffStrbufNextIndexC(&result->version, iStart + 1, ')'); + ffStrbufSubstrBefore(&result->version, iEnd); + ffStrbufSubstrAfter(&result->version, iStart); + } + } + } + else if (ffStrbufEqualS(&result->name, "launchd")) + { + if (ffProcessAppendStdOut(&result->version, (char* const[]) { + "/bin/launchctl", + "version", + NULL, + }) == NULL && result->version.length) + { + uint32_t iStart = ffStrbufFirstIndexS(&result->version, "Version "); + if (iStart < result->version.length) + { + iStart += strlen("Version"); + uint32_t iEnd = ffStrbufNextIndexC(&result->version, iStart + 1, ':'); + ffStrbufSubstrBefore(&result->version, iEnd); + ffStrbufSubstrAfter(&result->version, iStart); + } + } + } + + return NULL; +} diff --git a/src/detection/initsystem/initsystem_nosupport.c b/src/detection/initsystem/initsystem_nosupport.c new file mode 100644 index 0000000000..b22a6b33d2 --- /dev/null +++ b/src/detection/initsystem/initsystem_nosupport.c @@ -0,0 +1,6 @@ +#include "initsystem.h" + +const char* ffDetectInitSystem(FF_MAYBE_UNUSED FFInitSystemResult* result) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/os/os_linux.c b/src/detection/os/os_linux.c index 89c6faf4c1..a4ea2f5cf1 100644 --- a/src/detection/os/os_linux.c +++ b/src/detection/os/os_linux.c @@ -157,6 +157,12 @@ static bool detectDebianDerived(FFOSResult* result) ffStrbufSetNS(&result->versionID, versionEnd - versionStart, result->prettyName.chars + versionStart); return true; } + else if (ffStrbufStartsWithS(&result->name, "Loc-OS")) + { + ffStrbufSetS(&result->id, "locos"); + ffStrbufSetS(&result->idLike, "debian"); + return true; + } else if (ffPathExists("/usr/bin/pveversion", FF_PATHTYPE_FILE)) { ffStrbufSetS(&result->id, "pve"); diff --git a/src/detection/os/os_windows.cpp b/src/detection/os/os_windows.cpp index bd442da7da..8734f74c17 100644 --- a/src/detection/os/os_windows.cpp +++ b/src/detection/os/os_windows.cpp @@ -4,6 +4,7 @@ extern "C" { } #include "util/windows/unicode.hpp" #include "util/windows/wmi.hpp" +#include "util/stringUtils.h" static const char* getOsNameByWmi(FFstrbuf* osName) { @@ -73,8 +74,8 @@ void ffDetectOSImpl(FFOSResult* os) if(ffStrbufEndsWithC(&os->prettyName, 'r')) { if(os->variant.chars[0] == 'R' && - isdigit(os->variant.chars[1]) && - (os->variant.chars[2] == '\0' || os->variant.chars[2] == ' ')) + ffCharIsDigit(os->variant.chars[1]) && + (os->variant.chars[2] == '\0' || os->variant.chars[2] == ' ')) { ffStrbufAppendF(&os->version, " R%c", os->variant.chars[1]); ffStrbufSubstrAfter(&os->variant, strlen("Rx ") - 1); diff --git a/src/detection/packages/packages.h b/src/detection/packages/packages.h index 4e954b96af..fd0cbec0fb 100644 --- a/src/detection/packages/packages.h +++ b/src/detection/packages/packages.h @@ -14,6 +14,9 @@ typedef struct FFPackagesResult uint32_t eopkg; uint32_t flatpakSystem; uint32_t flatpakUser; + uint32_t guixHome; + uint32_t guixSystem; + uint32_t guixUser; uint32_t lpkg; uint32_t lpkgbuild; uint32_t nixDefault; diff --git a/src/detection/packages/packages_linux.c b/src/detection/packages/packages_linux.c index 5933c87c2e..e3178d0e62 100644 --- a/src/detection/packages/packages_linux.c +++ b/src/detection/packages/packages_linux.c @@ -141,11 +141,11 @@ static bool isValidNixPkg(FFstrbuf* pkg) switch (state) { case START: - if (c >= '0' && c <= '9') + if (ffCharIsDigit(c)) state = DIGIT; break; case DIGIT: - if (c >= '0' && c <= '9') + if (ffCharIsDigit(c)) continue; if (c == '.') state = DOT; @@ -153,7 +153,7 @@ static bool isValidNixPkg(FFstrbuf* pkg) state = START; break; case DOT: - if (c >= '0' && c <= '9') + if (ffCharIsDigit(c)) state = MATCH; else state = START; @@ -408,6 +408,39 @@ static uint32_t getAM(FFstrbuf* baseDir) return result; } + +static uint32_t getGuixPackagesImpl(char* path) +{ + FF_STRBUF_AUTO_DESTROY output = ffStrbufCreateA(1024); + + ffProcessAppendStdOut(&output, (char* const[]) { + "guix", + "package", + "-p", + path, + "-I", + NULL + }); + + + //Each package is a new line in the output. + // If at least one line is found, add 1 for the last line. + uint32_t count = ffStrbufCountC(&output, '\n'); + if(count > 0) + count++; + + return count; +} + +static uint32_t getGuixPackages(FFstrbuf* baseDir, const char* dirname) +{ + uint32_t baseDirLength = baseDir->length; + ffStrbufAppendS(baseDir, dirname); + uint32_t num_elements = getGuixPackagesImpl(baseDir->chars); + ffStrbufSubstrBefore(baseDir, baseDirLength); + return num_elements; +} + static void getPackageCounts(FFstrbuf* baseDir, FFPackagesResult* packageCounts, FFPackagesOptions* options) { if (!(options->disabled & FF_PACKAGES_FLAG_APK_BIT)) packageCounts->apk += getNumStrings(baseDir, "/lib/apk/db/installed", "C:Q"); @@ -436,6 +469,10 @@ static void getPackageCounts(FFstrbuf* baseDir, FFPackagesResult* packageCounts, if (!(options->disabled & FF_PACKAGES_FLAG_OPKG_BIT)) packageCounts->opkg += getNumStrings(baseDir, "/usr/lib/opkg/status", "Package:"); // openwrt if (!(options->disabled & FF_PACKAGES_FLAG_AM_BIT)) packageCounts->am = getAM(baseDir); if (!(options->disabled & FF_PACKAGES_FLAG_SORCERY_BIT)) packageCounts->sorcery += getNumStrings(baseDir, "/var/state/sorcery/packages", ":installed:"); + if (!(options->disabled & FF_PACKAGES_FLAG_GUIX_BIT)) + { + packageCounts->guixSystem += getGuixPackages(baseDir, "/run/current-system/profile"); + } } static void getPackageCountsRegular(FFstrbuf* baseDir, FFPackagesResult* packageCounts, FFPackagesOptions* options) @@ -532,6 +569,12 @@ void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options) result->nixUser += getNixPackages(&stateDir, "nix/profile"); } + if (!(options->disabled & FF_PACKAGES_FLAG_GUIX_BIT)) + { + result->guixUser += getGuixPackages(&baseDir, ".guix-profile"); + result->guixHome += getGuixPackages(&baseDir, ".guix-home/profile"); + } + if (!(options->disabled & FF_PACKAGES_FLAG_FLATPAK_BIT)) result->flatpakUser = getFlatpak(&baseDir, "/.local/share/flatpak"); } diff --git a/src/detection/processes/processes_linux.c b/src/detection/processes/processes_linux.c index cff71038c3..25e3a84afd 100644 --- a/src/detection/processes/processes_linux.c +++ b/src/detection/processes/processes_linux.c @@ -1,8 +1,7 @@ #include "processes.h" #include "common/io/io.h" - -#include +#include "util/stringUtils.h" const char* ffDetectProcesses(uint32_t* result) { @@ -15,7 +14,7 @@ const char* ffDetectProcesses(uint32_t* result) struct dirent* entry; while ((entry = readdir(dir)) != NULL) { - if (entry->d_type == DT_DIR && isdigit(entry->d_name[0])) + if (entry->d_type == DT_DIR && ffCharIsDigit(entry->d_name[0])) ++num; } diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 77fd23c2ad..1d0cfc6fd7 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -4,18 +4,11 @@ #include "common/processing.h" #include "common/thread.h" #include "util/stringUtils.h" -#include "util/mallocHelper.h" #include #include #include -#if defined(__FreeBSD__) || defined(__APPLE__) - #include - #include - #include -#endif - static void setExeName(FFstrbuf* exe, const char** exeName) { assert(exe->length > 0); @@ -24,197 +17,8 @@ static void setExeName(FFstrbuf* exe, const char** exeName) *exeName = exe->chars + lastSlashIndex + 1; } -static void getProcessInformation(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath) -{ - assert(processName->length > 0); - ffStrbufClear(exe); - - #ifdef __linux__ - - char filePath[64]; - snprintf(filePath, sizeof(filePath), "/proc/%d/cmdline", (int)pid); - - if(ffAppendFileBuffer(filePath, exe)) - { - ffStrbufTrimRightSpace(exe); - ffStrbufRecalculateLength(exe); //Trim the arguments - ffStrbufTrimLeft(exe, '-'); //Login shells start with a dash - } - - snprintf(filePath, sizeof(filePath), "/proc/%d/exe", (int)pid); - ffStrbufEnsureFixedLengthFree(exePath, PATH_MAX); - ssize_t length = readlink(filePath, exePath->chars, exePath->allocated - 1); - if (length > 0) // doesn't contain trailing NUL - { - exePath->chars[length] = '\0'; - exePath->length = (uint32_t) length; - } - - #elif defined(__APPLE__) - - size_t len = 0; - int mibs[] = { CTL_KERN, KERN_PROCARGS2, pid }; - if (sysctl(mibs, sizeof(mibs) / sizeof(*mibs), NULL, &len, NULL, 0) == 0) - { - #ifndef MAC_OS_X_VERSION_10_15 - //don't know why if don't let len longer, proArgs2 and len will change during the following sysctl() in old MacOS version. - len++; - #endif - FF_AUTO_FREE char* const procArgs2 = malloc(len); - if (sysctl(mibs, sizeof(mibs) / sizeof(*mibs), procArgs2, &len, NULL, 0) == 0) - { - // https://gist.github.com/nonowarn/770696#file-getargv-c-L46 - uint32_t argc = *(uint32_t*) procArgs2; - const char* realExePath = procArgs2 + sizeof(argc); - - const char* arg0 = memchr(realExePath, '\0', len - (size_t) (realExePath - procArgs2)); - ffStrbufSetNS(exePath, (uint32_t) (arg0 - realExePath), realExePath); - - do arg0++; while (*arg0 == '\0'); - assert(arg0 < procArgs2 + len); - if (*arg0 == '-') arg0++; // Login shells - - ffStrbufSetS(exe, arg0); - } - } - - #elif defined(__FreeBSD__) - - size_t size = ARG_MAX; - FF_AUTO_FREE char* args = malloc(size); - - static_assert(ARG_MAX > PATH_MAX, ""); - - if(sysctl( - (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid}, 4, - args, &size, - NULL, 0 - ) == 0) - ffStrbufSetNS(exePath, (uint32_t) (size - 1), args); - - size = ARG_MAX; - if(sysctl( - (int[]){CTL_KERN, KERN_PROC, KERN_PROC_ARGS, pid}, 4, - args, &size, - NULL, 0 - ) == 0) - { - char* arg0 = args; - size_t arg0Len = strlen(args); - if (size > arg0Len + 1) - { - char* p = (char*) memrchr(args, '/', arg0Len); - if (p) - { - p++; - if (ffStrStartsWith(p, "python")) // /usr/local/bin/python3.9 /home/carter/.local/bin/xonsh - { - arg0 += arg0Len + 1; - } - } - } - if (arg0[0] == '-') arg0++; - ffStrbufSetS(exe, arg0); - } - - #endif - - if(exe->length == 0) - ffStrbufSet(exe, processName); - - setExeName(exe, exeName); -} - -static const char* getProcessNameAndPpid(pid_t pid, char* name, pid_t* ppid, int32_t* tty) -{ - if (pid <= 0) - return "Invalid pid"; - - #ifdef __linux__ - - char statFilePath[64]; - snprintf(statFilePath, sizeof(statFilePath), "/proc/%d/stat", (int)pid); - char buf[PROC_FILE_BUFFSIZ]; - ssize_t nRead = ffReadFileData(statFilePath, sizeof(buf) - 1, buf); - if(nRead < 0) - return "ffReadFileData(statFilePath, sizeof(buf)-1, buf) failed"; - buf[nRead] = '\0'; - - *ppid = 0; - static_assert(sizeof(*ppid) == sizeof(int), ""); - - int tty_; - if( - sscanf(buf, "%*s (%255[^)]) %*c %d %*d %*d %d", name, ppid, &tty_) < 2 || //stat (comm) state ppid pgrp session tty - !ffStrSet(name) || - *ppid == 0 - ) - return "sscanf(stat) failed"; - - if (tty) - *tty = tty_ & 0xFF; - - #elif defined(__APPLE__) - - struct kinfo_proc proc; - size_t size = sizeof(proc); - if(sysctl( - (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PID, pid}, 4, - &proc, &size, - NULL, 0 - )) - return "sysctl(KERN_PROC_PID) failed"; - - *ppid = (pid_t)proc.kp_eproc.e_ppid; - strcpy(name, proc.kp_proc.p_comm); //trancated to 16 chars - if (tty) - { - *tty = ((proc.kp_eproc.e_tdev >> 24) & 0xFF) == 0x10 - ? proc.kp_eproc.e_tdev & 0xFFFFFF - : -1; - } - - #elif defined(__FreeBSD__) - - struct kinfo_proc proc; - size_t size = sizeof(proc); - if(sysctl( - (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PID, pid}, 4, - &proc, &size, - NULL, 0 - )) - return "sysctl(KERN_PROC_PID) failed"; - - *ppid = (pid_t)proc.ki_ppid; - strcpy(name, proc.ki_comm); - if (tty) - { - if (proc.ki_tdev != NODEV && proc.ki_flag & P_CONTROLT) - { - const char* ttyName = devname(proc.ki_tdev, S_IFCHR); - if (ffStrStartsWith(ttyName, "pts/")) - *tty = (int32_t) strtol(ttyName + strlen("pts/"), NULL, 10); - else - *tty = -1; - } - else - *tty = -1; - } - - #else - - return "Unsupported platform"; - - #endif - - return NULL; -} - static pid_t getShellInfo(FFShellResult* result, pid_t pid) { - char name[256]; - name[0] = '\0'; - pid_t ppid = 0; int32_t tty = -1; @@ -227,35 +31,36 @@ static pid_t getShellInfo(FFShellResult* result, pid_t pid) userShellName = instance.state.platform.userShell.chars + index + 1; } - while (getProcessNameAndPpid(pid, name, &ppid, &tty) == NULL) + while (ffProcessGetBasicInfoLinux(pid, &result->processName, &ppid, &tty) == NULL) { - if (!ffStrEquals(userShellName, name)) + if (!ffStrbufEqualS(&result->processName, userShellName)) { //Common programs that are between terminal and own process, but are not the shell if( // tty < 0 || //A shell should connect to a tty - ffStrEquals(name, "sh") || //This prevents us from detecting things like pipes and redirects, i hope nobody uses plain `sh` as shell - ffStrEquals(name, "sudo") || - ffStrEquals(name, "su") || - ffStrEquals(name, "strace") || - ffStrEquals(name, "sshd") || - ffStrEquals(name, "gdb") || - ffStrEquals(name, "lldb") || - ffStrEquals(name, "lldb-mi") || - ffStrEquals(name, "login") || - ffStrEquals(name, "ltrace") || - ffStrEquals(name, "perf") || - ffStrEquals(name, "guake-wrapped") || - ffStrEquals(name, "time") || - ffStrEquals(name, "hyfetch") || //when hyfetch uses fastfetch as backend - ffStrEquals(name, "clifm") || //https://github.com/leo-arch/clifm/issues/289 - ffStrEquals(name, "valgrind") || - ffStrContainsIgnCase(name, "debug") || - ffStrContainsIgnCase(name, "not-found") || - ffStrEndsWith(name, ".sh") + ffStrbufEqualS(&result->processName, "sh") || //This prevents us from detecting things like pipes and redirects, i hope nobody uses plain `sh` as shell + ffStrbufEqualS(&result->processName, "sudo") || + ffStrbufEqualS(&result->processName, "su") || + ffStrbufEqualS(&result->processName, "strace") || + ffStrbufEqualS(&result->processName, "sshd") || + ffStrbufEqualS(&result->processName, "gdb") || + ffStrbufEqualS(&result->processName, "lldb") || + ffStrbufEqualS(&result->processName, "lldb-mi") || + ffStrbufEqualS(&result->processName, "login") || + ffStrbufEqualS(&result->processName, "ltrace") || + ffStrbufEqualS(&result->processName, "perf") || + ffStrbufEqualS(&result->processName, "guake-wrapped") || + ffStrbufEqualS(&result->processName, "time") || + ffStrbufEqualS(&result->processName, "hyfetch") || //when hyfetch uses fastfetch as backend + ffStrbufEqualS(&result->processName, "clifm") || //https://github.com/leo-arch/clifm/issues/289 + ffStrbufEqualS(&result->processName, "valgrind") || + ffStrbufContainS(&result->processName, "debug") || + ffStrbufContainS(&result->processName, "not-found") || + ffStrbufEndsWithS(&result->processName, ".sh") ) { pid = ppid; + ffStrbufClear(&result->processName); continue; } } @@ -263,8 +68,7 @@ static pid_t getShellInfo(FFShellResult* result, pid_t pid) result->pid = (uint32_t) pid; result->ppid = (uint32_t) ppid; result->tty = tty; - ffStrbufSetS(&result->processName, name); - getProcessInformation(pid, &result->processName, &result->exe, &result->exeName, &result->exePath); + ffProcessGetInfoLinux(pid, &result->processName, &result->exe, &result->exeName, &result->exePath); break; } return ppid; @@ -272,49 +76,47 @@ static pid_t getShellInfo(FFShellResult* result, pid_t pid) static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid) { - char name[256]; - name[0] = '\0'; - pid_t ppid = 0; - while (getProcessNameAndPpid(pid, name, &ppid, NULL) == NULL) + while (ffProcessGetBasicInfoLinux(pid, &result->processName, &ppid, NULL) == NULL) { //Known shells if ( - ffStrEquals(name, "sh") || - ffStrEquals(name, "ash") || - ffStrEquals(name, "bash") || - ffStrEquals(name, "zsh") || - ffStrEquals(name, "ksh") || - ffStrEquals(name, "mksh") || - ffStrEquals(name, "oksh") || - ffStrEquals(name, "csh") || - ffStrEquals(name, "tcsh") || - ffStrEquals(name, "fish") || - ffStrEquals(name, "dash") || - ffStrEquals(name, "pwsh") || - ffStrEquals(name, "nu") || - ffStrEquals(name, "git-shell") || - ffStrEquals(name, "elvish") || - ffStrEquals(name, "oil.ovm") || - ffStrEquals(name, "xonsh") || // works in Linux but not in macOS because kernel returns `Python` in this case - ffStrEquals(name, "login") || - ffStrEquals(name, "sshd") || - ffStrEquals(name, "clifm") || // https://github.com/leo-arch/clifm/issues/289 - ffStrEquals(name, "chezmoi") || // #762 + ffStrbufEqualS(&result->processName, "sh") || + ffStrbufEqualS(&result->processName, "ash") || + ffStrbufEqualS(&result->processName, "bash") || + ffStrbufEqualS(&result->processName, "zsh") || + ffStrbufEqualS(&result->processName, "ksh") || + ffStrbufEqualS(&result->processName, "mksh") || + ffStrbufEqualS(&result->processName, "oksh") || + ffStrbufEqualS(&result->processName, "csh") || + ffStrbufEqualS(&result->processName, "tcsh") || + ffStrbufEqualS(&result->processName, "fish") || + ffStrbufEqualS(&result->processName, "dash") || + ffStrbufEqualS(&result->processName, "pwsh") || + ffStrbufEqualS(&result->processName, "nu") || + ffStrbufEqualS(&result->processName, "git-shell") || + ffStrbufEqualS(&result->processName, "elvish") || + ffStrbufEqualS(&result->processName, "oil.ovm") || + ffStrbufEqualS(&result->processName, "xonsh") || // works in Linux but not in macOS because kernel returns `Python` in this case + ffStrbufEqualS(&result->processName, "login") || + ffStrbufEqualS(&result->processName, "sshd") || + ffStrbufEqualS(&result->processName, "clifm") || // https://github.com/leo-arch/clifm/issues/289 + ffStrbufEqualS(&result->processName, "chezmoi") || // #762 #ifdef __linux__ - ffStrStartsWith(name, "flatpak-") || // #707 + ffStrbufStartsWithS(&result->processName, "flatpak-") || // #707 #endif - ffStrEndsWith(name, ".sh") + ffStrbufEndsWithS(&result->processName, ".sh") ) { pid = ppid; + ffStrbufClear(&result->processName); continue; } #ifdef __APPLE__ // https://github.com/fastfetch-cli/fastfetch/discussions/501 - const char* pLeft = strstr(name, " ("); + const char* pLeft = strstr(result->processName.chars, " ("); if (pLeft) { pLeft += 2; @@ -324,7 +126,7 @@ static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid) for (; pLeft < pRight; ++pLeft) if (*pLeft < 'a' || *pLeft > 'z') break; - if (pLeft == pRight && getProcessNameAndPpid(ppid, name, &ppid, NULL) != NULL) + if (pLeft == pRight && ffProcessGetBasicInfoLinux(ppid, &result->processName, &ppid, NULL) != NULL) return 0; } } @@ -332,8 +134,7 @@ static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid) result->pid = (uint32_t) pid; result->ppid = (uint32_t) ppid; - ffStrbufSetS(&result->processName, name); - getProcessInformation(pid, &result->processName, &result->exe, &result->exeName, &result->exePath); + ffProcessGetInfoLinux(pid, &result->processName, &result->exe, &result->exeName, &result->exePath); break; } return ppid; @@ -347,11 +148,9 @@ static bool getTerminalInfoByPidEnv(FFTerminalResult* result, const char* pidEnv pid_t pid = (pid_t) strtol(envStr, NULL, 10); result->pid = (uint32_t) pid; - char name[256]; - if (getProcessNameAndPpid(pid, name, (pid_t*) &result->ppid, NULL) == NULL) + if (ffProcessGetBasicInfoLinux(pid, &result->processName, (pid_t*) &result->ppid, NULL) == NULL) { - ffStrbufSetS(&result->processName, name); - getProcessInformation(pid, &result->processName, &result->exe, &result->exeName, &result->exePath); + ffProcessGetInfoLinux(pid, &result->processName, &result->exe, &result->exeName, &result->exePath); return true; } diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index 7edfd0ef14..4470f22bc1 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -9,8 +9,6 @@ #include #include #include -#include -#include static bool getProductVersion(const wchar_t* filePath, FFstrbuf* version) { @@ -39,56 +37,13 @@ static bool getProductVersion(const wchar_t* filePath, FFstrbuf* version) return false; } -static bool getProcessInfo(uint32_t pid, uint32_t* ppid, FFstrbuf* pname, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath, bool* gui) -{ - FF_AUTO_CLOSE_FD HANDLE hProcess = pid == 0 - ? GetCurrentProcess() - : OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, TRUE, pid); - - if (gui) - *gui = GetGuiResources(hProcess, GR_GDIOBJECTS) > 0; - - if(ppid) - { - PROCESS_BASIC_INFORMATION info = {}; - ULONG size; - if(NT_SUCCESS(NtQueryInformationProcess(hProcess, ProcessBasicInformation, &info, sizeof(info), &size))) - { - assert(size == sizeof(info)); - *ppid = (uint32_t)info.InheritedFromUniqueProcessId; - } - else - return false; - } - if(exe) - { - DWORD bufSize = exe->allocated; - if(QueryFullProcessImageNameA(hProcess, 0, exe->chars, &bufSize)) - { - // We use full path here - // Querying command line of remote processes in Windows requires either WMI or ReadProcessMemory - exe->length = bufSize; - if (exePath) ffStrbufSet(exePath, exe); - } - else - return false; - } - if(pname && exeName) - { - *exeName = exe->chars + ffStrbufLastIndexC(exe, '\\') + 1; - ffStrbufSetS(pname, *exeName); - } - - return true; -} - bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version); static uint32_t getShellInfo(FFShellResult* result, uint32_t pid) { uint32_t ppid = 0; - while (pid != 0 && getProcessInfo(pid, &ppid, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL)) + while (pid != 0 && ffProcessGetInfoWindows(pid, &ppid, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL)) { ffStrbufSet(&result->prettyName, &result->processName); if(ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe")) @@ -183,7 +138,7 @@ static bool getTerminalFromEnv(FFTerminalResult* result) //ConEmu uint32_t pid = (uint32_t) strtoul(term, NULL, 10); result->pid = pid; - if(getProcessInfo(pid, NULL, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL)) + if(ffProcessGetInfoWindows(pid, NULL, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL)) { ffStrbufSet(&result->prettyName, &result->processName); if(ffStrbufEndsWithIgnCaseS(&result->prettyName, ".exe")) @@ -289,10 +244,17 @@ static bool detectDefaultTerminal(FFTerminalResult* result) static uint32_t getTerminalInfo(FFTerminalResult* result, uint32_t pid) { + if (getenv("MSYSTEM")) + { + // Don't try to detect terminals in MSYS shell + // It won't work because MSYS doesn't follow process tree of native Windows programs + return 0; + } + uint32_t ppid = 0; bool hasGui; - while (pid != 0 && getProcessInfo(pid, &ppid, &result->processName, &result->exe, &result->exeName, &result->exePath, &hasGui)) + while (pid != 0 && ffProcessGetInfoWindows(pid, &ppid, &result->processName, &result->exe, &result->exeName, &result->exePath, &hasGui)) { if(!hasGui || ffStrbufIgnCaseEqualS(&result->processName, "far.exe")) // Far includes GUI objects... { @@ -373,7 +335,7 @@ const FFShellResult* ffDetectShell(void) result.tty = -1; uint32_t ppid; - if(!getProcessInfo(0, &ppid, NULL, NULL, NULL, NULL, NULL)) + if(!ffProcessGetInfoWindows(0, &ppid, NULL, NULL, NULL, NULL, NULL)) return &result; ppid = getShellInfo(&result, ppid); diff --git a/src/detection/vulkan/vulkan.c b/src/detection/vulkan/vulkan.c index d43e47acd9..e71cfe18f1 100644 --- a/src/detection/vulkan/vulkan.c +++ b/src/detection/vulkan/vulkan.c @@ -76,7 +76,7 @@ static const char* detectVulkan(FFVulkanResult* result) ); VkInstance vkInstance; - if(ffvkCreateInstance(&(VkInstanceCreateInfo) { + VkResult res = ffvkCreateInstance(&(VkInstanceCreateInfo) { .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pNext = NULL, .pApplicationInfo = &(VkApplicationInfo) { @@ -95,8 +95,27 @@ static const char* detectVulkan(FFVulkanResult* result) .enabledExtensionCount = 0, .ppEnabledExtensionNames = NULL, .flags = 0 - }, NULL, &vkInstance) != VK_SUCCESS) - return "ffvkCreateInstance() failed"; + }, NULL, &vkInstance); + if(res != VK_SUCCESS) + { + switch (res) + { + case VK_ERROR_OUT_OF_HOST_MEMORY: + return "ffvkCreateInstance() failed: VK_ERROR_OUT_OF_HOST_MEMORY"; + case VK_ERROR_OUT_OF_DEVICE_MEMORY: + return "ffvkCreateInstance() failed: VK_ERROR_OUT_OF_DEVICE_MEMORY"; + case VK_ERROR_INITIALIZATION_FAILED: + return "ffvkCreateInstance() failed: VK_ERROR_INITIALIZATION_FAILED"; + case VK_ERROR_LAYER_NOT_PRESENT: + return "ffvkCreateInstance() failed: VK_ERROR_LAYER_NOT_PRESENT"; + case VK_ERROR_EXTENSION_NOT_PRESENT: + return "ffvkCreateInstance() failed: VK_ERROR_EXTENSION_NOT_PRESENT"; + case VK_ERROR_INCOMPATIBLE_DRIVER: + return "ffvkCreateInstance() failed: VK_ERROR_INCOMPATIBLE_DRIVER"; + default: + return "ffvkCreateInstance() failed: unknown error"; + } + } //if instance creation succeeded, but vkEnumerateInstanceVersion didn't, this means we are running against a vulkan 1.0 implementation //explicitly set this version, if no device is found, so we still have at least this info @@ -105,10 +124,23 @@ static const char* detectVulkan(FFVulkanResult* result) VkPhysicalDevice physicalDevices[128]; uint32_t physicalDeviceCount = (uint32_t) (sizeof(physicalDevices) / sizeof(*physicalDevices)); - if(ffvkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, physicalDevices) != VK_SUCCESS) + res = ffvkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, physicalDevices); + if(res != VK_SUCCESS) { ffvkDestroyInstance(vkInstance, NULL); - return "ffvkEnumeratePhysicalDevices() failed"; + switch (res) + { + case VK_ERROR_OUT_OF_HOST_MEMORY: + return "ffvkEnumeratePhysicalDevices() failed: VK_ERROR_OUT_OF_HOST_MEMORY"; + case VK_ERROR_OUT_OF_DEVICE_MEMORY: + return "ffvkEnumeratePhysicalDevices() failed: VK_ERROR_OUT_OF_DEVICE_MEMORY"; + case VK_ERROR_INITIALIZATION_FAILED: + return "ffvkEnumeratePhysicalDevices() failed: VK_ERROR_INITIALIZATION_FAILED"; + case VK_INCOMPLETE: + return "ffvkEnumeratePhysicalDevices() failed: VK_INCOMPLETE"; + default: + return "ffvkEnumeratePhysicalDevices() failed"; + } } PFN_vkGetPhysicalDeviceProperties ffvkGetPhysicalDeviceProperties = NULL; diff --git a/src/fastfetch.c b/src/fastfetch.c index cfe2d61857..bdaf281db4 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -265,6 +265,11 @@ static void listAvailablePresets(bool pretty) ffStrbufAppendS(path, "fastfetch/presets/"); ffListFilesRecursively(path->chars, pretty); } + + FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateCopy(&instance.state.platform.exePath); + ffStrbufSubstrBeforeLastC(&absolutePath, '/'); + ffStrbufAppendS(&absolutePath, "/presets/"); + ffListFilesRecursively(absolutePath.chars, pretty); } static void listAvailableLogos(void) @@ -284,12 +289,6 @@ static void listConfigPaths(void) uint32_t length = folder->length + (uint32_t) strlen("fastfetch") + 1 /* trailing slash */; ffStrbufAppendS(folder, "fastfetch/config.jsonc"); exists = ffPathExists(folder->chars, FF_PATHTYPE_FILE); - if (!exists) - { - ffStrbufSubstrBefore(folder, folder->length - (uint32_t) strlen("jsonc")); - ffStrbufAppendS(folder, "conf"); - exists = ffPathExists(folder->chars, FF_PATHTYPE_FILE); - } ffStrbufSubstrBefore(folder, length); printf("%s%s\n", folder->chars, exists ? " (*)" : ""); } diff --git a/src/logo/ascii/cereus.txt b/src/logo/ascii/cereus.txt new file mode 100644 index 0000000000..f198a16ad8 --- /dev/null +++ b/src/logo/ascii/cereus.txt @@ -0,0 +1,27 @@ + .. + '::,..... + .,;:llll;. $4 ... + $2...... $1''''.$4 ':::;. + $2 ..,::lll::;,..$4 ::::;. + $2 ':llllllllllll:' $4 ;:::; + $2 .;llllllllllllllll' $4 ;::;. +$3 .... $2 .;lllllllllllllllll:. $4 ;::;. +$3 .;::::, $2 ,lllllllllllllllllll. $4 . +$3 .::::::.$2 .lllllllllllllllllll:. +$3 .::::::. $2 ,lllllllllllllllllll:.$3 ...... +$3 .;:::::'$2 .;lllllllllllllllllll,$3 .,::::::,. +$3 .;::::;.$2.:lllllllllllllllllll.$3 .,::::::::;. +$3 .,;::;$2;lllllllllllllllllll;$3 .:::::::::;. +$3 ...$2,lllllllllllllllllll.$3 ':::::::::,. +$2 .:lllllllllllllllll, $3 .;::::::::;. +$2 .:llllllllllllllll:.$3 .;::::::::,. +$2 ,llllllllllllllll'$3 .';:::::::;. +$5 ... $2 .llllllllllllllll;$3,,,,;:::::::;,. +$5.:l:. $2 ,llllllllllllll;$3,,:::::::;,'.. +$5.;::, $2 .;lllllllllllll,$3 ''''''''''' +$5 .:::. $2 ':lllllllllll:. +$5 .;::' $2 .,:llllllllll, +$5 .,::;. $2 .';lllllllll' +$5 .,::;'.. $2 .';lllllll,. +$5 ..,;::;,. $2 ...,;lll:. +$5 ...''. $2 ..',;'. diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 78eb5493cc..c7ae03e725 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -860,6 +860,20 @@ static const FFlogo C[] = { .colorKeys = FF_COLOR_FG_GREEN, .colorTitle = FF_COLOR_FG_YELLOW, }, + // Cereus + { + .names = {"cereus", "Cereus Linux"}, + .lines = FASTFETCH_DATATEXT_LOGO_CEREUS, + .colors = { + FF_COLOR_FG_256 "173", + FF_COLOR_FG_256 "108", + FF_COLOR_FG_256 "71", + FF_COLOR_FG_256 "151", + FF_COLOR_FG_256 "72" + }, + .colorKeys = FF_COLOR_FG_256 "108", + .colorTitle = FF_COLOR_MODE_BOLD FF_COLOR_FG_WHITE, + }, // Chakra { .names = {"Chakra"}, diff --git a/src/logo/logo.c b/src/logo/logo.c index f8956ec740..01dfb1de38 100644 --- a/src/logo/logo.c +++ b/src/logo/logo.c @@ -113,7 +113,7 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement) ffStrbufAppendS(&result, "\e["); data += 2; - while(isdigit(*data) || *data == ';') + while(ffCharIsDigit(*data) || *data == ';') ffStrbufAppendC(&result, *data++); // number //We have a valid control sequence, print it and continue with next char @@ -219,13 +219,25 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement) ffWriteFDBuffer(FFUnixFD2NativeFD(STDOUT_FILENO), &result); } -static void logoApplyColors(const FFlogo* logo) +static void logoApplyColors(const FFlogo* logo, bool replacement) { if(instance.config.display.colorTitle.length == 0) ffStrbufAppendS(&instance.config.display.colorTitle, logo->colorTitle ? logo->colorTitle : logo->colors[0]); if(instance.config.display.colorKeys.length == 0) ffStrbufAppendS(&instance.config.display.colorKeys, logo->colorKeys ? logo->colorKeys : logo->colors[1]); + + if (replacement) + { + FFOptionsLogo* options = &instance.config.logo; + + const char* const* colors = logo->colors; + for(int i = 0; *colors != NULL && i < FASTFETCH_LOGO_MAX_COLORS; i++, colors++) + { + if(options->colors[i].length == 0) + ffStrbufAppendS(&options->colors[i], *colors); + } + } } static bool logoHasName(const FFlogo* logo, const FFstrbuf* name, bool small) @@ -301,30 +313,16 @@ static const FFlogo* logoGetBuiltinDetected(FFLogoSize size) return &ffLogoUnknown; } -static inline void logoApplyColorsDetected(void) -{ - logoApplyColors(logoGetBuiltinDetected(FF_LOGO_SIZE_NORMAL)); -} - static void logoPrintStruct(const FFlogo* logo) { - logoApplyColors(logo); - - FFOptionsLogo* options = &instance.config.logo; - - const char* const* colors = logo->colors; - for(int i = 0; *colors != NULL && i < FASTFETCH_LOGO_MAX_COLORS; i++, colors++) - { - if(options->colors[i].length == 0) - ffStrbufAppendS(&options->colors[i], *colors); - } + logoApplyColors(logo, true); ffLogoPrintChars(logo->lines, true); } static void logoPrintNone(void) { - logoApplyColorsDetected(); + logoApplyColors(logoGetBuiltinDetected(FF_LOGO_SIZE_NORMAL), false); instance.state.logoHeight = 0; instance.state.logoWidth = 0; } @@ -357,8 +355,8 @@ static bool logoPrintData(bool doColorReplacement) if(options->source.length == 0) return false; + logoApplyColors(logoGetBuiltinDetected(FF_LOGO_SIZE_NORMAL), doColorReplacement); ffLogoPrintChars(options->source.chars, doColorReplacement); - logoApplyColorsDetected(); return true; } @@ -407,7 +405,7 @@ static bool logoPrintFileIfExists(bool doColorReplacement, bool raw) return false; } - logoApplyColorsDetected(); + logoApplyColors(logoGetBuiltinDetected(FF_LOGO_SIZE_NORMAL), doColorReplacement); if(raw) ffLogoPrintCharsRaw(content.chars, content.length); else @@ -421,7 +419,7 @@ static bool logoPrintImageIfExists(FFLogoType logo, bool printError) if(!ffLogoPrintImageIfExists(logo, printError)) return false; - logoApplyColorsDetected(); + logoApplyColors(logoGetBuiltinDetected(FF_LOGO_SIZE_NORMAL), false); return true; } @@ -431,7 +429,7 @@ static bool logoTryKnownType(void) if(options->type == FF_LOGO_TYPE_NONE) { - logoApplyColorsDetected(); + logoApplyColors(logoGetBuiltinDetected(FF_LOGO_SIZE_NORMAL), false); return true; } diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index 918fc78191..7e1ff02d86 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -62,15 +62,15 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); ffTempsAppendNum(result->temperature, &tempStr, options->tempConfig, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_BATTERY_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_BATTERY_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->technology}, - {FF_FORMAT_ARG_TYPE_STRBUF, &capacityStr}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->status}, - {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr}, - {FF_FORMAT_ARG_TYPE_UINT, &result->cycleCount}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->serial}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufactureDate}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer, "manufacturer"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName, "model-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->technology, "technology"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &capacityStr, "capacity"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->status, "status"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr, "temperature"}, + {FF_FORMAT_ARG_TYPE_UINT, &result->cycleCount, "cycle-count"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->serial, "serial"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufactureDate, "manufacture-date"}, })); } } @@ -222,15 +222,15 @@ void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc, void ffPrintBatteryHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_BATTERY_MODULE_NAME, "{4}, {5}", FF_BATTERY_NUM_FORMAT_ARGS, ((const char* []) { - "Battery manufactor", - "Battery model", - "Battery technology", - "Battery capacity (percentage)", - "Battery status", - "Battery temperature (formatted)", - "Battery cycle count", - "Battery serial number", - "Battery manufactor date", + "Battery manufacturer - manufacturer", + "Battery model name - model-name", + "Battery technology - technology", + "Battery capacity (percentage) - capacity", + "Battery status - status", + "Battery temperature (formatted) - temperature", + "Battery cycle count - cycle-count", + "Battery serial number - serial", + "Battery manufactor date - manufacture-date", })); } diff --git a/src/modules/bios/bios.c b/src/modules/bios/bios.c index 3e9b73289f..5e9d1742cd 100644 --- a/src/modules/bios/bios.c +++ b/src/modules/bios/bios.c @@ -44,7 +44,7 @@ void ffPrintBios(FFBiosOptions* options) { ffStrbufClear(&key); FF_PARSE_FORMAT_STRING_CHECKED(&key, &options->moduleArgs.key, 1, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &bios.type}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bios.type, "type"}, })); } @@ -60,11 +60,11 @@ void ffPrintBios(FFBiosOptions* options) else { FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_BIOS_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &bios.date}, - {FF_FORMAT_ARG_TYPE_STRBUF, &bios.release}, - {FF_FORMAT_ARG_TYPE_STRBUF, &bios.vendor}, - {FF_FORMAT_ARG_TYPE_STRBUF, &bios.version}, - {FF_FORMAT_ARG_TYPE_STRBUF, &bios.type}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bios.date, "date"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bios.release, "release"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bios.vendor, "vendor"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bios.version, "version"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bios.type, "type"}, })); } @@ -146,11 +146,11 @@ void ffGenerateBiosJsonResult(FF_MAYBE_UNUSED FFBiosOptions* options, yyjson_mut void ffPrintBiosHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_BIOS_MODULE_NAME, "{4} ({2})", FF_BIOS_NUM_FORMAT_ARGS, ((const char* []) { - "bios date", - "bios release", - "bios vendor", - "bios version", - "firmware type", + "bios date - date", + "bios release - release", + "bios vendor - vendor", + "bios version - version", + "firmware type - type", })); } diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index 6beef48b70..578a201bfd 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -5,7 +5,7 @@ #include "modules/bluetooth/bluetooth.h" #include "util/stringUtils.h" -#define FF_BLUETOOTH_NUM_FORMAT_ARGS 4 +#define FF_BLUETOOTH_NUM_FORMAT_ARGS 5 static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* device, uint8_t index) { @@ -33,10 +33,11 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* de ffPercentAppendNum(&percentageStr, device->battery, options->percent, false, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_BLUETOOTH_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &device->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->address}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->type}, - {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr} + {FF_FORMAT_ARG_TYPE_STRBUF, &device->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->address, "address"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->type, "type"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr, "battery-percentage"}, + {FF_FORMAT_ARG_TYPE_BOOL, &device->connected, "connected"}, })); } } @@ -174,10 +175,11 @@ void ffGenerateBluetoothJsonResult(FF_MAYBE_UNUSED FFBluetoothOptions* options, void ffPrintBluetoothHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_BLUETOOTH_MODULE_NAME, "{1} ({4})", FF_BLUETOOTH_NUM_FORMAT_ARGS, ((const char* []) { - "Name", - "Address", - "Type", - "Battery percentage" + "Name - name", + "Address - address", + "Type - type", + "Battery percentage - battery-percentage", + "Is connected - connected", })); } diff --git a/src/modules/board/board.c b/src/modules/board/board.c index 4cbc21840c..26db6a18db 100644 --- a/src/modules/board/board.c +++ b/src/modules/board/board.c @@ -38,10 +38,10 @@ void ffPrintBoard(FFBoardOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_BOARD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_BOARD_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &result.name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.vendor}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.version}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.serial}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.vendor, "vendor"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.version, "version"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.serial, "serial"}, })); } @@ -125,10 +125,10 @@ void ffGenerateBoardJsonResult(FF_MAYBE_UNUSED FFBoardOptions* options, yyjson_m void ffPrintBoardHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_BOARD_MODULE_NAME, "{1} ({3})", FF_BOARD_NUM_FORMAT_ARGS, ((const char* []) { - "board name", - "board vendor", - "board version", - "board serial number", + "board name - name", + "board vendor - vendor", + "board version - version", + "board serial number - serial", })); } @@ -137,7 +137,7 @@ void ffInitBoardOptions(FFBoardOptions* options) ffOptionInitModuleBaseInfo( &options->moduleInfo, FF_BOARD_MODULE_NAME, - "Print mather board name and other info", + "Print motherboard name and other info", ffParseBoardCommandOptions, ffParseBoardJsonObject, ffPrintBoard, diff --git a/src/modules/bootmgr/bootmgr.c b/src/modules/bootmgr/bootmgr.c index 497c0d940e..dfdbdc4523 100644 --- a/src/modules/bootmgr/bootmgr.c +++ b/src/modules/bootmgr/bootmgr.c @@ -40,10 +40,10 @@ void ffPrintBootmgr(FFBootmgrOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_BOOTMGR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_BOOTMGR_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &bootmgr.name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &bootmgr.firmware}, - {FF_FORMAT_ARG_TYPE_STRBUF, &firmwareName}, - {FF_FORMAT_ARG_TYPE_BOOL, &bootmgr.secureBoot}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bootmgr.name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bootmgr.firmware, "firmware-path"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &firmwareName, "firmware-name"}, + {FF_FORMAT_ARG_TYPE_BOOL, &bootmgr.secureBoot, "secure-boot"}, })); } @@ -114,10 +114,10 @@ void ffGenerateBootmgrJsonResult(FF_MAYBE_UNUSED FFBootmgrOptions* options, yyjs void ffPrintBootmgrHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_BOOTMGR_MODULE_NAME, "{4} ({2})", FF_BOOTMGR_NUM_FORMAT_ARGS, ((const char* []) { - "Name / description", - "Firmware file path", - "Firmware file name", - "Is secure boot enabled", + "Name / description - name", + "Firmware file path - firmware-path", + "Firmware file name - firmware-name", + "Is secure boot enabled - secure-boot", })); } diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index 8e2aff84d2..01d0beb8f4 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -38,8 +38,8 @@ void ffPrintBrightness(FFBrightnessOptions* options) { uint32_t moduleIndex = result.length == 1 ? 0 : index + 1; FF_PARSE_FORMAT_STRING_CHECKED(&key, &options->moduleArgs.key, 2, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT, &moduleIndex}, - {FF_FORMAT_ARG_TYPE_STRBUF, &item->name} + {FF_FORMAT_ARG_TYPE_UINT, &moduleIndex, "index"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &item->name, "name"}, })); } @@ -70,11 +70,11 @@ void ffPrintBrightness(FFBrightnessOptions* options) FF_STRBUF_AUTO_DESTROY valueStr = ffStrbufCreate(); ffPercentAppendNum(&valueStr, percent, options->percent, false, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_BRIGHTNESS_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &valueStr}, - {FF_FORMAT_ARG_TYPE_STRBUF, &item->name}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &item->max}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &item->min}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &item->current}, + {FF_FORMAT_ARG_TYPE_STRBUF, &valueStr, "percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &item->name, "name"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &item->max, "max"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &item->min, "min"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &item->current, "current"}, })); } @@ -175,11 +175,11 @@ void ffGenerateBrightnessJsonResult(FF_MAYBE_UNUSED FFBrightnessOptions* options void ffPrintBrightnessHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_BRIGHTNESS_MODULE_NAME, "{1}", FF_BRIGHTNESS_NUM_FORMAT_ARGS, ((const char* []) { - "Screen brightness (percentage)", - "Screen name", - "Maximum brightness value", - "Minimum brightness value", - "Current brightness value", + "Screen brightness (percentage) - percentage", + "Screen name - name", + "Maximum brightness value - max", + "Minimum brightness value - min", + "Current brightness value - current", })); } diff --git a/src/modules/camera/camera.c b/src/modules/camera/camera.c index c976ac7641..0eb449052b 100644 --- a/src/modules/camera/camera.c +++ b/src/modules/camera/camera.c @@ -28,12 +28,12 @@ static void printDevice(FFCameraOptions* options, const FFCameraResult* device, else { FF_PRINT_FORMAT_CHECKED(FF_CAMERA_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_CAMERA_NUM_FORMAT_ARGS, (((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &device->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->vendor}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->colorspace}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->id}, - {FF_FORMAT_ARG_TYPE_UINT, &device->width}, - {FF_FORMAT_ARG_TYPE_UINT, &device->height}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->vendor, "vendor"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->colorspace, "colorspace"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->id, "id"}, + {FF_FORMAT_ARG_TYPE_UINT, &device->width, "width"}, + {FF_FORMAT_ARG_TYPE_UINT, &device->height, "height"}, }))); } } @@ -139,12 +139,12 @@ void ffGenerateCameraJsonResult(FF_MAYBE_UNUSED FFCameraOptions* options, yyjson void ffPrintCameraHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_CAMERA_MODULE_NAME, "{1} ({4}px x {5}px)", FF_CAMERA_NUM_FORMAT_ARGS, ((const char* []) { - "Device name", - "Vendor", - "Color space", - "Identifier", - "Width (in px)", - "Height (in px)", + "Device name - name", + "Vendor - vendor", + "Color space - colorspace", + "Identifier - id", + "Width (in px) - width", + "Height (in px) - height", })); } diff --git a/src/modules/chassis/chassis.c b/src/modules/chassis/chassis.c index b24009b42d..e3948bdec8 100644 --- a/src/modules/chassis/chassis.c +++ b/src/modules/chassis/chassis.c @@ -39,10 +39,10 @@ void ffPrintChassis(FFChassisOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_CHASSIS_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &result.type}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.vendor}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.version}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.serial}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.type, "type"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.vendor, "vendor"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.version, "version"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.serial, "serial"}, })); } @@ -126,10 +126,10 @@ void ffGenerateChassisJsonResult(FF_MAYBE_UNUSED FFChassisOptions* options, yyjs void ffPrintChassisHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_CHASSIS_MODULE_NAME, "{1}", FF_CHASSIS_NUM_FORMAT_ARGS, ((const char* []) { - "chassis type", - "chassis vendor", - "chassis version", - "chassis serial number", + "chassis type - type", + "chassis vendor - vendor", + "chassis version - version", + "chassis serial number - serial", })); } diff --git a/src/modules/colors/colors.c b/src/modules/colors/colors.c index 556d01e493..5eef93748b 100644 --- a/src/modules/colors/colors.c +++ b/src/modules/colors/colors.c @@ -25,7 +25,7 @@ void ffPrintColors(FFColorsOptions* options) // 3%d: Set the foreground color for(uint8_t i = options->block.range[0]; i <= min(options->block.range[1], 7); i++) { - if(!instance.config.display.pipe) + if (!instance.config.display.pipe) ffStrbufAppendF(&result, "\e[3%dm", i); for (uint8_t j = 0; j < options->block.width; j++) ffStrbufAppendS(&result, "█"); @@ -35,10 +35,10 @@ void ffPrintColors(FFColorsOptions* options) ffPrintLogoAndKey(FF_COLORS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); flag = true; - if(options->paddingLeft > 0) + if (options->paddingLeft > 0) ffPrintCharTimes(' ', options->paddingLeft); - if(!instance.config.display.pipe) + if (!instance.config.display.pipe) ffStrbufAppendS(&result, FASTFETCH_TEXT_MODIFIER_RESET); ffStrbufPutTo(&result, stdout); ffStrbufClear(&result); @@ -59,15 +59,20 @@ void ffPrintColors(FFColorsOptions* options) const char* symbol; switch (options->symbol) { - case FF_COLORS_SYMBOL_CIRCLE: symbol = "●"; break; - case FF_COLORS_SYMBOL_DIAMOND: symbol = "◆"; break; - case FF_COLORS_SYMBOL_TRIANGLE: symbol = "▲"; break; - case FF_COLORS_SYMBOL_SQUARE: symbol = "■"; break; - case FF_COLORS_SYMBOL_STAR: symbol = "★"; break; - default: symbol = "███"; break; + case FF_COLORS_SYMBOL_CIRCLE: symbol = "● "; break; + case FF_COLORS_SYMBOL_DIAMOND: symbol = "◆ "; break; + case FF_COLORS_SYMBOL_TRIANGLE: symbol = "▲ "; break; + case FF_COLORS_SYMBOL_SQUARE: symbol = "■ "; break; + case FF_COLORS_SYMBOL_STAR: symbol = "★ "; break; + default: symbol = "███ "; break; } for (int i = 8; i >= 1; --i) - ffStrbufAppendF(&result, "\e[3%dm%s ", i, symbol); + { + if (!instance.config.display.pipe) + ffStrbufAppendF(&result, "\e[3%dm", i); + ffStrbufAppendS(&result, symbol); + } + ffStrbufTrimRight(&result, ' '); } if (result.length > 0) diff --git a/src/modules/command/command.c b/src/modules/command/command.c index c57e910840..6eb8884075 100644 --- a/src/modules/command/command.c +++ b/src/modules/command/command.c @@ -40,7 +40,7 @@ void ffPrintCommand(FFCommandOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_COMMAND_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_COMMAND_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &result} + {FF_FORMAT_ARG_TYPE_STRBUF, &result, "result"} })); } } @@ -142,7 +142,7 @@ void ffGenerateCommandJsonResult(FF_MAYBE_UNUSED FFCommandOptions* options, yyjs void ffPrintCommandHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_COMMAND_MODULE_NAME, "{1}", FF_COMMAND_NUM_FORMAT_ARGS, ((const char* []) { - "Command result" + "Command result - result" })); } diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index d7ed70baa3..ed21740e46 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -107,16 +107,16 @@ void ffPrintCPU(FFCPUOptions* options) FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); ffTempsAppendNum(cpu.temperature, &tempStr, options->tempConfig, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_CPU_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &cpu.name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &cpu.vendor}, - {FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresPhysical}, - {FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresLogical}, - {FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresOnline}, - {FF_FORMAT_ARG_TYPE_STRING, freqBase}, - {FF_FORMAT_ARG_TYPE_STRING, freqMax}, - {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr}, - {FF_FORMAT_ARG_TYPE_STRBUF, &coreTypes}, - {FF_FORMAT_ARG_TYPE_STRING, freqBioslimit}, + {FF_FORMAT_ARG_TYPE_STRBUF, &cpu.name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &cpu.vendor, "vendor"}, + {FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresPhysical, "cores-physical"}, + {FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresLogical, "cores-logical"}, + {FF_FORMAT_ARG_TYPE_UINT16, &cpu.coresOnline, "cores-online"}, + {FF_FORMAT_ARG_TYPE_STRING, freqBase, "freq-base"}, + {FF_FORMAT_ARG_TYPE_STRING, freqMax, "freq-max"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr, "temperature"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &coreTypes, "core-types"}, + {FF_FORMAT_ARG_TYPE_STRING, freqBioslimit, "freq-bios-limit"}, })); } } @@ -255,16 +255,16 @@ void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_ void ffPrintCPUHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_CPU_MODULE_NAME, "{1} ({5}) @ {7} GHz", FF_CPU_NUM_FORMAT_ARGS, ((const char* []) { - "Name", - "Vendor", - "Physical core count", - "Logical core count", - "Online core count", - "Base frequency", - "Max frequency", - "Temperature (formatted)", - "Logical core count grouped by frequency", - "Bios limited frequency", + "Name - name", + "Vendor - vendor", + "Physical core count - cores-physical", + "Logical core count - cores-logical", + "Online core count - cores-online", + "Base frequency - freq-base", + "Max frequency - freq-max", + "Temperature (formatted) - temperature", + "Logical core count grouped by frequency - core-types", + "Bios limited frequency - freq-bios-limit", })); } diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index aa3bfccac0..b90e475bc2 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -80,11 +80,11 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options) FF_STRBUF_AUTO_DESTROY maxStr = ffStrbufCreate(); ffPercentAppendNum(&maxStr, maxValue, options->percent, false, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_CPUUSAGE_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &avgStr}, - {FF_FORMAT_ARG_TYPE_STRBUF, &maxStr}, - {FF_FORMAT_ARG_TYPE_UINT, &maxIndex}, - {FF_FORMAT_ARG_TYPE_STRBUF, &minStr}, - {FF_FORMAT_ARG_TYPE_UINT, &minIndex}, + {FF_FORMAT_ARG_TYPE_STRBUF, &avgStr, "avg"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &maxStr, "max"}, + {FF_FORMAT_ARG_TYPE_UINT, &maxIndex, "max-index"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &minStr, "min"}, + {FF_FORMAT_ARG_TYPE_UINT, &minIndex, "min-index"}, })); } } @@ -167,11 +167,11 @@ void ffGenerateCPUUsageJsonResult(FF_MAYBE_UNUSED FFCPUUsageOptions* options, yy void ffPrintCPUUsageHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_CPUUSAGE_MODULE_NAME, "{1}", FF_CPUUSAGE_NUM_FORMAT_ARGS, ((const char* []) { - "CPU usage (percentage, average)", - "CPU usage (percentage, maximum)", - "CPU core index of maximum usage", - "CPU usage (percentage, minimum)", - "CPU core index of minimum usage", + "CPU usage (percentage, average) - avg", + "CPU usage (percentage, maximum) - max", + "CPU core index of maximum usage - max-index", + "CPU usage (percentage, minimum) - min", + "CPU core index of minimum usage - min-index", })); } diff --git a/src/modules/cursor/cursor.c b/src/modules/cursor/cursor.c index 5493762800..64e60e6664 100644 --- a/src/modules/cursor/cursor.c +++ b/src/modules/cursor/cursor.c @@ -39,8 +39,8 @@ void ffPrintCursor(FFCursorOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_CURSOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_CURSOR_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &result.theme}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.size} + {FF_FORMAT_ARG_TYPE_STRBUF, &result.theme, "theme"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.size, "size"}, })); } } @@ -113,8 +113,8 @@ void ffGenerateCursorJsonResult(FF_MAYBE_UNUSED FFCursorOptions* options, yyjson void ffPrintCursorHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_CURSOR_MODULE_NAME, "{1} ({2}px)", FF_CURSOR_NUM_FORMAT_ARGS, ((const char* []) { - "Cursor theme", - "Cursor size" + "Cursor theme - theme", + "Cursor size - size" })); } diff --git a/src/modules/custom/custom.c b/src/modules/custom/custom.c index 47a83f77ea..1c5d829b39 100644 --- a/src/modules/custom/custom.c +++ b/src/modules/custom/custom.c @@ -6,10 +6,7 @@ void ffPrintCustom(FFCustomOptions* options) { - ffPrintLogoAndKey(FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); - ffStrbufWriteTo(&options->moduleArgs.outputFormat, stdout); - if(!instance.config.display.pipe) - puts(FASTFETCH_TEXT_MODIFIER_RESET); + ffPrintFormat(FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, 0, ((FFformatarg[]) {})); } bool ffParseCustomCommandOptions(FFCustomOptions* options, const char* key, const char* value) diff --git a/src/modules/datetime/datetime.c b/src/modules/datetime/datetime.c index 5027cc8036..b583e642b8 100644 --- a/src/modules/datetime/datetime.c +++ b/src/modules/datetime/datetime.c @@ -66,28 +66,28 @@ void ffPrintDateTimeFormat(struct tm* tm, const FFModuleArgs* moduleArgs) strftime(result.timezoneName, sizeof(result.timezoneName), "%Z", tm); FF_PRINT_FORMAT_CHECKED(FF_DATETIME_DISPLAY_NAME, 0, moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_DATETIME_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_UINT16, &result.year}, // 1 - {FF_FORMAT_ARG_TYPE_UINT8, &result.yearShort}, // 2 - {FF_FORMAT_ARG_TYPE_UINT8, &result.month}, // 3 - {FF_FORMAT_ARG_TYPE_STRING, result.monthPretty}, // 4 - {FF_FORMAT_ARG_TYPE_STRING, result.monthName}, // 5 - {FF_FORMAT_ARG_TYPE_STRING, result.monthNameShort}, // 6 - {FF_FORMAT_ARG_TYPE_UINT8, &result.week}, // 7 - {FF_FORMAT_ARG_TYPE_STRING, result.weekday}, // 8 - {FF_FORMAT_ARG_TYPE_STRING, result.weekdayShort}, // 9 - {FF_FORMAT_ARG_TYPE_UINT16, &result.dayInYear}, // 10 - {FF_FORMAT_ARG_TYPE_UINT8, &result.dayInMonth}, // 11 - {FF_FORMAT_ARG_TYPE_UINT8, &result.dayInWeek}, // 12 - {FF_FORMAT_ARG_TYPE_UINT8, &result.hour}, // 13 - {FF_FORMAT_ARG_TYPE_STRING, result.hourPretty}, // 14 - {FF_FORMAT_ARG_TYPE_UINT8, &result.hour12}, // 15 - {FF_FORMAT_ARG_TYPE_STRING, result.hour12Pretty}, // 16 - {FF_FORMAT_ARG_TYPE_UINT8, &result.minute}, // 17 - {FF_FORMAT_ARG_TYPE_STRING, result.minutePretty}, // 18 - {FF_FORMAT_ARG_TYPE_UINT8, &result.second}, // 19 - {FF_FORMAT_ARG_TYPE_STRING, result.secondPretty}, // 20 - {FF_FORMAT_ARG_TYPE_STRING, result.offsetFromUtc}, // 21 - {FF_FORMAT_ARG_TYPE_STRING, result.timezoneName}, // 22 + {FF_FORMAT_ARG_TYPE_UINT16, &result.year, "year"}, // 1 + {FF_FORMAT_ARG_TYPE_UINT8, &result.yearShort, "year-short"}, // 2 + {FF_FORMAT_ARG_TYPE_UINT8, &result.month, "month"}, // 3 + {FF_FORMAT_ARG_TYPE_STRING, result.monthPretty, "month-pretty"}, // 4 + {FF_FORMAT_ARG_TYPE_STRING, result.monthName, "month-name"}, // 5 + {FF_FORMAT_ARG_TYPE_STRING, result.monthNameShort, "month-name-short"}, // 6 + {FF_FORMAT_ARG_TYPE_UINT8, &result.week, "week"}, // 7 + {FF_FORMAT_ARG_TYPE_STRING, result.weekday, "weekday"}, // 8 + {FF_FORMAT_ARG_TYPE_STRING, result.weekdayShort, "weekday-short"}, // 9 + {FF_FORMAT_ARG_TYPE_UINT16, &result.dayInYear, "day-in-year"}, // 10 + {FF_FORMAT_ARG_TYPE_UINT8, &result.dayInMonth, "day-in-month"}, // 11 + {FF_FORMAT_ARG_TYPE_UINT8, &result.dayInWeek, "day-in-week"}, // 12 + {FF_FORMAT_ARG_TYPE_UINT8, &result.hour, "hour"}, // 13 + {FF_FORMAT_ARG_TYPE_STRING, result.hourPretty, "hour-pretty"}, // 14 + {FF_FORMAT_ARG_TYPE_UINT8, &result.hour12, "hour-12"}, // 15 + {FF_FORMAT_ARG_TYPE_STRING, result.hour12Pretty, "hour-12-pretty"}, // 16 + {FF_FORMAT_ARG_TYPE_UINT8, &result.minute, "minute"}, // 17 + {FF_FORMAT_ARG_TYPE_STRING, result.minutePretty, "minute-pretty"}, // 18 + {FF_FORMAT_ARG_TYPE_UINT8, &result.second, "second"}, // 19 + {FF_FORMAT_ARG_TYPE_STRING, result.secondPretty, "second-pretty"}, // 20 + {FF_FORMAT_ARG_TYPE_STRING, result.offsetFromUtc, "offset-from-utc"}, // 21 + {FF_FORMAT_ARG_TYPE_STRING, result.timezoneName, "timezone-name"}, // 22 })); } @@ -158,28 +158,28 @@ void ffGenerateDateTimeJsonResult(FF_MAYBE_UNUSED FFDateTimeOptions* options, yy void ffPrintDateTimeHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_DATETIME_MODULE_NAME, "{1}-{4}-{11} {14}:{18}:{20}", FF_DATETIME_NUM_FORMAT_ARGS, ((const char* []) { - "year", - "last two digits of year", - "month", - "month with leading zero", - "month name", - "month name short", - "week number on year", - "weekday", - "weekday short", - "day in year", - "day in month", - "day in Week", - "hour", - "hour with leading zero", - "hour 12h format", - "hour 12h format with leading zero", - "minute", - "minute with leading zero", - "second", - "second with leading zero", - "offset from UTC in the ISO 8601 format", - "locale-dependent timezone name or abbreviation", + "year - year", + "last two digits of year - year-short", + "month - month", + "month with leading zero - month-pretty", + "month name - month-name", + "month name short - month-name-short", + "week number on year - week", + "weekday - weekday", + "weekday short - weekday-short", + "day in year - day-in-year", + "day in month - day-in-month", + "day in week - day-in-week", + "hour - hour", + "hour with leading zero - hour-pretty", + "hour 12h format - hour-12", + "hour 12h format with leading zero - hour-12-pretty", + "minute - minute", + "minute with leading zero - minute-pretty", + "second - second", + "second with leading zero - second-pretty", + "offset from UTC in the ISO 8601 format - offset-from-utc", + "locale-dependent timezone name or abbreviation - timezone-name", })); } diff --git a/src/modules/de/de.c b/src/modules/de/de.c index b9e84a96b9..998742ef00 100644 --- a/src/modules/de/de.c +++ b/src/modules/de/de.c @@ -37,9 +37,9 @@ void ffPrintDE(FFDEOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_DE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_DE_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &result->deProcessName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->dePrettyName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &version} + {FF_FORMAT_ARG_TYPE_STRBUF, &result->deProcessName, "process-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->dePrettyName, "pretty-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &version, "version"} })); } } @@ -116,9 +116,9 @@ void ffGenerateDEJsonResult(FF_MAYBE_UNUSED FFDEOptions* options, yyjson_mut_doc void ffPrintDEHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_DE_MODULE_NAME, "{2} {3}", FF_DE_NUM_FORMAT_ARGS, ((const char* []) { - "DE process name", - "DE pretty name", - "DE version" + "DE process name - process-name", + "DE pretty name - pretty-name", + "DE version - version" })); } diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 8942754bed..0f225be2ed 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -36,9 +36,9 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) else { FF_PARSE_FORMAT_STRING_CHECKED(&key, &options->moduleArgs.key, 3, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &disk->mountpoint}, - {FF_FORMAT_ARG_TYPE_STRBUF, &disk->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &disk->mountFrom}, + {FF_FORMAT_ARG_TYPE_STRBUF, &disk->mountpoint, "mountpoint"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &disk->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &disk->mountFrom, "mount-from"}, })); } @@ -115,18 +115,18 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) bool isReadOnly = !!(disk->type & FF_DISK_VOLUME_TYPE_READONLY_BIT); FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISK_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty}, - {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty}, - {FF_FORMAT_ARG_TYPE_STRBUF, &bytesPercentageStr}, - {FF_FORMAT_ARG_TYPE_UINT, &disk->filesUsed}, - {FF_FORMAT_ARG_TYPE_UINT, &disk->filesTotal}, - {FF_FORMAT_ARG_TYPE_STRBUF, &filesPercentageStr}, - {FF_FORMAT_ARG_TYPE_BOOL, &isExternal}, - {FF_FORMAT_ARG_TYPE_BOOL, &isHidden}, - {FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem}, - {FF_FORMAT_ARG_TYPE_STRBUF, &disk->name}, - {FF_FORMAT_ARG_TYPE_BOOL, &isReadOnly}, - {FF_FORMAT_ARG_TYPE_STRING, ffTimeToShortStr(disk->createTime)}, + {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty, "size-used"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty, "size-total"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &bytesPercentageStr, "size-percentage"}, + {FF_FORMAT_ARG_TYPE_UINT, &disk->filesUsed, "files-used"}, + {FF_FORMAT_ARG_TYPE_UINT, &disk->filesTotal, "files-total"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &filesPercentageStr, "files-percentage"}, + {FF_FORMAT_ARG_TYPE_BOOL, &isExternal, "is-external"}, + {FF_FORMAT_ARG_TYPE_BOOL, &isHidden, "is-hidden"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem, "filesystem"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &disk->name, "name"}, + {FF_FORMAT_ARG_TYPE_BOOL, &isReadOnly, "is-readonly"}, + {FF_FORMAT_ARG_TYPE_STRING, ffTimeToShortStr(disk->createTime), "create-time"}, })); } } @@ -428,18 +428,18 @@ void ffGenerateDiskJsonResult(FFDiskOptions* options, yyjson_mut_doc* doc, yyjso void ffPrintDiskHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_DISK_MODULE_NAME, "{1} / {2} ({3}) - {9}", FF_DISK_NUM_FORMAT_ARGS, ((const char* []) { - "Size used", - "Size total", - "Size percentage", - "Files used", - "Files total", - "Files percentage", - "True if external volume", - "True if hidden volume", - "Filesystem", - "Label / name", - "True if read-only", - "Create time in local timezone", + "Size used - size-used", + "Size total - size-total", + "Size percentage - size-percentage", + "Files used - files-used", + "Files total - files-total", + "Files percentage - files-percentage", + "True if external volume - is-external", + "True if hidden volume - is-hidden", + "Filesystem - filesystem", + "Label / name - name", + "True if read-only - is-readonly", + "Create time in local timezone - create-time", })); } diff --git a/src/modules/diskio/diskio.c b/src/modules/diskio/diskio.c index dc45f4c973..424226b600 100644 --- a/src/modules/diskio/diskio.c +++ b/src/modules/diskio/diskio.c @@ -23,9 +23,9 @@ static void formatKey(const FFDiskIOOptions* options, FFDiskIOResult* dev, uint3 { ffStrbufClear(key); FF_PARSE_FORMAT_STRING_CHECKED(key, &options->moduleArgs.key, 3, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT, &index}, - {FF_FORMAT_ARG_TYPE_STRBUF, &dev->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &dev->devPath}, + {FF_FORMAT_ARG_TYPE_UINT, &index, "index"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &dev->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &dev->devPath, "dev-path"}, })); } } @@ -75,14 +75,14 @@ void ffPrintDiskIO(FFDiskIOOptions* options) if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s"); FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISKIO_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &buffer}, - {FF_FORMAT_ARG_TYPE_STRBUF, &buffer2}, - {FF_FORMAT_ARG_TYPE_STRBUF, &dev->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &dev->devPath}, - {FF_FORMAT_ARG_TYPE_UINT64, &dev->bytesRead}, - {FF_FORMAT_ARG_TYPE_UINT64, &dev->bytesWritten}, - {FF_FORMAT_ARG_TYPE_UINT64, &dev->readCount}, - {FF_FORMAT_ARG_TYPE_UINT64, &dev->writeCount}, + {FF_FORMAT_ARG_TYPE_STRBUF, &buffer, "size-read"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &buffer2, "size-written"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &dev->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &dev->devPath, "dev-path"}, + {FF_FORMAT_ARG_TYPE_UINT64, &dev->bytesRead, "bytes-read"}, + {FF_FORMAT_ARG_TYPE_UINT64, &dev->bytesWritten, "bytes-written"}, + {FF_FORMAT_ARG_TYPE_UINT64, &dev->readCount, "read-count"}, + {FF_FORMAT_ARG_TYPE_UINT64, &dev->writeCount, "write-count"}, })); } ++index; @@ -193,14 +193,14 @@ void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, y void ffPrintDiskIOHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_DISKIO_MODULE_NAME, "{1} (R) - {2} (W)", FF_DISKIO_NUM_FORMAT_ARGS, ((const char* []) { - "Size of data read [per second] (formatted)", - "Size of data written [per second] (formatted)", - "Device name", - "Device raw file path", - "Size of data read [per second] (in bytes)", - "Size of data written [per second] (in bytes)", - "Number of reads", - "Number of writes", + "Size of data read [per second] (formatted) - size-read", + "Size of data written [per second] (formatted) - size-written", + "Device name - name", + "Device raw file path - dev-path", + "Size of data read [per second] (in bytes) - bytes-read", + "Size of data written [per second] (in bytes) - bytes-written", + "Number of reads - read-count", + "Number of writes - write-count", })); } diff --git a/src/modules/display/display.c b/src/modules/display/display.c index 0ca9e07483..008f4ce666 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -90,9 +90,9 @@ void ffPrintDisplay(FFDisplayOptions* options) else { FF_PARSE_FORMAT_STRING_CHECKED(&key, &options->moduleArgs.key, 3, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT, &moduleIndex}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->name}, - {FF_FORMAT_ARG_TYPE_STRING, displayType}, + {FF_FORMAT_ARG_TYPE_UINT, &moduleIndex, "index"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRING, displayType, "type"}, })); } @@ -126,15 +126,15 @@ void ffPrintDisplay(FFDisplayOptions* options) else { FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISPLAY_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_UINT, &result->width}, - {FF_FORMAT_ARG_TYPE_UINT, &result->height}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &result->refreshRate}, - {FF_FORMAT_ARG_TYPE_UINT, &result->scaledWidth}, - {FF_FORMAT_ARG_TYPE_UINT, &result->scaledHeight}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->name}, - {FF_FORMAT_ARG_TYPE_STRING, displayType}, - {FF_FORMAT_ARG_TYPE_UINT, &result->rotation}, - {FF_FORMAT_ARG_TYPE_BOOL, &result->primary}, + {FF_FORMAT_ARG_TYPE_UINT, &result->width, "width"}, + {FF_FORMAT_ARG_TYPE_UINT, &result->height, "height"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &result->refreshRate, "refresh-rate"}, + {FF_FORMAT_ARG_TYPE_UINT, &result->scaledWidth, "scaled-width"}, + {FF_FORMAT_ARG_TYPE_UINT, &result->scaledHeight, "scaled-height"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRING, displayType, "type"}, + {FF_FORMAT_ARG_TYPE_UINT, &result->rotation, "rotation"}, + {FF_FORMAT_ARG_TYPE_BOOL, &result->primary, "is-primary"}, })); } } @@ -311,15 +311,15 @@ void ffGenerateDisplayJsonResult(FF_MAYBE_UNUSED FFDisplayOptions* options, yyjs void ffPrintDisplayHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_DISPLAY_MODULE_NAME, "{1}x{2} @ {3}Hz (as {4}x{5}) [{7}]", FF_DISPLAY_NUM_FORMAT_ARGS, ((const char* []) { - "Screen width (in pixels)", - "Screen height (in pixels)", - "Screen refresh rate (in Hz)", - "Screen scaled width (in pixels)", - "Screen scaled height (in pixels)", - "Screen name", - "Screen type (builtin, external or unknown)", - "Screen rotation (in degrees)", - "True if being the primary screen", + "Screen width (in pixels) - width", + "Screen height (in pixels) - height", + "Screen refresh rate (in Hz) - refresh-rate", + "Screen scaled width (in pixels) - scaled-width", + "Screen scaled height (in pixels) - scaled-height", + "Screen name - name", + "Screen type (builtin, external or unknown) - type", + "Screen rotation (in degrees) - rotation", + "True if being the primary screen - is-primary", })); } diff --git a/src/modules/editor/editor.c b/src/modules/editor/editor.c index 996096ce59..7a9f8d3645 100644 --- a/src/modules/editor/editor.c +++ b/src/modules/editor/editor.c @@ -5,13 +5,14 @@ #include "modules/editor/editor.h" #include "util/stringUtils.h" -#define FF_EDITOR_NUM_FORMAT_ARGS 4 +#define FF_EDITOR_NUM_FORMAT_ARGS 5 void ffPrintEditor(FFEditorOptions* options) { FFEditorResult result = { .name = ffStrbufCreate(), .path = ffStrbufCreate(), + .exe = ffStrbufCreate(), .version = ffStrbufCreate(), }; const char* error = ffDetectEditor(&result); @@ -22,21 +23,35 @@ void ffPrintEditor(FFEditorOptions* options) return; } - ffPrintLogoAndKey(FF_EDITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); - if (result.exe) + if (options->moduleArgs.outputFormat.length == 0) { - fputs(result.exe, stdout); - if (result.version.length) - printf(" (%s)", result.version.chars); + ffPrintLogoAndKey(FF_EDITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + if (result.exe.length) + { + ffStrbufWriteTo(&result.exe, stdout); + if (result.version.length) + printf(" (%s)", result.version.chars); + } + else + { + ffStrbufWriteTo(&result.name, stdout); + } + putchar('\n'); } else { - ffStrbufWriteTo(&result.name, stdout); + FF_PRINT_FORMAT_CHECKED(FF_EDITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_EDITOR_NUM_FORMAT_ARGS, ((FFformatarg[]){ + {FF_FORMAT_ARG_TYPE_STRING, &result.type, "type"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.exe, "exe-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.path, "path"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.version, "version"}, + })); } - putchar('\n'); ffStrbufDestroy(&result.name); ffStrbufDestroy(&result.path); + ffStrbufDestroy(&result.exe); ffStrbufDestroy(&result.version); } @@ -94,24 +109,23 @@ void ffGenerateEditorJsonResult(FF_MAYBE_UNUSED FFEditorOptions* options, yyjson yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); yyjson_mut_obj_add_strbuf(doc, obj, "name", &result.name); yyjson_mut_obj_add_strbuf(doc, obj, "path", &result.path); - if (result.exe) - yyjson_mut_obj_add_strcpy(doc, obj, "exe", result.exe); - else - yyjson_mut_obj_add_null(doc, obj, "exe"); + yyjson_mut_obj_add_strbuf(doc, obj, "exe", &result.exe); yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version); ffStrbufDestroy(&result.name); ffStrbufDestroy(&result.path); + ffStrbufDestroy(&result.exe); ffStrbufDestroy(&result.version); } void ffPrintEditorHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_EDITOR_MODULE_NAME, "{2} ({4})", FF_EDITOR_NUM_FORMAT_ARGS, ((const char* []) { - "Name", - "Exe name", - "Full path", - "Version", + "Type (Visual / Editor) - type", + "Name - name", + "Exe name of real path - exe-name", + "Full path of real path - full-path", + "Version - version", })); } diff --git a/src/modules/font/font.c b/src/modules/font/font.c index 4cfeeb6d9f..f6014f1a7e 100644 --- a/src/modules/font/font.c +++ b/src/modules/font/font.c @@ -29,11 +29,11 @@ void ffPrintFont(FFFontOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_FONT_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_FONT_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &font.fonts[0]}, - {FF_FORMAT_ARG_TYPE_STRBUF, &font.fonts[1]}, - {FF_FORMAT_ARG_TYPE_STRBUF, &font.fonts[2]}, - {FF_FORMAT_ARG_TYPE_STRBUF, &font.fonts[3]}, - {FF_FORMAT_ARG_TYPE_STRBUF, &font.display}, + {FF_FORMAT_ARG_TYPE_STRBUF, &font.fonts[0], "font1"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &font.fonts[1], "font2"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &font.fonts[2], "font3"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &font.fonts[3], "font4"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &font.display, "combined"}, })); } } @@ -107,11 +107,11 @@ void ffGenerateFontJsonResult(FF_MAYBE_UNUSED FFFontOptions* options, yyjson_mut void ffPrintFontHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_FONT_MODULE_NAME, "{5}", FF_FONT_NUM_FORMAT_ARGS, ((const char* []) { - "Font 1", - "Font 2", - "Font 3", - "Font 4", - "Combined fonts" + "Font 1 - font1", + "Font 2 - font2", + "Font 3 - font3", + "Font 4 - font4", + "Combined fonts for display - combined" })); } diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index bc5417d586..062e375b86 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -29,9 +29,9 @@ static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device ffPercentAppendNum(&percentageStr, device->battery, options->percent, false, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_GAMEPAD_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &device->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->serial}, - {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->serial, "serial"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr, "battery-percentage"}, })); } } @@ -136,9 +136,9 @@ void ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs void ffPrintGamepadHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_GAMEPAD_MODULE_NAME, "{1} ({3})", FF_GAMEPAD_NUM_FORMAT_ARGS, ((const char* []) { - "Name", - "Serial number", - "Battery percentage", + "Name - name", + "Serial number - serial", + "Battery percentage - battery-percentage", })); } diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index b687b5a463..2e59cabadf 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -76,18 +76,18 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate(); ffTempsAppendNum(gpu->temperature, &tempStr, options->tempConfig, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_GPU_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_GPU_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor}, - {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->driver}, - {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr}, - {FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount}, - {FF_FORMAT_ARG_TYPE_STRING, type}, - {FF_FORMAT_ARG_TYPE_UINT64, &gpu->dedicated.total}, - {FF_FORMAT_ARG_TYPE_UINT64, &gpu->dedicated.used}, - {FF_FORMAT_ARG_TYPE_UINT64, &gpu->shared.total}, - {FF_FORMAT_ARG_TYPE_UINT64, &gpu->shared.used}, - {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->platformApi}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->frequency}, + {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor, "vendor"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->driver, "driver"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr, "temperature"}, + {FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount, "core-count"}, + {FF_FORMAT_ARG_TYPE_STRING, type, "type"}, + {FF_FORMAT_ARG_TYPE_UINT64, &gpu->dedicated.total, "dedicated-total"}, + {FF_FORMAT_ARG_TYPE_UINT64, &gpu->dedicated.used, "dedicated-used"}, + {FF_FORMAT_ARG_TYPE_UINT64, &gpu->shared.total, "shared-total"}, + {FF_FORMAT_ARG_TYPE_UINT64, &gpu->shared.used, "shared-used"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->platformApi, "platform-api"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->frequency, "frequency"}, })); } } @@ -368,18 +368,18 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_ void ffPrintGPUHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_GPU_MODULE_NAME, "{1} {2}", FF_GPU_NUM_FORMAT_ARGS, ((const char* []) { - "GPU vendor", - "GPU name", - "GPU driver", - "GPU temperature", - "GPU core count", - "GPU type", - "GPU total dedicated memory", - "GPU used dedicated memory", - "GPU total shared memory", - "GPU used shared memory", - "The platform API that GPU supports", - "Current frequency in GHz", + "GPU vendor - vendor", + "GPU name - name", + "GPU driver - driver", + "GPU temperature - temperature", + "GPU core count - core-count", + "GPU type - type", + "GPU total dedicated memory - dedicated-total", + "GPU used dedicated memory - dedicated-used", + "GPU total shared memory - shared-total", + "GPU used shared memory - shared-used", + "The platform API used when detecting the GPU - platform-api", + "Current frequency in GHz - frequency", })); } diff --git a/src/modules/host/host.c b/src/modules/host/host.c index 3c93f128bb..229c5a4d3d 100644 --- a/src/modules/host/host.c +++ b/src/modules/host/host.c @@ -49,13 +49,13 @@ void ffPrintHost(FFHostOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_HOST_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_HOST_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &host.family}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host.name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host.version}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host.sku}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host.vendor}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host.serial}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host.uuid}, + {FF_FORMAT_ARG_TYPE_STRBUF, &host.family, "family"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &host.name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &host.version, "version"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &host.sku, "sku"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &host.vendor, "vendor"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &host.serial, "serial"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &host.uuid, "uuid"}, })); } @@ -150,13 +150,13 @@ void ffGenerateHostJsonResult(FF_MAYBE_UNUSED FFHostOptions* options, yyjson_mut void ffPrintHostHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_HOST_MODULE_NAME, "{2} {3}", FF_HOST_NUM_FORMAT_ARGS, ((const char* []) { - "product family", - "product name", - "product version", - "product sku", - "product vendor", - "product serial number", - "product uuid", + "product family - family", + "product name - name", + "product version - version", + "product sku - sku", + "product vendor - vendor", + "product serial number - serial", + "product uuid - uuid", })); } diff --git a/src/modules/icons/icons.c b/src/modules/icons/icons.c index 771b64576b..722ddee1ad 100644 --- a/src/modules/icons/icons.c +++ b/src/modules/icons/icons.c @@ -25,7 +25,7 @@ void ffPrintIcons(FFIconsOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_ICONS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_ICONS_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &icons} + {FF_FORMAT_ARG_TYPE_STRBUF, &icons, "combined"} })); } } @@ -82,7 +82,7 @@ void ffGenerateIconsJsonResult(FF_MAYBE_UNUSED FFIconsOptions* options, yyjson_m void ffPrintIconsHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_ICONS_MODULE_NAME, "{1}", FF_ICONS_NUM_FORMAT_ARGS, ((const char* []) { - "Combined icons" + "Combined icons - combined" })); } diff --git a/src/modules/initsystem/initsystem.c b/src/modules/initsystem/initsystem.c new file mode 100644 index 0000000000..f7e1101cb9 --- /dev/null +++ b/src/modules/initsystem/initsystem.c @@ -0,0 +1,143 @@ +#include "common/printing.h" +#include "common/jsonconfig.h" +#include "detection/initsystem/initsystem.h" +#include "modules/initsystem/initsystem.h" +#include "util/stringUtils.h" + +#define FF_INITSYSTEM_NUM_FORMAT_ARGS 4 +#define FF_INITSYSTEM_DISPLAY_NAME "Init System" + +void ffPrintInitSystem(FFInitSystemOptions* options) +{ + FFInitSystemResult result = { + .name = ffStrbufCreate(), + .exe = ffStrbufCreate(), + .version = ffStrbufCreate(), + .pid = 1, + }; + + const char* error = ffDetectInitSystem(&result); + + if(error) + { + ffPrintError(FF_INITSYSTEM_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); + goto exit; + } + + if(options->moduleArgs.outputFormat.length == 0) + { + ffPrintLogoAndKey(FF_INITSYSTEM_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + ffStrbufWriteTo(&result.name, stdout); + if (result.version.length) + printf(" (%s)\n", result.version.chars); + else + putchar('\n'); + } + else + { + FF_PRINT_FORMAT_CHECKED(FF_INITSYSTEM_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_INITSYSTEM_NUM_FORMAT_ARGS, ((FFformatarg[]) { + {FF_FORMAT_ARG_TYPE_STRBUF, &result.name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.exe, "exe"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.version, "version"}, + {FF_FORMAT_ARG_TYPE_UINT, &result.pid, "pid"}, + })); + } + +exit: + ffStrbufDestroy(&result.name); + ffStrbufDestroy(&result.exe); +} + +bool ffParseInitSystemCommandOptions(FFInitSystemOptions* options, const char* key, const char* value) +{ + const char* subKey = ffOptionTestPrefix(key, FF_INITSYSTEM_MODULE_NAME); + if (!subKey) return false; + if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) + return true; + + return false; +} + +void ffParseInitSystemJsonObject(FFInitSystemOptions* options, yyjson_val* module) +{ + yyjson_val *key_, *val; + size_t idx, max; + yyjson_obj_foreach(module, idx, max, key_, val) + { + const char* key = yyjson_get_str(key_); + if(ffStrEqualsIgnCase(key, "type")) + continue; + + if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) + continue; + + ffPrintError(FF_INITSYSTEM_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", key); + } +} + +void ffGenerateInitSystemJsonConfig(FFInitSystemOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyInitSystemOptions))) FFInitSystemOptions defaultOptions; + ffInitInitSystemOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + +void ffGenerateInitSystemJsonResult(FF_MAYBE_UNUSED FFInitSystemOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + FFInitSystemResult result = { + .name = ffStrbufCreate(), + .exe = ffStrbufCreate(), + .version = ffStrbufCreate(), + .pid = 1, + }; + + const char* error = ffDetectInitSystem(&result); + + if (error) + { + yyjson_mut_obj_add_str(doc, module, "error", error); + goto exit; + } + + yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); + yyjson_mut_obj_add_strbuf(doc, obj, "name", &result.name); + yyjson_mut_obj_add_strbuf(doc, obj, "exe", &result.exe); + yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version); + yyjson_mut_obj_add_uint(doc, obj, "pid", result.pid); + +exit: + ffStrbufDestroy(&result.name); + ffStrbufDestroy(&result.exe); +} + +void ffPrintInitSystemHelpFormat(void) +{ + FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_INITSYSTEM_DISPLAY_NAME, "{1}", FF_INITSYSTEM_NUM_FORMAT_ARGS, ((const char* []) { + "init system name - name", + "init system exe path - exe", + "init system version path - version", + "init system pid - pid", + })); +} + +void ffInitInitSystemOptions(FFInitSystemOptions* options) +{ + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_INITSYSTEM_MODULE_NAME, + "Print init system (pid 1) name and version", + ffParseInitSystemCommandOptions, + ffParseInitSystemJsonObject, + ffPrintInitSystem, + ffGenerateInitSystemJsonResult, + ffPrintInitSystemHelpFormat, + ffGenerateInitSystemJsonConfig + ); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyInitSystemOptions(FFInitSystemOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/initsystem/initsystem.h b/src/modules/initsystem/initsystem.h new file mode 100644 index 0000000000..718f6691b6 --- /dev/null +++ b/src/modules/initsystem/initsystem.h @@ -0,0 +1,9 @@ +#pragma once + +#include "fastfetch.h" + +#define FF_INITSYSTEM_MODULE_NAME "InitSystem" + +void ffPrintInitSystem(FFInitSystemOptions* options); +void ffInitInitSystemOptions(FFInitSystemOptions* options); +void ffDestroyInitSystemOptions(FFInitSystemOptions* options); diff --git a/src/modules/initsystem/option.h b/src/modules/initsystem/option.h new file mode 100644 index 0000000000..aa46206709 --- /dev/null +++ b/src/modules/initsystem/option.h @@ -0,0 +1,11 @@ +#pragma once + +// This file will be included in "fastfetch.h", do NOT put unnecessary things here + +#include "common/option.h" + +typedef struct FFInitSystemOptions +{ + FFModuleBaseInfo moduleInfo; + FFModuleArgs moduleArgs; +} FFInitSystemOptions; diff --git a/src/modules/kernel/kernel.c b/src/modules/kernel/kernel.c index 43cdf766f5..862ee19892 100644 --- a/src/modules/kernel/kernel.c +++ b/src/modules/kernel/kernel.c @@ -21,11 +21,11 @@ void ffPrintKernel(FFKernelOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_KERNEL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_KERNEL_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemRelease}, - {FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemVersion}, - {FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemArchitecture}, - {FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemDisplayVersion} + {FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemName, "sysname"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemRelease, "release"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemVersion, "version"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemArchitecture, "arch"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemDisplayVersion, "display-version"}, })); } } @@ -78,11 +78,11 @@ void ffGenerateKernelJsonResult(FF_MAYBE_UNUSED FFKernelOptions* options, yyjson void ffPrintKernelHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_KERNEL_MODULE_NAME, "{1} {2}", FF_KERNEL_NUM_FORMAT_ARGS, ((const char* []) { - "Sysname", - "Release", - "Version", - "Architecture", - "Display version", + "Sysname - sysname", + "Release - release", + "Version - version", + "Architecture - arch", + "Display version - display-version", })); } diff --git a/src/modules/lm/lm.c b/src/modules/lm/lm.c index 24e497bcf8..e2ef460802 100644 --- a/src/modules/lm/lm.c +++ b/src/modules/lm/lm.c @@ -39,9 +39,9 @@ void ffPrintLM(FFLMOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_LM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_LM_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &result.service}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.type}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.version}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.service, "service"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.type, "type"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.version, "version"}, })); } ffStrbufDestroy(&result.service); @@ -118,9 +118,9 @@ void ffGenerateLMJsonResult(FF_MAYBE_UNUSED FFLMOptions* options, yyjson_mut_doc void ffPrintLMHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_LM_MODULE_NAME, "{1} {3} ({2})", FF_LM_NUM_FORMAT_ARGS, ((const char* []) { - "LM service", - "LM type", - "LM version" + "LM service - service", + "LM type - type", + "LM version - version" })); } diff --git a/src/modules/loadavg/loadavg.c b/src/modules/loadavg/loadavg.c index 0caf0f445b..09c1a54651 100644 --- a/src/modules/loadavg/loadavg.c +++ b/src/modules/loadavg/loadavg.c @@ -25,9 +25,9 @@ void ffPrintLoadavg(FFLoadavgOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_LOADAVG_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_LOADAVG_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_DOUBLE, &result[0]}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &result[1]}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &result[2]}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &result[0], "loadavg1"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &result[1], "loadavg2"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &result[2], "loadavg3"}, })); } } @@ -101,9 +101,9 @@ void ffGenerateLoadavgJsonResult(FF_MAYBE_UNUSED FFLoadavgOptions* options, yyjs void ffPrintLoadavgHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_LOADAVG_MODULE_NAME, "{1}, {2}, {3}", FF_LOADAVG_NUM_FORMAT_ARGS, ((const char* []) { - "Load average over 1min", - "Load average over 5min", - "Load average over 15min", + "Load average over 1min - loadavg1", + "Load average over 5min - loadavg2", + "Load average over 15min - loadavg3", })); } diff --git a/src/modules/locale/locale.c b/src/modules/locale/locale.c index c797eba34e..33bb5003ce 100644 --- a/src/modules/locale/locale.c +++ b/src/modules/locale/locale.c @@ -25,7 +25,7 @@ void ffPrintLocale(FFLocaleOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_LOCALE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_LOCALE_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &locale} + {FF_FORMAT_ARG_TYPE_STRBUF, &locale, "result"} })); } } @@ -82,7 +82,7 @@ void ffGenerateLocaleJsonResult(FF_MAYBE_UNUSED FFLocaleOptions* options, yyjson void ffPrintLocaleHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_LOCALE_MODULE_NAME, "{1}", FF_LOCALE_NUM_FORMAT_ARGS, ((const char* []) { - "Locale code" + "Locale code - result" })); } diff --git a/src/modules/localip/localip.c b/src/modules/localip/localip.c index 9cb042eb2b..28aa7d4d33 100644 --- a/src/modules/localip/localip.c +++ b/src/modules/localip/localip.c @@ -26,9 +26,9 @@ static void formatKey(const FFLocalIpOptions* options, FFLocalIpResult* ip, uint { ffStrbufClear(key); FF_PARSE_FORMAT_STRING_CHECKED(key, &options->moduleArgs.key, 3, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT, &index}, - {FF_FORMAT_ARG_TYPE_STRBUF, &ip->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &ip->mac}, + {FF_FORMAT_ARG_TYPE_UINT, &index, "index"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &ip->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &ip->mac, "mac"}, })); } } @@ -111,11 +111,11 @@ void ffPrintLocalIp(FFLocalIpOptions* options) else { FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_LOCALIP_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &ip->ipv4}, - {FF_FORMAT_ARG_TYPE_STRBUF, &ip->ipv6}, - {FF_FORMAT_ARG_TYPE_STRBUF, &ip->mac}, - {FF_FORMAT_ARG_TYPE_STRBUF, &ip->name}, - {FF_FORMAT_ARG_TYPE_BOOL, &ip->defaultRoute}, + {FF_FORMAT_ARG_TYPE_STRBUF, &ip->ipv4, "ipv4"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &ip->ipv6, "ipv6"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &ip->mac, "mac"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &ip->name, "ifname"}, + {FF_FORMAT_ARG_TYPE_BOOL, &ip->defaultRoute, "is-default-route"}, })); } ++index; @@ -387,11 +387,11 @@ void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjs void ffPrintLocalIpHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_LOCALIP_MODULE_NAME, "{1}", FF_LOCALIP_NUM_FORMAT_ARGS, ((const char* []) { - "Local IPv4 address", - "Local IPv6 address", - "Physical (MAC) address", - "Interface name", - "Is default route" + "Local IPv4 address - ipv4", + "Local IPv6 address - ipv6", + "Physical (MAC) address - mac", + "Interface name - ifname", + "Is default route - is-default-route" })); } diff --git a/src/modules/media/media.c b/src/modules/media/media.c index 22c1a2f94d..691511bc27 100644 --- a/src/modules/media/media.c +++ b/src/modules/media/media.c @@ -96,11 +96,11 @@ void ffPrintMedia(FFMediaOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_MEDIA_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_MEDIA_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &songPretty}, - {FF_FORMAT_ARG_TYPE_STRBUF, &media->song}, - {FF_FORMAT_ARG_TYPE_STRBUF, &media->artist}, - {FF_FORMAT_ARG_TYPE_STRBUF, &media->album}, - {FF_FORMAT_ARG_TYPE_STRBUF, &media->status} + {FF_FORMAT_ARG_TYPE_STRBUF, &songPretty, "combined"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &media->song, "title"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &media->artist, "artist"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &media->album, "album"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &media->status, "status"}, })); } } @@ -160,11 +160,11 @@ void ffGenerateMediaJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_m void ffPrintMediaHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_MEDIA_MODULE_NAME, "{3} - {1} ({5})", FF_MEDIA_NUM_FORMAT_ARGS, ((const char* []) { - "Pretty media name", - "Media name", - "Artist name", - "Album name", - "Status", + "Pretty media name - combined", + "Media name - title", + "Artist name - artist", + "Album name - album", + "Status - status", })); } diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index 9f143d0aad..df623e8c53 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -59,9 +59,9 @@ void ffPrintMemory(FFMemoryOptions* options) FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); ffPercentAppendNum(&percentageStr, percentage, options->percent, false, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_MEMORY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_MEMORY_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty}, - {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty}, - {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr}, + {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty, "used"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty, "total"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr, "percentage"}, })); } } @@ -128,9 +128,9 @@ void ffGenerateMemoryJsonResult(FF_MAYBE_UNUSED FFMemoryOptions* options, yyjson void ffPrintMemoryHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_MEMORY_MODULE_NAME, "{1} / {2} ({3})", FF_MEMORY_NUM_FORMAT_ARGS, ((const char* []) { - "Used size", - "Total size", - "Percentage used", + "Used size - used", + "Total size - total", + "Percentage used - percentage", })); } diff --git a/src/modules/modules.h b/src/modules/modules.h index 7971b4abf5..aebd0ac6f3 100644 --- a/src/modules/modules.h +++ b/src/modules/modules.h @@ -28,6 +28,7 @@ #include "modules/gpu/gpu.h" #include "modules/host/host.h" #include "modules/icons/icons.h" +#include "modules/initsystem/initsystem.h" #include "modules/kernel/kernel.h" #include "modules/lm/lm.h" #include "modules/loadavg/loadavg.h" diff --git a/src/modules/monitor/monitor.c b/src/modules/monitor/monitor.c index cc4d82eed4..f1c62963e1 100644 --- a/src/modules/monitor/monitor.c +++ b/src/modules/monitor/monitor.c @@ -42,8 +42,8 @@ void ffPrintMonitor(FFMonitorOptions* options) { uint32_t moduleIndex = result.length == 1 ? 0 : index + 1; FF_PARSE_FORMAT_STRING_CHECKED(&key, &options->moduleArgs.key, 2, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT, &moduleIndex}, - {FF_FORMAT_ARG_TYPE_STRBUF, &display->name}, + {FF_FORMAT_ARG_TYPE_UINT, &moduleIndex, "index"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &display->name, "name"}, })); } @@ -69,16 +69,16 @@ void ffPrintMonitor(FFMonitorOptions* options) buf[0] = '\0'; FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_MONITOR_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &display->name}, - {FF_FORMAT_ARG_TYPE_UINT, &display->width}, - {FF_FORMAT_ARG_TYPE_UINT, &display->height}, - {FF_FORMAT_ARG_TYPE_UINT, &display->physicalWidth}, - {FF_FORMAT_ARG_TYPE_UINT, &display->physicalHeight}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &inch}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &ppi}, - {FF_FORMAT_ARG_TYPE_UINT16, &display->manufactureYear}, - {FF_FORMAT_ARG_TYPE_UINT16, &display->manufactureWeek}, - {FF_FORMAT_ARG_TYPE_STRING, buf}, + {FF_FORMAT_ARG_TYPE_STRBUF, &display->name, "name"}, + {FF_FORMAT_ARG_TYPE_UINT, &display->width, "width"}, + {FF_FORMAT_ARG_TYPE_UINT, &display->height, "height"}, + {FF_FORMAT_ARG_TYPE_UINT, &display->physicalWidth, "physical-width"}, + {FF_FORMAT_ARG_TYPE_UINT, &display->physicalHeight, "physical-height"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &inch, "inch"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &ppi, "ppi"}, + {FF_FORMAT_ARG_TYPE_UINT16, &display->manufactureYear, "manufacture-year"}, + {FF_FORMAT_ARG_TYPE_UINT16, &display->manufactureWeek, "manufacture-week"}, + {FF_FORMAT_ARG_TYPE_STRING, buf, "serial"}, })); } @@ -180,16 +180,16 @@ void ffGenerateMonitorJsonResult(FF_MAYBE_UNUSED FFMonitorOptions* options, yyjs void ffPrintMonitorHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_MONITOR_MODULE_NAME, "{2}x{3} px - {4}x{5} mm ({6} inches, {7} ppi)", FF_MONITOR_NUM_FORMAT_ARGS, ((const char* []) { - "Display name", - "Native resolution width in pixels", - "Native resolution height in pixels", - "Physical width in millimeters", - "Physical height in millimeters", - "Physical diagonal length in inches", - "Pixels per inch (PPI)", - "Year of manufacturing", - "Nth week of manufacturing in the year", - "Serial number", + "Display name - name", + "Native resolution width in pixels - width", + "Native resolution height in pixels - height", + "Physical width in millimeters - physical-width", + "Physical height in millimeters - physical-height", + "Physical diagonal length in inches - inch", + "Pixels per inch (PPI) - ppi", + "Year of manufacturing - manufacture-year", + "Nth week of manufacturing in the year - manufacture-week", + "Serial number - serial", })); } diff --git a/src/modules/netio/netio.c b/src/modules/netio/netio.c index e230536ecd..10d7a3ca12 100644 --- a/src/modules/netio/netio.c +++ b/src/modules/netio/netio.c @@ -26,8 +26,8 @@ static void formatKey(const FFNetIOOptions* options, FFNetIOResult* inf, uint32_ { ffStrbufClear(key); FF_PARSE_FORMAT_STRING_CHECKED(key, &options->moduleArgs.key, 2, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT, &index}, - {FF_FORMAT_ARG_TYPE_STRBUF, &inf->name}, + {FF_FORMAT_ARG_TYPE_UINT, &index, "index"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &inf->name, "name"}, })); } } @@ -80,18 +80,18 @@ void ffPrintNetIO(FFNetIOOptions* options) if (!options->detectTotal) ffStrbufAppendS(&buffer2, "/s"); FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_NETIO_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &buffer}, - {FF_FORMAT_ARG_TYPE_STRBUF, &buffer2}, - {FF_FORMAT_ARG_TYPE_STRBUF, &inf->name}, - {FF_FORMAT_ARG_TYPE_BOOL, &inf->defaultRoute}, - {FF_FORMAT_ARG_TYPE_UINT64, &inf->txBytes}, - {FF_FORMAT_ARG_TYPE_UINT64, &inf->rxBytes}, - {FF_FORMAT_ARG_TYPE_UINT64, &inf->txPackets}, - {FF_FORMAT_ARG_TYPE_UINT64, &inf->rxPackets}, - {FF_FORMAT_ARG_TYPE_UINT64, &inf->rxErrors}, - {FF_FORMAT_ARG_TYPE_UINT64, &inf->txErrors}, - {FF_FORMAT_ARG_TYPE_UINT64, &inf->rxDrops}, - {FF_FORMAT_ARG_TYPE_UINT64, &inf->txDrops}, + {FF_FORMAT_ARG_TYPE_STRBUF, &buffer, "rx-size"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &buffer2, "tx-size"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &inf->name, "ifname"}, + {FF_FORMAT_ARG_TYPE_BOOL, &inf->defaultRoute, "is-default-route"}, + {FF_FORMAT_ARG_TYPE_UINT64, &inf->txBytes, "tx-bytes"}, + {FF_FORMAT_ARG_TYPE_UINT64, &inf->rxBytes, "rx-bytes"}, + {FF_FORMAT_ARG_TYPE_UINT64, &inf->txPackets, "tx-packets"}, + {FF_FORMAT_ARG_TYPE_UINT64, &inf->rxPackets, "rx-packets"}, + {FF_FORMAT_ARG_TYPE_UINT64, &inf->rxErrors, "rx-errors"}, + {FF_FORMAT_ARG_TYPE_UINT64, &inf->txErrors, "tx-errors"}, + {FF_FORMAT_ARG_TYPE_UINT64, &inf->rxDrops, "rx-drops"}, + {FF_FORMAT_ARG_TYPE_UINT64, &inf->txDrops, "tx-drops"}, })); } ++index; @@ -219,18 +219,18 @@ void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyj void ffPrintNetIOHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_NETIO_MODULE_NAME, "{1} (IN) - {2} (OUT)", FF_NETIO_NUM_FORMAT_ARGS, ((const char* []) { - "Size of data received [per second] (formatted)", - "Size of data sent [per second] (formatted)", - "Interface name", - "Is default route", - "Size of data received [per second] (in bytes)", - "Size of data sent [per second] (in bytes)", - "Number of packets received [per second]", - "Number of packets sent [per second]", - "Number of errors received [per second]", - "Number of errors sent [per second]", - "Number of packets dropped when receiving [per second]", - "Number of packets dropped when sending [per second]", + "Size of data received [per second] (formatted) - rx-size", + "Size of data sent [per second] (formatted) - tx-size", + "Interface name - ifname", + "Is default route - is-default-route", + "Size of data received [per second] (in bytes) - rx-bytes", + "Size of data sent [per second] (in bytes) - tx-bytes", + "Number of packets received [per second] - rx-packets", + "Number of packets sent [per second] - tx-packets", + "Number of errors received [per second] - rx-errors", + "Number of errors sent [per second] - tx-errors", + "Number of packets dropped when receiving [per second] - rx-drops", + "Number of packets dropped when sending [per second] - tx-drops", })); } diff --git a/src/modules/opencl/opencl.c b/src/modules/opencl/opencl.c index ed8e053c55..3a21351850 100644 --- a/src/modules/opencl/opencl.c +++ b/src/modules/opencl/opencl.c @@ -27,9 +27,9 @@ void ffPrintOpenCL(FFOpenCLOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_OPENCL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_OPENCL_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.version}, - {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.device}, - {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.vendor}, + {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.version, "version"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.device, "device"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.vendor, "vendor"}, })); } } @@ -103,9 +103,9 @@ void ffGenerateOpenCLJsonResult(FF_MAYBE_UNUSED FFOpenCLOptions* options, yyjson void ffPrintOpenCLHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_OPENCL_MODULE_NAME, "{1}", FF_OPENCL_NUM_FORMAT_ARGS, ((const char* []) { - "version", - "device", - "vendor" + "version - version", + "device - device", + "vendor - vendor" })); } diff --git a/src/modules/opengl/opengl.c b/src/modules/opengl/opengl.c index 17fbe52c4e..3f9e422112 100644 --- a/src/modules/opengl/opengl.c +++ b/src/modules/opengl/opengl.c @@ -29,10 +29,10 @@ void ffPrintOpenGL(FFOpenGLOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_OPENGL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_OPENGL_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &result.version}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.renderer}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.vendor}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.slv}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.version, "version"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.renderer, "renderer"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.vendor, "vendor"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.slv, "slv"}, })); } @@ -161,10 +161,10 @@ void ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson void ffPrintOpenGLHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_OPENGL_MODULE_NAME, "{1}", FF_OPENGL_NUM_FORMAT_ARGS, ((const char* []) { - "version", - "renderer", - "vendor", - "shading language version" + "version - version", + "renderer - renderer", + "vendor - vendor", + "shading language version - slv" })); } diff --git a/src/modules/options.h b/src/modules/options.h index e75dd6bce3..f3df14ee27 100644 --- a/src/modules/options.h +++ b/src/modules/options.h @@ -28,6 +28,7 @@ #include "modules/gamepad/option.h" #include "modules/gpu/option.h" #include "modules/icons/option.h" +#include "modules/initsystem/option.h" #include "modules/kernel/option.h" #include "modules/loadavg/option.h" #include "modules/locale/option.h" diff --git a/src/modules/os/os.c b/src/modules/os/os.c index 40fbb7fde9..87cb7a1b76 100644 --- a/src/modules/os/os.c +++ b/src/modules/os/os.c @@ -112,18 +112,18 @@ void ffPrintOS(FFOSOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_OS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_OS_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.systemName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &os->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &os->prettyName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &os->id}, - {FF_FORMAT_ARG_TYPE_STRBUF, &os->idLike}, - {FF_FORMAT_ARG_TYPE_STRBUF, &os->variant}, - {FF_FORMAT_ARG_TYPE_STRBUF, &os->variantID}, - {FF_FORMAT_ARG_TYPE_STRBUF, &os->version}, - {FF_FORMAT_ARG_TYPE_STRBUF, &os->versionID}, - {FF_FORMAT_ARG_TYPE_STRBUF, &os->codename}, - {FF_FORMAT_ARG_TYPE_STRBUF, &os->buildID}, - {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.systemArchitecture} + {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.systemName, "sysname"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &os->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &os->prettyName, "pretty-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &os->id, "id"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &os->idLike, "id-like"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &os->variant, "variant"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &os->variantID, "variant-id"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &os->version, "version"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &os->versionID, "version-id"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &os->codename, "codename"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &os->buildID, "build-id"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.systemArchitecture, "arch"} })); } } @@ -189,18 +189,18 @@ void ffGenerateOSJsonResult(FF_MAYBE_UNUSED FFOSOptions* options, yyjson_mut_doc void ffPrintOSHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_OS_MODULE_NAME, "{3} {10} {12}", FF_OS_NUM_FORMAT_ARGS, ((const char* []) { - "Name of the kernel (Linux, WIN32_NT, Darwin, FreeBSD)", - "Name of the OS", - "Pretty name of the OS", - "ID of the OS", - "ID like of the OS", - "Variant of the OS", - "Variant ID of the OS", - "Version of the OS", - "Version ID of the OS", - "Version codename of the OS", - "Build ID of the OS", - "Architecture of the OS" + "Name of the kernel (Linux, WIN32_NT, Darwin, FreeBSD) - sysname", + "Name of the OS - name", + "Pretty name of the OS - pretty-name", + "ID of the OS - id", + "ID like of the OS - id-like", + "Variant of the OS - variant", + "Variant ID of the OS - variant-id", + "Version of the OS - version", + "Version ID of the OS - version-id", + "Version codename of the OS - codename", + "Build ID of the OS - build-id", + "Architecture of the OS - arch", })); } diff --git a/src/modules/packages/option.h b/src/modules/packages/option.h index f294b916c7..2456ce85a3 100644 --- a/src/modules/packages/option.h +++ b/src/modules/packages/option.h @@ -30,6 +30,7 @@ typedef enum FFPackagesFlags FF_PACKAGES_FLAG_SORCERY_BIT = 1 << 20, FF_PACKAGES_FLAG_LPKG_BIT = 1 << 21, FF_PACKAGES_FLAG_LPKGBUILD_BIT = 1 << 22, + FF_PACKAGES_FLAG_GUIX_BIT = 1 << 23, } FFPackagesFlags; typedef struct FFPackagesOptions diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index 229e1f43c8..f88390cb0c 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -4,7 +4,7 @@ #include "modules/packages/packages.h" #include "util/stringUtils.h" -#define FF_PACKAGES_NUM_FORMAT_ARGS 32 +#define FF_PACKAGES_NUM_FORMAT_ARGS 36 void ffPrintPackages(FFPackagesOptions* options) { @@ -68,6 +68,9 @@ void ffPrintPackages(FFPackagesOptions* options) FF_PRINT_PACKAGE(sorcery) FF_PRINT_PACKAGE(lpkg) FF_PRINT_PACKAGE(lpkgbuild) + FF_PRINT_PACKAGE_NAME(guixSystem, "guix-system") + FF_PRINT_PACKAGE_NAME(guixUser, "guix-user") + FF_PRINT_PACKAGE_NAME(guixHome, "guix-home") putchar('\n'); } @@ -76,39 +79,44 @@ void ffPrintPackages(FFPackagesOptions* options) uint32_t nixAll = counts.nixDefault + counts.nixSystem + counts.nixUser; uint32_t flatpakAll = counts.flatpakSystem + counts.flatpakUser; uint32_t brewAll = counts.brew + counts.brewCask; + uint32_t guixAll = counts.guixSystem + counts.guixUser + counts.guixHome; FF_PRINT_FORMAT_CHECKED(FF_PACKAGES_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_PACKAGES_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT, &counts.all}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.pacman}, - {FF_FORMAT_ARG_TYPE_STRBUF, &counts.pacmanBranch}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.dpkg}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.rpm}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.emerge}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.eopkg}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.xbps}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.nixSystem}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.nixUser}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.nixDefault}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.apk}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.pkg}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.flatpakSystem}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.flatpakUser}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.snap}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.brew}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.brewCask}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.macports}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.scoop}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.choco}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.pkgtool}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.paludis}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.winget}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.opkg}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.am}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.sorcery}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.lpkg}, - {FF_FORMAT_ARG_TYPE_UINT, &counts.lpkgbuild}, - {FF_FORMAT_ARG_TYPE_UINT, &nixAll}, - {FF_FORMAT_ARG_TYPE_UINT, &flatpakAll}, - {FF_FORMAT_ARG_TYPE_UINT, &brewAll}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.all, "all"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.pacman, "pacman"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &counts.pacmanBranch, "pacman-branch"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.dpkg, "dpkg"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.rpm, "rpm"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.emerge, "emerge"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.eopkg, "eopkg"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.xbps, "xbps"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.nixSystem, "nix-system"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.nixUser, "nix-user"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.nixDefault, "nix-default"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.apk, "apk"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.pkg, "pkg"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.flatpakSystem, "flatpak-system"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.flatpakUser, "flatpak-user"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.snap, "snap"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.brew, "brew"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.brewCask, "brew-cask"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.macports, "macports"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.scoop, "scoop"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.choco, "choco"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.pkgtool, "pkgtool"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.paludis, "paludis"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.winget, "winget"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.opkg, "opkg"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.am, "am"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.sorcery, "sorcery"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.lpkg, "lpkg"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.lpkgbuild, "lpkgbuild"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.guixSystem, "guix-system"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.guixUser, "guix-user"}, + {FF_FORMAT_ARG_TYPE_UINT, &counts.guixHome, "guix-home"}, + {FF_FORMAT_ARG_TYPE_UINT, &nixAll, "nix-all"}, + {FF_FORMAT_ARG_TYPE_UINT, &flatpakAll, "flatpak-all"}, + {FF_FORMAT_ARG_TYPE_UINT, &brewAll, "brew-all"}, + {FF_FORMAT_ARG_TYPE_UINT, &guixAll, "guix-all"}, })); } @@ -157,6 +165,9 @@ bool ffParsePackagesCommandOptions(FFPackagesOptions* options, const char* key, case 'F': if (false); FF_TEST_PACKAGE_NAME(FLATPAK) break; + case 'G': if (false); + FF_TEST_PACKAGE_NAME(GUIX) + break; case 'L': if (false); FF_TEST_PACKAGE_NAME(LPKG) FF_TEST_PACKAGE_NAME(LPKGBUILD) @@ -262,6 +273,9 @@ void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module) case 'F': if (false); FF_TEST_PACKAGE_NAME(FLATPAK) break; + case 'G': if (false); + FF_TEST_PACKAGE_NAME(GUIX) + break; case 'L': if (false); FF_TEST_PACKAGE_NAME(LPKG) FF_TEST_PACKAGE_NAME(LPKGBUILD) @@ -341,6 +355,7 @@ void ffGeneratePackagesJsonConfig(FFPackagesOptions* options, yyjson_mut_doc* do FF_TEST_PACKAGE_NAME(XBPS) FF_TEST_PACKAGE_NAME(AM) FF_TEST_PACKAGE_NAME(SORCERY) + FF_TEST_PACKAGE_NAME(GUIX) #undef FF_TEST_PACKAGE_NAME } } @@ -388,44 +403,51 @@ void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yy FF_APPEND_PACKAGE_COUNT(opkg) FF_APPEND_PACKAGE_COUNT(am) FF_APPEND_PACKAGE_COUNT(sorcery) + FF_APPEND_PACKAGE_COUNT(guixSystem) + FF_APPEND_PACKAGE_COUNT(guixUser) + FF_APPEND_PACKAGE_COUNT(guixHome) yyjson_mut_obj_add_strbuf(doc, obj, "pacmanBranch", &counts.pacmanBranch); } void ffPrintPackagesHelpFormat(void) { - FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_PACKAGES_MODULE_NAME, "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (emerge), {7} (eopkg), {8} (xbps), {9} (nix-system), {10} (nix-user), {11} (nix-default), {12} (apk), {13} (pkg), {14} (flatpak-system), {15} (flatpack-user), {16} (snap), {17} (brew), {18} (brew-cask), {19} (MacPorts), {20} (scoop), {21} (choco), {22} (pkgtool), {23} (paludis), {24} (winget), {25} (opkg), {26} (am), {27} (sorcery), {28} (lpkg), {29} (lpkgbuild)", FF_PACKAGES_NUM_FORMAT_ARGS, ((const char* []) { - "Number of all packages", - "Number of pacman packages", - "Pacman branch on manjaro", - "Number of dpkg packages", - "Number of rpm packages", - "Number of emerge packages", - "Number of eopkg packages", - "Number of xbps packages", - "Number of nix-system packages", - "Number of nix-user packages", - "Number of nix-default packages", - "Number of apk packages", - "Number of pkg packages", - "Number of flatpak-system packages", - "Number of flatpak-user packages", - "Number of snap packages", - "Number of brew packages", - "Number of brew-cask packages", - "Number of macports packages", - "Number of scoop packages", - "Number of choco packages", - "Number of pkgtool packages", - "Number of paludis packages", - "Number of winget packages", - "Number of opkg packages", - "Number of am packages", - "Number of sorcery packages", - "Number of lpkg packages", - "Number of lpkgbuild packages", - "Total number of all nix packages", - "Total number of all flatpak packages", - "Total number of all brew packages", + FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_PACKAGES_MODULE_NAME, "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (emerge), {7} (eopkg), {8} (xbps), {9} (nix-system), {10} (nix-user), {11} (nix-default), {12} (apk), {13} (pkg), {14} (flatpak-system), {15} (flatpack-user), {16} (snap), {17} (brew), {18} (brew-cask), {19} (MacPorts), {20} (scoop), {21} (choco), {22} (pkgtool), {23} (paludis), {24} (winget), {25} (opkg), {26} (am), {27} (sorcery), {28} (lpkg), {29} (lpkgbuild), {30} (guix-system), {31} (guix-user), {32} (guix-home)", FF_PACKAGES_NUM_FORMAT_ARGS, ((const char* []) { + "Number of all packages - all", + "Number of pacman packages - pacman", + "Pacman branch on manjaro - pacman-branch", + "Number of dpkg packages - dpkg", + "Number of rpm packages - rpm", + "Number of emerge packages - emerge", + "Number of eopkg packages - eopkg", + "Number of xbps packages - xbps", + "Number of nix-system packages - nix-system", + "Number of nix-user packages - nix-user", + "Number of nix-default packages - nix-default", + "Number of apk packages - apk", + "Number of pkg packages - pkg", + "Number of flatpak-system packages - flatpak-system", + "Number of flatpak-user packages - flatpak-user", + "Number of snap packages - snap", + "Number of brew packages - brew", + "Number of brew-cask packages - brew-cask", + "Number of macports packages - macports", + "Number of scoop packages - scoop", + "Number of choco packages - choco", + "Number of pkgtool packages - pkgtool", + "Number of paludis packages - paludis", + "Number of winget packages - winget", + "Number of opkg packages - opkg", + "Number of am packages - am", + "Number of sorcery packages - sorcery", + "Number of lpkg packages - lpkg", + "Number of lpkgbuild packages - lpkgbuild", + "Number of guix-system packages - guix-system", + "Number of guix-user packages - guix-user", + "Number of guix-home packages - guix-home", + "Total number of all nix packages - nix-all", + "Total number of all flatpak packages - flatpak-all", + "Total number of all brew packages - brew-all", + "Total number of all guix packages - guix-all", })); } diff --git a/src/modules/physicaldisk/physicaldisk.c b/src/modules/physicaldisk/physicaldisk.c index 73380bcdff..8827eb3175 100644 --- a/src/modules/physicaldisk/physicaldisk.c +++ b/src/modules/physicaldisk/physicaldisk.c @@ -24,9 +24,9 @@ static void formatKey(const FFPhysicalDiskOptions* options, FFPhysicalDiskResult { ffStrbufClear(key); FF_PARSE_FORMAT_STRING_CHECKED(key, &options->moduleArgs.key, 3, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT, &index}, - {FF_FORMAT_ARG_TYPE_STRBUF, &dev->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &dev->devPath}, + {FF_FORMAT_ARG_TYPE_UINT, &index, "index"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &dev->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &dev->devPath, "dev-path"}, })); } } @@ -108,16 +108,16 @@ void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options) if (dev->type & FF_PHYSICALDISK_TYPE_READWRITE) readOnlyType = "Read-write"; FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_PHYSICALDISK_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &buffer}, - {FF_FORMAT_ARG_TYPE_STRBUF, &dev->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &dev->interconnect}, - {FF_FORMAT_ARG_TYPE_STRING, physicalType}, - {FF_FORMAT_ARG_TYPE_STRBUF, &dev->devPath}, - {FF_FORMAT_ARG_TYPE_STRBUF, &dev->serial}, - {FF_FORMAT_ARG_TYPE_STRING, removableType}, - {FF_FORMAT_ARG_TYPE_STRING, readOnlyType}, - {FF_FORMAT_ARG_TYPE_STRBUF, &dev->revision}, - {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr}, + {FF_FORMAT_ARG_TYPE_STRBUF, &buffer, "size"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &dev->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &dev->interconnect, "interconnect"}, + {FF_FORMAT_ARG_TYPE_STRING, physicalType, "type"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &dev->devPath, "dev-path"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &dev->serial, "serial"}, + {FF_FORMAT_ARG_TYPE_STRING, removableType, "removable-type"}, + {FF_FORMAT_ARG_TYPE_STRING, readOnlyType, "readonly-type"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &dev->revision, "revision"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &tempStr, "temperature"}, })); } ++index; @@ -252,7 +252,7 @@ void ffGeneratePhysicalDiskJsonResult(FFPhysicalDiskOptions* options, yyjson_mut void ffPrintPhysicalDiskHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_PHYSICALDISK_MODULE_NAME, "{1} [{6}, {7}, {8}]", FF_PHYSICALDISK_NUM_FORMAT_ARGS, ((const char* []) { - "Device size (formatted)", + "Device size (formatted) - ", "Device name", "Device interconnect type", "Device raw file path", diff --git a/src/modules/physicalmemory/physicalmemory.c b/src/modules/physicalmemory/physicalmemory.c index 8b92517a7e..fd748d4c8c 100644 --- a/src/modules/physicalmemory/physicalmemory.c +++ b/src/modules/physicalmemory/physicalmemory.c @@ -54,17 +54,17 @@ void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options) else { FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_PHYSICALMEMORY_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_UINT64, &device->size}, - {FF_FORMAT_ARG_TYPE_STRBUF, &prettySize}, - {FF_FORMAT_ARG_TYPE_UINT, &device->maxSpeed}, - {FF_FORMAT_ARG_TYPE_UINT, &device->runningSpeed}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->type}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->formFactor}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &device->locator}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->vendor}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->serial}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->partNumber}, - {FF_FORMAT_ARG_TYPE_BOOL, &device->ecc}, + {FF_FORMAT_ARG_TYPE_UINT64, &device->size, "bytes"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &prettySize, "size"}, + {FF_FORMAT_ARG_TYPE_UINT, &device->maxSpeed, "max-speed"}, + {FF_FORMAT_ARG_TYPE_UINT, &device->runningSpeed, "running-speed"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->type, "type"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->formFactor, "form-factor"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &device->locator, "locator"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->vendor, "vendor"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->serial, "serial"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->partNumber, "part-number"}, + {FF_FORMAT_ARG_TYPE_BOOL, &device->ecc, "is-ecc-enabled"}, })); } } @@ -156,17 +156,17 @@ void ffGeneratePhysicalMemoryJsonResult(FF_MAYBE_UNUSED FFPhysicalMemoryOptions* void ffPrintPhysicalMemoryHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_PHYSICALMEMORY_MODULE_NAME, "{7} {5}-{3}: {2}, running at {4} MT/s", FF_PHYSICALMEMORY_NUM_FORMAT_ARGS, ((const char* []) { - "Size (in bytes)", - "Size formatted", - "Max speed (in MT/s)", - "Running speed (in MT/s)", - "Type (DDR4, DDR5, etc.)", - "Form factor (SODIMM, DIMM, etc.)", - "Bank/Device Locator (BANK0/SIMM0, BANK0/SIMM1, etc.)", - "Vendor", - "Serial number", - "Part number", - "ECC enabled", + "Size (in bytes) - bytes", + "Size formatted - size", + "Max speed (in MT/s) - max-speed", + "Running speed (in MT/s) - running-speed", + "Type (DDR4, DDR5, etc.) - type", + "Form factor (SODIMM, DIMM, etc.) - form-factor", + "Bank/Device Locator (BANK0/SIMM0, BANK0/SIMM1, etc.) - locator", + "Vendor - vendor", + "Serial number - serial", + "Part number - part-number", + "True if ECC enabled - is-ecc-enabled", })); } diff --git a/src/modules/player/player.c b/src/modules/player/player.c index ea3af7fa2c..df6c8a534a 100644 --- a/src/modules/player/player.c +++ b/src/modules/player/player.c @@ -65,10 +65,10 @@ void ffPrintPlayer(FFPlayerOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_PLAYER_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_PLAYER_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &playerPretty}, - {FF_FORMAT_ARG_TYPE_STRBUF, &media->player}, - {FF_FORMAT_ARG_TYPE_STRBUF, &media->playerId}, - {FF_FORMAT_ARG_TYPE_STRBUF, &media->url} + {FF_FORMAT_ARG_TYPE_STRBUF, &playerPretty, "player"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &media->player, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &media->playerId, "id"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &media->url, "url"} })); } } @@ -127,10 +127,10 @@ void ffGeneratePlayerJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_ void ffPrintPlayerHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_PLAYER_MODULE_NAME, "{1}", FF_PLAYER_NUM_FORMAT_ARGS, ((const char* []) { - "Pretty player name", - "Player name", - "Player Identifier", - "URL name" + "Pretty player name - player", + "Player name - name", + "Player Identifier - id", + "URL name - url", })); } diff --git a/src/modules/poweradapter/poweradapter.c b/src/modules/poweradapter/poweradapter.c index e07e15a11e..b5c570a1c4 100644 --- a/src/modules/poweradapter/poweradapter.c +++ b/src/modules/poweradapter/poweradapter.c @@ -39,12 +39,12 @@ void ffPrintPowerAdapter(FFPowerAdapterOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_POWERADAPTER_DISPLAY_NAME, i, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_POWERADAPTER_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_INT, &result->watts}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->description}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->serial}, + {FF_FORMAT_ARG_TYPE_INT, &result->watts, "watts"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer, "manufacturer"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName, "model-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->description, "description"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->serial, "serial"}, })); } @@ -129,12 +129,12 @@ void ffGeneratePowerAdapterJsonResult(FF_MAYBE_UNUSED FFPowerAdapterOptions* opt void ffPrintPowerAdapterHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_POWERADAPTER_MODULE_NAME, "{1}W", FF_POWERADAPTER_NUM_FORMAT_ARGS, ((const char* []) { - "PowerAdapter watts", - "PowerAdapter name", - "PowerAdapter manufacturer", - "PowerAdapter model", - "PowerAdapter description", - "PowerAdapter serial number", + "PowerAdapter watts - watts", + "PowerAdapter name - name", + "PowerAdapter manufacturer - manufacturer", + "PowerAdapter model - model", + "PowerAdapter description - description", + "PowerAdapter serial number - serial", })); } diff --git a/src/modules/processes/processes.c b/src/modules/processes/processes.c index 34ed40afc7..77cf64275b 100644 --- a/src/modules/processes/processes.c +++ b/src/modules/processes/processes.c @@ -26,7 +26,7 @@ void ffPrintProcesses(FFProcessesOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_PROCESSES_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_PROCESSES_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT, &numProcesses} + {FF_FORMAT_ARG_TYPE_UINT, &numProcesses, "result"} })); } } @@ -83,7 +83,7 @@ void ffGenerateProcessesJsonResult(FF_MAYBE_UNUSED FFProcessesOptions* options, void ffPrintProcessesHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_PROCESSES_MODULE_NAME, "{1}", FF_PROCESSES_NUM_FORMAT_ARGS, (const char* []) { - "Count" + "Proecess count - result" }); } diff --git a/src/modules/publicip/publicip.c b/src/modules/publicip/publicip.c index 7de5047908..daf09593c4 100644 --- a/src/modules/publicip/publicip.c +++ b/src/modules/publicip/publicip.c @@ -31,8 +31,8 @@ void ffPrintPublicIp(FFPublicIpOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_PUBLICIP_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_PUBLICIP_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &result.ip}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result.location}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.ip, "ip"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result.location, "location"}, })); } @@ -144,8 +144,8 @@ void ffGeneratePublicIpJsonResult(FFPublicIpOptions* options, yyjson_mut_doc* do void ffPrintPublicIpHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_PUBLICIP_MODULE_NAME, "{1} ({2})", FF_PUBLICIP_NUM_FORMAT_ARGS, ((const char* []) { - "Public IP address", - "Location" + "Public IP address - ip", + "Location - location", })); } diff --git a/src/modules/shell/shell.c b/src/modules/shell/shell.c index 8056ae854d..ef0c6f79ea 100644 --- a/src/modules/shell/shell.c +++ b/src/modules/shell/shell.c @@ -32,14 +32,14 @@ void ffPrintShell(FFShellOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_SHELL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_SHELL_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &result->processName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->exe}, - {FF_FORMAT_ARG_TYPE_STRING, result->exeName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->version}, - {FF_FORMAT_ARG_TYPE_UINT, &result->pid}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->prettyName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->exePath}, - {FF_FORMAT_ARG_TYPE_INT, &result->tty}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->processName, "process-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->exe, "exe"}, + {FF_FORMAT_ARG_TYPE_STRING, result->exeName, "exe-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->version, "version"}, + {FF_FORMAT_ARG_TYPE_UINT, &result->pid, "pid"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->prettyName, "pretty-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->exePath, "exe-path"}, + {FF_FORMAT_ARG_TYPE_INT, &result->tty, "tty"}, })); } } @@ -107,14 +107,14 @@ void ffGenerateShellJsonResult(FF_MAYBE_UNUSED FFShellOptions* options, yyjson_m void ffPrintShellHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_SHELL_MODULE_NAME, "{3} {4}", FF_SHELL_NUM_FORMAT_ARGS, ((const char* []) { - "Shell process name", - "The first argument of the command line when running the shell", - "Shell base name of arg0", - "Shell version", - "Shell pid", - "Shell pretty name", - "Shell full exe path", - "Shell tty used", + "Shell process name - process-name", + "The first argument of the command line when running the shell - exe", + "Shell base name of arg0 - exe-name", + "Shell version - version", + "Shell pid - pid", + "Shell pretty name - pretty-name", + "Shell full exe path - exe-path", + "Shell tty used - tty", })); } diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index 9b9437be92..0b1c39cbfb 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -50,10 +50,10 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui ffPercentAppendNum(&percentageStr, device->volume, options->percent, false, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_SOUND_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_SOUND_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_BOOL, &device->main}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr}, - {FF_FORMAT_ARG_TYPE_STRBUF, &device->identifier} + {FF_FORMAT_ARG_TYPE_BOOL, &device->main, "is-main"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr, "volume-percentage"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &device->identifier, "identifier"}, })); } } @@ -226,10 +226,10 @@ void ffGenerateSoundJsonResult(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_m void ffPrintSoundHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_SOUND_MODULE_NAME, "{2} ({3}%)", FF_SOUND_NUM_FORMAT_ARGS, ((const char* []) { - "Is main sound device", - "Device name", - "Volume", - "Identifier" + "Is main sound device - is-main", + "Device name - name", + "Volume (in percentage) - volume-percentage", + "Identifier - identifier", })); } diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index 4b68c47097..ac2b277b03 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -68,9 +68,9 @@ void ffPrintSwap(FFSwapOptions* options) FF_STRBUF_AUTO_DESTROY percentageStr = ffStrbufCreate(); ffPercentAppendNum(&percentageStr, percentage, options->percent, false, &options->moduleArgs); FF_PRINT_FORMAT_CHECKED(FF_SWAP_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_SWAP_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty}, - {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty}, - {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr}, + {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty, "used"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty, "total"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &percentageStr, "percentage"}, })); } } @@ -137,9 +137,9 @@ void ffGenerateSwapJsonResult(FF_MAYBE_UNUSED FFSwapOptions* options, yyjson_mut void ffPrintSwapHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_SWAP_MODULE_NAME, "{1} / {2} ({3})", FF_SWAP_NUM_FORMAT_ARGS, ((const char* []) { - "Used size", - "Total size", - "Percentage used" + "Used size - used", + "Total size - total", + "Percentage used - percentage", })); } diff --git a/src/modules/terminal/terminal.c b/src/modules/terminal/terminal.c index fb5defdeb6..b5f2509dfc 100644 --- a/src/modules/terminal/terminal.c +++ b/src/modules/terminal/terminal.c @@ -30,14 +30,14 @@ void ffPrintTerminal(FFTerminalOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_TERMINAL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_TERMINAL_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &result->processName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->exe}, - {FF_FORMAT_ARG_TYPE_STRING, result->exeName}, - {FF_FORMAT_ARG_TYPE_UINT, &result->pid}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->prettyName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->version}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->exePath}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->tty}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->processName, "process-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->exe, "exe"}, + {FF_FORMAT_ARG_TYPE_STRING, result->exeName, "exe-name"}, + {FF_FORMAT_ARG_TYPE_UINT, &result->pid, "pid"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->prettyName, "pretty-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->version, "version"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->exePath, "exe-path"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->tty, "tty"}, })); } } @@ -102,14 +102,14 @@ void ffGenerateTerminalJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yy void ffPrintTerminalHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_TERMINAL_MODULE_NAME, "{5} {6}", FF_TERMINAL_NUM_FORMAT_ARGS, ((const char* []) { - "Terminal process name", - "The first argument of the command line when running the terminal", - "Terminal base name of arg0", - "Terminal pid", - "Terminal pretty name", - "Terminal version", - "Terminal full exe path", - "Terminal tty / pts used", + "Terminal process name - process-name", + "The first argument of the command line when running the terminal - exe", + "Terminal base name of arg0 - exe-name", + "Terminal pid - pid", + "Terminal pretty name - pretty-name", + "Terminal version - version", + "Terminal full exe path - exe-path", + "Terminal tty / pts used - tty", })); } diff --git a/src/modules/terminalfont/terminalfont.c b/src/modules/terminalfont/terminalfont.c index 944f18fdba..6dd1b17bc7 100644 --- a/src/modules/terminalfont/terminalfont.c +++ b/src/modules/terminalfont/terminalfont.c @@ -34,10 +34,10 @@ void ffPrintTerminalFont(FFTerminalFontOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_TERMINALFONT_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_TERMINALFONT_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont.font.pretty}, - {FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont.font.name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont.font.size}, - {FF_FORMAT_ARG_TYPE_LIST, &terminalFont.font.styles} + {FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont.font.pretty, "combined"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont.font.name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &terminalFont.font.size, "size"}, + {FF_FORMAT_ARG_TYPE_LIST, &terminalFont.font.styles, "styles"}, })); } } @@ -124,10 +124,10 @@ void ffGenerateTerminalFontJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options void ffPrintTerminalFontHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_TERMINALFONT_MODULE_NAME, "{1}", FF_TERMINALFONT_NUM_FORMAT_ARGS, ((const char* []) { - "Terminal font combined", - "Terminal font name", - "Terminal font size", - "Terminal font styles" + "Terminal font combined - combined", + "Terminal font name - name", + "Terminal font size - size", + "Terminal font styles - styles", })); } diff --git a/src/modules/terminalsize/terminalsize.c b/src/modules/terminalsize/terminalsize.c index c54bf52d00..425df3bc89 100644 --- a/src/modules/terminalsize/terminalsize.c +++ b/src/modules/terminalsize/terminalsize.c @@ -30,10 +30,10 @@ void ffPrintTerminalSize(FFTerminalSizeOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_TERMINALSIZE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_TERMINALSIZE_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT16, &result.rows}, - {FF_FORMAT_ARG_TYPE_UINT16, &result.columns}, - {FF_FORMAT_ARG_TYPE_UINT16, &result.width}, - {FF_FORMAT_ARG_TYPE_UINT16, &result.height} + {FF_FORMAT_ARG_TYPE_UINT16, &result.rows, "rows"}, + {FF_FORMAT_ARG_TYPE_UINT16, &result.columns, "columns"}, + {FF_FORMAT_ARG_TYPE_UINT16, &result.width, "width"}, + {FF_FORMAT_ARG_TYPE_UINT16, &result.height, "height"}, })); } } @@ -94,10 +94,10 @@ void ffGenerateTerminalSizeJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options void ffPrintTerminalSizeHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_TERMINALSIZE_MODULE_NAME, "{1} columns x {2} rows ({3}px x {4}px)", FF_TERMINALSIZE_NUM_FORMAT_ARGS, ((const char* []) { - "Terminal rows", - "Terminal columns", - "Terminal width (in pixels)", - "Terminal height (in pixels)" + "Terminal rows - rows", + "Terminal columns - columns", + "Terminal width (in pixels) - width", + "Terminal height (in pixels) - height", })); } diff --git a/src/modules/terminaltheme/terminaltheme.c b/src/modules/terminaltheme/terminaltheme.c index 76510f644e..21a06ec768 100644 --- a/src/modules/terminaltheme/terminaltheme.c +++ b/src/modules/terminaltheme/terminaltheme.c @@ -33,10 +33,10 @@ void ffPrintTerminalTheme(FFTerminalThemeOptions* options) snprintf(fg, sizeof(fg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.fg.r, result.fg.g, result.fg.b); snprintf(bg, sizeof(bg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.bg.r, result.bg.g, result.bg.b); FF_PRINT_FORMAT_CHECKED(FF_TERMINALTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_TERMINALTHEME_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRING, fg}, - {FF_FORMAT_ARG_TYPE_STRING, result.fg.dark ? "Dark" : "Light"}, - {FF_FORMAT_ARG_TYPE_STRING, bg}, - {FF_FORMAT_ARG_TYPE_STRING, result.bg.dark ? "Dark" : "Light"}, + {FF_FORMAT_ARG_TYPE_STRING, fg, "fg-color"}, + {FF_FORMAT_ARG_TYPE_STRING, result.fg.dark ? "Dark" : "Light", "fg-type"}, + {FF_FORMAT_ARG_TYPE_STRING, bg, "bg-color"}, + {FF_FORMAT_ARG_TYPE_STRING, result.bg.dark ? "Dark" : "Light", "bg-type"}, })); } } @@ -105,10 +105,10 @@ void ffGenerateTerminalThemeJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* option void ffPrintTerminalThemeHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_TERMINALTHEME_MODULE_NAME, "{1} (FG) {3} (BG) [{4}]", FF_TERMINALTHEME_NUM_FORMAT_ARGS, ((const char* []) { - "Terminal foreground color", - "Terminal foreground type (Dark / Light)", - "Terminal background color", - "Terminal background type (Dark / Light)", + "Terminal foreground color - fg-color", + "Terminal foreground type (Dark / Light) - fg-type", + "Terminal background color - bg-color", + "Terminal background type (Dark / Light) - bg-type", })); } diff --git a/src/modules/theme/theme.c b/src/modules/theme/theme.c index 3d29027806..8e8ea78d5c 100644 --- a/src/modules/theme/theme.c +++ b/src/modules/theme/theme.c @@ -25,7 +25,7 @@ void ffPrintTheme(FFThemeOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_THEME_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_THEME_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &theme} + {FF_FORMAT_ARG_TYPE_STRBUF, &theme, "combined"}, })); } } @@ -82,7 +82,7 @@ void ffGenerateThemeJsonResult(FF_MAYBE_UNUSED FFThemeOptions* options, yyjson_m void ffPrintThemeHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_THEME_MODULE_NAME, "{1}", FF_THEME_NUM_FORMAT_ARGS, ((const char* []) { - "Combined themes" + "Combined themes - combined", })); } diff --git a/src/modules/title/title.c b/src/modules/title/title.c index 661d099cf8..115cd61e59 100644 --- a/src/modules/title/title.c +++ b/src/modules/title/title.c @@ -57,14 +57,14 @@ void ffPrintTitle(FFTitleOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_TITLE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_TITLE_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.userName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &hostName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.homeDir}, - {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.exePath}, - {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.userShell}, - {FF_FORMAT_ARG_TYPE_STRBUF, &userNameColored}, - {FF_FORMAT_ARG_TYPE_STRBUF, &atColored}, - {FF_FORMAT_ARG_TYPE_STRBUF, &hostNameColored}, + {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.userName, "user-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &hostName, "host-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.homeDir, "home-dir"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.exePath, "exe-path"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.userShell, "user-shell"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &userNameColored, "user-name-colored"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &atColored, "at-symbol-colored"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &hostNameColored, "host-name-colored"}, })); } } @@ -182,14 +182,14 @@ void ffGenerateTitleJsonResult(FF_MAYBE_UNUSED FFTitleOptions* options, yyjson_m void ffPrintTitleHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_TITLE_MODULE_NAME, "{6}{7}{8}", FF_TITLE_NUM_FORMAT_ARGS, ((const char* []) { - "User name", - "Host name", - "Home directory", - "Executable path of current process", - "User's default shell", - "User name (colored)", - "@ symbol (colored)", - "Host name (colored)" + "User name - user-name", + "Host name - host-name", + "Home directory - home-dir", + "Executable path of current process - exe-path", + "User's default shell - user-shell", + "User name (colored) - user-name-colored", + "@ symbol (colored) - at-symbol-colored", + "Host name (colored) - host-name-colored", })); } diff --git a/src/modules/uptime/uptime.c b/src/modules/uptime/uptime.c index 1a513152a6..5ff4c5728f 100644 --- a/src/modules/uptime/uptime.c +++ b/src/modules/uptime/uptime.c @@ -79,12 +79,12 @@ void ffPrintUptime(FFUptimeOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_UPTIME_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_UPTIME_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_UINT, &days}, - {FF_FORMAT_ARG_TYPE_UINT, &hours}, - {FF_FORMAT_ARG_TYPE_UINT, &minutes}, - {FF_FORMAT_ARG_TYPE_UINT, &seconds}, - {FF_FORMAT_ARG_TYPE_UINT, &milliseconds}, - {FF_FORMAT_ARG_TYPE_STRING, ffTimeToShortStr(result.uptime)}, + {FF_FORMAT_ARG_TYPE_UINT, &days, "days"}, + {FF_FORMAT_ARG_TYPE_UINT, &hours, "hours"}, + {FF_FORMAT_ARG_TYPE_UINT, &minutes, "minutes"}, + {FF_FORMAT_ARG_TYPE_UINT, &seconds, "seconds"}, + {FF_FORMAT_ARG_TYPE_UINT, &milliseconds, "milliseconds"}, + {FF_FORMAT_ARG_TYPE_STRING, ffTimeToShortStr(result.uptime), "boot-time"}, })); } } @@ -143,12 +143,12 @@ void ffGenerateUptimeJsonResult(FF_MAYBE_UNUSED FFUptimeOptions* options, yyjson void ffPrintUptimeHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_UPTIME_MODULE_NAME, "{1} days {2} hours {3} mins", FF_UPTIME_NUM_FORMAT_ARGS, ((const char* []) { - "Days", - "Hours", - "Minutes", - "Seconds", - "Milliseconds", - "Boot time in local timezone", + "Days - days", + "Hours - hours", + "Minutes - minutes", + "Seconds - seconds", + "Milliseconds - milliseconds", + "Boot time in local timezone - boot-time", })); } diff --git a/src/modules/users/users.c b/src/modules/users/users.c index f3068ab268..3e81d7a24a 100644 --- a/src/modules/users/users.c +++ b/src/modules/users/users.c @@ -69,11 +69,11 @@ void ffPrintUsers(FFUsersOptions* options) FFUserResult* user = (FFUserResult*)ffListGet(&users, i); FF_PRINT_FORMAT_CHECKED(FF_USERS_MODULE_NAME, users.length == 1 ? 0 : (uint8_t) (i + 1), &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_USERS_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &user->name}, - {FF_FORMAT_ARG_TYPE_STRBUF, &user->hostName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &user->sessionName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &user->clientIp}, - {FF_FORMAT_ARG_TYPE_STRING, ffTimeToShortStr(user->loginTime)}, + {FF_FORMAT_ARG_TYPE_STRBUF, &user->name, "name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &user->hostName, "host-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &user->sessionName, "session-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &user->clientIp, "client-ip"}, + {FF_FORMAT_ARG_TYPE_STRING, ffTimeToShortStr(user->loginTime), "login-time"}, })); } } @@ -176,11 +176,11 @@ void ffGenerateUsersJsonResult(FF_MAYBE_UNUSED FFUsersOptions* options, yyjson_m void ffPrintUsersHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_USERS_MODULE_NAME, "{1}@{2} - login time {5}", FF_USERS_NUM_FORMAT_ARGS, ((const char* []) { - "User name", - "Host name", - "Session name", - "Client IP", - "Login Time in local timezone" + "User name - user-name", + "Host name - host-name", + "Session name - session", + "Client IP - client-ip", + "Login Time in local timezone - login-time", })); } diff --git a/src/modules/version/version.c b/src/modules/version/version.c index 2c8dee161b..66a4f0fb73 100644 --- a/src/modules/version/version.c +++ b/src/modules/version/version.c @@ -32,15 +32,15 @@ void ffPrintVersion(FFVersionOptions* options) } FF_PRINT_FORMAT_CHECKED(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_VERSION_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRING, result.projectName}, - {FF_FORMAT_ARG_TYPE_STRING, result.version}, - {FF_FORMAT_ARG_TYPE_STRING, result.versionTweak}, - {FF_FORMAT_ARG_TYPE_STRING, result.debugMode ? "debug" : "release"}, - {FF_FORMAT_ARG_TYPE_STRING, result.architecture}, - {FF_FORMAT_ARG_TYPE_STRING, result.cmakeBuiltType}, - {FF_FORMAT_ARG_TYPE_STRING, result.compileTime}, - {FF_FORMAT_ARG_TYPE_STRING, result.compiler}, - {FF_FORMAT_ARG_TYPE_STRBUF, &buf}, + {FF_FORMAT_ARG_TYPE_STRING, result.projectName, "project-name"}, + {FF_FORMAT_ARG_TYPE_STRING, result.version, "version"}, + {FF_FORMAT_ARG_TYPE_STRING, result.versionTweak, "version-tweak"}, + {FF_FORMAT_ARG_TYPE_STRING, result.debugMode ? "debug" : "release", "build-type"}, + {FF_FORMAT_ARG_TYPE_STRING, result.architecture, "arch"}, + {FF_FORMAT_ARG_TYPE_STRING, result.cmakeBuiltType, "cmake-built-type"}, + {FF_FORMAT_ARG_TYPE_STRING, result.compileTime, "compile-time"}, + {FF_FORMAT_ARG_TYPE_STRING, result.compiler, "compiler"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &buf, "libc-used"}, })); } } @@ -115,15 +115,15 @@ void ffGenerateVersionJsonResult(FF_MAYBE_UNUSED FFVersionOptions* options, yyjs void ffPrintVersionHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_VERSION_MODULE_NAME, "{1} {2}{3} ({5})", FF_VERSION_NUM_FORMAT_ARGS, ((const char* []) { - "Project name", - "Version", - "Version tweak", - "Build type (debug or release)", - "Architecture", - "CMake build type (Debug, Release, RelWithDebInfo, MinSizeRel)", - "Date time when compiling", - "Compiler used", - "Libc used" + "Project name - name", + "Version - version", + "Version tweak - version-tweak", + "Build type (debug or release) - build-type", + "Architecture - arch", + "CMake build type when compiling (Debug, Release, RelWithDebInfo, MinSizeRel) - cmake-built-type", + "Date time when compiling - compile-time", + "Compiler used when compiling - compiler", + "Libc used when compiling - libc", })); } diff --git a/src/modules/vulkan/vulkan.c b/src/modules/vulkan/vulkan.c index 5f9557f2cf..7bb57300bf 100644 --- a/src/modules/vulkan/vulkan.c +++ b/src/modules/vulkan/vulkan.c @@ -44,10 +44,10 @@ void ffPrintVulkan(FFVulkanOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_VULKAN_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_VULKAN_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->driver}, - {FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->apiVersion}, - {FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->conformanceVersion}, - {FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->instanceVersion}, + {FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->driver, "driver"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->apiVersion, "api-version"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->conformanceVersion, "conformance-version"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->instanceVersion, "instance-version"}, })); } } @@ -146,10 +146,10 @@ void ffGenerateVulkanJsonResult(FF_MAYBE_UNUSED FFVulkanOptions* options, yyjson void ffPrintVulkanHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_VULKAN_MODULE_NAME, "{2} - {1}", FF_VULKAN_NUM_FORMAT_ARGS, ((const char* []) { - "Driver name", - "API version", - "Conformance version", - "Instance version", + "Driver name - driver", + "API version - api-version", + "Conformance version - conformance-version", + "Instance version - instance-version", })); } diff --git a/src/modules/wallpaper/wallpaper.c b/src/modules/wallpaper/wallpaper.c index 5e0afbe348..5ec868d8b6 100644 --- a/src/modules/wallpaper/wallpaper.c +++ b/src/modules/wallpaper/wallpaper.c @@ -36,8 +36,8 @@ void ffPrintWallpaper(FFWallpaperOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_WALLPAPER_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_WALLPAPER_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRING, filename}, - {FF_FORMAT_ARG_TYPE_STRBUF, &fullpath}, + {FF_FORMAT_ARG_TYPE_STRING, filename, "file-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &fullpath, "full-path"}, })); } } @@ -92,8 +92,8 @@ void ffGenerateWallpaperJsonResult(FF_MAYBE_UNUSED FFWallpaperOptions* options, void ffPrintWallpaperHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_WALLPAPER_MODULE_NAME, "{1}", FF_WALLPAPER_NUM_FORMAT_ARGS, ((const char* []) { - "File name", - "Full path", + "File name - file-name", + "Full path - full-path", })); } diff --git a/src/modules/weather/weather.c b/src/modules/weather/weather.c index ccb1f22dbe..68539d3e87 100644 --- a/src/modules/weather/weather.c +++ b/src/modules/weather/weather.c @@ -26,7 +26,7 @@ void ffPrintWeather(FFWeatherOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_WEATHER_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_WEATHER_NUM_FORMAT_ARGS, ((FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &result} + {FF_FORMAT_ARG_TYPE_STRBUF, &result, "result"}, })); } } @@ -128,7 +128,7 @@ void ffGenerateWeatherJsonResult(FFWeatherOptions* options, yyjson_mut_doc* doc, void ffPrintWeatherHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_WEATHER_MODULE_NAME, "{1}", FF_WEATHER_NUM_FORMAT_ARGS, ((const char* []) { - "Weather result" + "Weather result - result", })); } diff --git a/src/modules/wifi/wifi.c b/src/modules/wifi/wifi.c index 0edc32d549..489063f603 100644 --- a/src/modules/wifi/wifi.c +++ b/src/modules/wifi/wifi.c @@ -47,16 +47,16 @@ void ffPrintWifi(FFWifiOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_WIFI_MODULE_NAME, moduleIndex, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_WIFI_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &item->inf.description}, - {FF_FORMAT_ARG_TYPE_STRBUF, &item->inf.status}, - {FF_FORMAT_ARG_TYPE_STRBUF, &item->conn.status}, - {FF_FORMAT_ARG_TYPE_STRBUF, &item->conn.ssid}, - {FF_FORMAT_ARG_TYPE_STRBUF, &item->conn.macAddress}, - {FF_FORMAT_ARG_TYPE_STRBUF, &item->conn.protocol}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &item->conn.signalQuality}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &item->conn.rxRate}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &item->conn.txRate}, - {FF_FORMAT_ARG_TYPE_STRBUF, &item->conn.security}, + {FF_FORMAT_ARG_TYPE_STRBUF, &item->inf.description, "inf-desc"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &item->inf.status, "inf-status"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &item->conn.status, "status"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &item->conn.ssid, "ssid"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &item->conn.macAddress, "mac-address"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &item->conn.protocol, "protocol"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &item->conn.signalQuality, "signal-quality"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &item->conn.rxRate, "rx-rate"}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &item->conn.txRate, "tx-rate"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &item->conn.security, "security"}, })); } @@ -150,16 +150,16 @@ void ffGenerateWifiJsonResult(FF_MAYBE_UNUSED FFWifiOptions* options, yyjson_mut void ffPrintWifiHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_WIFI_MODULE_NAME, "{4} - {10}", FF_WIFI_NUM_FORMAT_ARGS, ((const char* []) { - "Interface description", - "Interface status", - "Connection status", - "Connection SSID", - "Connection BSSID", - "Connection protocol", - "Connection signal quality (percentage)", - "Connection RX rate", - "Connection TX rate", - "Connection Security algorithm" + "Interface description - inf-desc", + "Interface status - inf-status", + "Connection status - status", + "Connection SSID - ssid", + "Connection BSSID - bssid", + "Connection protocol - protocol", + "Connection signal quality (percentage) - signal-quality", + "Connection RX rate - rx-rate", + "Connection TX rate - tx-rate", + "Connection Security algorithm - security", })); } diff --git a/src/modules/wm/wm.c b/src/modules/wm/wm.c index dd0f02b26a..a4c4156be5 100644 --- a/src/modules/wm/wm.c +++ b/src/modules/wm/wm.c @@ -46,10 +46,10 @@ void ffPrintWM(FFWMOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_WM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_WM_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProcessName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmPrettyName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProtocolName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &pluginName}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProcessName, "process-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmPrettyName, "pretty-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProtocolName, "protocol-name"}, + {FF_FORMAT_ARG_TYPE_STRBUF, &pluginName, "plugin-name"}, })); } } @@ -128,10 +128,10 @@ void ffGenerateWMJsonResult(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc void ffPrintWMHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_WM_MODULE_NAME, "{2} ({3})", FF_WM_NUM_FORMAT_ARGS, ((const char* []) { - "WM process name", - "WM pretty name", - "WM protocol name", - "WM plugin name" + "WM process name - process-name", + "WM pretty name - pretty-name", + "WM protocol name - protocol-name", + "WM plugin name - plugin-name", })); } diff --git a/src/modules/wmtheme/wmtheme.c b/src/modules/wmtheme/wmtheme.c index 74f0326ca4..74c0e686ea 100644 --- a/src/modules/wmtheme/wmtheme.c +++ b/src/modules/wmtheme/wmtheme.c @@ -20,7 +20,7 @@ void ffPrintWMTheme(FFWMThemeOptions* options) else { FF_PRINT_FORMAT_CHECKED(FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_WMTHEME_NUM_FORMAT_ARGS, ((FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &themeOrError} + {FF_FORMAT_ARG_TYPE_STRBUF, &themeOrError, "result"}, })); } } @@ -80,7 +80,7 @@ void ffGenerateWMThemeJsonResult(FF_MAYBE_UNUSED FFWMThemeOptions* options, yyjs void ffPrintWMthemeHelpFormat(void) { FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_WMTHEME_MODULE_NAME, "{1}", FF_WMTHEME_NUM_FORMAT_ARGS, ((const char* []) { - "WM theme" + "WM theme - result", })); } diff --git a/src/options/display.c b/src/options/display.c index 35815f7c0e..09cfce649d 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -51,6 +51,9 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va const char* colorOutput = yyjson_get_str(yyjson_obj_get(val, "output")); if (colorOutput) ffOptionParseColor(colorOutput, &options->colorOutput); + const char* colorSeparator = yyjson_get_str(yyjson_obj_get(val, "separator")); + if (colorSeparator) + ffOptionParseColor(colorSeparator, &options->colorSeparator); } else return "display.color must be either a string or an object"; @@ -252,6 +255,11 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key optionCheckString(key, value, &options->colorOutput); ffOptionParseColor(value, &options->colorOutput); } + else if(ffStrEqualsIgnCase(subkey, "separator")) + { + optionCheckString(key, value, &options->colorSeparator); + ffOptionParseColor(value, &options->colorSeparator); + } else return false; } @@ -355,6 +363,7 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options) ffStrbufInit(&options->colorKeys); ffStrbufInit(&options->colorTitle); ffStrbufInit(&options->colorOutput); + ffStrbufInit(&options->colorSeparator); options->brightColor = true; ffStrbufInitStatic(&options->keyValueSeparator, ": "); @@ -399,6 +408,7 @@ void ffOptionsDestroyDisplay(FFOptionsDisplay* options) ffStrbufDestroy(&options->colorKeys); ffStrbufDestroy(&options->colorTitle); ffStrbufDestroy(&options->colorOutput); + ffStrbufDestroy(&options->colorSeparator); ffStrbufDestroy(&options->keyValueSeparator); ffStrbufDestroy(&options->barCharElapsed); ffStrbufDestroy(&options->barCharTotal); @@ -435,6 +445,10 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do yyjson_mut_obj_add_strbuf(doc, color, "keys", &options->colorKeys); if (!ffStrbufEqual(&options->colorTitle, &defaultOptions.colorTitle)) yyjson_mut_obj_add_strbuf(doc, color, "title", &options->colorTitle); + if (!ffStrbufEqual(&options->colorOutput, &defaultOptions.colorOutput)) + yyjson_mut_obj_add_strbuf(doc, color, "output", &options->colorOutput); + if (!ffStrbufEqual(&options->colorSeparator, &defaultOptions.colorSeparator)) + yyjson_mut_obj_add_strbuf(doc, color, "separator", &options->colorSeparator); if (yyjson_mut_obj_size(color) > 0) { if (yyjson_mut_obj_size(color) == 2 && ffStrbufEqual(&options->colorKeys, &options->colorTitle)) diff --git a/src/options/display.h b/src/options/display.h index e2307b2d43..aaba0d412e 100644 --- a/src/options/display.h +++ b/src/options/display.h @@ -22,6 +22,7 @@ typedef struct FFOptionsDisplay FFstrbuf colorKeys; FFstrbuf colorTitle; FFstrbuf colorOutput; + FFstrbuf colorSeparator; bool brightColor; diff --git a/src/options/modules.c b/src/options/modules.c index 64faf0e635..728bccf4d5 100644 --- a/src/options/modules.c +++ b/src/options/modules.c @@ -29,6 +29,7 @@ void ffOptionsInitModules(FFOptionsModules* options) ffInitGamepadOptions(&options->gamepad); ffInitHostOptions(&options->host); ffInitIconsOptions(&options->icons); + ffInitInitSystemOptions(&options->initSystem); ffInitKernelOptions(&options->kernel); ffInitLMOptions(&options->lm); ffInitLoadavgOptions(&options->loadavg); @@ -97,6 +98,7 @@ void ffOptionsDestroyModules(FFOptionsModules* options) ffDestroyGamepadOptions(&options->gamepad); ffDestroyHostOptions(&options->host); ffDestroyIconsOptions(&options->icons); + ffDestroyInitSystemOptions(&options->initSystem); ffDestroyKernelOptions(&options->kernel); ffDestroyLMOptions(&options->lm); ffDestroyLoadavgOptions(&options->loadavg); diff --git a/src/options/modules.h b/src/options/modules.h index aeebe33fc8..79e25ce2e8 100644 --- a/src/options/modules.h +++ b/src/options/modules.h @@ -30,6 +30,7 @@ typedef struct FFOptionsModules FFGamepadOptions gamepad; FFHostOptions host; FFIconsOptions icons; + FFInitSystemOptions initSystem; FFKernelOptions kernel; FFLMOptions lm; FFLoadavgOptions loadavg; diff --git a/src/util/stringUtils.h b/src/util/stringUtils.h index ad24057b56..a7dea3fbe2 100644 --- a/src/util/stringUtils.h +++ b/src/util/stringUtils.h @@ -74,3 +74,8 @@ static inline bool ffCharIsEnglishAlphabet(char c) { return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); } + +static inline bool ffCharIsDigit(char c) +{ + return '0' <= c && c <= '9'; +}