Merge pull request #526 from fastfetch-cli/dev

Release v2.0.1 (stable)
This commit is contained in:
Carter Li
2023-08-20 22:35:09 -04:00
committed by GitHub
222 changed files with 19519 additions and 2338 deletions
+1 -6
View File
@@ -19,11 +19,6 @@ assignees: ''
# Often helpful information: # Often helpful information:
Output of `fastfetch --version`:
```
//paste here
```
The content of the configuration file you use (if any) The content of the configuration file you use (if any)
``` ```
//paste here //paste here
@@ -34,7 +29,7 @@ Output of `env NO_CONFIG=1 fastfetch --load-config all --show-errors --stat --mu
Note that this output will contain you public IP. If it is not relevant for the issue, feel free to remove it before uploading. Note that this output will contain you public IP. If it is not relevant for the issue, feel free to remove it before uploading.
If you get the following error: `Error: couldn't find config: [...]`, copy the files in [presets](../../presets/) to `/usr/share/fastfetch/presets/` or `~/.local/share/fastfetch/presets/`. If you get the following error: `Error: couldn't find config: [...]`, copy the files in [presets](../../presets/) to `/usr/share/fastfetch/presets/` or `~/.local/share/fastfetch/presets/`.
If this isn't possible (or too much work) for you, post the output of `env NO_CONFIG=1 fastfetch --show-errors --stat --multithreading false --disable-linewrap false --hide-cursor false`. If this isn't possible (or too much work) for you, post the output of `env NO_CONFIG=1 fastfetch --show-errors --stat --multithreading false --disable-linewrap false --hide-cursor false && fastfetch --version`.
--> -->
``` ```
+25 -2
View File
@@ -1,4 +1,27 @@
# 2.0.0 (beta) # 2.0.1
First stable release of Fastfetch V2
Changes:
* Unescape strings only when parsing `.conf` files
* Previously: `$ NO_CONFIG=1 fastfetch --os-key \\\\ -s os -l none` prints `\: *`. Note the backslashs are unescaped twice (once by shell and once by fastfetch).
* Now: `$ NO_CONFIG=1 fastfetch --os-key \\\\ -s os -l none` prints `\\: *`
* Remove option shortcut `-c` (alias of `--color`), which is more commonly used as alias of `--config`
* Rename `--recache` to `--logo-recache` (which is used for regenerate image logo cache). Remove option shortcut `-r` (alias of `--recache`).
* Detecting brightness of external displays with DDC/CI is no longer guarded behind `--allow-slow-operations` (Brightness)
Features:
* Add `--key-width` for aligning the left edge of values, supported both for global `--key-width` and specific module `--module-key-width`
* Add `--bar-char-elapsed`, `--bar-char-total`, `--bar-width` and `--bar-border` options
* Add CMake option `ENABLE_SYSTEM_YYJSON`, which allow building fastfetch with system-provided yyjson (for package managers)
* Add new module `Version`, which prints fastfetch version (like `fastfetch --version`)
Bugfixes:
* Fix label detection. Use `--disk-key 'Disk ({2})'` to display it (Disk, Linux)
* Fix some module options were not inited
* Fix terminal version and font detection on NixOS (Terminal, Linux)
# 2.0.0-beta
Fastfetch v2 introduces a new configuration file format: JSON config. Please refer to <https://github.com/fastfetch-cli/fastfetch/wiki/Configuration> for details. Fastfetch v2 introduces a new configuration file format: JSON config. Please refer to <https://github.com/fastfetch-cli/fastfetch/wiki/Configuration> for details.
@@ -32,7 +55,7 @@ Features:
* Support iTerm non-ascii font detection (Terminal, macOS) * Support iTerm non-ascii font detection (Terminal, macOS)
* Add option `--title-color-user`, `--title-color-at` and `--title-color-host` (Title) * Add option `--title-color-user`, `--title-color-at` and `--title-color-host` (Title)
* Add Exherbo logo and package manager count (Packages, Linux, #503) * Add Exherbo logo and package manager count (Packages, Linux, #503)
* Add module `Terminal Size` which prints the number of terminal width and height in charactors and pixels * Add module `Terminal Size` which prints the number of terminal width and height in characters and pixels
* Add new option `--temperature-unit` * Add new option `--temperature-unit`
* Better CPU and Host detection for Android (Android) * Better CPU and Host detection for Android (Android)
* Support yakuake terminal version & font detection (Terminal, Linux) * Support yakuake terminal version & font detection (Terminal, Linux)
+25 -25
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url & FetchContent cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url
project(fastfetch project(fastfetch
VERSION 2.0.0 VERSION 2.0.1
LANGUAGES C LANGUAGES C
DESCRIPTION "Fast system information tool" DESCRIPTION "Fast system information tool"
HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
@@ -36,24 +36,6 @@ endif()
include(CheckIncludeFile) include(CheckIncludeFile)
include(FetchContent)
function(ff_fetch_dep package repo tag)
FetchContent_Declare(
"${package}"
GIT_REPOSITORY "${repo}"
GIT_TAG "${tag}"
GIT_PROGRESS TRUE
)
FetchContent_GetProperties("${package}")
if(NOT ${package}_POPULATED)
message("-- Fetching dependency ${package}@${tag} from ${repo}")
FetchContent_Populate(${package})
add_subdirectory(${${package}_SOURCE_DIR} ${${package}_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endfunction()
ff_fetch_dep(yyjson "https://github.com/ibireme/yyjson" "0.7.0")
##################### #####################
# Configure options # # Configure options #
##################### #####################
@@ -87,6 +69,7 @@ cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR BSD" OFF)
cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF) cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF) cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF)
cmake_dependent_option(ENABLE_PCI_MEMORY "Enable detecting GPU memory size with libpci" OFF "LINUX OR BSD" OFF) cmake_dependent_option(ENABLE_PCI_MEMORY "Enable detecting GPU memory size with libpci" OFF "LINUX OR BSD" OFF)
cmake_dependent_option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embeded) yyjson library" OFF "LINUX OR APPLE OR BSD OR WIN32 OR ANDROID" OFF)
option(BUILD_TESTS "Build tests" OFF) # Also create test executables 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(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds
@@ -228,7 +211,6 @@ fastfetch_load_text(src/data/structure.txt DATATEXT_STRUCTURE)
fastfetch_load_text(src/data/config_system.txt DATATEXT_CONFIG_SYSTEM) fastfetch_load_text(src/data/config_system.txt DATATEXT_CONFIG_SYSTEM)
fastfetch_load_text(src/data/config_user.txt DATATEXT_CONFIG_USER) fastfetch_load_text(src/data/config_user.txt DATATEXT_CONFIG_USER)
fastfetch_load_text(src/data/config_user.jsonc DATATEXT_CONFIG_USER_JSONC) fastfetch_load_text(src/data/config_user.jsonc DATATEXT_CONFIG_USER_JSONC)
fastfetch_load_text(src/data/modules.txt DATATEXT_MODULES)
fastfetch_load_text(src/data/help.txt DATATEXT_HELP) fastfetch_load_text(src/data/help.txt DATATEXT_HELP)
fastfetch_load_text(src/data/help_color.txt DATATEXT_HELP_COLOR) fastfetch_load_text(src/data/help_color.txt DATATEXT_HELP_COLOR)
fastfetch_load_text(src/data/help_format.txt DATATEXT_HELP_FORMAT) fastfetch_load_text(src/data/help_format.txt DATATEXT_HELP_FORMAT)
@@ -270,11 +252,13 @@ file(GENERATE OUTPUT logo_builtin.h CONTENT "${LOGO_BUILTIN_H}")
set(LIBFASTFETCH_SRC set(LIBFASTFETCH_SRC
src/common/bar.c src/common/bar.c
src/common/commandoption.c
src/common/font.c src/common/font.c
src/common/format.c src/common/format.c
src/common/init.c src/common/init.c
src/common/jsonconfig.c src/common/jsonconfig.c
src/common/library.c src/common/library.c
src/common/modules.c
src/common/option.c src/common/option.c
src/common/parsing.c src/common/parsing.c
src/common/printing.c src/common/printing.c
@@ -295,6 +279,7 @@ set(LIBFASTFETCH_SRC
src/detection/packages/packages.c src/detection/packages/packages.c
src/detection/terminalfont/terminalfont.c src/detection/terminalfont/terminalfont.c
src/detection/terminalshell/terminalshell.c src/detection/terminalshell/terminalshell.c
src/detection/version/version.c
src/detection/vulkan/vulkan.c src/detection/vulkan/vulkan.c
src/logo/builtin.c src/logo/builtin.c
src/logo/image/im6.c src/logo/image/im6.c
@@ -350,6 +335,7 @@ set(LIBFASTFETCH_SRC
src/modules/title/title.c src/modules/title/title.c
src/modules/uptime/uptime.c src/modules/uptime/uptime.c
src/modules/users/users.c src/modules/users/users.c
src/modules/version/version.c
src/modules/vulkan/vulkan.c src/modules/vulkan/vulkan.c
src/modules/wallpaper/wallpaper.c src/modules/wallpaper/wallpaper.c
src/modules/weather/weather.c src/modules/weather/weather.c
@@ -618,12 +604,29 @@ endif()
include(CheckFunctionExists) include(CheckFunctionExists)
check_function_exists(wcwidth HAVE_WCWIDTH) check_function_exists(wcwidth HAVE_WCWIDTH)
if(NOT HAVE_WCWIDTH) if(NOT HAVE_WCWIDTH)
list(APPEND LIBFASTFETCH_SRC src/util/wcwidth.c) list(APPEND LIBFASTFETCH_SRC src/3rdparty/mk_wcwidch/wcwidth.c)
endif()
if(ENABLE_SYSTEM_YYJSON)
find_package(yyjson)
if(yyjson_FOUND)
message(STATUS "System provided yyjson is used")
else()
message(FATAL_ERROR "ENABLE_SYSTEM_YYJSON is set but system provided yyjson is not found")
endif()
else()
list(APPEND LIBFASTFETCH_SRC
src/3rdparty/yyjson/yyjson.c
)
endif() endif()
add_library(libfastfetch OBJECT add_library(libfastfetch OBJECT
${LIBFASTFETCH_SRC} ${LIBFASTFETCH_SRC}
) )
if(yyjson_FOUND)
target_compile_definitions(libfastfetch PRIVATE FF_USE_SYSTEM_YYJSON)
target_link_libraries(libfastfetch PRIVATE yyjson)
endif()
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE)
if(WIN32) if(WIN32)
@@ -847,7 +850,6 @@ target_include_directories(libfastfetch
target_link_libraries(libfastfetch target_link_libraries(libfastfetch
PRIVATE ${CMAKE_DL_LIBS} PRIVATE ${CMAKE_DL_LIBS}
PRIVATE yyjson
) )
###################### ######################
@@ -862,7 +864,6 @@ target_compile_definitions(fastfetch
) )
target_link_libraries(fastfetch target_link_libraries(fastfetch
PRIVATE libfastfetch PRIVATE libfastfetch
PRIVATE yyjson
) )
add_executable(flashfetch add_executable(flashfetch
@@ -873,7 +874,6 @@ target_compile_definitions(flashfetch
) )
target_link_libraries(flashfetch target_link_libraries(flashfetch
PRIVATE libfastfetch PRIVATE libfastfetch
PRIVATE yyjson
) )
if(WIN32) if(WIN32)
+2 -2
View File
@@ -96,14 +96,14 @@ All categories not listed here should work without needing a specific implementa
##### Available Modules ##### Available Modules
``` ```
Battery, Bios, Bluetooth, Board, Break, Brightness, Colors, Command, CPU, CPUUsage, Cursor, Custom, Date, DateTime, DE, Disk, Display, Font, Gamepad, GPU, Host, Icons, Kernel, LM, Locale, LocalIP, Media, Memory, Monitor, OpenCL, OpenGL, Packages, Player, Power Adapter, Processes, PublicIP, Separator, OS, Shell, Sound, Swap, Terminal, Terminal Font, Terminal Size, Theme, Time, Title, Uptime, Vulkan, Wallpaper, Wifi, WM, WMTheme Battery, Bios, Bluetooth, Board, Break, Brightness, Colors, Command, CPU, CPUUsage, Cursor, Custom, Date, DateTime, DE, Disk, Display, Font, Gamepad, GPU, Host, Icons, Kernel, LM, Locale, LocalIP, Media, Memory, Monitor, OpenCL, OpenGL, OS, Packages, Player, Power Adapter, Processes, PublicIP, Separator, Shell, Sound, Swap, Terminal, Terminal Font, Terminal Size, Theme, Time, Title, Uptime, Version, Vulkan, Wallpaper, Weather, Wifi, WM, WMTheme
``` ```
##### Builtin logos ##### Builtin logos
<!-- `Content of src/logo/builtin.c`.split('\n').map(x => x.trim()).filter(x => x.startsWith('// ')).map(x => x.slice(3)).sort((a,b)=>a.toUpperCase().localeCompare(b.toUpperCase())).join(', ') --> <!-- `Content of src/logo/builtin.c`.split('\n').map(x => x.trim()).filter(x => x.startsWith('// ')).map(x => x.slice(3)).sort((a,b)=>a.toUpperCase().localeCompare(b.toUpperCase())).join(', ') -->
``` ```
AIX, AlmaLinux, Alpine, Alpine2Small, AlpineSmall, Alter, Amazon, AmogOS, Anarchy, Android, AndroidSmall, Antergos, Antix, AoscOS, AoscOsRetro, AoscOsRetro_small, Aperture, Apple, AppleSmall, Apricity, Arch, Arch2, ArchBox, Archcraft, Archcraft2, Archlabs, ArchSmall, ArchStrike, ArcoLinux, ArcoLinuxSmall, ArseLinux, Artix, Artix2Small, ArtixSmall, Arya, Asahi, Aster, AsteroidOS, AstOS, Astra, Ataraxia, Athena, Bedrock, BigLinux, Bitrig, BlackArch, BlackPanther, BLAG, BlankOn, BlueLight, Bodhi, Bonsai, BSD, BunsenLabs, CachyOS, CachyOSSmall, Calculate, CalinixOS, CalinixOSSmall, Carbs, CBL-Mariner, CelOS, Center, CentOS, CentOSSmall, Chakra, ChaletOS, Chapeau, ChonkySealOS, Chrom, Cleanjaro, CleanjaroSmall, ClearLinux, ClearOS, Clover, Cobalt, Condres, ContainerLinux, CRUX, CRUXSmall, CrystalLinux, Cucumber, CutefishOS, CuteOS, CyberOS, Dahlia, DarkOS, Debian, DebianSmall, Deepin, DesaOS, Devuan, DevuanSmall, DietPi, DracOS, DragonFly, DragonFlyOld, DragonFlySmall, Drauger, Droidian, Elementary, ElementarySmall, Elive, EncryptOS, Endeavour, Endless, Enso, EuroLinux, EvolutionOS, Exherbo, ExodiaPredator, Fedora, FedoraOld, FedoraSmall, FemboyOS, Feren, Finnix, Floflis, FreeBSD, FreeBSDSmall, FreeMiNT, Frugalware, Funtoo, GalliumOS, Garuda, GarudaDragon, GarudaSmall, Gentoo, GentooSmall, GhostBSD, Glaucus, GNewSense, Gnome, GNU, GoboLinux, GrapheneOS, Grombyang, Guix, GuixSmall, Haiku, HaikuSmall, HamoniKR, HarDClanZ, HardenedBSD, Hash, Huayra, Hybrid, HydroOS, Hyperbola, HyperbolaSmall, Iglunix, InstantOS, IRIX, Itc, Januslinux, Kaisen, Kali, KaliSmall, KaOS, KDENeon, Kibojoe, KISSLinux, Kogaion, Korora, KrassOS, KSLinux, Kubuntu, LangitKetujuh, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, Laxeros, LEDE, LibreELEC, Linspire, Linux, LinuxLight, LinuxLightSmall, LinuxMint, LinuxMintOld, LinuxMintSmall, LinuxSmall, Live_Raizo, LMDE, Lunar, MacOS, MacOS2, MacOS2Small, MacOSSmall, Mageia, MageiaSmall, MagpieOS, Mandriva, Manjaro, ManjaroSmall, MassOS, MatuusOS, MaUI, Meowix, Mer, Minix, Mint, MintOld, MintSmall, MiracleLinux, Msys2, MX, MXSmall, Namib, Nekos, Neptune, NetBSD, NetRunner, Nitrux, NixOS, NixOS_small, NixOsOld, NixOsSmall, Nobara, NomadBSD, Nurunner, NuTyX, Obarun, OBRevenge, OmniOS, OpenBSD, OpenBSDSmall, OpenEuler, OpenIndiana, OpenKylin, OpenMamba, OpenMandriva, OpenStage, OpenSuse, OpenSuseLeap, OpenSuseSmall, OpenSuseTumbleweed, OpenWrt, OPNsense, Oracle, Orchid, OrchidSmall, OS_Elbrus, OSMC, OSX, OSXSmall, PacBSD, Panwah, Parabola, ParabolaSmall, Parch, Pardus, Parrot, Parsix, PCBSD, PCLinuxOS, PearOS, Pengwin, Pentoo, Peppermint, PhyOS, Pisi, PNMLinux, Pop, PopSmall, Porteus, PostMarketOS, PostMarketOSSmall, Proxmox, PuffOS, Puppy, PureOS, PureOSSmall, Q4OS, Qubes, Qubyt, Quibian, Radix, Raspbian, RaspbianSmall, RavynOS, Reborn, RebornSmall, RedCore, RedHatEnterpriseLinux, RedHatEnterpriseLinux_old, RedstarOS, Refracted Devuan, Regata, Regolith, RhaymOS, RockyLinux, RockyLinuxSmall, RosaLinux, Sabayon, Sabotage, Sailfish, SalentOS, SalientOS, Salix, SambaBOX, Sasanqua, Scientific, Semc, Septor, Serene, SharkLinux, ShastraOS, Siduction, SkiffOS, Slackel, Slackware, SlackwareSmall, Slitaz, SmartOS, Soda, Solaris, SolarisSmall, Solus, SourceMage, Sparky, Star, SteamOS, StockLinux, Sulin, Suse, SuseSmall, Swagarch, T2, Tails, TeArch, TorizonCore, Trisquel, Twister, Ubuntu, Ubuntu2Old, Ubuntu2Small, UbuntuBudgie, UbuntuCinnamon, UbuntuGnome, UbuntuKde, UbuntuKylin, UbuntuMate, UbuntuOld, UbuntuSmall, UbuntuStudio, UbuntuSway, UbuntuTouch, UbuntuUnity, Ultramarine, Univalent, Univention, UOS, UrukOS, Uwuntu, Vanilla, Venom, Vnux, Void, VoidSmall, Vzlinux, WiiLinuxNgx, Windows, Windows11, Windows11Small, Windows8, Windows95, Xferience, YiffOS, Zorin AerOS, AIX, AlmaLinux, Alpine, Alpine2Small, AlpineSmall, Alter, Amazon, AmogOS, Anarchy, Android, AndroidSmall, Antergos, Antix, AoscOS, AoscOsRetro, AoscOsRetro_small, Aperture, Apple, AppleSmall, Apricity, Arch, Arch2, ArchBox, Archcraft, Archcraft2, Archlabs, ArchSmall, ArchStrike, ArcoLinux, ArcoLinuxSmall, ArseLinux, Artix, Artix2Small, ArtixSmall, Arya, Asahi, Aster, AsteroidOS, AstOS, Astra, Ataraxia, Athena, Bedrock, BigLinux, Bitrig, BlackArch, BlackPanther, BLAG, BlankOn, BlueLight, Bodhi, Bonsai, BSD, BunsenLabs, CachyOS, CachyOSSmall, Calculate, CalinixOS, CalinixOSSmall, Carbs, CBL-Mariner, CelOS, Center, CentOS, CentOSSmall, Chakra, ChaletOS, Chapeau, ChonkySealOS, Chrom, Cleanjaro, CleanjaroSmall, ClearLinux, ClearOS, Clover, Cobalt, Condres, ContainerLinux, CRUX, CRUXSmall, CrystalLinux, Cucumber, CutefishOS, CuteOS, CyberOS, Dahlia, DarkOS, Debian, DebianSmall, Deepin, DesaOS, Devuan, DevuanSmall, DietPi, DracOS, DragonFly, DragonFlyOld, DragonFlySmall, Drauger, Droidian, Elementary, ElementarySmall, Elive, EncryptOS, Endeavour, Endless, Enso, EuroLinux, EvolutionOS, Exherbo, ExodiaPredator, Fedora, FedoraOld, FedoraSmall, FemboyOS, Feren, Finnix, Floflis, FreeBSD, FreeBSDSmall, FreeMiNT, Frugalware, Funtoo, GalliumOS, Garuda, GarudaDragon, GarudaSmall, Gentoo, GentooSmall, GhostBSD, Glaucus, GNewSense, Gnome, GNU, GoboLinux, GrapheneOS, Grombyang, Guix, GuixSmall, Haiku, HaikuSmall, HamoniKR, HarDClanZ, HardenedBSD, Hash, Huayra, Hybrid, HydroOS, Hyperbola, HyperbolaSmall, Iglunix, InstantOS, IRIX, Itc, Januslinux, Kaisen, Kali, KaliSmall, KaOS, KDENeon, Kibojoe, KISSLinux, Kogaion, Korora, KrassOS, KSLinux, Kubuntu, LangitKetujuh, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, LAST, Laxeros, LEDE, LibreELEC, Linspire, Linux, LinuxLight, LinuxLightSmall, LinuxMint, LinuxMintOld, LinuxMintSmall, LinuxSmall, Live_Raizo, LMDE, Lunar, MacOS, MacOS2, MacOS2Small, MacOSSmall, Mageia, MageiaSmall, MagpieOS, Mandriva, Manjaro, ManjaroSmall, MassOS, MatuusOS, MaUI, Meowix, Mer, Minix, Mint, MintOld, MintSmall, MiracleLinux, MOS, Msys2, MX, MXSmall, Namib, Nekos, Neptune, NetBSD, NetRunner, Nitrux, NixOS, NixOS_small, NixOsOld, NixOsSmall, Nobara, NomadBSD, Nurunner, NuTyX, Obarun, OBRevenge, OmniOS, OpenBSD, OpenBSDSmall, OpenEuler, OpenIndiana, OpenKylin, OpenMamba, OpenMandriva, OpenStage, OpenSuse, OpenSuseLeap, OpenSuseSmall, OpenSuseTumbleweed, OpenWrt, OPNsense, Oracle, Orchid, OrchidSmall, OS_Elbrus, OSMC, OSX, OSXSmall, PacBSD, Panwah, Parabola, ParabolaSmall, Parch, Pardus, Parrot, Parsix, PCBSD, PCLinuxOS, PearOS, Pengwin, Pentoo, Peppermint, PhyOS, Pisi, PNMLinux, Pop, PopSmall, Porteus, PostMarketOS, PostMarketOSSmall, Proxmox, PuffOS, Puppy, PureOS, PureOSSmall, Q4OS, Qubes, Qubyt, Quibian, Radix, Raspbian, RaspbianSmall, RavynOS, Reborn, RebornSmall, RedCore, RedHatEnterpriseLinux, RedHatEnterpriseLinux_old, RedstarOS, Refracted Devuan, Regata, Regolith, RhaymOS, RockyLinux, RockyLinuxSmall, RosaLinux, Sabayon, Sabotage, Sailfish, SalentOS, SalientOS, Salix, SambaBOX, Sasanqua, Scientific, Semc, Septor, Serene, SharkLinux, ShastraOS, Siduction, SkiffOS, Slackel, Slackware, SlackwareSmall, Slitaz, SmartOS, Soda, Solaris, SolarisSmall, Solus, SourceMage, Sparky, Star, SteamOS, StockLinux, Sulin, Suse, SuseSmall, Swagarch, T2, Tails, TeArch, TorizonCore, Trisquel, Twister, Ubuntu, Ubuntu2Old, Ubuntu2Small, UbuntuBudgie, UbuntuCinnamon, UbuntuGnome, UbuntuKde, UbuntuKylin, UbuntuMate, UbuntuOld, UbuntuSmall, UbuntuStudio, UbuntuSway, UbuntuTouch, UbuntuUnity, Ultramarine, Univalent, Univention, UOS, UrukOS, Uwuntu, Vanilla, Venom, Vnux, Void, VoidSmall, Vzlinux, WiiLinuxNgx, Windows, Windows11, Windows11Small, Windows8, Windows95, Xferience, YiffOS, Zorin
``` ```
Run `fastfetch --print-logos` to print them Run `fastfetch --print-logos` to print them
+96
View File
@@ -17,6 +17,12 @@
"title": "Color of the module key. Left empty to use `display.color.keys`", "title": "Color of the module key. Left empty to use `display.color.keys`",
"$ref": "#/$defs/colors" "$ref": "#/$defs/colors"
}, },
"keyWidth": {
"title": "Width of the module key. Use 0 to use `display.keyWidth`",
"type": "integer",
"minimum": 0,
"default": 0
},
"format": { "format": {
"title": "Output format of the module", "title": "Output format of the module",
"type": "string" "type": "string"
@@ -155,6 +161,11 @@
"title": "Whether to preserve the aspect ratio of the logo. Supported by iTerm image protocol", "title": "Whether to preserve the aspect ratio of the logo. Supported by iTerm image protocol",
"default": false "default": false
}, },
"recache": {
"type": "boolean",
"title": "If true, regenerate image logo cache",
"default": false
},
"chafa": { "chafa": {
"type": "object", "type": "object",
"title": "Chafa configuration. See chafa document for details", "title": "Chafa configuration. See chafa document for details",
@@ -221,6 +232,11 @@
"title": "Use multiple threads to detect values", "title": "Use multiple threads to detect values",
"default": true "default": true
}, },
"thread": {
"type": "boolean",
"title": "Alias of multithreading",
"default": true
},
"stat": { "stat": {
"type": "boolean", "type": "boolean",
"title": "Show time usage (in ms) for individual modules", "title": "Show time usage (in ms) for individual modules",
@@ -309,6 +325,12 @@
"type": "boolean", "type": "boolean",
"default": true "default": true
}, },
"keyWidth": {
"title": "Align the width of keys to number of characters, 0 to disable",
"type": "integer",
"minimum": 0,
"default": 0
},
"binaryPrefix": { "binaryPrefix": {
"type": "string", "type": "string",
"title": "Set the binary prefix to used when printing bytes", "title": "Set the binary prefix to used when printing bytes",
@@ -335,6 +357,33 @@
"enum": ["CELSIUS", "C", "FAHRENHEIT", "F", "KELVIN", "K"], "enum": ["CELSIUS", "C", "FAHRENHEIT", "F", "KELVIN", "K"],
"default": "C" "default": "C"
}, },
"bar": {
"type": "object",
"title": "Set the bar configuration",
"properties": {
"charElapsed": {
"type": "string",
"title": "Set the character to use in elapsed part",
"default": "■"
},
"charTotal": {
"type": "string",
"title": "Set the character to use in total part",
"default": "-"
},
"border": {
"type": "boolean",
"title": "Whether to show a border around the bar",
"default": true
},
"width": {
"type": "integer",
"title": "Set the width of the bar, in number of characters",
"minimum": 1,
"default": 10
}
}
},
"percentType": { "percentType": {
"type": "number", "type": "number",
"title": "Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number", "title": "Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number",
@@ -509,6 +558,7 @@
"theme", "theme",
"uptime", "uptime",
"users", "users",
"version",
"vulkan", "vulkan",
"wallpaper", "wallpaper",
"weather", "weather",
@@ -577,6 +627,7 @@
"theme", "theme",
"uptime", "uptime",
"users", "users",
"version",
"vulkan", "vulkan",
"wallpaper", "wallpaper",
"wm", "wm",
@@ -590,6 +641,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -617,6 +671,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -640,6 +697,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -663,6 +723,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -716,6 +779,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -736,6 +802,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"title": "Text to print", "title": "Text to print",
"type": "string" "type": "string"
@@ -772,6 +841,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -814,6 +886,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -851,6 +926,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -903,6 +981,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -931,6 +1012,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -961,6 +1045,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -1003,6 +1090,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -1044,6 +1134,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
@@ -1077,6 +1170,9 @@
"keyColor": { "keyColor": {
"$ref": "#/$defs/keyColor" "$ref": "#/$defs/keyColor"
}, },
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": { "format": {
"$ref": "#/$defs/format" "$ref": "#/$defs/format"
} }
+1 -1
View File
@@ -1 +1 @@
--structure Title:Separator:OS:Host:Bios:Board:Chassis:Kernel:Uptime:Processes:Packages:Shell:Display:Brightness:Monitor:LM:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Wallpaper:Terminal:TerminalFont:TerminalSize:CPU:CPUUsage:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Media:PublicIP:LocalIP:Wifi:DateTime:Locale:Vulkan:OpenGL:OpenCL:Users:Bluetooth:Sound:Gamepad:Weather:Break:Colors --structure Title:Separator:OS:Host:Bios:Board:Chassis:Kernel:Uptime:Processes:Packages:Shell:Display:Brightness:Monitor:LM:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Wallpaper:Terminal:TerminalFont:TerminalSize:CPU:CPUUsage:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Media:PublicIP:LocalIP:Wifi:DateTime:Locale:Vulkan:OpenGL:OpenCL:Users:Bluetooth:Sound:Gamepad:Weather:Version:Break:Colors
+1
View File
@@ -51,6 +51,7 @@
"sound", "sound",
"gamepad", "gamepad",
"weather", "weather",
"version",
"break", "break",
"colors" "colors"
] ]
+28
View File
@@ -0,0 +1,28 @@
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"type": "small"
},
"display": {
"percentType": 6,
"keyWidth": 11,
"bar": {
"charElapsed": "=",
"charTotal": "-",
"width": 13
}
},
"modules": [
"title",
"separator",
"memory",
"swap",
"disk",
"battery",
{
"type": "colors",
"paddingLeft": 11,
"symbol": "circle"
}
]
}
+7
View File
@@ -0,0 +1,7 @@
{
"home": "https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c",
"license": "Embed in source",
"version": "2007-05-26 (Unicode 5.0)",
"author": "Markus Kuhn",
"modified": "CarterLi"
}
+6
View File
@@ -0,0 +1,6 @@
{
"home": "https://github.com/ibireme/yyjson",
"license": "MIT ( embed in source )",
"version": "5e3b26d2659287d31e2f8e10f95f95feb7e5ab3a",
"author": "ibireme"
}
+9281
View File
File diff suppressed because it is too large Load Diff
+7846
View File
File diff suppressed because it is too large Load Diff
+45 -39
View File
@@ -1,51 +1,57 @@
#include "common/bar.h"
#include "common/color.h"
#include "util/textModifier.h" #include "util/textModifier.h"
#include "bar.h"
// green, yellow, red: print the color on nth (0~9) block void ffAppendPercentBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, uint8_t red)
// set its value == 10 means the color will not be printed
void ffAppendPercentBar(FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_t yellow, uint8_t red)
{ {
assert(green <= 10 && yellow <= 10 && red <= 10); assert(green <= 100 && yellow <= 100 && red <= 100);
// [ 0%, 5%) prints 0 blocks uint32_t blocksPercent = (uint32_t) (percent / 100.0 * instance.config.barWidth + 0.5);
// [ 5%, 15%) prints 1 block; uint32_t blocksGreen = (uint32_t) (green / 100.0 * instance.config.barWidth + 0.5);
// ... uint32_t blocksYellow = (uint32_t) (yellow / 100.0 * instance.config.barWidth + 0.5);
// [85%, 95%) prints 9 blocks; uint32_t blocksRed = (uint32_t) (red / 100.0 * instance.config.barWidth + 0.5);
// [95%,100%] prints 10 blocks assert(blocksPercent <= instance.config.barWidth);
percent = (uint8_t)(percent + 5) / 10;
assert(percent <= 10);
if(!instance.config.pipe) if(instance.config.barBorder)
ffStrbufAppendS(buffer, "\033[97m[ "); {
else if(!instance.config.pipe)
ffStrbufAppendS(buffer, "[ "); ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m[ ");
else
ffStrbufAppendS(buffer, "[ ");
}
for (uint8_t i = 0; i < percent; ++i) for (uint32_t i = 0; i < blocksPercent; ++i)
{ {
if(!instance.config.pipe) if(!instance.config.pipe)
{ {
if (i == green) if (i == blocksGreen)
ffStrbufAppendS(buffer, "\033[32m"); ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_GREEN "m");
else if (i == yellow) else if (i == blocksYellow)
ffStrbufAppendS(buffer, "\033[93m"); ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_YELLOW "m");
else if (i == red) else if (i == blocksRed)
ffStrbufAppendS(buffer, "\033[91m"); ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_RED "m");
} }
ffStrbufAppendS(buffer, ""); ffStrbufAppend(buffer, &instance.config.barCharElapsed);
} }
if (percent < 10) if (blocksPercent < instance.config.barWidth)
{ {
if(!instance.config.pipe) if(!instance.config.pipe)
ffStrbufAppendS(buffer, "\033[97m"); ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m");
for (uint8_t i = percent; i < 10; ++i) for (uint32_t i = blocksPercent; i < instance.config.barWidth; ++i)
ffStrbufAppendS(buffer, "-"); ffStrbufAppend(buffer, &instance.config.barCharTotal);
}
if(instance.config.barBorder)
{
if(!instance.config.pipe)
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m ]");
else
ffStrbufAppendS(buffer, " ]");
} }
if(!instance.config.pipe) if(!instance.config.pipe)
ffStrbufAppendS(buffer, "\033[97m ]" FASTFETCH_TEXT_MODIFIER_RESET); ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET);
else
ffStrbufAppendS(buffer, " ]");
} }
// if (green < yellow) // if (green < yellow)
@@ -57,7 +63,7 @@ void ffAppendPercentBar(FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_
// [green, 100]: print green // [green, 100]: print green
// [yellow, green): print yellow // [yellow, green): print yellow
// [0, yellow): PRINT RED // [0, yellow): PRINT RED
void ffAppendPercentNum(FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_t yellow, bool parentheses) void ffAppendPercentNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, bool parentheses)
{ {
assert(green <= 100 && yellow <= 100); assert(green <= 100 && yellow <= 100);
@@ -71,23 +77,23 @@ void ffAppendPercentNum(FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_
if(green < yellow) if(green < yellow)
{ {
if (percent <= green) if (percent <= green)
ffStrbufAppendS(buffer, "\033[32m"); ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_GREEN "m");
else if (percent <= yellow) else if (percent <= yellow)
ffStrbufAppendS(buffer, "\033[93m"); ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_YELLOW "m");
else else
ffStrbufAppendS(buffer, "\033[91m"); ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_RED "m");
} }
else else
{ {
if (percent >= green) if (percent >= green)
ffStrbufAppendS(buffer, "\033[32m"); ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_GREEN "m");
else if (percent >= yellow) else if (percent >= yellow)
ffStrbufAppendS(buffer, "\033[93m"); ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_YELLOW "m");
else else
ffStrbufAppendS(buffer, "\033[91m"); ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_RED "m");
} }
} }
ffStrbufAppendF(buffer, "%u%%", (unsigned) percent); ffStrbufAppendF(buffer, "%u%%", (unsigned) (percent + 0.5));
if (colored && !instance.config.pipe) if (colored && !instance.config.pipe)
{ {
+2 -2
View File
@@ -13,7 +13,7 @@ enum
FF_PERCENTAGE_TYPE_NUM_COLOR_BIT = 1 << 3, FF_PERCENTAGE_TYPE_NUM_COLOR_BIT = 1 << 3,
}; };
void ffAppendPercentBar(FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_t yellow, uint8_t red); void ffAppendPercentBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, uint8_t red);
void ffAppendPercentNum(FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_t yellow, bool parentheses); void ffAppendPercentNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, bool parentheses);
#endif #endif
+32
View File
@@ -0,0 +1,32 @@
#include "commandoption.h"
#include "util/stringUtils.h"
#include <ctype.h>
bool ffParseModuleCommand(const char* type)
{
if(!isalpha(type[0])) return false;
for (FFModuleBaseInfo** modules = ffModuleInfos[toupper(type[0]) - 'A']; *modules; ++modules)
{
FFModuleBaseInfo* baseInfo = *modules;
if (ffStrEqualsIgnCase(type, baseInfo->name))
{
baseInfo->printModule(baseInfo);
return true;
}
}
return false;
}
bool ffParseModuleOptions(const char* key, const char* value)
{
if (!ffStrStartsWith(key, "--") || !isalpha(key[2])) return false;
for (FFModuleBaseInfo** modules = ffModuleInfos[toupper(key[2]) - 'A']; *modules; ++modules)
{
FFModuleBaseInfo* baseInfo = *modules;
if (baseInfo->parseCommandOptions(baseInfo, key, value)) return true;
}
return false;
}
+11
View File
@@ -0,0 +1,11 @@
#pragma once
#ifndef FF_INCLUDED_common_commandoption
#define FF_INCLUDED_common_commandoption
#include "fastfetch.h"
bool ffParseModuleCommand(const char* type);
bool ffParseModuleOptions(const char* key, const char* value);
#endif
+96 -82
View File
@@ -48,7 +48,6 @@ static void defaultConfig(void)
#endif #endif
instance.config.showErrors = false; instance.config.showErrors = false;
instance.config.recache = false;
instance.config.allowSlowOperations = false; instance.config.allowSlowOperations = false;
instance.config.pipe = !isatty(STDOUT_FILENO); instance.config.pipe = !isatty(STDOUT_FILENO);
@@ -68,58 +67,69 @@ static void defaultConfig(void)
instance.config.multithreading = true; instance.config.multithreading = true;
instance.config.stat = false; instance.config.stat = false;
instance.config.noBuffer = false; instance.config.noBuffer = false;
instance.config.keyWidth = 0;
ffInitTitleOptions(&instance.config.title); ffStrbufInitStatic(&instance.config.barCharElapsed, "");
ffInitOSOptions(&instance.config.os); ffStrbufInitStatic(&instance.config.barCharTotal, "-");
ffInitHostOptions(&instance.config.host); instance.config.barWidth = 10;
instance.config.barBorder = true;
instance.config.percentType = 1;
ffInitBatteryOptions(&instance.config.battery);
ffInitBiosOptions(&instance.config.bios); ffInitBiosOptions(&instance.config.bios);
ffInitBluetoothOptions(&instance.config.bluetooth);
ffInitBoardOptions(&instance.config.board); ffInitBoardOptions(&instance.config.board);
ffInitBreakOptions(&instance.config.break_);
ffInitBrightnessOptions(&instance.config.brightness); ffInitBrightnessOptions(&instance.config.brightness);
ffInitChassisOptions(&instance.config.chassis);
ffInitCommandOptions(&instance.config.command);
ffInitCustomOptions(&instance.config.custom);
ffInitKernelOptions(&instance.config.kernel);
ffInitUptimeOptions(&instance.config.uptime);
ffInitProcessesOptions(&instance.config.processes);
ffInitPackagesOptions(&instance.config.packages);
ffInitShellOptions(&instance.config.shell);
ffInitDisplayOptions(&instance.config.display);
ffInitDEOptions(&instance.config.de);
ffInitWMOptions(&instance.config.wm);
ffInitWMThemeOptions(&instance.config.wmTheme);
ffInitThemeOptions(&instance.config.theme);
ffInitIconsOptions(&instance.config.icons);
ffInitFontOptions(&instance.config.font);
ffInitCursorOptions(&instance.config.cursor);
ffInitTerminalOptions(&instance.config.terminal);
ffInitTerminalFontOptions(&instance.config.terminalFont);
ffInitCPUOptions(&instance.config.cpu); ffInitCPUOptions(&instance.config.cpu);
ffInitCPUUsageOptions(&instance.config.cpuUsage); ffInitCPUUsageOptions(&instance.config.cpuUsage);
ffInitGPUOptions(&instance.config.gpu); ffInitChassisOptions(&instance.config.chassis);
ffInitMemoryOptions(&instance.config.memory); ffInitColorsOptions(&instance.config.colors);
ffInitSwapOptions(&instance.config.swap); ffInitCommandOptions(&instance.config.command);
ffInitCursorOptions(&instance.config.cursor);
ffInitCustomOptions(&instance.config.custom);
ffInitDEOptions(&instance.config.de);
ffInitDateTimeOptions(&instance.config.dateTime);
ffInitDiskOptions(&instance.config.disk); ffInitDiskOptions(&instance.config.disk);
ffInitBatteryOptions(&instance.config.battery); ffInitDisplayOptions(&instance.config.display);
ffInitPowerAdapterOptions(&instance.config.powerAdapter); ffInitFontOptions(&instance.config.font);
ffInitGPUOptions(&instance.config.gpu);
ffInitGamepadOptions(&instance.config.gamepad);
ffInitHostOptions(&instance.config.host);
ffInitIconsOptions(&instance.config.icons);
ffInitKernelOptions(&instance.config.kernel);
ffInitLMOptions(&instance.config.lm); ffInitLMOptions(&instance.config.lm);
ffInitLocaleOptions(&instance.config.locale);
ffInitLocalIpOptions(&instance.config.localIP); ffInitLocalIpOptions(&instance.config.localIP);
ffInitLocaleOptions(&instance.config.locale);
ffInitMediaOptions(&instance.config.media);
ffInitMemoryOptions(&instance.config.memory);
ffInitMonitorOptions(&instance.config.monitor);
ffInitOSOptions(&instance.config.os);
ffInitOpenCLOptions(&instance.config.openCL);
ffInitOpenGLOptions(&instance.config.openGL);
ffInitPackagesOptions(&instance.config.packages);
ffInitPlayerOptions(&instance.config.player);
ffInitPowerAdapterOptions(&instance.config.powerAdapter);
ffInitProcessesOptions(&instance.config.processes);
ffInitPublicIpOptions(&instance.config.publicIP); ffInitPublicIpOptions(&instance.config.publicIP);
ffInitSeparatorOptions(&instance.config.separator);
ffInitShellOptions(&instance.config.shell);
ffInitSoundOptions(&instance.config.sound);
ffInitSwapOptions(&instance.config.swap);
ffInitTerminalFontOptions(&instance.config.terminalFont);
ffInitTerminalOptions(&instance.config.terminal);
ffInitTerminalSizeOptions(&instance.config.terminalSize);
ffInitThemeOptions(&instance.config.theme);
ffInitTitleOptions(&instance.config.title);
ffInitUptimeOptions(&instance.config.uptime);
ffInitUsersOptions(&instance.config.users);
ffInitVersionOptions(&instance.config.version);
ffInitVulkanOptions(&instance.config.vulkan);
ffInitWMOptions(&instance.config.wm);
ffInitWMThemeOptions(&instance.config.wmTheme);
ffInitWallpaperOptions(&instance.config.wallpaper);
ffInitWeatherOptions(&instance.config.weather); ffInitWeatherOptions(&instance.config.weather);
ffInitWifiOptions(&instance.config.wifi); ffInitWifiOptions(&instance.config.wifi);
ffInitPlayerOptions(&instance.config.player);
ffInitMediaOptions(&instance.config.media);
ffInitDateTimeOptions(&instance.config.dateTime);
ffInitVulkanOptions(&instance.config.vulkan);
ffInitWallpaperOptions(&instance.config.wallpaper);
ffInitOpenGLOptions(&instance.config.openGL);
ffInitOpenCLOptions(&instance.config.openCL);
ffInitUsersOptions(&instance.config.users);
ffInitBluetoothOptions(&instance.config.bluetooth);
ffInitSoundOptions(&instance.config.sound);
ffInitSeparatorOptions(&instance.config.separator);
ffInitGamepadOptions(&instance.config.gamepad);
ffInitColorsOptions(&instance.config.colors);
ffStrbufInit(&instance.config.libPCI); ffStrbufInit(&instance.config.libPCI);
ffStrbufInit(&instance.config.libVulkan); ffStrbufInit(&instance.config.libVulkan);
@@ -145,8 +155,6 @@ static void defaultConfig(void)
ffStrbufInit(&instance.config.libPulse); ffStrbufInit(&instance.config.libPulse);
ffStrbufInit(&instance.config.libnm); ffStrbufInit(&instance.config.libnm);
ffStrbufInit(&instance.config.libDdcutil); ffStrbufInit(&instance.config.libDdcutil);
instance.config.percentType = 1;
} }
void ffInitInstance(void) void ffInitInstance(void)
@@ -272,63 +280,69 @@ static void destroyConfig(void)
ffStrbufDestroy(&instance.config.colorKeys); ffStrbufDestroy(&instance.config.colorKeys);
ffStrbufDestroy(&instance.config.colorTitle); ffStrbufDestroy(&instance.config.colorTitle);
ffStrbufDestroy(&instance.config.keyValueSeparator); ffStrbufDestroy(&instance.config.keyValueSeparator);
ffStrbufDestroy(&instance.config.barCharElapsed);
ffStrbufDestroy(&instance.config.barCharTotal);
#if defined(__linux__) || defined(__FreeBSD__) #if defined(__linux__) || defined(__FreeBSD__)
ffStrbufDestroy(&instance.config.playerName); ffStrbufDestroy(&instance.config.playerName);
ffStrbufDestroy(&instance.config.osFile); ffStrbufDestroy(&instance.config.osFile);
#endif #endif
ffDestroyTitleOptions(&instance.config.title); ffDestroyBatteryOptions(&instance.config.battery);
ffDestroyOSOptions(&instance.config.os);
ffDestroyHostOptions(&instance.config.host);
ffDestroyBiosOptions(&instance.config.bios); ffDestroyBiosOptions(&instance.config.bios);
ffDestroyBluetoothOptions(&instance.config.bluetooth);
ffDestroyBoardOptions(&instance.config.board); ffDestroyBoardOptions(&instance.config.board);
ffDestroyBreakOptions(&instance.config.break_);
ffDestroyBrightnessOptions(&instance.config.brightness); ffDestroyBrightnessOptions(&instance.config.brightness);
ffDestroyChassisOptions(&instance.config.chassis);
ffDestroyCommandOptions(&instance.config.command);
ffDestroyCustomOptions(&instance.config.custom);
ffDestroyKernelOptions(&instance.config.kernel);
ffDestroyUptimeOptions(&instance.config.uptime);
ffDestroyProcessesOptions(&instance.config.processes);
ffDestroyPackagesOptions(&instance.config.packages);
ffDestroyShellOptions(&instance.config.shell);
ffDestroyDisplayOptions(&instance.config.display);
ffDestroyDEOptions(&instance.config.de);
ffDestroyWMOptions(&instance.config.wm);
ffDestroyWMThemeOptions(&instance.config.wmTheme);
ffDestroyThemeOptions(&instance.config.theme);
ffDestroyIconsOptions(&instance.config.icons);
ffDestroyFontOptions(&instance.config.font);
ffDestroyCursorOptions(&instance.config.cursor);
ffDestroyTerminalOptions(&instance.config.terminal);
ffDestroyTerminalFontOptions(&instance.config.terminalFont);
ffDestroyCPUOptions(&instance.config.cpu); ffDestroyCPUOptions(&instance.config.cpu);
ffDestroyCPUUsageOptions(&instance.config.cpuUsage); ffDestroyCPUUsageOptions(&instance.config.cpuUsage);
ffDestroyGPUOptions(&instance.config.gpu); ffDestroyChassisOptions(&instance.config.chassis);
ffDestroyMemoryOptions(&instance.config.memory); ffDestroyColorsOptions(&instance.config.colors);
ffDestroySwapOptions(&instance.config.swap); ffDestroyCommandOptions(&instance.config.command);
ffDestroyCursorOptions(&instance.config.cursor);
ffDestroyCustomOptions(&instance.config.custom);
ffDestroyDEOptions(&instance.config.de);
ffDestroyDateTimeOptions(&instance.config.dateTime);
ffDestroyDiskOptions(&instance.config.disk); ffDestroyDiskOptions(&instance.config.disk);
ffDestroyBatteryOptions(&instance.config.battery); ffDestroyDisplayOptions(&instance.config.display);
ffDestroyPowerAdapterOptions(&instance.config.powerAdapter); ffDestroyFontOptions(&instance.config.font);
ffDestroyGPUOptions(&instance.config.gpu);
ffDestroyGamepadOptions(&instance.config.gamepad);
ffDestroyHostOptions(&instance.config.host);
ffDestroyIconsOptions(&instance.config.icons);
ffDestroyKernelOptions(&instance.config.kernel);
ffDestroyLMOptions(&instance.config.lm); ffDestroyLMOptions(&instance.config.lm);
ffDestroyLocaleOptions(&instance.config.locale);
ffDestroyLocalIpOptions(&instance.config.localIP); ffDestroyLocalIpOptions(&instance.config.localIP);
ffDestroyLocaleOptions(&instance.config.locale);
ffDestroyMediaOptions(&instance.config.media);
ffDestroyMemoryOptions(&instance.config.memory);
ffDestroyMonitorOptions(&instance.config.monitor);
ffDestroyOSOptions(&instance.config.os);
ffDestroyOpenCLOptions(&instance.config.openCL);
ffDestroyOpenGLOptions(&instance.config.openGL);
ffDestroyPackagesOptions(&instance.config.packages);
ffDestroyPlayerOptions(&instance.config.player);
ffDestroyPowerAdapterOptions(&instance.config.powerAdapter);
ffDestroyProcessesOptions(&instance.config.processes);
ffDestroyPublicIpOptions(&instance.config.publicIP); ffDestroyPublicIpOptions(&instance.config.publicIP);
ffDestroySeparatorOptions(&instance.config.separator);
ffDestroyShellOptions(&instance.config.shell);
ffDestroySoundOptions(&instance.config.sound);
ffDestroySwapOptions(&instance.config.swap);
ffDestroyTerminalFontOptions(&instance.config.terminalFont);
ffDestroyTerminalOptions(&instance.config.terminal);
ffDestroyTerminalSizeOptions(&instance.config.terminalSize);
ffDestroyThemeOptions(&instance.config.theme);
ffDestroyTitleOptions(&instance.config.title);
ffDestroyUptimeOptions(&instance.config.uptime);
ffDestroyUsersOptions(&instance.config.users);
ffDestroyVersionOptions(&instance.config.version);
ffDestroyVulkanOptions(&instance.config.vulkan);
ffDestroyWMOptions(&instance.config.wm);
ffDestroyWMThemeOptions(&instance.config.wmTheme);
ffDestroyWallpaperOptions(&instance.config.wallpaper); ffDestroyWallpaperOptions(&instance.config.wallpaper);
ffDestroyWeatherOptions(&instance.config.weather); ffDestroyWeatherOptions(&instance.config.weather);
ffDestroyWifiOptions(&instance.config.wifi); ffDestroyWifiOptions(&instance.config.wifi);
ffDestroyPlayerOptions(&instance.config.player);
ffDestroyMediaOptions(&instance.config.media);
ffDestroyDateTimeOptions(&instance.config.dateTime);
ffDestroyVulkanOptions(&instance.config.vulkan);
ffDestroyOpenGLOptions(&instance.config.openGL);
ffDestroyOpenCLOptions(&instance.config.openCL);
ffDestroyUsersOptions(&instance.config.users);
ffDestroyBluetoothOptions(&instance.config.bluetooth);
ffDestroySeparatorOptions(&instance.config.separator);
ffDestroySoundOptions(&instance.config.sound);
ffDestroyGamepadOptions(&instance.config.gamepad);
ffDestroyColorsOptions(&instance.config.colors);
ffStrbufDestroy(&instance.config.libPCI); ffStrbufDestroy(&instance.config.libPCI);
ffStrbufDestroy(&instance.config.libVulkan); ffStrbufDestroy(&instance.config.libVulkan);
+73 -153
View File
@@ -17,14 +17,19 @@ bool ffJsonConfigParseModuleArgs(const char* key, yyjson_val* val, FFModuleArgs*
ffStrbufSetNS(&moduleArgs->key, (uint32_t) yyjson_get_len(val), yyjson_get_str(val)); ffStrbufSetNS(&moduleArgs->key, (uint32_t) yyjson_get_len(val), yyjson_get_str(val));
return true; return true;
} }
else if(ffStrEqualsIgnCase(key, "format"))
{
ffStrbufSetNS(&moduleArgs->outputFormat, (uint32_t) yyjson_get_len(val), yyjson_get_str(val));
return true;
}
else if(ffStrEqualsIgnCase(key, "keyColor")) else if(ffStrEqualsIgnCase(key, "keyColor"))
{ {
ffOptionParseColor(yyjson_get_str(val), &moduleArgs->keyColor); ffOptionParseColor(yyjson_get_str(val), &moduleArgs->keyColor);
return true; return true;
} }
else if(ffStrEqualsIgnCase(key, "format")) else if(ffStrEqualsIgnCase(key, "keyWidth"))
{ {
ffStrbufSetNS(&moduleArgs->outputFormat, (uint32_t) yyjson_get_len(val), yyjson_get_str(val)); moduleArgs->keyWidth = (uint32_t) yyjson_get_uint(val);
return true; return true;
} }
return false; return false;
@@ -65,165 +70,53 @@ const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair p
return "Invalid enum value type; must be a string or integer"; return "Invalid enum value type; must be a string or integer";
} }
static inline bool tryModule(const char* type, yyjson_val* module, const char* moduleName, void (*const f)(yyjson_val *module)) static bool parseModuleJsonObject(const char* type, yyjson_val* jsonVal)
{ {
if (ffStrEqualsIgnCase(type, moduleName)) if(!isalpha(type[0])) return false;
for (FFModuleBaseInfo** modules = ffModuleInfos[toupper(type[0]) - 'A']; *modules; ++modules)
{ {
f(module); FFModuleBaseInfo* baseInfo = *modules;
return true; if (ffStrEqualsIgnCase(type, baseInfo->name))
{
if (jsonVal) baseInfo->parseJsonObject(baseInfo, jsonVal);
baseInfo->printModule(baseInfo);
return true;
}
} }
return false; return false;
} }
static bool parseModuleJsonObject(const char* type, yyjson_val* module) static void prepareModuleJsonObject(const char* type, yyjson_val* module)
{ {
switch (toupper(type[0])) FFconfig* cfg = &instance.config;
switch (type[0])
{ {
case 'B': { case 'b': case 'B': {
return if (ffStrEqualsIgnCase(type, FF_CPUUSAGE_MODULE_NAME))
tryModule(type, module, FF_BATTERY_MODULE_NAME, ffParseBatteryJsonObject) || ffPrepareCPUUsage();
tryModule(type, module, FF_BIOS_MODULE_NAME, ffParseBiosJsonObject) || break;
tryModule(type, module, FF_BLUETOOTH_MODULE_NAME, ffParseBluetoothJsonObject) ||
tryModule(type, module, FF_BOARD_MODULE_NAME, ffParseBoardJsonObject) ||
tryModule(type, module, FF_BREAK_MODULE_NAME, ffParseBreakJsonObject) ||
tryModule(type, module, FF_BRIGHTNESS_MODULE_NAME, ffParseBrightnessJsonObject) ||
false;
} }
case 'p': case 'P': {
case 'C': { if (ffStrEqualsIgnCase(type, FF_PUBLICIP_MODULE_NAME))
return {
tryModule(type, module, FF_CHASSIS_MODULE_NAME, ffParseChassisJsonObject) || if (module) ffParsePublicIpJsonObject(&cfg->publicIP, module);
tryModule(type, module, FF_COMMAND_MODULE_NAME, ffParseCommandJsonObject) || ffPreparePublicIp(&cfg->publicIP);
tryModule(type, module, FF_COLORS_MODULE_NAME, ffParseColorsJsonObject) || }
tryModule(type, module, FF_CPU_MODULE_NAME, ffParseCPUJsonObject) || break;
tryModule(type, module, FF_CPUUSAGE_MODULE_NAME, ffParseCPUUsageJsonObject) ||
tryModule(type, module, FF_CURSOR_MODULE_NAME, ffParseCursorJsonObject) ||
tryModule(type, module, FF_CUSTOM_MODULE_NAME, ffParseCustomJsonObject) ||
false;
} }
case 'w': case 'W': {
case 'D': { if (ffStrEqualsIgnCase(type, FF_WEATHER_MODULE_NAME))
return {
tryModule(type, module, FF_DATETIME_MODULE_NAME, ffParseDateTimeJsonObject) || if (module) ffParseWeatherJsonObject(&cfg->weather, module);
tryModule(type, module, FF_DE_MODULE_NAME, ffParseDEJsonObject) || ffPrepareWeather(&cfg->weather);
tryModule(type, module, FF_DISPLAY_MODULE_NAME, ffParseDisplayJsonObject) || }
tryModule(type, module, FF_DISK_MODULE_NAME, ffParseDiskJsonObject) || break;
false;
} }
case 'F': {
return
tryModule(type, module, FF_FONT_MODULE_NAME, ffParseFontJsonObject) ||
false;
}
case 'G': {
return
tryModule(type, module, FF_GAMEPAD_MODULE_NAME, ffParseGamepadJsonObject) ||
tryModule(type, module, FF_GPU_MODULE_NAME, ffParseGPUJsonObject) ||
false;
}
case 'H': {
return
tryModule(type, module, FF_HOST_MODULE_NAME, ffParseHostJsonObject) ||
false;
}
case 'I': {
return
tryModule(type, module, FF_ICONS_MODULE_NAME, ffParseIconsJsonObject) ||
false;
}
case 'K': {
return
tryModule(type, module, FF_KERNEL_MODULE_NAME, ffParseKernelJsonObject) ||
false;
}
case 'L': {
return
tryModule(type, module, FF_LM_MODULE_NAME, ffParseLMJsonObject) ||
tryModule(type, module, FF_LOCALE_MODULE_NAME, ffParseLocaleJsonObject) ||
tryModule(type, module, FF_LOCALIP_MODULE_NAME, ffParseLocalIpJsonObject) ||
false;
}
case 'M': {
return
tryModule(type, module, FF_MEDIA_MODULE_NAME, ffParseMediaJsonObject) ||
tryModule(type, module, FF_MEMORY_MODULE_NAME, ffParseMemoryJsonObject) ||
tryModule(type, module, FF_MONITOR_MODULE_NAME, ffParseMonitorJsonObject) ||
false;
}
case 'O': {
return
tryModule(type, module, FF_OPENCL_MODULE_NAME, ffParseOpenCLJsonObject) ||
tryModule(type, module, FF_OPENGL_MODULE_NAME, ffParseOpenGLJsonObject) ||
tryModule(type, module, FF_OS_MODULE_NAME, ffParseOSJsonObject) ||
false;
}
case 'P': {
return
tryModule(type, module, FF_PACKAGES_MODULE_NAME, ffParsePackagesJsonObject) ||
tryModule(type, module, FF_PLAYER_MODULE_NAME, ffParsePlayerJsonObject) ||
tryModule(type, module, FF_POWERADAPTER_MODULE_NAME, ffParsePowerAdapterJsonObject) ||
tryModule(type, module, FF_PROCESSES_MODULE_NAME, ffParseProcessesJsonObject) ||
tryModule(type, module, FF_PUBLICIP_MODULE_NAME, ffParsePublicIpJsonObject) ||
false;
}
case 'S': {
return
tryModule(type, module, FF_SEPARATOR_MODULE_NAME, ffParseSeparatorJsonObject) ||
tryModule(type, module, FF_SHELL_MODULE_NAME, ffParseShellJsonObject) ||
tryModule(type, module, FF_SOUND_MODULE_NAME, ffParseSoundJsonObject) ||
tryModule(type, module, FF_SWAP_MODULE_NAME, ffParseSwapJsonObject) ||
false;
}
case 'T': {
return
tryModule(type, module, FF_TERMINAL_MODULE_NAME, ffParseTerminalJsonObject) ||
tryModule(type, module, FF_TERMINALFONT_MODULE_NAME, ffParseTerminalFontJsonObject) ||
tryModule(type, module, FF_TERMINALSIZE_MODULE_NAME, ffParseTerminalSizeJsonObject) ||
tryModule(type, module, FF_TITLE_MODULE_NAME, ffParseTitleJsonObject) ||
tryModule(type, module, FF_THEME_MODULE_NAME, ffParseThemeJsonObject) ||
false;
}
case 'U': {
return
tryModule(type, module, FF_UPTIME_MODULE_NAME, ffParseUptimeJsonObject) ||
tryModule(type, module, FF_USERS_MODULE_NAME, ffParseUsersJsonObject) ||
false;
}
case 'V': {
return
tryModule(type, module, FF_VULKAN_MODULE_NAME, ffParseVulkanJsonObject) ||
false;
}
case 'W': {
return
tryModule(type, module, FF_WALLPAPER_MODULE_NAME, ffParseWallpaperJsonObject) ||
tryModule(type, module, FF_WEATHER_MODULE_NAME, ffParseWeatherJsonObject) ||
tryModule(type, module, FF_WM_MODULE_NAME, ffParseWMJsonObject) ||
tryModule(type, module, FF_WIFI_MODULE_NAME, ffParseWifiJsonObject) ||
tryModule(type, module, FF_WMTHEME_MODULE_NAME, ffParseWMThemeJsonObject) ||
false;
}
default:
return false;
} }
} }
static const char* printJsonConfig(void) static const char* printJsonConfig(bool prepare)
{ {
yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc);
assert(root); assert(root);
@@ -240,7 +133,7 @@ static const char* printJsonConfig(void)
yyjson_arr_foreach(modules, idx, max, item) yyjson_arr_foreach(modules, idx, max, item)
{ {
uint64_t ms = 0; uint64_t ms = 0;
if(__builtin_expect(instance.config.stat, false)) if(!prepare && instance.config.stat)
ms = ffTimeGetTick(); ms = ffTimeGetTick();
yyjson_val* module = item; yyjson_val* module = item;
@@ -257,10 +150,12 @@ static const char* printJsonConfig(void)
else else
return "modules must be an array of strings or objects"; return "modules must be an array of strings or objects";
if(!parseModuleJsonObject(type, module)) if(prepare)
prepareModuleJsonObject(type, module);
else if(!parseModuleJsonObject(type, module))
return "Unknown module type"; return "Unknown module type";
if(__builtin_expect(instance.config.stat, false)) if(!prepare && instance.config.stat)
{ {
char str[32]; char str[32];
int len = snprintf(str, sizeof str, "%" PRIu64 "ms", ffTimeGetTick() - ms); int len = snprintf(str, sizeof str, "%" PRIu64 "ms", ffTimeGetTick() - ms);
@@ -431,8 +326,33 @@ const char* ffParseDisplayJsonConfig(void)
} }
else if (ffStrEqualsIgnCase(key, "percentType")) else if (ffStrEqualsIgnCase(key, "percentType"))
config->percentType = (uint32_t) yyjson_get_uint(val); config->percentType = (uint32_t) yyjson_get_uint(val);
else if (ffStrEqualsIgnCase(key, "bar"))
{
if (yyjson_is_obj(val))
{
const char* charElapsed = yyjson_get_str(yyjson_obj_get(val, "charElapsed"));
if (charElapsed)
ffStrbufSetS(&config->barCharElapsed, charElapsed);
const char* charTotal = yyjson_get_str(yyjson_obj_get(val, "charTotal"));
if (charTotal)
ffStrbufSetS(&config->barCharTotal, charTotal);
yyjson_val* border = yyjson_obj_get(val, "border");
if (border)
config->barBorder = yyjson_get_bool(border);
yyjson_val* width = yyjson_obj_get(val, "width");
if (width)
config->barWidth = (uint8_t) yyjson_get_uint(width);
}
else
return "display.bar must be an object";
}
else if (ffStrEqualsIgnCase(key, "noBuffer")) else if (ffStrEqualsIgnCase(key, "noBuffer"))
config->noBuffer = yyjson_get_bool(val); config->noBuffer = yyjson_get_bool(val);
else if (ffStrEqualsIgnCase(key, "keyWidth"))
config->keyWidth = (uint32_t) yyjson_get_uint(val);
else else
return "Unknown display property"; return "Unknown display property";
} }
@@ -515,9 +435,9 @@ const char* ffParseLibraryJsonConfig(void)
return NULL; return NULL;
} }
void ffPrintJsonConfig(void) void ffPrintJsonConfig(bool prepare)
{ {
const char* error = printJsonConfig(); const char* error = printJsonConfig(prepare);
if (error) if (error)
ffPrintErrorString("JsonConfig", 0, NULL, NULL, "%s", error); ffPrintErrorString("JsonConfig", 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "%s", error);
} }
+4 -4
View File
@@ -4,7 +4,7 @@
bool ffJsonConfigParseModuleArgs(const char* key, yyjson_val* val, FFModuleArgs* moduleArgs); bool ffJsonConfigParseModuleArgs(const char* key, yyjson_val* val, FFModuleArgs* moduleArgs);
const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair pairs[]); const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair pairs[]);
void ffPrintJsonConfig(); void ffPrintJsonConfig(bool prepare);
const char* ffParseGeneralJsonConfig(); const char* ffParseGeneralJsonConfig(void);
const char* ffParseDisplayJsonConfig(); const char* ffParseDisplayJsonConfig(void);
const char* ffParseLibraryJsonConfig(); const char* ffParseLibraryJsonConfig(void);
+164
View File
@@ -0,0 +1,164 @@
#include "fastfetch.h"
static FFModuleBaseInfo* A[] = {
NULL,
};
static FFModuleBaseInfo* B[] = {
(void*) &instance.config.battery,
(void*) &instance.config.bios,
(void*) &instance.config.bluetooth,
(void*) &instance.config.board,
(void*) &instance.config.break_,
(void*) &instance.config.brightness,
NULL,
};
static FFModuleBaseInfo* C[] = {
(void*) &instance.config.chassis,
(void*) &instance.config.command,
(void*) &instance.config.colors,
(void*) &instance.config.cpu,
(void*) &instance.config.cpuUsage,
(void*) &instance.config.cursor,
(void*) &instance.config.custom,
NULL,
};
static FFModuleBaseInfo* D[] = {
(void*) &instance.config.dateTime,
(void*) &instance.config.de,
(void*) &instance.config.display,
(void*) &instance.config.disk,
NULL,
};
static FFModuleBaseInfo* E[] = {
NULL,
};
static FFModuleBaseInfo* F[] = {
(void*) &instance.config.font,
NULL,
};
static FFModuleBaseInfo* G[] = {
(void*) &instance.config.gamepad,
(void*) &instance.config.gpu,
NULL,
};
static FFModuleBaseInfo* H[] = {
(void*) &instance.config.host,
NULL,
};
static FFModuleBaseInfo* I[] = {
(void*) &instance.config.icons,
NULL,
};
static FFModuleBaseInfo* J[] = {
NULL,
};
static FFModuleBaseInfo* K[] = {
(void*) &instance.config.kernel,
NULL,
};
static FFModuleBaseInfo* L[] = {
(void*) &instance.config.lm,
(void*) &instance.config.locale,
(void*) &instance.config.localIP,
NULL,
};
static FFModuleBaseInfo* M[] = {
(void*) &instance.config.media,
(void*) &instance.config.memory,
(void*) &instance.config.monitor,
NULL,
};
static FFModuleBaseInfo* N[] = {
NULL,
};
static FFModuleBaseInfo* O[] = {
(void*) &instance.config.openCL,
(void*) &instance.config.openGL,
(void*) &instance.config.os,
NULL,
};
static FFModuleBaseInfo* P[] = {
(void*) &instance.config.packages,
(void*) &instance.config.player,
(void*) &instance.config.powerAdapter,
(void*) &instance.config.processes,
(void*) &instance.config.publicIP,
NULL,
};
static FFModuleBaseInfo* Q[] = {
NULL,
};
static FFModuleBaseInfo* R[] = {
NULL,
};
static FFModuleBaseInfo* S[] = {
(void*) &instance.config.separator,
(void*) &instance.config.shell,
(void*) &instance.config.sound,
(void*) &instance.config.swap,
NULL,
};
static FFModuleBaseInfo* T[] = {
(void*) &instance.config.terminal,
(void*) &instance.config.terminalFont,
(void*) &instance.config.terminalSize,
(void*) &instance.config.title,
(void*) &instance.config.theme,
NULL,
};
static FFModuleBaseInfo* U[] = {
(void*) &instance.config.uptime,
(void*) &instance.config.users,
NULL,
};
static FFModuleBaseInfo* V[] = {
(void*) &instance.config.version,
(void*) &instance.config.vulkan,
NULL,
};
static FFModuleBaseInfo* W[] = {
(void*) &instance.config.wallpaper,
(void*) &instance.config.weather,
(void*) &instance.config.wm,
(void*) &instance.config.wifi,
(void*) &instance.config.wmTheme,
NULL,
};
static FFModuleBaseInfo* X[] = {
NULL,
};
static FFModuleBaseInfo* Y[] = {
NULL,
};
static FFModuleBaseInfo* Z[] = {
NULL,
};
FFModuleBaseInfo** ffModuleInfos[] = {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
};
+8 -2
View File
@@ -34,6 +34,11 @@ bool ffOptionParseModuleArgs(const char* argumentKey, const char* subKey, const
ffOptionParseString(argumentKey, value, &result->key); ffOptionParseString(argumentKey, value, &result->key);
return true; return true;
} }
else if(ffStrEqualsIgnCase(subKey, "format"))
{
ffOptionParseString(argumentKey, value, &result->outputFormat);
return true;
}
else if(ffStrEqualsIgnCase(subKey, "key-color")) else if(ffStrEqualsIgnCase(subKey, "key-color"))
{ {
if(value == NULL) if(value == NULL)
@@ -44,9 +49,9 @@ bool ffOptionParseModuleArgs(const char* argumentKey, const char* subKey, const
ffOptionParseColor(value, &result->keyColor); ffOptionParseColor(value, &result->keyColor);
return true; return true;
} }
else if(ffStrEqualsIgnCase(subKey, "format")) else if(ffStrEqualsIgnCase(subKey, "key-width"))
{ {
ffOptionParseString(argumentKey, value, &result->outputFormat); result->keyWidth = ffOptionParseUInt32(argumentKey, value);
return true; return true;
} }
return false; return false;
@@ -175,6 +180,7 @@ void ffOptionInitModuleArg(FFModuleArgs* args)
ffStrbufInit(&args->key); ffStrbufInit(&args->key);
ffStrbufInit(&args->keyColor); ffStrbufInit(&args->keyColor);
ffStrbufInit(&args->outputFormat); ffStrbufInit(&args->outputFormat);
args->keyWidth = 0;
} }
void ffOptionDestroyModuleArg(FFModuleArgs* args) void ffOptionDestroyModuleArg(FFModuleArgs* args)
+26
View File
@@ -2,11 +2,37 @@
#include "util/FFstrbuf.h" #include "util/FFstrbuf.h"
struct yyjson_val;
// Must be the first field of FFModuleOptions
typedef struct FFModuleBaseInfo
{
const char* name;
bool (*parseCommandOptions)(void* options, const char* key, const char* value);
void (*parseJsonObject)(void* options, struct yyjson_val *module);
void (*printModule)(void* options);
} FFModuleBaseInfo;
static inline void ffOptionInitModuleBaseInfo(
FFModuleBaseInfo* baseInfo,
const char* name,
void* parseCommandOptions, // bool (*const parseCommandOptions)(void* options, const char* key, const char* value)
void* parseJsonObject, // void (*const parseJsonObject)(void* options, yyjson_val *module)
void* printModule // void (*const printModule)(void* options)
)
{
baseInfo->name = name;
baseInfo->parseCommandOptions = (__typeof__(baseInfo->parseCommandOptions)) parseCommandOptions;
baseInfo->parseJsonObject = (__typeof__(baseInfo->parseJsonObject)) parseJsonObject;
baseInfo->printModule = (__typeof__(baseInfo->printModule)) printModule;
}
typedef struct FFModuleArgs typedef struct FFModuleArgs
{ {
FFstrbuf key; FFstrbuf key;
FFstrbuf keyColor; FFstrbuf keyColor;
FFstrbuf outputFormat; FFstrbuf outputFormat;
uint32_t keyWidth;
} FFModuleArgs; } FFModuleArgs;
typedef struct FFKeyValuePair typedef struct FFKeyValuePair
+27 -53
View File
@@ -2,7 +2,7 @@
#include "common/printing.h" #include "common/printing.h"
#include "util/textModifier.h" #include "util/textModifier.h"
void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor) void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType)
{ {
ffLogoPrintLine(); ffLogoPrintLine();
@@ -16,14 +16,14 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFstrb
if (instance.config.brightColor) if (instance.config.brightColor)
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout); fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
if(customKeyColor != NULL && customKeyColor->length > 0) if(moduleArgs && !(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_COLOR) && moduleArgs->keyColor.length > 0)
ffPrintColor(customKeyColor); ffPrintColor(&moduleArgs->keyColor);
else else
ffPrintColor(&instance.config.colorKeys); ffPrintColor(&instance.config.colorKeys);
} }
//NULL check is required for modules with custom keys, e.g. disk with the folder path //NULL check is required for modules with custom keys, e.g. disk with the folder path
if(customKeyFormat == NULL || customKeyFormat->length == 0) if((printType & FF_PRINT_TYPE_NO_CUSTOM_KEY) || !moduleArgs || moduleArgs->key.length == 0)
{ {
fputs(moduleName, stdout); fputs(moduleName, stdout);
@@ -33,10 +33,10 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFstrb
else else
{ {
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
ffParseFormatString(&key, customKeyFormat, 1, (FFformatarg[]){ ffParseFormatString(&key, &moduleArgs->key, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex} {FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex}
}); });
ffPrintUserString(key.chars); ffStrbufWriteTo(&key, stdout);
} }
if(!instance.config.pipe) if(!instance.config.pipe)
@@ -46,32 +46,37 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFstrb
if(!instance.config.pipe) if(!instance.config.pipe)
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
}
void ffPrintFormatString(const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments)
{
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateA(256);
ffParseFormatString(&buffer, format, numArgs, arguments);
if(buffer.length > 0) if (!instance.config.pipe && !(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_WIDTH))
{ {
ffPrintLogoAndKey(moduleName, moduleIndex, customKeyFormat, customKeyColor); uint32_t keyWidth = moduleArgs && moduleArgs->keyWidth > 0 ? moduleArgs->keyWidth : instance.config.keyWidth;
ffPrintUserString(buffer.chars); if (keyWidth > 0)
putchar('\n'); printf("\e[%uG", (unsigned) (keyWidth + instance.state.logoWidth));
} }
} }
void ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments) void ffPrintFormatString(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, uint32_t numArgs, const FFformatarg* arguments)
{ {
ffPrintFormatString(moduleName, moduleIndex, &moduleArgs->key, &moduleArgs->keyColor, &moduleArgs->outputFormat, numArgs, arguments); FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
if (moduleArgs)
ffParseFormatString(&buffer, &moduleArgs->outputFormat, numArgs, arguments);
else
ffStrbufAppendS(&buffer, "unknown");
if(buffer.length > 0)
{
ffPrintLogoAndKey(moduleName, moduleIndex, moduleArgs, printType);
ffStrbufPutTo(&buffer, stdout);
}
} }
static void printError(const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const char* message, va_list arguments) static void printError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, va_list arguments)
{ {
if(!instance.config.showErrors) if(!instance.config.showErrors)
return; return;
ffPrintLogoAndKey(moduleName, moduleIndex, customKeyFormat, customKeyColor); ffPrintLogoAndKey(moduleName, moduleIndex, moduleArgs, printType);
if(!instance.config.pipe) if(!instance.config.pipe)
fputs(FASTFETCH_TEXT_MODIFIER_ERROR, stdout); fputs(FASTFETCH_TEXT_MODIFIER_ERROR, stdout);
@@ -84,11 +89,11 @@ static void printError(const char* moduleName, uint8_t moduleIndex, const FFstrb
putchar('\n'); putchar('\n');
} }
void ffPrintErrorString(const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const char* message, ...) void ffPrintErrorString(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, ...)
{ {
va_list arguments; va_list arguments;
va_start(arguments, message); va_start(arguments, message);
printError(moduleName, moduleIndex, customKeyFormat, customKeyColor, message, arguments); printError(moduleName, moduleIndex, moduleArgs, printType, message, arguments);
va_end(arguments); va_end(arguments);
} }
@@ -96,7 +101,7 @@ void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArg
{ {
va_list arguments; va_list arguments;
va_start(arguments, message); va_start(arguments, message);
printError(moduleName, moduleIndex, &moduleArgs->key, &moduleArgs->keyColor, message, arguments); printError(moduleName, moduleIndex, moduleArgs, FF_PRINT_TYPE_DEFAULT, message, arguments);
va_end(arguments); va_end(arguments);
} }
@@ -125,34 +130,3 @@ void ffPrintCharTimes(char c, uint32_t times)
if(remaining > 0) if(remaining > 0)
fwrite(str, 1, remaining, stdout); fwrite(str, 1, remaining, stdout);
} }
void ffPrintUserString(const char* value)
{
while(*value != '\0')
{
if(*value != '\\')
{
putchar(*value);
++value;
continue;
}
++value;
if(*value == 'n')
putchar('\n');
else if(*value == 't')
putchar('\t');
else if(*value == 'e')
putchar('\e');
else if(*value == '\\')
putchar('\\');
else
{
putchar('\\');
putchar(*value);
}
++value;
}
}
+15 -5
View File
@@ -6,13 +6,23 @@
#include "fastfetch.h" #include "fastfetch.h"
#include "common/format.h" #include "common/format.h"
void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor); typedef enum FFPrintType {
void ffPrintFormatString(const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments); FF_PRINT_TYPE_DEFAULT = 0,
void ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments); FF_PRINT_TYPE_NO_CUSTOM_KEY = 1 << 0,
FF_C_PRINTF(5, 6) void ffPrintErrorString(const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const char* message, ...); FF_PRINT_TYPE_NO_CUSTOM_KEY_COLOR = 1 << 1,
FF_PRINT_TYPE_NO_CUSTOM_KEY_WIDTH = 1 << 2,
FF_PRINT_TYPE_NO_CUSTOM_OUTPUT_FORMAT = 1 << 3, // reserved
} FFPrintType;
void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType);
void ffPrintFormatString(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, uint32_t numArgs, const FFformatarg* arguments);
static inline void ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments)
{
ffPrintFormatString(moduleName, moduleIndex, moduleArgs, FF_PRINT_TYPE_DEFAULT, numArgs, arguments);
}
FF_C_PRINTF(5, 6) void ffPrintErrorString(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, ...);
FF_C_PRINTF(4, 5) void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...); FF_C_PRINTF(4, 5) void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...);
void ffPrintColor(const FFstrbuf* colorValue); void ffPrintColor(const FFstrbuf* colorValue);
void ffPrintCharTimes(char c, uint32_t times); void ffPrintCharTimes(char c, uint32_t times);
void ffPrintUserString(const char* str);
#endif #endif
+3
View File
@@ -376,6 +376,7 @@
#--player-key Media Player #--player-key Media Player
#--media-key Media #--media-key Media
#--datetime-key Date Time #--datetime-key Date Time
#--version-key Version
#--vulkan-key Vulkan #--vulkan-key Vulkan
#--opengl-key OpenGL #--opengl-key OpenGL
#--opencl-key OpenCL #--opencl-key OpenCL
@@ -426,6 +427,7 @@
#--player-format #--player-format
#--media-format #--media-format
#--datetime-format #--datetime-format
#--version-format
#--vulkan-format #--vulkan-format
#--opengl-format #--opengl-format
#--opencl-format #--opencl-format
@@ -473,6 +475,7 @@
#--player-key-color #--player-key-color
#--media-key-color #--media-key-color
#--datetime-key-color #--datetime-key-color
#--version-key-color
#--vulkan-key-color #--vulkan-key-color
#--opengl-key-color #--opengl-key-color
#--opencl-key-color #--opencl-key-color
+8 -1
View File
@@ -40,6 +40,7 @@ Logo options:
--logo-padding-right <padding>: Set the padding on the right of the logo --logo-padding-right <padding>: Set the padding on the right of the logo
--logo-padding-top <padding>: Set the padding on the top of the logo --logo-padding-top <padding>: Set the padding on the top of the logo
--logo-print-remaining <?value>: Whether to print the remaining logo, if it has more lines than modules to display --logo-print-remaining <?value>: Whether to print the remaining logo, if it has more lines than modules to display
--logo-recache <?value>: If true, regenerate image logo cache
--file <file>: Short for --logo-type file --logo <file> --file <file>: Short for --logo-type file --logo <file>
--file-raw <file>: Short for --logo-type file-raw --logo <file> --file-raw <file>: Short for --logo-type file-raw --logo <file>
--data <data>: Short for --logo-type data --logo <data> --data <data>: Short for --logo-type data --logo <data>
@@ -58,8 +59,9 @@ Display options:
-s,--structure <structure>: Set the structure of the fetch. Must be a colon separated list of keys. Use "fastfetch --list-modules" to see the ones available. -s,--structure <structure>: Set the structure of the fetch. Must be a colon separated list of keys. Use "fastfetch --list-modules" to see the ones available.
--color-keys <color>: Set the color of the keys --color-keys <color>: Set the color of the keys
--color-title <color>: Set the color of the title --color-title <color>: Set the color of the title
--color <color>: Set the color of both the keys and title
--key-width <num>: Align the width of keys to <num> characters
--bright-color <?value>: Set if the keys, title and ASCII logo should be printed in bright color. Default is true --bright-color <?value>: Set if the keys, title and ASCII logo should be printed in bright color. Default is true
-c,--color <color>: Set the color of both the keys and title
--separator <str>: Set the separator between key and value. Default is a colon with a space --separator <str>: Set the separator between key and value. Default is a colon with a space
--set <key=value>: Hard set the value of a key --set <key=value>: Hard set the value of a key
--set-keyless <key=value>: Hard set the value of a key, but don't print the key or the separator --set-keyless <key=value>: Hard set the value of a key, but don't print the key or the separator
@@ -68,6 +70,10 @@ Display options:
--hide-cursor <?value>: Whether to hide the cursor during the run --hide-cursor <?value>: Whether to hide the cursor during the run
--binary-prefix <value>: Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC --binary-prefix <value>: Set the binary prefix to used. Must be IEC, SI or JEDEC. Default is IEC
--percent-type <value>: Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number. Default is 1 --percent-type <value>: Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number. Default is 1
--bar-char-elapsed <str>: Set the character to use in elapsed part. Default is '■'
--bar-char-total <str>: Set the character to use in total part. Default is '-'
--bar-width <?num>: Set the width of the bar, in number of characters. Default is 10
--bar-border <?value>: Whether to show a border around the bar. Default is true
--no-buffer <?value>: Set if the stdout application buffer should be disabled. Default is false --no-buffer <?value>: Set if the stdout application buffer should be disabled. Default is false
--size-ndigits <value>: Set the number of digits to keep after the decimal point when formatting sizes --size-ndigits <value>: Set the number of digits to keep after the decimal point when formatting sizes
--size-max-prefix <value>: Set the largest binary prefix to use when formatting sizes. Default is YB --size-max-prefix <value>: Set the largest binary prefix to use when formatting sizes. Default is YB
@@ -82,6 +88,7 @@ General module options:
For modules which print multiple lines, the string is parsed as a format string with the index as first character. For modules which print multiple lines, the string is parsed as a format string with the index as first character.
--<module>-key-color <format>: Override the global `--color-keys` option for each specific module. --<module>-key-color <format>: Override the global `--color-keys` option for each specific module.
--<module>-key-width <num>: Override the global `--key-width` option for each specific module.
Library options: Set the path of a library to load Library options: Set the path of a library to load
--lib-PCI <path> --lib-PCI <path>
-45
View File
@@ -1,45 +0,0 @@
Battery
Bios
Bluetooth
Board
Break
Chassis
Colors
CPU
CPUUsage
Cursor
Date
Datetime
DE
Disk
Display
Font
GPU
Host
Icons
Kernel
Locale
LocalIP
Media
Memory
OpenGL
OS
Packages
Player
PowerAdapter
Processes
PublicIP
Separator
Shell
Swap
Terminal
TerminalFont
Theme
Time
Title
Uptime
Vulkan
Weather
Wifi
WM
WMTheme
+4 -2
View File
@@ -31,7 +31,7 @@ static const char* detectWithDisplayServices(const FFDisplayServerResult* displa
// https://github.com/waydabber/m1ddc // https://github.com/waydabber/m1ddc
// Works for Apple Silicon and USB-C adapter connection ( but not HTMI ) // Works for Apple Silicon and USB-C adapter connection ( but not HTMI )
static const char* detectWithDdcci(FFlist* result) FF_MAYBE_UNUSED static const char* detectWithDdcci(FFlist* result)
{ {
if (!IOAVServiceCreate || !IOAVServiceReadI2C) if (!IOAVServiceCreate || !IOAVServiceReadI2C)
return "IOAVService is not available"; return "IOAVService is not available";
@@ -108,8 +108,10 @@ const char* ffDetectBrightness(FFlist* result)
detectWithDisplayServices(displayServer, result); detectWithDisplayServices(displayServer, result);
if (instance.config.allowSlowOperations && displayServer->displays.length > result->length) #ifdef __aarch64__
if (displayServer->displays.length > result->length)
detectWithDdcci(result); detectWithDdcci(result);
#endif
return NULL; return NULL;
} }
+3 -6
View File
@@ -139,12 +139,9 @@ const char* ffDetectBrightness(FFlist* result)
detectWithBacklight(result); detectWithBacklight(result);
#ifdef FF_HAVE_DDCUTIL #ifdef FF_HAVE_DDCUTIL
if (instance.config.allowSlowOperations) const FFDisplayServerResult* displayServer = ffConnectDisplayServer();
{ if (result->length < displayServer->displays.length)
const FFDisplayServerResult* displayServer = ffConnectDisplayServer(); detectWithDdcci(result);
if (result->length < displayServer->displays.length)
detectWithDdcci(result);
}
#endif #endif
return NULL; return NULL;
@@ -76,7 +76,7 @@ const char* ffDetectBrightness(FFlist* result)
if (hasBuiltinDisplay(displayServer)) if (hasBuiltinDisplay(displayServer))
detectWithWmi(result); detectWithWmi(result);
if (instance.config.allowSlowOperations && result->length < displayServer->displays.length) if (result->length < displayServer->displays.length)
detectWithDdcci(displayServer, result); detectWithDdcci(displayServer, result);
return NULL; return NULL;
} }
+2
View File
@@ -35,6 +35,8 @@ const char* ffGetCpuUsageResult(double* result)
if(inUseAll2 != inUseAll1) if(inUseAll2 != inUseAll1)
{ {
*result = (double)(inUseAll2 - inUseAll1) / (double)(totalAll2 - totalAll1) * 100; *result = (double)(inUseAll2 - inUseAll1) / (double)(totalAll2 - totalAll1) * 100;
inUseAll1 = inUseAll2;
totalAll1 = totalAll2;
return NULL; return NULL;
} }
else else
+10 -10
View File
@@ -3,19 +3,19 @@
#include <sys/mount.h> #include <sys/mount.h>
#ifdef __FreeBSD__ #ifdef __FreeBSD__
#include "util/stringUtils.h"
static void detectFsInfo(struct statfs* fs, FFDisk* disk) static void detectFsInfo(struct statfs* fs, FFDisk* disk)
{ {
if( if(ffStrbufEqualS(&disk->filesystem, "zfs"))
ffStrbufStartsWithS(&disk->mountpoint, "/boot") || {
ffStrbufStartsWithS(&disk->mountpoint, "/dev") || disk->type = !ffStrStartsWith(fs->f_mntfromname, "zroot/") || ffStrStartsWith(fs->f_mntfromname, "zroot/ROOT/")
ffStrbufStartsWithS(&disk->mountpoint, "/var") || ? FF_DISK_TYPE_REGULAR_BIT
ffStrbufStartsWithS(&disk->mountpoint, "/tmp") || : FF_DISK_TYPE_SUBVOLUME_BIT;
ffStrbufStartsWithS(&disk->mountpoint, "/proc") || }
ffStrbufStartsWithS(&disk->mountpoint, "/zroot") || else if(!ffStrStartsWith(fs->f_mntfromname, "/dev/"))
ffStrbufStartsWithS(&disk->mountpoint, "/compat/linux/")
)
disk->type = FF_DISK_TYPE_HIDDEN_BIT; disk->type = FF_DISK_TYPE_HIDDEN_BIT;
else if((fs->f_flags & MNT_NOSUID) || !(fs->f_flags & MNT_LOCAL)) else if(!(fs->f_flags & MNT_LOCAL))
disk->type = FF_DISK_TYPE_EXTERNAL_BIT; disk->type = FF_DISK_TYPE_EXTERNAL_BIT;
else else
disk->type = FF_DISK_TYPE_REGULAR_BIT; disk->type = FF_DISK_TYPE_REGULAR_BIT;
+19 -7
View File
@@ -122,20 +122,32 @@ static void detectName(FFDisk* disk, const FFstrbuf* device)
FF_STRBUF_AUTO_DESTROY basePath = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY basePath = ffStrbufCreate();
//Try partlabel first //Try label first
ffStrbufSetS(&basePath, "/dev/disk/by-partlabel/"); ffStrbufSetS(&basePath, "/dev/disk/by-label/");
detectNameFromPath(disk, &deviceStat, &basePath); detectNameFromPath(disk, &deviceStat, &basePath);
//Try label second
if(disk->name.length == 0) if(disk->name.length == 0)
{ {
ffStrbufSetS(&basePath, "/dev/disk/by-label/"); //Try partlabel second
ffStrbufSetS(&basePath, "/dev/disk/by-partlabel/");
detectNameFromPath(disk, &deviceStat, &basePath); detectNameFromPath(disk, &deviceStat, &basePath);
} }
//Use the mountpoint as a last resort // Basic\x20data\x20partition
if(disk->name.length == 0) for (uint32_t i = ffStrbufFirstIndexS(&disk->name, "\\x");
ffStrbufAppend(&disk->name, &disk->mountpoint); i != disk->name.length;
i = ffStrbufNextIndexS(&disk->name, i + 1, "\\x"))
{
uint32_t len = (uint32_t) strlen("\\x20");
if (disk->name.length >= len)
{
char bak = disk->name.chars[i + len];
disk->name.chars[i + len] = '\0';
disk->name.chars[i] = (char) strtoul(&disk->name.chars[i + 2], NULL, 16);
ffStrbufRemoveSubstr(&disk->name, i + 1, i + len);
disk->name.chars[i + 1] = bak;
}
}
} }
#ifdef __ANDROID__ #ifdef __ANDROID__
+1 -1
View File
@@ -59,7 +59,7 @@ const char* ffDetectHost(FFHostResult* host)
ffStrbufAppendF(&host->productName, " - %s", wslDistroName); ffStrbufAppendF(&host->productName, " - %s", wslDistroName);
ffStrbufAppendS(&host->productFamily, "WSL"); ffStrbufAppendS(&host->productFamily, "WSL");
FF_STRBUF_AUTO_DESTROY wslVer = ffStrbufCreate(); //Wide charactors FF_STRBUF_AUTO_DESTROY wslVer = ffStrbufCreate(); //Wide characters
if(!ffProcessAppendStdOut(&wslVer, (char* const[]){ if(!ffProcessAppendStdOut(&wslVer, (char* const[]){
"wsl.exe", "wsl.exe",
"--version", "--version",
+4 -11
View File
@@ -3,7 +3,6 @@
#include "common/io/io.h" #include "common/io/io.h"
#include "util/edidHelper.h" #include "util/edidHelper.h"
#include "util/stringUtils.h" #include "util/stringUtils.h"
#include "util/mallocHelper.h"
#include <dirent.h> #include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
@@ -30,15 +29,9 @@ const char* ffDetectMonitor(FFlist* results)
ffStrbufAppendS(&drmDir, entry->d_name); ffStrbufAppendS(&drmDir, entry->d_name);
ffStrbufAppendS(&drmDir, "/edid"); ffStrbufAppendS(&drmDir, "/edid");
struct stat fileStat; uint8_t edidData[512];
if (stat(drmDir.chars, &fileStat) < 0 || fileStat.st_size == 0 || fileStat.st_size % 128 != 0) ssize_t edidLength = ffReadFileData(drmDir.chars, sizeof(edidData), edidData);
{ if(edidLength <= 0 || edidLength % 128 != 0)
ffStrbufSubstrBefore(&drmDir, drmDirLength);
continue;
}
FF_AUTO_FREE uint8_t* edidData = malloc((size_t) fileStat.st_size);
if(ffReadFileData(drmDir.chars, sizeof(edidData), edidData) != sizeof(edidData))
{ {
ffStrbufSubstrBefore(&drmDir, drmDirLength); ffStrbufSubstrBefore(&drmDir, drmDirLength);
continue; continue;
@@ -54,7 +47,7 @@ const char* ffDetectMonitor(FFlist* results)
ffStrbufInit(&display->name); ffStrbufInit(&display->name);
ffEdidGetName(edidData, &display->name); ffEdidGetName(edidData, &display->name);
ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight); ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight);
display->hdrCompatible = ffEdidGetHdrCompatible(edidData, (uint32_t) fileStat.st_size); display->hdrCompatible = ffEdidGetHdrCompatible(edidData, (uint32_t) edidLength);
} }
ffStrbufSubstrBefore(&drmDir, drmDirLength); ffStrbufSubstrBefore(&drmDir, drmDirLength);
+1 -2
View File
@@ -62,7 +62,6 @@ FF_MAYBE_UNUSED static void detectTTY(FFTerminalFontResult* terminalFont)
#include "common/processing.h" #include "common/processing.h"
#include <stdlib.h> #include <stdlib.h>
#include <yyjson.h>
static const char* detectWTProfile(yyjson_val* profile, FFstrbuf* name, double* size) static const char* detectWTProfile(yyjson_val* profile, FFstrbuf* name, double* size)
{ {
@@ -355,7 +354,7 @@ static bool detectTerminalFontCommon(const FFTerminalShellResult* terminalShell,
#ifndef _WIN32 #ifndef _WIN32
else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalExe, "/dev/pts/")) else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalExe, "/dev/pts/"))
ffStrbufAppendS(&terminalFont->error, "Terminal font detection is not supported on PTS"); ffStrbufAppendS(&terminalFont->error, "Terminal font detection is not supported on PTS");
else if(ffStrbufIgnCaseEqualS(&terminalShell->terminalPrettyName, "kitty")) else if(ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "kitty"))
detectKitty(terminalFont); detectKitty(terminalFont);
else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalExe, "/dev/tty")) else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalExe, "/dev/tty"))
detectTTY(terminalFont); detectTTY(terminalFont);
@@ -375,12 +375,19 @@ const FFTerminalShellResult* ffDetectTerminalShell()
ffStrbufInitS(&result.shellPrettyName, result.shellExeName); ffStrbufInitS(&result.shellPrettyName, result.shellExeName);
} }
if(result.terminalExeName[0] == '.' && ffStrEndsWith(result.terminalExeName, "-wrapper"))
{
// For NixOS. Ref: #510 and https://github.com/NixOS/nixpkgs/pull/249428
// We use terminalProcessName when detecting version and font, overriding it for simplication
ffStrbufSetNS(
&result.terminalProcessName,
(uint32_t) (strlen(result.terminalExeName) - strlen(".-wrapper")),
result.terminalExeName + 1);
}
if(ffStrbufEqualS(&result.terminalProcessName, "wezterm-gui")) if(ffStrbufEqualS(&result.terminalProcessName, "wezterm-gui"))
ffStrbufInitStatic(&result.terminalPrettyName, "WezTerm"); ffStrbufInitStatic(&result.terminalPrettyName, "WezTerm");
else if(ffStrbufEqualS(&result.terminalProcessName, ".kitty-wrapped"))
ffStrbufInitStatic(&result.terminalPrettyName, "kitty"); // #510
#if defined(__linux__) || defined(__FreeBSD__) #if defined(__linux__) || defined(__FreeBSD__)
else if(ffStrbufStartsWithS(&result.terminalProcessName, "gnome-terminal-")) else if(ffStrbufStartsWithS(&result.terminalProcessName, "gnome-terminal-"))
+35
View File
@@ -0,0 +1,35 @@
#include "version.h"
#if defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64)
#define FF_ARCHITECTURE "x86_64"
#elif defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(__i586__) || defined(__i586) || defined(__i686__) || defined(__i686)
#define FF_ARCHITECTURE "i386"
#elif defined(__aarch64__)
#define FF_ARCHITECTURE "aarch64"
#elif defined(__arm__)
#define FF_ARCHITECTURE "arm"
#elif defined(__mips__)
#define FF_ARCHITECTURE "mips"
#elif defined(__powerpc__) || defined(__powerpc)
#define FF_ARCHITECTURE "powerpc"
#elif defined(__riscv__) || defined(__riscv)
#define FF_ARCHITECTURE "riscv"
#elif defined(__s390x__)
#define FF_ARCHITECTURE "s390x"
#else
#define FF_ARCHITECTURE "unknown"
#endif
void ffDetectVersion(FFVersionResult* version)
{
version->projectName = FASTFETCH_PROJECT_NAME;
version->architecture = FF_ARCHITECTURE;
version->version = FASTFETCH_PROJECT_VERSION;
version->versionTweak = FASTFETCH_PROJECT_VERSION_TWEAK;
version->cmakeBuiltType = FASTFETCH_PROJECT_CMAKE_BUILD_TYPE;
#ifndef NDEBUG
version->debugMode = true;
#else
version->debugMode = false;
#endif
}
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#ifndef FF_INCLUDED_detection_version_version
#define FF_INCLUDED_detection_version_version
#include "fastfetch.h"
typedef struct FFVersionResult
{
const char* projectName;
const char* architecture;
const char* version;
const char* versionTweak;
const char* cmakeBuiltType;
bool debugMode;
} FFVersionResult;
void ffDetectVersion(FFVersionResult* version);
#endif
+131 -257
View File
@@ -1,9 +1,11 @@
#include "fastfetch.h" #include "fastfetch.h"
#include "common/commandoption.h"
#include "common/printing.h" #include "common/printing.h"
#include "common/parsing.h" #include "common/parsing.h"
#include "common/io/io.h" #include "common/io/io.h"
#include "common/time.h" #include "common/time.h"
#include "common/jsonconfig.h" #include "common/jsonconfig.h"
#include "detection/version/version.h"
#include "util/stringUtils.h" #include "util/stringUtils.h"
#include "logo/logo.h" #include "logo/logo.h"
#include "fastfetch_datatext.h" #include "fastfetch_datatext.h"
@@ -455,6 +457,17 @@ static inline void printCommandHelp(const char* command)
"second with leading zero" "second with leading zero"
); );
} }
else if(ffStrEqualsIgnCase(command, "version-format"))
{
constructAndPrintCommandHelpFormat("version", "{1} {2}{3} (5)", 6,
"Project name",
"Version",
"Version tweak",
"Build type (debug or release)",
"Architecture",
"CMake build type (Debug, Release, RelWithDebInfo, MinSizeRel)"
);
}
else if(ffStrEqualsIgnCase(command, "vulkan-format")) else if(ffStrEqualsIgnCase(command, "vulkan-format"))
{ {
constructAndPrintCommandHelpFormat("vulkan", "{} (driver), {} (api version)", 3, constructAndPrintCommandHelpFormat("vulkan", "{} (driver), {} (api version)", 3,
@@ -553,6 +566,19 @@ static void listDataPaths(void)
} }
} }
static void listModules()
{
unsigned count = 0;
for (int i = 0; i <= 'Z' - 'A'; ++i)
{
for (FFModuleBaseInfo** modules = ffModuleInfos[i]; *modules; ++modules)
{
++count;
printf("%d)%s%s\n", count, count > 9 ? " " : " ", (*modules)->name);
}
}
}
static void parseOption(FFdata* data, const char* key, const char* value); static void parseOption(FFdata* data, const char* key, const char* value);
static bool parseJsoncFile(const char* path) static bool parseJsoncFile(const char* path)
@@ -563,7 +589,7 @@ static bool parseJsoncFile(const char* path)
{ {
if (error.code != YYJSON_READ_ERROR_FILE_OPEN) if (error.code != YYJSON_READ_ERROR_FILE_OPEN)
{ {
fprintf(stderr, "ERROR: failed to parse JSON config file `%s` at pos %zu: %s\n", path, error.pos, error.msg); fprintf(stderr, "Error: failed to parse JSON config file `%s` at pos %zu: %s\n", path, error.pos, error.msg);
exit(477); exit(477);
} }
return false; return false;
@@ -584,6 +610,7 @@ static bool parseConfigFile(FFdata* data, const char* path)
char* line = NULL; char* line = NULL;
size_t len = 0; size_t len = 0;
ssize_t read; ssize_t read;
FF_STRBUF_AUTO_DESTROY unescaped = ffStrbufCreate();
while ((read = getline(&line, &len, file)) != -1) while ((read = getline(&line, &len, file)) != -1)
{ {
@@ -628,7 +655,42 @@ static bool parseConfigFile(FFdata* data, const char* path)
--lineEnd; --lineEnd;
} }
parseOption(data, lineStart, valueStart); if (strchr(valueStart, '\\'))
{
// Unescape all `\x`s
const char* value = valueStart;
while(*value != '\0')
{
if(*value != '\\')
{
ffStrbufAppendC(&unescaped, *value);
++value;
continue;
}
++value;
switch(*value)
{
case 'n': ffStrbufAppendC(&unescaped, '\n'); break;
case 't': ffStrbufAppendC(&unescaped, '\t'); break;
case 'e': ffStrbufAppendC(&unescaped, '\e'); break;
case '\\': ffStrbufAppendC(&unescaped, '\\'); break;
default:
ffStrbufAppendC(&unescaped, '\\');
ffStrbufAppendC(&unescaped, *value);
break;
}
++value;
}
parseOption(data, lineStart, unescaped.chars);
ffStrbufClear(&unescaped);
}
else
{
parseOption(data, lineStart, valueStart);
}
} }
if(line != NULL) if(line != NULL)
@@ -733,6 +795,13 @@ static inline void optionCheckString(const char* key, const char* value, FFstrbu
ffStrbufEnsureFree(buffer, 63); //This is not needed, as ffStrbufSetS will resize capacity if needed, but giving a higher start should improve performance ffStrbufEnsureFree(buffer, 63); //This is not needed, as ffStrbufSetS will resize capacity if needed, but giving a higher start should improve performance
} }
static void printVersion()
{
FFVersionResult result = {};
ffDetectVersion(&result);
printf("%s %s%s%s (%s)\n", result.projectName, result.version, result.versionTweak, result.debugMode ? "-debug" : "", result.architecture);
}
static void parseOption(FFdata* data, const char* key, const char* value) static void parseOption(FFdata* data, const char* key, const char* value)
{ {
/////////////////////// ///////////////////////
@@ -746,37 +815,7 @@ static void parseOption(FFdata* data, const char* key, const char* value)
} }
else if(ffStrEqualsIgnCase(key, "-v") || ffStrEqualsIgnCase(key, "--version")) else if(ffStrEqualsIgnCase(key, "-v") || ffStrEqualsIgnCase(key, "--version"))
{ {
#ifndef NDEBUG printVersion();
#define FF_BUILD_TYPE "-debug"
#else
#define FF_BUILD_TYPE
#endif
#if defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64)
#define FF_ARCHITECTURE "x86_64"
#elif defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(__i586__) || defined(__i586) || defined(__i686__) || defined(__i686)
#define FF_ARCHITECTURE "i386"
#elif defined(__aarch64__)
#define FF_ARCHITECTURE "aarch64"
#elif defined(__arm__)
#define FF_ARCHITECTURE "arm"
#elif defined(__mips__)
#define FF_ARCHITECTURE "mips"
#elif defined(__powerpc__) || defined(__powerpc)
#define FF_ARCHITECTURE "powerpc"
#elif defined(__riscv__) || defined(__riscv)
#define FF_ARCHITECTURE "riscv"
#elif defined(__s390x__)
#define FF_ARCHITECTURE "s390x"
#else
#define FF_ARCHITECTURE "unknown"
#endif
puts("fastfetch " FASTFETCH_PROJECT_VERSION FASTFETCH_PROJECT_VERSION_TWEAK FF_BUILD_TYPE " (" FF_ARCHITECTURE ")");
#undef FF_ARCHITECTURE
#undef FF_BUILD_TYPE
exit(0); exit(0);
} }
else if(ffStrEqualsIgnCase(key, "--version-raw")) else if(ffStrEqualsIgnCase(key, "--version-raw"))
@@ -815,7 +854,7 @@ static void parseOption(FFdata* data, const char* key, const char* value)
const char* subkey = key + strlen("--list"); const char* subkey = key + strlen("--list");
if(ffStrEqualsIgnCase(subkey, "-modules")) if(ffStrEqualsIgnCase(subkey, "-modules"))
{ {
puts(FASTFETCH_DATATEXT_MODULES); listModules();
exit(0); exit(0);
} }
else if(ffStrEqualsIgnCase(subkey, "-presets")) else if(ffStrEqualsIgnCase(subkey, "-presets"))
@@ -893,8 +932,6 @@ static void parseOption(FFdata* data, const char* key, const char* value)
//General options// //General options//
/////////////////// ///////////////////
else if(ffStrEqualsIgnCase(key, "-r") || ffStrEqualsIgnCase(key, "--recache"))
instance.config.recache = ffOptionParseBoolean(value);
else if(ffStrEqualsIgnCase(key, "--load-config")) else if(ffStrEqualsIgnCase(key, "--load-config"))
optionParseConfigFile(data, key, value); optionParseConfigFile(data, key, value);
else if(ffStrEqualsIgnCase(key, "--gen-config")) else if(ffStrEqualsIgnCase(key, "--gen-config"))
@@ -951,24 +988,32 @@ static void parseOption(FFdata* data, const char* key, const char* value)
ffOptionParseString(key, value, &data->structure); ffOptionParseString(key, value, &data->structure);
else if(ffStrEqualsIgnCase(key, "--separator")) else if(ffStrEqualsIgnCase(key, "--separator"))
ffOptionParseString(key, value, &instance.config.keyValueSeparator); ffOptionParseString(key, value, &instance.config.keyValueSeparator);
else if(ffStrEqualsIgnCase(key, "--color-keys")) else if(ffStrStartsWith(key, "--color"))
{ {
optionCheckString(key, value, &instance.config.colorKeys); const char* subkey = key + strlen("--color");
ffOptionParseColor(value, &instance.config.colorKeys); if(*subkey == '\0')
} {
else if(ffStrEqualsIgnCase(key, "--color-title")) optionCheckString(key, value, &instance.config.colorKeys);
{ ffOptionParseColor(value, &instance.config.colorKeys);
optionCheckString(key, value, &instance.config.colorTitle); ffStrbufSet(&instance.config.colorTitle, &instance.config.colorKeys);
ffOptionParseColor(value, &instance.config.colorTitle); }
else if(ffStrEqualsIgnCase(subkey, "-keys"))
{
optionCheckString(key, value, &instance.config.colorKeys);
ffOptionParseColor(value, &instance.config.colorKeys);
}
else if(ffStrEqualsIgnCase(key, "-title"))
{
optionCheckString(key, value, &instance.config.colorTitle);
ffOptionParseColor(value, &instance.config.colorTitle);
}
else
goto error;
} }
else if(ffStrEqualsIgnCase(key, "--key-width"))
instance.config.keyWidth = ffOptionParseUInt32(key, value);
else if(ffStrEqualsIgnCase(key, "--bright-color")) else if(ffStrEqualsIgnCase(key, "--bright-color"))
instance.config.brightColor = ffOptionParseBoolean(value); instance.config.brightColor = ffOptionParseBoolean(value);
else if(ffStrEqualsIgnCase(key, "-c") || ffStrEqualsIgnCase(key, "--color"))
{
optionCheckString(key, value, &instance.config.colorKeys);
ffOptionParseColor(value, &instance.config.colorKeys);
ffStrbufSet(&instance.config.colorTitle, &instance.config.colorKeys);
}
else if(ffStrEqualsIgnCase(key, "--binary-prefix")) else if(ffStrEqualsIgnCase(key, "--binary-prefix"))
{ {
instance.config.binaryPrefixType = (FFBinaryPrefixType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { instance.config.binaryPrefixType = (FFBinaryPrefixType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
@@ -1011,64 +1056,20 @@ static void parseOption(FFdata* data, const char* key, const char* value)
instance.config.percentType = ffOptionParseUInt32(key, value); instance.config.percentType = ffOptionParseUInt32(key, value);
else if(ffStrEqualsIgnCase(key, "--no-buffer")) else if(ffStrEqualsIgnCase(key, "--no-buffer"))
instance.config.noBuffer = ffOptionParseBoolean(value); instance.config.noBuffer = ffOptionParseBoolean(value);
else if(ffStrStartsWithIgnCase(key, "--bar"))
/////////////////////// {
//Module args options// const char* subkey = key + strlen("--bar");
/////////////////////// if(ffStrEqualsIgnCase(subkey, "-char-elapsed"))
ffOptionParseString(key, value, &instance.config.barCharElapsed);
else if(ffParseOSCommandOptions(&instance.config.os, key, value)) {} else if(ffStrEqualsIgnCase(subkey, "-char-total"))
else if(ffParseHostCommandOptions(&instance.config.host, key, value)) {} ffOptionParseString(key, value, &instance.config.barCharTotal);
else if(ffParseOSCommandOptions(&instance.config.os, key, value)) {} else if(ffStrEqualsIgnCase(subkey, "-width"))
else if(ffParseBiosCommandOptions(&instance.config.bios, key, value)) {} instance.config.barWidth = (uint8_t) ffOptionParseUInt32(key, value);
else if(ffParseBoardCommandOptions(&instance.config.board, key, value)) {} else if(ffStrEqualsIgnCase(subkey, "-border"))
else if(ffParseChassisCommandOptions(&instance.config.chassis, key, value)) {} instance.config.barBorder = ffOptionParseBoolean(value);
else if(ffParseCommandCommandOptions(&instance.config.command, key, value)) {} else
else if(ffParseCustomCommandOptions(&instance.config.custom, key, value)) {} goto error;
else if(ffParseKernelCommandOptions(&instance.config.kernel, key, value)) {} }
else if(ffParseUptimeCommandOptions(&instance.config.uptime, key, value)) {}
else if(ffParseProcessesCommandOptions(&instance.config.processes, key, value)) {}
else if(ffParsePackagesCommandOptions(&instance.config.packages, key, value)) {}
else if(ffParseShellCommandOptions(&instance.config.shell, key, value)) {}
else if(ffParseDisplayCommandOptions(&instance.config.display, key, value)) {}
else if(ffParseBrightnessCommandOptions(&instance.config.brightness, key, value)) {}
else if(ffParseMonitorCommandOptions(&instance.config.nativeResolution, key, value)) {}
else if(ffParseDECommandOptions(&instance.config.de, key, value)) {}
else if(ffParseWifiCommandOptions(&instance.config.wifi, key, value)) {}
else if(ffParseWMCommandOptions(&instance.config.wm, key, value)) {}
else if(ffParseWMThemeCommandOptions(&instance.config.wmTheme, key, value)) {}
else if(ffParseTitleCommandOptions(&instance.config.title, key, value)) {}
else if(ffParseThemeCommandOptions(&instance.config.theme, key, value)) {}
else if(ffParseIconsCommandOptions(&instance.config.icons, key, value)) {}
else if(ffParseWallpaperCommandOptions(&instance.config.wallpaper, key, value)) {}
else if(ffParseFontCommandOptions(&instance.config.font, key, value)) {}
else if(ffParseCursorCommandOptions(&instance.config.cursor, key, value)) {}
else if(ffParseTerminalCommandOptions(&instance.config.terminal, key, value)) {}
else if(ffParseTerminalFontCommandOptions(&instance.config.terminalFont, key, value)) {}
else if(ffParseTerminalSizeCommandOptions(&instance.config.terminalSize, key, value)) {}
else if(ffParseCPUCommandOptions(&instance.config.cpu, key, value)) {}
else if(ffParseCPUUsageCommandOptions(&instance.config.cpuUsage, key, value)) {}
else if(ffParseGPUCommandOptions(&instance.config.gpu, key, value)) {}
else if(ffParseMemoryCommandOptions(&instance.config.memory, key, value)) {}
else if(ffParseSwapCommandOptions(&instance.config.swap, key, value)) {}
else if(ffParseDiskCommandOptions(&instance.config.disk, key, value)) {}
else if(ffParseBatteryCommandOptions(&instance.config.battery, key, value)) {}
else if(ffParsePowerAdapterCommandOptions(&instance.config.powerAdapter, key, value)) {}
else if(ffParseLocaleCommandOptions(&instance.config.locale, key, value)) {}
else if(ffParseLocalIpCommandOptions(&instance.config.localIP, key, value)) {}
else if(ffParsePublicIpCommandOptions(&instance.config.publicIP, key, value)) {}
else if(ffParseWeatherCommandOptions(&instance.config.weather, key, value)) {}
else if(ffParsePlayerCommandOptions(&instance.config.player, key, value)) {}
else if(ffParseMediaCommandOptions(&instance.config.media, key, value)) {}
else if(ffParseDateTimeCommandOptions(&instance.config.dateTime, key, value)) {}
else if(ffParseVulkanCommandOptions(&instance.config.vulkan, key, value)) {}
else if(ffParseOpenGLCommandOptions(&instance.config.openGL, key, value)) {}
else if(ffParseOpenCLCommandOptions(&instance.config.openCL, key, value)) {}
else if(ffParseUsersCommandOptions(&instance.config.users, key, value)) {}
else if(ffParseBluetoothCommandOptions(&instance.config.bluetooth, key, value)) {}
else if(ffParseSeparatorCommandOptions(&instance.config.separator, key, value)) {}
else if(ffParseSoundCommandOptions(&instance.config.sound, key, value)) {}
else if(ffParseGamepadCommandOptions(&instance.config.gamepad, key, value)) {}
else if(ffParseColorsCommandOptions(&instance.config.colors, key, value)) {}
/////////////////// ///////////////////
//Library options// //Library options//
@@ -1129,6 +1130,12 @@ static void parseOption(FFdata* data, const char* key, const char* value)
goto error; goto error;
} }
///////////////////////
//Module args options//
///////////////////////
else if(ffParseModuleOptions(key, value)) {}
////////////////// //////////////////
//Unknown option// //Unknown option//
////////////////// //////////////////
@@ -1175,6 +1182,13 @@ static void parseArguments(FFdata* data, int argc, const char** argv)
for(int i = 1; i < argc; i++) for(int i = 1; i < argc; i++)
{ {
const char* key = argv[i];
if(*key != '-')
{
fprintf(stderr, "Error: invalid option: %s. An option must start with `-`\n", key);
exit(400);
}
if(i == argc - 1 || ( if(i == argc - 1 || (
*argv[i + 1] == '-' && *argv[i + 1] == '-' &&
strcasecmp(argv[i], "--separator-string") != 0 // Separator string can start with a - strcasecmp(argv[i], "--separator-string") != 0 // Separator string can start with a -
@@ -1206,152 +1220,8 @@ static void parseStructureCommand(const char* line, FFlist* customValues)
} }
} }
switch (toupper(line[0])) if(!ffParseModuleCommand(line))
{ ffPrintErrorString(line, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "<no implementation provided>");
case 'B':
if(ffStrEqualsIgnCase(line, FF_BATTERY_MODULE_NAME))
return ffPrintBattery(&instance.config.battery);
if(ffStrEqualsIgnCase(line, FF_BIOS_MODULE_NAME))
return ffPrintBios(&instance.config.bios);
if(ffStrEqualsIgnCase(line, FF_BLUETOOTH_MODULE_NAME))
return ffPrintBluetooth(&instance.config.bluetooth);
if(ffStrEqualsIgnCase(line, FF_BOARD_MODULE_NAME))
return ffPrintBoard(&instance.config.board);
if(ffStrEqualsIgnCase(line, FF_BREAK_MODULE_NAME))
return ffPrintBreak();
if(ffStrEqualsIgnCase(line, FF_BRIGHTNESS_MODULE_NAME))
return ffPrintBrightness(&instance.config.brightness);
break;
case 'C':
if(ffStrEqualsIgnCase(line, FF_CHASSIS_MODULE_NAME))
return ffPrintChassis(&instance.config.chassis);
if(ffStrEqualsIgnCase(line, FF_COMMAND_MODULE_NAME))
return ffPrintCommand(&instance.config.command);
if(ffStrEqualsIgnCase(line, FF_CPU_MODULE_NAME))
return ffPrintCPU(&instance.config.cpu);
if(ffStrEqualsIgnCase(line, FF_CPUUSAGE_MODULE_NAME))
return ffPrintCPUUsage(&instance.config.cpuUsage);
if(ffStrEqualsIgnCase(line, FF_COLORS_MODULE_NAME))
return ffPrintColors(&instance.config.colors);
if(ffStrEqualsIgnCase(line, FF_CURSOR_MODULE_NAME))
return ffPrintCursor(&instance.config.cursor);
if(ffStrEqualsIgnCase(line, FF_CUSTOM_MODULE_NAME))
return ffPrintCustom(&instance.config.custom);
break;
case 'D':
if(ffStrEqualsIgnCase(line, FF_DATETIME_MODULE_NAME))
return ffPrintDateTime(&instance.config.dateTime);
if(ffStrEqualsIgnCase(line, FF_DE_MODULE_NAME))
return ffPrintDE(&instance.config.de);
if(ffStrEqualsIgnCase(line, FF_DISPLAY_MODULE_NAME))
return ffPrintDisplay(&instance.config.display);
if(ffStrEqualsIgnCase(line, FF_DISK_MODULE_NAME))
return ffPrintDisk(&instance.config.disk);
break;
case 'F':
if(ffStrEqualsIgnCase(line, FF_FONT_MODULE_NAME))
return ffPrintFont(&instance.config.font);
break;
case 'G':
if(ffStrEqualsIgnCase(line, FF_GAMEPAD_MODULE_NAME))
return ffPrintGamepad(&instance.config.gamepad);
if(ffStrEqualsIgnCase(line, FF_GPU_MODULE_NAME))
return ffPrintGPU(&instance.config.gpu);
break;
case 'H':
if(ffStrEqualsIgnCase(line, FF_HOST_MODULE_NAME))
return ffPrintHost(&instance.config.host);
break;
case 'I':
if(ffStrEqualsIgnCase(line, FF_ICONS_MODULE_NAME))
return ffPrintIcons(&instance.config.icons);
break;
case 'K':
if(ffStrEqualsIgnCase(line, FF_KERNEL_MODULE_NAME))
return ffPrintKernel(&instance.config.kernel);
break;
case 'L':
if(ffStrEqualsIgnCase(line, FF_LM_MODULE_NAME))
return ffPrintLM(&instance.config.lm);
if(ffStrEqualsIgnCase(line, FF_LOCALE_MODULE_NAME))
return ffPrintLocale(&instance.config.locale);
if(ffStrEqualsIgnCase(line, FF_LOCALIP_MODULE_NAME))
return ffPrintLocalIp(&instance.config.localIP);
break;
case 'M':
if(ffStrEqualsIgnCase(line, FF_MEDIA_MODULE_NAME))
return ffPrintMedia(&instance.config.media);
if(ffStrEqualsIgnCase(line, FF_MEMORY_MODULE_NAME))
return ffPrintMemory(&instance.config.memory);
if(ffStrEqualsIgnCase(line, FF_MONITOR_MODULE_NAME))
return ffPrintMonitor(&instance.config.nativeResolution);
break;
case 'O':
if(ffStrEqualsIgnCase(line, FF_OPENCL_MODULE_NAME))
return ffPrintOpenCL(&instance.config.openCL);
if(ffStrEqualsIgnCase(line, FF_OPENGL_MODULE_NAME))
return ffPrintOpenGL(&instance.config.openGL);
if(ffStrEqualsIgnCase(line, FF_OS_MODULE_NAME))
return ffPrintOS(&instance.config.os);
break;
case 'P':
if(ffStrEqualsIgnCase(line, FF_PACKAGES_MODULE_NAME))
return ffPrintPackages(&instance.config.packages);
if(ffStrEqualsIgnCase(line, FF_PLAYER_MODULE_NAME))
return ffPrintPlayer(&instance.config.player);
if(ffStrEqualsIgnCase(line, FF_POWERADAPTER_MODULE_NAME))
return ffPrintPowerAdapter(&instance.config.powerAdapter);
if(ffStrEqualsIgnCase(line, FF_PROCESSES_MODULE_NAME))
return ffPrintProcesses(&instance.config.processes);
if(ffStrEqualsIgnCase(line, FF_PUBLICIP_MODULE_NAME))
return ffPrintPublicIp(&instance.config.publicIP);
break;
case 'S':
if(ffStrEqualsIgnCase(line, FF_SEPARATOR_MODULE_NAME))
return ffPrintSeparator(&instance.config.separator);
if(ffStrEqualsIgnCase(line, FF_SHELL_MODULE_NAME))
return ffPrintShell(&instance.config.shell);
if(ffStrEqualsIgnCase(line, FF_SOUND_MODULE_NAME))
return ffPrintSound(&instance.config.sound);
if(ffStrEqualsIgnCase(line, FF_SWAP_MODULE_NAME))
return ffPrintSwap(&instance.config.swap);
break;
case 'T':
if(ffStrEqualsIgnCase(line, FF_TERMINAL_MODULE_NAME))
return ffPrintTerminal(&instance.config.terminal);
if(ffStrEqualsIgnCase(line, FF_TERMINALFONT_MODULE_NAME))
return ffPrintTerminalFont(&instance.config.terminalFont);
if(ffStrEqualsIgnCase(line, FF_TERMINALSIZE_MODULE_NAME))
return ffPrintTerminalSize(&instance.config.terminalSize);
if(ffStrEqualsIgnCase(line, FF_TITLE_MODULE_NAME))
return ffPrintTitle(&instance.config.title);
if(ffStrEqualsIgnCase(line, FF_THEME_MODULE_NAME))
return ffPrintTheme(&instance.config.theme);
break;
case 'U':
if(ffStrEqualsIgnCase(line, FF_UPTIME_MODULE_NAME))
return ffPrintUptime(&instance.config.uptime);
if(ffStrEqualsIgnCase(line, FF_USERS_MODULE_NAME))
return ffPrintUsers(&instance.config.users);
break;
case 'V':
if(ffStrEqualsIgnCase(line, FF_VULKAN_MODULE_NAME))
return ffPrintVulkan(&instance.config.vulkan);
break;
case 'W':
if(ffStrEqualsIgnCase(line, FF_WALLPAPER_MODULE_NAME))
return ffPrintWallpaper(&instance.config.wallpaper);
if(ffStrEqualsIgnCase(line, FF_WEATHER_MODULE_NAME))
return ffPrintWeather(&instance.config.weather);
if(ffStrEqualsIgnCase(line, FF_WIFI_MODULE_NAME))
return ffPrintWifi(&instance.config.wifi);
if(ffStrEqualsIgnCase(line, FF_WM_MODULE_NAME))
return ffPrintWM(&instance.config.wm);
if(ffStrEqualsIgnCase(line, FF_WMTHEME_MODULE_NAME))
return ffPrintWMTheme(&instance.config.wmTheme);
break;
}
ffPrintErrorString(line, 0, NULL, NULL, "<no implementation provided>");
} }
int main(int argc, const char** argv) int main(int argc, const char** argv)
@@ -1384,7 +1254,11 @@ int main(int argc, const char** argv)
} }
} }
if(data.structure.length > 0 || !instance.state.configDoc) const bool useJsonConfig = data.structure.length == 0 && instance.state.configDoc;
if(useJsonConfig)
ffPrintJsonConfig(true);
else
{ {
//If we don't have a custom structure, use the default one //If we don't have a custom structure, use the default one
if(data.structure.length == 0) if(data.structure.length == 0)
@@ -1409,9 +1283,9 @@ int main(int argc, const char** argv)
if (!instance.config.noBuffer) fflush(stdout); if (!instance.config.noBuffer) fflush(stdout);
#endif #endif
if (data.structure.length == 0 && instance.state.configDoc) if (useJsonConfig)
{ {
ffPrintJsonConfig(); ffPrintJsonConfig(false);
} }
else else
{ {
+62 -53
View File
@@ -7,7 +7,12 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <yyjson.h>
#ifdef FF_USE_SYSTEM_YYJSON
#include <yyjson.h>
#else
#include "3rdparty/yyjson/yyjson.h"
#endif
#include "util/FFstrbuf.h" #include "util/FFstrbuf.h"
#include "util/FFlist.h" #include "util/FFlist.h"
@@ -44,7 +49,6 @@ typedef struct FFconfig
FFstrbuf keyValueSeparator; FFstrbuf keyValueSeparator;
bool showErrors; bool showErrors;
bool recache;
bool allowSlowOperations; bool allowSlowOperations;
bool disableLinewrap; bool disableLinewrap;
bool hideCursor; bool hideCursor;
@@ -53,11 +57,17 @@ typedef struct FFconfig
uint8_t sizeNdigits; uint8_t sizeNdigits;
uint8_t sizeMaxPrefix; uint8_t sizeMaxPrefix;
FFTemperatureUnit temperatureUnit; FFTemperatureUnit temperatureUnit;
FFstrbuf barCharElapsed;
FFstrbuf barCharTotal;
uint8_t barWidth;
bool barBorder;
uint32_t percentType;
bool pipe; //disables logo and all escape sequences bool pipe; //disables logo and all escape sequences
bool multithreading; bool multithreading;
bool stat; bool stat;
bool noBuffer; bool noBuffer;
int32_t processingTimeout; int32_t processingTimeout;
uint32_t keyWidth;
// Module options that cannot be put in module option structure // Module options that cannot be put in module option structure
#if defined(__linux__) || defined(__FreeBSD__) #if defined(__linux__) || defined(__FreeBSD__)
@@ -68,59 +78,61 @@ typedef struct FFconfig
int32_t wmiTimeout; int32_t wmiTimeout;
#endif #endif
FFTitleOptions title; FFBatteryOptions battery;
FFOSOptions os;
FFHostOptions host;
FFBiosOptions bios; FFBiosOptions bios;
FFBluetoothOptions bluetooth;
FFBoardOptions board; FFBoardOptions board;
FFBreakOptions break_;
FFBrightnessOptions brightness; FFBrightnessOptions brightness;
FFChassisOptions chassis;
FFCommandOptions command;
FFKernelOptions kernel;
FFUptimeOptions uptime;
FFProcessesOptions processes;
FFPackagesOptions packages;
FFShellOptions shell;
FFDisplayOptions display;
FFDEOptions de;
FFWallpaperOptions wallpaper;
FFWifiOptions wifi;
FFWMOptions wm;
FFWMThemeOptions wmTheme;
FFThemeOptions theme;
FFIconsOptions icons;
FFFontOptions font;
FFCursorOptions cursor;
FFTerminalOptions terminal;
FFTerminalFontOptions terminalFont;
FFTerminalSizeOptions terminalSize;
FFCPUOptions cpu; FFCPUOptions cpu;
FFCPUUsageOptions cpuUsage; FFCPUUsageOptions cpuUsage;
FFCustomOptions custom; FFChassisOptions chassis;
FFGPUOptions gpu;
FFMemoryOptions memory;
FFSwapOptions swap;
FFDiskOptions disk;
FFBatteryOptions battery;
FFPowerAdapterOptions powerAdapter;
FFLMOptions lm;
FFLocaleOptions locale;
FFLocalIpOptions localIP;
FFPublicIpOptions publicIP;
FFWeatherOptions weather;
FFPlayerOptions player;
FFMediaOptions media;
FFMonitorOptions nativeResolution;
FFDateTimeOptions dateTime;
FFVulkanOptions vulkan;
FFOpenGLOptions openGL;
FFOpenCLOptions openCL;
FFUsersOptions users;
FFBluetoothOptions bluetooth;
FFSeparatorOptions separator;
FFSoundOptions sound;
FFGamepadOptions gamepad;
FFColorsOptions colors; FFColorsOptions colors;
FFCommandOptions command;
FFCursorOptions cursor;
FFCustomOptions custom;
FFDEOptions de;
FFDateTimeOptions dateTime;
FFDiskOptions disk;
FFDisplayOptions display;
FFFontOptions font;
FFGPUOptions gpu;
FFGamepadOptions gamepad;
FFHostOptions host;
FFIconsOptions icons;
FFKernelOptions kernel;
FFLMOptions lm;
FFLocalIpOptions localIP;
FFLocaleOptions locale;
FFMediaOptions media;
FFMemoryOptions memory;
FFMonitorOptions monitor;
FFOSOptions os;
FFOpenCLOptions openCL;
FFOpenGLOptions openGL;
FFPackagesOptions packages;
FFPlayerOptions player;
FFPowerAdapterOptions powerAdapter;
FFProcessesOptions processes;
FFPublicIpOptions publicIP;
FFSeparatorOptions separator;
FFShellOptions shell;
FFSoundOptions sound;
FFSwapOptions swap;
FFTerminalFontOptions terminalFont;
FFTerminalOptions terminal;
FFTerminalSizeOptions terminalSize;
FFThemeOptions theme;
FFTitleOptions title;
FFUptimeOptions uptime;
FFUsersOptions users;
FFVersionOptions version;
FFVulkanOptions vulkan;
FFWMOptions wm;
FFWMThemeOptions wmTheme;
FFWallpaperOptions wallpaper;
FFWeatherOptions weather;
FFWifiOptions wifi;
FFstrbuf libPCI; FFstrbuf libPCI;
FFstrbuf libVulkan; FFstrbuf libVulkan;
@@ -146,10 +158,6 @@ typedef struct FFconfig
FFstrbuf libPulse; FFstrbuf libPulse;
FFstrbuf libnm; FFstrbuf libnm;
FFstrbuf libDdcutil; FFstrbuf libDdcutil;
uint32_t percentType;
bool jsonConfig;
} FFconfig; } FFconfig;
typedef struct FFstate typedef struct FFstate
@@ -168,6 +176,7 @@ typedef struct FFinstance
FFstate state; FFstate state;
} FFinstance; } FFinstance;
extern FFinstance instance; // Defined in `common/init.c` extern FFinstance instance; // Defined in `common/init.c`
extern FFModuleBaseInfo** ffModuleInfos[];
////////////////////// //////////////////////
// Init functions // // Init functions //
+1
View File
@@ -10,6 +10,7 @@
#define FASTFETCH_PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@ #define FASTFETCH_PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@
#define FASTFETCH_PROJECT_VERSION_TWEAK "@PROJECT_VERSION_TWEAK@" #define FASTFETCH_PROJECT_VERSION_TWEAK "@PROJECT_VERSION_TWEAK@"
#define FASTFETCH_PROJECT_VERSION_TWEAK_NUM @PROJECT_VERSION_TWEAK_NUM@ #define FASTFETCH_PROJECT_VERSION_TWEAK_NUM @PROJECT_VERSION_TWEAK_NUM@
#define FASTFETCH_PROJECT_CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@"
#define FASTFETCH_PROJECT_HOMEPAGE_URL "@PROJECT_HOMEPAGE_URL@" #define FASTFETCH_PROJECT_HOMEPAGE_URL "@PROJECT_HOMEPAGE_URL@"
#define FASTFETCH_PROJECT_DESCRIPTION "@PROJECT_DESCRIPTION@" #define FASTFETCH_PROJECT_DESCRIPTION "@PROJECT_DESCRIPTION@"
#define FASTFETCH_PROJECT_LICENSE "@PROJECT_LICENSE@" #define FASTFETCH_PROJECT_LICENSE "@PROJECT_LICENSE@"
-1
View File
@@ -7,7 +7,6 @@
#define FASTFETCH_DATATEXT_CONFIG_SYSTEM "@DATATEXT_CONFIG_SYSTEM@" #define FASTFETCH_DATATEXT_CONFIG_SYSTEM "@DATATEXT_CONFIG_SYSTEM@"
#define FASTFETCH_DATATEXT_CONFIG_USER "@DATATEXT_CONFIG_USER@" //Requires FASTFETCH_PROJECT_VERSION and FASTFETCH_DATATEXT_STRUCTURE to be set #define FASTFETCH_DATATEXT_CONFIG_USER "@DATATEXT_CONFIG_USER@" //Requires FASTFETCH_PROJECT_VERSION and FASTFETCH_DATATEXT_STRUCTURE to be set
#define FASTFETCH_DATATEXT_CONFIG_USER_JSONC "@DATATEXT_CONFIG_USER_JSONC@" #define FASTFETCH_DATATEXT_CONFIG_USER_JSONC "@DATATEXT_CONFIG_USER_JSONC@"
#define FASTFETCH_DATATEXT_MODULES "@DATATEXT_MODULES@"
#define FASTFETCH_DATATEXT_HELP "@DATATEXT_HELP@" #define FASTFETCH_DATATEXT_HELP "@DATATEXT_HELP@"
#define FASTFETCH_DATATEXT_HELP_COLOR "@DATATEXT_HELP_COLOR@" #define FASTFETCH_DATATEXT_HELP_COLOR "@DATATEXT_HELP_COLOR@"
#define FASTFETCH_DATATEXT_HELP_FORMAT "@DATATEXT_HELP_FORMAT@" #define FASTFETCH_DATATEXT_HELP_FORMAT "@DATATEXT_HELP_FORMAT@"
+1 -1
View File
@@ -62,7 +62,7 @@ int main(void)
//ffPrintBluetooth(&instance.config.bluetooth); //ffPrintBluetooth(&instance.config.bluetooth);
//ffPrintSound(&instance.config.sound); //ffPrintSound(&instance.config.sound);
//ffPrintGamepad(&instance.config.gamepad); //ffPrintGamepad(&instance.config.gamepad);
ffPrintBreak(); ffPrintBreak(&instance.config.break_);
ffPrintColors(&instance.config.colors); ffPrintColors(&instance.config.colors);
ffFinish(); ffFinish();
+21
View File
@@ -0,0 +1,21 @@
ooo OOO OOO ooo
oOO OOo
oOO OOo
oOO OOo
oOO OOo
oOO OOo
oOO OOo
OOo
OOo
OOo
OOo
OOo
OOo
oOO OOo
oOO OOo
oOO OOo
oOO OOo
oO OOo
oOO OOo
oOO OOo
ooo OOO OOO ooo
+18
View File
@@ -0,0 +1,18 @@
:--==========================--:
.-=================================.
-==================================-
====================================
=======-....:==========:....:=======
=======: -======-. .=======
=======: :====- .=======
=======: :==: .=======
=======: .. .=======
=======: .: .: .=======
=======: .=- :=: .=======
=======: .===. .-==: .=======
=======: .==========: .=======
=======: :==========: :=======
====================================
-===================================
.==================================:
:--===========================-:.
+19 -15
View File
@@ -1,15 +1,19 @@
::::::: ::::::: `-`
mMMMMMMm dMMMMMMm -yys+/-`
/MMMMMMMo +MMMMMMM/ `oyyyyy: /osyyyyso+:.
yMMMMMMN mMMMMMMy /yyyyy+`+yyyyyyyyyys/.
NMMMMMMs oMMMMMMm .-yyyyys.:+//+oyyyyyyyo.
+MMMMMMN: NMMMMMM+ `oy/`oyyyyy/ ./syyyyy:
hMMMMMMy sMMMMMMy syyys`:yyyyyo` :yyyyy:
:NMMMMMM::NMMMMMN: /yyyyo .syyyyy- .yyyyy.
oMMMMMMyyMMMMMM+ yyyyy. +yyyyy/ /yyyy/
dMMMMMMMMMMMMh `yyyyy :yyyyys` -yyyyo
/MMMMMMMMMMMN: yyyyy. `syyyyy- /yyyy/
sMMMMMMMMMMo /yyyyo /yyyyy+ .yyyyy.
mMMMMMMMMd syyyys. -yyyyys.:yyyy:
+MMMMMMMN: `oyyyyyo-` `oyyyyy:.sy:
:::::: :syyyyyyso+/++`/yyyyyo``
-oyyyyyyyyyyy-.syyyys.
-/+osyyyyso.`+yyyyy/
.-/+syo`
`.
+11
View File
@@ -0,0 +1,11 @@
++**
*===**====+*
*====* +===+
*==*+===* *===*
*===* *===+ *===*
*===* +===+ *===*
*===* +===* *===*
*===* *===+*==*
+===+ *===+=*
*+====**===*
**++
+28
View File
@@ -13,6 +13,15 @@ const FFlogo ffLogoUnknown = {
}; };
static const FFlogo A[] = { static const FFlogo A[] = {
// AerOS
{
.names = {"aerOS"},
.lines = FASTFETCH_DATATEXT_LOGO_AEROS,
.colors = {
FF_COLOR_FG_CYAN,
FF_COLOR_FG_CYAN,
},
},
// AIX // AIX
{ {
.names = {"aix"}, .names = {"aix"},
@@ -2332,6 +2341,15 @@ static const FFlogo M[] = {
.colorKeys = FF_COLOR_FG_256 "29", .colorKeys = FF_COLOR_FG_256 "29",
.colorTitle = FF_COLOR_FG_WHITE, .colorTitle = FF_COLOR_FG_WHITE,
}, },
// MOS
{
.names = {"MOS"},
.lines = FASTFETCH_DATATEXT_LOGO_MOS,
.colors = {
FF_COLOR_FG_CYAN,
FF_COLOR_FG_BLUE,
},
},
// Msys2 // Msys2
{ {
.names = {"Msys2"}, .names = {"Msys2"},
@@ -3899,6 +3917,16 @@ static const FFlogo V[] = {
FF_COLOR_FG_BLUE, FF_COLOR_FG_BLUE,
}, },
}, },
// VenomSmall
{
.names = {"Venom_small"},
.type = FF_LOGO_LINE_TYPE_SMALL_BIT,
.lines = FASTFETCH_DATATEXT_LOGO_VENOM_SMALL,
.colors = {
FF_COLOR_FG_LIGHT_BLACK,
FF_COLOR_FG_BLUE,
},
},
// Vnux // Vnux
{ {
.names = {"Vnux"}, .names = {"Vnux"},
+1 -1
View File
@@ -698,7 +698,7 @@ static bool printImageIfExistsSlowPath(FFLogoType type, bool printError)
ffStrbufAppendF(&requestData.cacheDir, "%u", requestData.logoPixelHeight); ffStrbufAppendF(&requestData.cacheDir, "%u", requestData.logoPixelHeight);
ffStrbufAppendC(&requestData.cacheDir, '/'); ffStrbufAppendC(&requestData.cacheDir, '/');
if(!instance.config.recache && printCached(&requestData)) if(!instance.config.logo.recache && printCached(&requestData))
{ {
ffStrbufDestroy(&requestData.cacheDir); ffStrbufDestroy(&requestData.cacheDir);
return true; return true;
+8
View File
@@ -16,6 +16,7 @@ void ffInitLogoOptions(FFLogoOptions* options)
options->paddingRight = 4; options->paddingRight = 4;
options->printRemaining = true; options->printRemaining = true;
options->preserveAspectRadio = false; options->preserveAspectRadio = false;
options->recache = false;
options->chafaFgOnly = false; options->chafaFgOnly = false;
ffStrbufInitStatic(&options->chafaSymbols, "block+border+space-wide-inverted"); // Chafa default ffStrbufInitStatic(&options->chafaSymbols, "block+border+space-wide-inverted"); // Chafa default
@@ -113,6 +114,8 @@ logoType:
options->printRemaining = ffOptionParseBoolean(value); options->printRemaining = ffOptionParseBoolean(value);
else if(strcasecmp(subKey, "preserve-aspect-radio") == 0) else if(strcasecmp(subKey, "preserve-aspect-radio") == 0)
options->preserveAspectRadio = ffOptionParseBoolean(value); options->preserveAspectRadio = ffOptionParseBoolean(value);
else if(strcasecmp(subKey, "recache") == 0)
options->recache = ffOptionParseBoolean(value);
else else
return false; return false;
} }
@@ -334,6 +337,11 @@ const char* ffParseLogoJsonConfig(void)
options->preserveAspectRadio = yyjson_get_bool(val); options->preserveAspectRadio = yyjson_get_bool(val);
continue; continue;
} }
else if (strcasecmp(key, "recache") == 0)
{
options->recache = yyjson_get_bool(val);
continue;
}
else if (strcasecmp(key, "chafa") == 0) else if (strcasecmp(key, "chafa") == 0)
{ {
if (!yyjson_is_obj(val)) if (!yyjson_is_obj(val))
+1
View File
@@ -35,6 +35,7 @@ typedef struct FFLogoOptions
uint32_t paddingRight; uint32_t paddingRight;
bool printRemaining; bool printRemaining;
bool preserveAspectRadio; bool preserveAspectRadio;
bool recache;
bool chafaFgOnly; bool chafaFgOnly;
FFstrbuf chafaSymbols; FFstrbuf chafaSymbols;
+30 -38
View File
@@ -12,7 +12,7 @@ static void printBattery(FFBatteryOptions* options, BatteryResult* result, uint8
{ {
if(instance.config.battery.moduleArgs.outputFormat.length == 0) if(instance.config.battery.moduleArgs.outputFormat.length == 0)
{ {
ffPrintLogoAndKey(FF_BATTERY_MODULE_NAME, index, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(FF_BATTERY_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
bool showStatus = bool showStatus =
!(instance.config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT) && !(instance.config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT) &&
@@ -26,11 +26,11 @@ static void printBattery(FFBatteryOptions* options, BatteryResult* result, uint8
if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{ {
if(result->capacity <= 20) if(result->capacity <= 20)
ffAppendPercentBar(&str, (uint8_t)result->capacity, 10, 10, 0); ffAppendPercentBar(&str, result->capacity, 100, 100, 0);
else if(result->capacity <= 50) else if(result->capacity <= 50)
ffAppendPercentBar(&str, (uint8_t)result->capacity, 10, 0, 10); ffAppendPercentBar(&str, result->capacity, 100, 0, 100);
else else
ffAppendPercentBar(&str, (uint8_t)result->capacity, 0, 10, 10); ffAppendPercentBar(&str, result->capacity, 0, 100, 100);
} }
if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
@@ -38,7 +38,7 @@ static void printBattery(FFBatteryOptions* options, BatteryResult* result, uint8
if(str.length > 0) if(str.length > 0)
ffStrbufAppendC(&str, ' '); ffStrbufAppendC(&str, ' ');
ffAppendPercentNum(&str, (uint8_t) result->capacity, 51, 21, str.length > 0); ffAppendPercentNum(&str, result->capacity, 51, 21, str.length > 0);
} }
} }
@@ -105,7 +105,7 @@ void ffPrintBattery(FFBatteryOptions* options)
void ffInitBatteryOptions(FFBatteryOptions* options) void ffInitBatteryOptions(FFBatteryOptions* options)
{ {
options->moduleName = FF_BATTERY_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BATTERY_MODULE_NAME, ffParseBatteryCommandOptions, ffParseBatteryJsonObject, ffPrintBattery);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
options->temp = false; options->temp = false;
@@ -147,41 +147,33 @@ void ffDestroyBatteryOptions(FFBatteryOptions* options)
#endif #endif
} }
void ffParseBatteryJsonObject(yyjson_val* module) void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module)
{ {
FFBatteryOptions __attribute__((__cleanup__(ffDestroyBatteryOptions))) options; yyjson_val *key_, *val;
ffInitBatteryOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
#ifdef __linux__
if (ffStrEqualsIgnCase(key, "dir"))
{ {
const char* key = yyjson_get_str(key_); ffStrbufSetS(&options->dir, yyjson_get_str(val));
if(ffStrEqualsIgnCase(key, "type")) continue;
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
#ifdef __linux__
if (ffStrEqualsIgnCase(key, "dir"))
{
ffStrbufSetS(&options.dir, yyjson_get_str(val));
continue;
}
#endif
if (ffStrEqualsIgnCase(key, "temp"))
{
options.temp = yyjson_get_bool(val);
continue;
}
ffPrintError(FF_BATTERY_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
} }
} #endif
ffPrintBattery(&options); if (ffStrEqualsIgnCase(key, "temp"))
{
options->temp = yyjson_get_bool(val);
continue;
}
ffPrintError(FF_BATTERY_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
+1 -1
View File
@@ -9,4 +9,4 @@ void ffPrintBattery(FFBatteryOptions* options);
void ffInitBatteryOptions(FFBatteryOptions* options); void ffInitBatteryOptions(FFBatteryOptions* options);
bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, const char* value); bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, const char* value);
void ffDestroyBatteryOptions(FFBatteryOptions* options); void ffDestroyBatteryOptions(FFBatteryOptions* options);
void ffParseBatteryJsonObject(yyjson_val* module); void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,7 +6,7 @@
typedef struct FFBatteryOptions typedef struct FFBatteryOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
bool temp; bool temp;
+12 -20
View File
@@ -30,7 +30,7 @@ void ffPrintBios(FFBiosOptions* options)
if(options->moduleArgs.outputFormat.length == 0) if(options->moduleArgs.outputFormat.length == 0)
{ {
ffPrintLogoAndKey(FF_BIOS_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(FF_BIOS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&bios.version, stdout); ffStrbufWriteTo(&bios.version, stdout);
if (bios.release.length) if (bios.release.length)
printf(" (%s)", bios.release.chars); printf(" (%s)", bios.release.chars);
@@ -55,7 +55,7 @@ exit:
void ffInitBiosOptions(FFBiosOptions* options) void ffInitBiosOptions(FFBiosOptions* options)
{ {
options->moduleName = FF_BIOS_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BIOS_MODULE_NAME, ffParseBiosCommandOptions, ffParseBiosJsonObject, ffPrintBios);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
} }
@@ -74,27 +74,19 @@ void ffDestroyBiosOptions(FFBiosOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseBiosJsonObject(yyjson_val* module) void ffParseBiosJsonObject(FFBiosOptions* options, yyjson_val* module)
{ {
FFBiosOptions __attribute__((__cleanup__(ffDestroyBiosOptions))) options; yyjson_val *key_, *val;
ffInitBiosOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue; continue;
ffPrintError(FF_BIOS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); ffPrintError(FF_BIOS_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
ffPrintBios(&options);
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintBios(FFBiosOptions* options);
void ffInitBiosOptions(FFBiosOptions* options); void ffInitBiosOptions(FFBiosOptions* options);
bool ffParseBiosCommandOptions(FFBiosOptions* options, const char* key, const char* value); bool ffParseBiosCommandOptions(FFBiosOptions* options, const char* key, const char* value);
void ffDestroyBiosOptions(FFBiosOptions* options); void ffDestroyBiosOptions(FFBiosOptions* options);
void ffParseBiosJsonObject(yyjson_val* module); void ffParseBiosJsonObject(FFBiosOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,6 +6,6 @@
typedef struct FFBiosOptions typedef struct FFBiosOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
} FFBiosOptions; } FFBiosOptions;
+18 -26
View File
@@ -10,7 +10,7 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothDevice* de
{ {
if(options->moduleArgs.outputFormat.length == 0) if(options->moduleArgs.outputFormat.length == 0)
{ {
ffPrintLogoAndKey(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&device->name, stdout); ffStrbufWriteTo(&device->name, stdout);
if(device->battery > 0) if(device->battery > 0)
@@ -75,7 +75,7 @@ void ffPrintBluetooth(FFBluetoothOptions* options)
void ffInitBluetoothOptions(FFBluetoothOptions* options) void ffInitBluetoothOptions(FFBluetoothOptions* options)
{ {
options->moduleName = FF_BLUETOOTH_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BLUETOOTH_MODULE_NAME, ffParseBluetoothCommandOptions, ffParseBluetoothJsonObject, ffPrintBluetooth);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
options->showDisconnected = false; options->showDisconnected = false;
} }
@@ -101,33 +101,25 @@ void ffDestroyBluetoothOptions(FFBluetoothOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseBluetoothJsonObject(yyjson_val* module) void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module)
{ {
FFBluetoothOptions __attribute__((__cleanup__(ffDestroyBluetoothOptions))) options; yyjson_val *key_, *val;
ffInitBluetoothOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "showDisconnected"))
{ {
const char* key = yyjson_get_str(key_); options->showDisconnected = yyjson_get_bool(val);
if(ffStrEqualsIgnCase(key, "type")) continue;
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "showDisconnected"))
{
options.showDisconnected = yyjson_get_bool(val);
continue;
}
ffPrintError(FF_BLUETOOTH_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
} }
}
ffPrintBluetooth(&options); ffPrintError(FF_BLUETOOTH_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintBluetooth(FFBluetoothOptions* options);
void ffInitBluetoothOptions(FFBluetoothOptions* options); void ffInitBluetoothOptions(FFBluetoothOptions* options);
bool ffParseBluetoothCommandOptions(FFBluetoothOptions* options, const char* key, const char* value); bool ffParseBluetoothCommandOptions(FFBluetoothOptions* options, const char* key, const char* value);
void ffDestroyBluetoothOptions(FFBluetoothOptions* options); void ffDestroyBluetoothOptions(FFBluetoothOptions* options);
void ffParseBluetoothJsonObject(yyjson_val* module); void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,7 +6,7 @@
typedef struct FFBluetoothOptions typedef struct FFBluetoothOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
bool showDisconnected; bool showDisconnected;
+12 -20
View File
@@ -28,7 +28,7 @@ void ffPrintBoard(FFBoardOptions* options)
if(options->moduleArgs.outputFormat.length == 0) if(options->moduleArgs.outputFormat.length == 0)
{ {
ffPrintLogoAndKey(FF_BOARD_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(FF_BOARD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&result.name, stdout); ffStrbufWriteTo(&result.name, stdout);
if (result.version.length) if (result.version.length)
printf(" (%s)", result.version.chars); printf(" (%s)", result.version.chars);
@@ -51,7 +51,7 @@ exit:
void ffInitBoardOptions(FFBoardOptions* options) void ffInitBoardOptions(FFBoardOptions* options)
{ {
options->moduleName = FF_BOARD_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BOARD_MODULE_NAME, ffParseBoardCommandOptions, ffParseBoardJsonObject, ffPrintBoard);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
} }
@@ -70,27 +70,19 @@ void ffDestroyBoardOptions(FFBoardOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseBoardJsonObject(yyjson_val* module) void ffParseBoardJsonObject(FFBoardOptions* options, yyjson_val* module)
{ {
FFBoardOptions __attribute__((__cleanup__(ffDestroyBoardOptions))) options; yyjson_val *key_, *val;
ffInitBoardOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue; continue;
ffPrintError(FF_BOARD_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); ffPrintError(FF_BOARD_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
ffPrintBoard(&options);
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintBoard(FFBoardOptions* options);
void ffInitBoardOptions(FFBoardOptions* options); void ffInitBoardOptions(FFBoardOptions* options);
bool ffParseBoardCommandOptions(FFBoardOptions* options, const char* key, const char* value); bool ffParseBoardCommandOptions(FFBoardOptions* options, const char* key, const char* value);
void ffDestroyBoardOptions(FFBoardOptions* options); void ffDestroyBoardOptions(FFBoardOptions* options);
void ffParseBoardJsonObject(yyjson_val* module); void ffParseBoardJsonObject(FFBoardOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,6 +6,6 @@
typedef struct FFBoardOptions typedef struct FFBoardOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
} FFBoardOptions; } FFBoardOptions;
+18 -3
View File
@@ -1,13 +1,28 @@
#include "common/printing.h" #include "common/printing.h"
#include "modules/break/break.h" #include "modules/break/break.h"
void ffPrintBreak(void) void ffPrintBreak(FF_MAYBE_UNUSED FFBreakOptions* options)
{ {
ffLogoPrintLine(); ffLogoPrintLine();
putchar('\n'); putchar('\n');
} }
void ffParseBreakJsonObject(FF_MAYBE_UNUSED yyjson_val* module) void ffInitBreakOptions(FF_MAYBE_UNUSED FFBreakOptions* options)
{ {
return ffPrintBreak(); ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BREAK_MODULE_NAME, ffParseBreakCommandOptions, ffParseBreakJsonObject, ffPrintBreak);
}
bool ffParseBreakCommandOptions(FF_MAYBE_UNUSED FFBreakOptions* options, FF_MAYBE_UNUSED const char* key, FF_MAYBE_UNUSED const char* value)
{
return false;
}
void ffDestroyBreakOptions(FF_MAYBE_UNUSED FFBreakOptions* options)
{
}
void ffParseBreakJsonObject(FF_MAYBE_UNUSED FFBreakOptions* options, FF_MAYBE_UNUSED yyjson_val* module)
{
ffPrintBreak(options);
return;
} }
+5 -2
View File
@@ -4,5 +4,8 @@
#define FF_BREAK_MODULE_NAME "Break" #define FF_BREAK_MODULE_NAME "Break"
void ffPrintBreak(); void ffPrintBreak(FFBreakOptions* options);
void ffParseBreakJsonObject(yyjson_val* module); void ffInitBreakOptions(FFBreakOptions* options);
bool ffParseBreakCommandOptions(FFBreakOptions* options, const char* key, const char* value);
void ffDestroyBreakOptions(FFBreakOptions* options);
void ffParseBreakJsonObject(FFBreakOptions* options, yyjson_val* module);
+10
View File
@@ -0,0 +1,10 @@
#pragma once
// This file will be included in "fastfetch.h", do NOT put unnecessary things here
#include "common/option.h"
typedef struct FFBreakOptions
{
FFModuleBaseInfo moduleInfo;
} FFBreakOptions;
+20 -24
View File
@@ -27,6 +27,7 @@ void ffPrintBrightness(FFBrightnessOptions* options)
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
uint32_t index = 0;
FF_LIST_FOR_EACH(FFBrightnessResult, item, result) FF_LIST_FOR_EACH(FFBrightnessResult, item, result)
{ {
if(options->moduleArgs.key.length == 0) if(options->moduleArgs.key.length == 0)
@@ -35,7 +36,9 @@ void ffPrintBrightness(FFBrightnessOptions* options)
} }
else else
{ {
ffParseFormatString(&key, &options->moduleArgs.key, 1, (FFformatarg[]){ uint32_t moduleIndex = result.length == 1 ? 0 : index + 1;
ffParseFormatString(&key, &options->moduleArgs.key, 2, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT, &moduleIndex},
{FF_FORMAT_ARG_TYPE_STRBUF, &item->name} {FF_FORMAT_ARG_TYPE_STRBUF, &item->name}
}); });
} }
@@ -44,11 +47,11 @@ void ffPrintBrightness(FFBrightnessOptions* options)
if(options->moduleArgs.outputFormat.length == 0) if(options->moduleArgs.outputFormat.length == 0)
{ {
ffPrintLogoAndKey(key.chars, 0, NULL, &options->moduleArgs.keyColor); ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
if (instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) if (instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{ {
ffAppendPercentBar(&str, (uint8_t) (item->value + 0.5), 0, 10, 10); ffAppendPercentBar(&str, item->value, 0, 100, 100);
} }
if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
@@ -56,14 +59,14 @@ void ffPrintBrightness(FFBrightnessOptions* options)
if(str.length > 0) if(str.length > 0)
ffStrbufAppendC(&str, ' '); ffStrbufAppendC(&str, ' ');
ffAppendPercentNum(&str, (uint8_t) (item->value + 0.5), 10, 10, str.length > 0); ffAppendPercentNum(&str, item->value, 10, 10, str.length > 0);
} }
ffStrbufPutTo(&str, stdout); ffStrbufPutTo(&str, stdout);
} }
else else
{ {
ffPrintFormatString(key.chars, 0, NULL, &options->moduleArgs.keyColor, &options->moduleArgs.outputFormat, FF_BRIGHTNESS_NUM_FORMAT_ARGS, (FFformatarg[]) { ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_BRIGHTNESS_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_FLOAT, &item->value}, {FF_FORMAT_ARG_TYPE_FLOAT, &item->value},
{FF_FORMAT_ARG_TYPE_STRBUF, &item->name}, {FF_FORMAT_ARG_TYPE_STRBUF, &item->name},
}); });
@@ -71,12 +74,13 @@ void ffPrintBrightness(FFBrightnessOptions* options)
ffStrbufClear(&key); ffStrbufClear(&key);
ffStrbufDestroy(&item->name); ffStrbufDestroy(&item->name);
++index;
} }
} }
void ffInitBrightnessOptions(FFBrightnessOptions* options) void ffInitBrightnessOptions(FFBrightnessOptions* options)
{ {
options->moduleName = FF_BRIGHTNESS_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BRIGHTNESS_MODULE_NAME, ffParseBrightnessCommandOptions, ffParseBrightnessJsonObject, ffPrintBrightness);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
} }
@@ -95,27 +99,19 @@ void ffDestroyBrightnessOptions(FFBrightnessOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseBrightnessJsonObject(yyjson_val* module) void ffParseBrightnessJsonObject(FFBrightnessOptions* options, yyjson_val* module)
{ {
FFBrightnessOptions __attribute__((__cleanup__(ffDestroyBrightnessOptions))) options; yyjson_val *key_, *val;
ffInitBrightnessOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue; continue;
ffPrintError(FF_BRIGHTNESS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); ffPrintError(FF_BRIGHTNESS_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
ffPrintBrightness(&options);
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintBrightness(FFBrightnessOptions* options);
void ffInitBrightnessOptions(FFBrightnessOptions* options); void ffInitBrightnessOptions(FFBrightnessOptions* options);
bool ffParseBrightnessCommandOptions(FFBrightnessOptions* options, const char* key, const char* value); bool ffParseBrightnessCommandOptions(FFBrightnessOptions* options, const char* key, const char* value);
void ffDestroyBrightnessOptions(FFBrightnessOptions* options); void ffDestroyBrightnessOptions(FFBrightnessOptions* options);
void ffParseBrightnessJsonObject(yyjson_val* module); void ffParseBrightnessJsonObject(FFBrightnessOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,6 +6,6 @@
typedef struct FFBrightnessOptions typedef struct FFBrightnessOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
} FFBrightnessOptions; } FFBrightnessOptions;
+12 -20
View File
@@ -29,7 +29,7 @@ void ffPrintChassis(FFChassisOptions* options)
if(options->moduleArgs.outputFormat.length == 0) if(options->moduleArgs.outputFormat.length == 0)
{ {
ffPrintLogoAndKey(FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&result.type, stdout); ffStrbufWriteTo(&result.type, stdout);
if (result.version.length) if (result.version.length)
printf(" (%s)", result.version.chars); printf(" (%s)", result.version.chars);
@@ -52,7 +52,7 @@ exit:
void ffInitChassisOptions(FFChassisOptions* options) void ffInitChassisOptions(FFChassisOptions* options)
{ {
options->moduleName = FF_CHASSIS_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CHASSIS_MODULE_NAME, ffParseChassisCommandOptions, ffParseChassisJsonObject, ffPrintChassis);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
} }
@@ -71,27 +71,19 @@ void ffDestroyChassisOptions(FFChassisOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseChassisJsonObject(yyjson_val* module) void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module)
{ {
FFChassisOptions __attribute__((__cleanup__(ffDestroyChassisOptions))) options; yyjson_val *key_, *val;
ffInitChassisOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue; continue;
ffPrintError(FF_CHASSIS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); ffPrintError(FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
ffPrintChassis(&options);
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintChassis(FFChassisOptions* options);
void ffInitChassisOptions(FFChassisOptions* options); void ffInitChassisOptions(FFChassisOptions* options);
bool ffParseChassisCommandOptions(FFChassisOptions* options, const char* key, const char* value); bool ffParseChassisCommandOptions(FFChassisOptions* options, const char* key, const char* value);
void ffDestroyChassisOptions(FFChassisOptions* options); void ffDestroyChassisOptions(FFChassisOptions* options);
void ffParseChassisJsonObject(yyjson_val* module); void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,6 +6,6 @@
typedef struct FFChassisOptions typedef struct FFChassisOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
} FFChassisOptions; } FFChassisOptions;
+33 -41
View File
@@ -57,7 +57,7 @@ void ffPrintColors(FFColorsOptions* options)
void ffInitColorsOptions(FFColorsOptions* options) void ffInitColorsOptions(FFColorsOptions* options)
{ {
options->moduleName = FF_COLORS_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COLORS_MODULE_NAME, ffParseColorsCommandOptions, ffParseColorsJsonObject, ffPrintColors);
options->symbol = FF_COLORS_SYMBOL_BLOCK; options->symbol = FF_COLORS_SYMBOL_BLOCK;
options->paddingLeft = 0; options->paddingLeft = 0;
} }
@@ -94,49 +94,41 @@ void ffDestroyColorsOptions(FF_MAYBE_UNUSED FFColorsOptions* options)
{ {
} }
void ffParseColorsJsonObject(yyjson_val* module) void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module)
{ {
FFColorsOptions __attribute__((__cleanup__(ffDestroyColorsOptions))) options; yyjson_val *key_, *val;
ffInitColorsOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
if (ffStrEqualsIgnCase(key, "symbol"))
{ {
const char* key = yyjson_get_str(key_); int value;
if(ffStrEqualsIgnCase(key, "type")) const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
continue; { "block", FF_COLORS_SYMBOL_BLOCK },
{ "circle", FF_COLORS_SYMBOL_CIRCLE },
if (ffStrEqualsIgnCase(key, "symbol")) { "diamond", FF_COLORS_SYMBOL_DIAMOND },
{ { "triangle", FF_COLORS_SYMBOL_TRIANGLE },
int value; { "square", FF_COLORS_SYMBOL_SQUARE },
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { { "star", FF_COLORS_SYMBOL_STAR },
{ "block", FF_COLORS_SYMBOL_BLOCK }, {},
{ "circle", FF_COLORS_SYMBOL_CIRCLE }, });
{ "diamond", FF_COLORS_SYMBOL_DIAMOND }, if (error)
{ "triangle", FF_COLORS_SYMBOL_TRIANGLE }, ffPrintErrorString(FF_COLORS_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Invalid %s value: %s", key, error);
{ "square", FF_COLORS_SYMBOL_SQUARE }, else
{ "star", FF_COLORS_SYMBOL_STAR }, options->symbol = (FFColorsSymbol) value;
{}, continue;
});
if (error)
ffPrintErrorString(FF_COLORS_MODULE_NAME, 0, NULL, NULL, "Invalid %s value: %s", key, error);
else
options.symbol = (FFColorsSymbol) value;
continue;
}
if (ffStrEqualsIgnCase(key, "paddingLeft"))
{
options.paddingLeft = (uint32_t) yyjson_get_uint(val);
continue;
}
ffPrintErrorString(FF_COLORS_MODULE_NAME, 0, NULL, NULL, "Unknown JSON key %s", key);
} }
}
ffPrintColors(&options); if (ffStrEqualsIgnCase(key, "paddingLeft"))
{
options->paddingLeft = (uint32_t) yyjson_get_uint(val);
continue;
}
ffPrintErrorString(FF_COLORS_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Unknown JSON key %s", key);
}
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintColors(FFColorsOptions* options);
void ffInitColorsOptions(FFColorsOptions* options); void ffInitColorsOptions(FFColorsOptions* options);
void ffDestroyColorsOptions(FFColorsOptions* options); void ffDestroyColorsOptions(FFColorsOptions* options);
bool ffParseColorsCommandOptions(FFColorsOptions* options, const char* key, const char* value); bool ffParseColorsCommandOptions(FFColorsOptions* options, const char* key, const char* value);
void ffParseColorsJsonObject(yyjson_val* module); void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module);
+1 -1
View File
@@ -16,7 +16,7 @@ typedef enum FFColorsSymbol
typedef struct FFColorsOptions typedef struct FFColorsOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFColorsSymbol symbol; FFColorsSymbol symbol;
uint32_t paddingLeft; uint32_t paddingLeft;
} FFColorsOptions; } FFColorsOptions;
+24 -32
View File
@@ -30,13 +30,13 @@ void ffPrintCommand(FFCommandOptions* options)
return; return;
} }
ffPrintLogoAndKey(FF_COMMAND_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(FF_COMMAND_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufPutTo(&result, stdout); ffStrbufPutTo(&result, stdout);
} }
void ffInitCommandOptions(FFCommandOptions* options) void ffInitCommandOptions(FFCommandOptions* options)
{ {
options->moduleName = FF_COMMAND_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COMMAND_MODULE_NAME, ffParseCommandCommandOptions, ffParseCommandJsonObject, ffPrintCommand);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
ffStrbufInitStatic(&options->shell, ffStrbufInitStatic(&options->shell,
@@ -79,39 +79,31 @@ void ffDestroyCommandOptions(FFCommandOptions* options)
ffStrbufDestroy(&options->text); ffStrbufDestroy(&options->text);
} }
void ffParseCommandJsonObject(yyjson_val* module) void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module)
{ {
FFCommandOptions __attribute__((__cleanup__(ffDestroyCommandOptions))) options; yyjson_val *key_, *val;
ffInitCommandOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "shell"))
{ {
const char* key = yyjson_get_str(key_); ffStrbufSetS(&options->shell, yyjson_get_str(val));
if(ffStrEqualsIgnCase(key, "type")) continue;
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "shell"))
{
ffStrbufSetS(&options.shell, yyjson_get_str(val));
continue;
}
if (ffStrEqualsIgnCase(key, "text"))
{
ffStrbufSetS(&options.text, yyjson_get_str(val));
continue;
}
ffPrintError(FF_COMMAND_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
} }
}
ffPrintCommand(&options); if (ffStrEqualsIgnCase(key, "text"))
{
ffStrbufSetS(&options->text, yyjson_get_str(val));
continue;
}
ffPrintError(FF_COMMAND_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintCommand(FFCommandOptions* options);
void ffInitCommandOptions(FFCommandOptions* options); void ffInitCommandOptions(FFCommandOptions* options);
bool ffParseCommandCommandOptions(FFCommandOptions* options, const char* key, const char* value); bool ffParseCommandCommandOptions(FFCommandOptions* options, const char* key, const char* value);
void ffDestroyCommandOptions(FFCommandOptions* options); void ffDestroyCommandOptions(FFCommandOptions* options);
void ffParseCommandJsonObject(yyjson_val* module); void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,7 +6,7 @@
typedef struct FFCommandOptions typedef struct FFCommandOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
FFstrbuf shell; FFstrbuf shell;
+18 -26
View File
@@ -30,7 +30,7 @@ void ffPrintCPU(FFCPUOptions* options)
{ {
if(options->moduleArgs.outputFormat.length == 0) if(options->moduleArgs.outputFormat.length == 0)
{ {
ffPrintLogoAndKey(FF_CPU_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
@@ -79,7 +79,7 @@ void ffPrintCPU(FFCPUOptions* options)
void ffInitCPUOptions(FFCPUOptions* options) void ffInitCPUOptions(FFCPUOptions* options)
{ {
options->moduleName = FF_CPU_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPU_MODULE_NAME, ffParseCPUCommandOptions, ffParseCPUJsonObject, ffPrintCPU);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
options->temp = false; options->temp = false;
} }
@@ -105,33 +105,25 @@ void ffDestroyCPUOptions(FFCPUOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseCPUJsonObject(yyjson_val* module) void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module)
{ {
FFCPUOptions __attribute__((__cleanup__(ffDestroyCPUOptions))) options; yyjson_val *key_, *val;
ffInitCPUOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "temp"))
{ {
const char* key = yyjson_get_str(key_); options->temp = yyjson_get_bool(val);
if(ffStrEqualsIgnCase(key, "type")) continue;
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "temp"))
{
options.temp = yyjson_get_bool(val);
continue;
}
ffPrintError(FF_CPU_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
} }
}
ffPrintCPU(&options); ffPrintError(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintCPU(FFCPUOptions* options);
void ffInitCPUOptions(FFCPUOptions* options); void ffInitCPUOptions(FFCPUOptions* options);
bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char* value); bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char* value);
void ffDestroyCPUOptions(FFCPUOptions* options); void ffDestroyCPUOptions(FFCPUOptions* options);
void ffParseCPUJsonObject(yyjson_val* module); void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,7 +6,7 @@
typedef struct FFCPUOptions typedef struct FFCPUOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
bool temp; bool temp;
+14 -22
View File
@@ -21,16 +21,16 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
if(options->moduleArgs.outputFormat.length == 0) if(options->moduleArgs.outputFormat.length == 0)
{ {
ffPrintLogoAndKey(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
ffAppendPercentBar(&str, (uint8_t)percentage, 0, 5, 8); ffAppendPercentBar(&str, percentage, 0, 50, 80);
if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
{ {
if(str.length > 0) if(str.length > 0)
ffStrbufAppendC(&str, ' '); ffStrbufAppendC(&str, ' ');
ffAppendPercentNum(&str, (uint8_t) percentage, 50, 80, str.length > 0); ffAppendPercentNum(&str, percentage, 50, 80, str.length > 0);
} }
ffStrbufPutTo(&str, stdout); ffStrbufPutTo(&str, stdout);
} }
@@ -44,7 +44,7 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
void ffInitCPUUsageOptions(FFCPUUsageOptions* options) void ffInitCPUUsageOptions(FFCPUUsageOptions* options)
{ {
options->moduleName = FF_CPUUSAGE_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPUUSAGE_MODULE_NAME, ffParseCPUUsageCommandOptions, ffParseCPUUsageJsonObject, ffPrintCPUUsage);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
} }
@@ -63,27 +63,19 @@ void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseCPUUsageJsonObject(yyjson_val* module) void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module)
{ {
FFCPUUsageOptions __attribute__((__cleanup__(ffDestroyCPUUsageOptions))) options; yyjson_val *key_, *val;
ffInitCPUUsageOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue; continue;
ffPrintError(FF_CPUUSAGE_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); ffPrintError(FF_CPUUSAGE_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
ffPrintCPUUsage(&options);
} }
+1 -1
View File
@@ -10,4 +10,4 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options);
void ffInitCPUUsageOptions(FFCPUUsageOptions* options); void ffInitCPUUsageOptions(FFCPUUsageOptions* options);
bool ffParseCPUUsageCommandOptions(FFCPUUsageOptions* options, const char* key, const char* value); bool ffParseCPUUsageCommandOptions(FFCPUUsageOptions* options, const char* key, const char* value);
void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options); void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options);
void ffParseCPUUsageJsonObject(yyjson_val* module); void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,6 +6,6 @@
typedef struct FFCPUUsageOptions typedef struct FFCPUUsageOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
} FFCPUUsageOptions; } FFCPUUsageOptions;
+12 -20
View File
@@ -28,7 +28,7 @@ void ffPrintCursor(FFCursorOptions* options)
if(options->moduleArgs.outputFormat.length == 0) if(options->moduleArgs.outputFormat.length == 0)
{ {
ffPrintLogoAndKey(FF_CURSOR_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(FF_CURSOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&result.theme, stdout); ffStrbufWriteTo(&result.theme, stdout);
if(result.size.length > 0) if(result.size.length > 0)
@@ -52,7 +52,7 @@ void ffPrintCursor(FFCursorOptions* options)
void ffInitCursorOptions(FFCursorOptions* options) void ffInitCursorOptions(FFCursorOptions* options)
{ {
options->moduleName = FF_CURSOR_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CURSOR_MODULE_NAME, ffParseCursorCommandOptions, ffParseCursorJsonObject, ffPrintCursor);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
} }
@@ -71,27 +71,19 @@ void ffDestroyCursorOptions(FFCursorOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseCursorJsonObject(yyjson_val* module) void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module)
{ {
FFCursorOptions __attribute__((__cleanup__(ffDestroyCursorOptions))) options; yyjson_val *key_, *val;
ffInitCursorOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue; continue;
ffPrintError(FF_CURSOR_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); ffPrintError(FF_CURSOR_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
ffPrintCursor(&options);
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintCursor(FFCursorOptions* options);
void ffInitCursorOptions(FFCursorOptions* options); void ffInitCursorOptions(FFCursorOptions* options);
bool ffParseCursorCommandOptions(FFCursorOptions* options, const char* key, const char* value); bool ffParseCursorCommandOptions(FFCursorOptions* options, const char* key, const char* value);
void ffDestroyCursorOptions(FFCursorOptions* options); void ffDestroyCursorOptions(FFCursorOptions* options);
void ffParseCursorJsonObject(yyjson_val* module); void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,6 +6,6 @@
typedef struct FFCursorOptions typedef struct FFCursorOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
} FFCursorOptions; } FFCursorOptions;
+13 -21
View File
@@ -12,14 +12,14 @@ void ffPrintCustom(FFCustomOptions* options)
return; return;
} }
ffPrintLogoAndKey(options->moduleArgs.key.length == 0 ? NULL : FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(options->moduleArgs.key.length == 0 ? NULL : FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffPrintUserString(options->moduleArgs.outputFormat.chars); ffStrbufWriteTo(&options->moduleArgs.outputFormat, stdout);
puts(FASTFETCH_TEXT_MODIFIER_RESET); puts(FASTFETCH_TEXT_MODIFIER_RESET);
} }
void ffInitCustomOptions(FFCustomOptions* options) void ffInitCustomOptions(FFCustomOptions* options)
{ {
options->moduleName = FF_CUSTOM_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CUSTOM_MODULE_NAME, ffParseCustomCommandOptions, ffParseCustomJsonObject, ffPrintCustom);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
} }
@@ -38,27 +38,19 @@ void ffDestroyCustomOptions(FFCustomOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseCustomJsonObject(yyjson_val* module) void ffParseCustomJsonObject(FFCustomOptions* options, yyjson_val* module)
{ {
FFCustomOptions __attribute__((__cleanup__(ffDestroyCustomOptions))) options; yyjson_val *key_, *val;
ffInitCustomOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue; continue;
ffPrintError(FF_CUSTOM_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); ffPrintError(FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
ffPrintCustom(&options);
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintCustom(FFCustomOptions* options);
void ffInitCustomOptions(FFCustomOptions* options); void ffInitCustomOptions(FFCustomOptions* options);
bool ffParseCustomCommandOptions(FFCustomOptions* options, const char* key, const char* value); bool ffParseCustomCommandOptions(FFCustomOptions* options, const char* key, const char* value);
void ffDestroyCustomOptions(FFCustomOptions* options); void ffDestroyCustomOptions(FFCustomOptions* options);
void ffParseCustomJsonObject(yyjson_val* module); void ffParseCustomJsonObject(FFCustomOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,6 +6,6 @@
typedef struct FFCustomOptions typedef struct FFCustomOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
} FFCustomOptions; } FFCustomOptions;
+12 -20
View File
@@ -43,7 +43,7 @@ void ffPrintDateTime(FFDateTimeOptions* options)
} }
const FFDateTimeResult* datetime = ffDetectDateTime(); const FFDateTimeResult* datetime = ffDetectDateTime();
ffPrintLogoAndKey(FF_DATETIME_DISPLAY_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(FF_DATETIME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
//yyyy-MM-dd HH:mm:ss //yyyy-MM-dd HH:mm:ss
printf("%u-%s-%02u %s:%s:%s\n", datetime->year, datetime->monthPretty.chars, datetime->dayInMonth, datetime->hourPretty.chars, datetime->minutePretty.chars, datetime->secondPretty.chars); printf("%u-%s-%02u %s:%s:%s\n", datetime->year, datetime->monthPretty.chars, datetime->dayInMonth, datetime->hourPretty.chars, datetime->minutePretty.chars, datetime->secondPretty.chars);
@@ -51,7 +51,7 @@ void ffPrintDateTime(FFDateTimeOptions* options)
void ffInitDateTimeOptions(FFDateTimeOptions* options) void ffInitDateTimeOptions(FFDateTimeOptions* options)
{ {
options->moduleName = FF_DATETIME_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DATETIME_MODULE_NAME, ffParseDateTimeCommandOptions, ffParseDateTimeJsonObject, ffPrintDateTime);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
} }
@@ -70,27 +70,19 @@ void ffDestroyDateTimeOptions(FFDateTimeOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseDateTimeJsonObject(yyjson_val* module) void ffParseDateTimeJsonObject(FFDateTimeOptions* options, yyjson_val* module)
{ {
FFDateTimeOptions __attribute__((__cleanup__(ffDestroyDateTimeOptions))) options; yyjson_val *key_, *val;
ffInitDateTimeOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue; continue;
ffPrintError(FF_DATETIME_DISPLAY_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); ffPrintError(FF_DATETIME_DISPLAY_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
ffPrintDateTime(&options);
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintDateTime(FFDateTimeOptions* options);
void ffInitDateTimeOptions(FFDateTimeOptions* options); void ffInitDateTimeOptions(FFDateTimeOptions* options);
bool ffParseDateTimeCommandOptions(FFDateTimeOptions* options, const char* key, const char* value); bool ffParseDateTimeCommandOptions(FFDateTimeOptions* options, const char* key, const char* value);
void ffDestroyDateTimeOptions(FFDateTimeOptions* options); void ffDestroyDateTimeOptions(FFDateTimeOptions* options);
void ffParseDateTimeJsonObject(yyjson_val* module); void ffParseDateTimeJsonObject(FFDateTimeOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,6 +6,6 @@
typedef struct FFDateTimeOptions typedef struct FFDateTimeOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
} FFDateTimeOptions; } FFDateTimeOptions;
+12 -20
View File
@@ -18,7 +18,7 @@ void ffPrintDE(FFDEOptions* options)
if(options->moduleArgs.outputFormat.length == 0) if(options->moduleArgs.outputFormat.length == 0)
{ {
ffPrintLogoAndKey(FF_DE_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor); ffPrintLogoAndKey(FF_DE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&result->dePrettyName, stdout); ffStrbufWriteTo(&result->dePrettyName, stdout);
@@ -42,7 +42,7 @@ void ffPrintDE(FFDEOptions* options)
void ffInitDEOptions(FFDEOptions* options) void ffInitDEOptions(FFDEOptions* options)
{ {
options->moduleName = FF_DE_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DE_MODULE_NAME, ffParseDECommandOptions, ffParseDEJsonObject, ffPrintDE);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
} }
@@ -61,27 +61,19 @@ void ffDestroyDEOptions(FFDEOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseDEJsonObject(yyjson_val* module) void ffParseDEJsonObject(FFDEOptions* options, yyjson_val* module)
{ {
FFDEOptions __attribute__((__cleanup__(ffDestroyDEOptions))) options; yyjson_val *key_, *val;
ffInitDEOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue; continue;
ffPrintError(FF_DE_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); ffPrintError(FF_DE_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
ffPrintDE(&options);
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintDE(FFDEOptions* options);
void ffInitDEOptions(FFDEOptions* options); void ffInitDEOptions(FFDEOptions* options);
bool ffParseDECommandOptions(FFDEOptions* options, const char* key, const char* value); bool ffParseDECommandOptions(FFDEOptions* options, const char* key, const char* value);
void ffDestroyDEOptions(FFDEOptions* options); void ffDestroyDEOptions(FFDEOptions* options);
void ffParseDEJsonObject(yyjson_val* module); void ffParseDEJsonObject(FFDEOptions* options, yyjson_val* module);
+1 -1
View File
@@ -6,6 +6,6 @@
typedef struct FFDEOptions typedef struct FFDEOptions
{ {
const char* moduleName; FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs; FFModuleArgs moduleArgs;
} FFDEOptions; } FFDEOptions;
+61 -69
View File
@@ -34,8 +34,9 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
} }
else else
{ {
ffParseFormatString(&key, &options->moduleArgs.key, 1, (FFformatarg[]){ ffParseFormatString(&key, &options->moduleArgs.key, 2, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->mountpoint} {FF_FORMAT_ARG_TYPE_STRBUF, &disk->mountpoint},
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->name},
}); });
} }
@@ -45,11 +46,11 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
FF_STRBUF_AUTO_DESTROY totalPretty = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY totalPretty = ffStrbufCreate();
ffParseSize(disk->bytesTotal, &totalPretty); ffParseSize(disk->bytesTotal, &totalPretty);
uint8_t bytesPercentage = disk->bytesTotal > 0 ? (uint8_t) (((long double) disk->bytesUsed / (long double) disk->bytesTotal) * 100.0) : 0; double bytesPercentage = disk->bytesTotal > 0 ? (double) disk->bytesUsed / (double) disk->bytesTotal * 100.0 : 0;
if(options->moduleArgs.outputFormat.length == 0) if(options->moduleArgs.outputFormat.length == 0)
{ {
ffPrintLogoAndKey(key.chars, 0, NULL, &options->moduleArgs.keyColor); ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY);
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
@@ -57,7 +58,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
{ {
if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{ {
ffAppendPercentBar(&str, bytesPercentage, 0, 5, 8); ffAppendPercentBar(&str, bytesPercentage, 0, 50, 80);
ffStrbufAppendC(&str, ' '); ffStrbufAppendC(&str, ' ');
} }
@@ -66,7 +67,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
{ {
ffAppendPercentNum(&str, (uint8_t) bytesPercentage, 50, 80, str.length > 0); ffAppendPercentNum(&str, bytesPercentage, 50, 80, str.length > 0);
ffStrbufAppendC(&str, ' '); ffStrbufAppendC(&str, ' ');
} }
} }
@@ -95,7 +96,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
bool isExternal = !!(disk->type & FF_DISK_TYPE_EXTERNAL_BIT); bool isExternal = !!(disk->type & FF_DISK_TYPE_EXTERNAL_BIT);
bool isHidden = !!(disk->type & FF_DISK_TYPE_HIDDEN_BIT); bool isHidden = !!(disk->type & FF_DISK_TYPE_HIDDEN_BIT);
ffPrintFormatString(key.chars, 0, NULL, &options->moduleArgs.keyColor, &options->moduleArgs.outputFormat, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){ ffPrintFormatString(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, &usedPretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
{FF_FORMAT_ARG_TYPE_UINT8, &bytesPercentage}, {FF_FORMAT_ARG_TYPE_UINT8, &bytesPercentage},
@@ -183,10 +184,9 @@ void ffPrintDisk(FFDiskOptions* options)
} }
} }
void ffInitDiskOptions(FFDiskOptions* options) void ffInitDiskOptions(FFDiskOptions* options)
{ {
options->moduleName = FF_DISK_MODULE_NAME; ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISK_MODULE_NAME, ffParseDiskCommandOptions, ffParseDiskJsonObject, ffPrintDisk);
ffOptionInitModuleArg(&options->moduleArgs); ffOptionInitModuleArg(&options->moduleArgs);
ffStrbufInit(&options->folders); ffStrbufInit(&options->folders);
@@ -259,69 +259,61 @@ void ffDestroyDiskOptions(FFDiskOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs); ffOptionDestroyModuleArg(&options->moduleArgs);
} }
void ffParseDiskJsonObject(yyjson_val* module) void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
{ {
FFDiskOptions __attribute__((__cleanup__(ffDestroyDiskOptions))) options; yyjson_val *key_, *val;
ffInitDiskOptions(&options); size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
if (module)
{ {
yyjson_val *key_, *val; const char* key = yyjson_get_str(key_);
size_t idx, max; if(ffStrEqualsIgnCase(key, "type"))
yyjson_obj_foreach(module, idx, max, key_, val) continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "folders"))
{ {
const char* key = yyjson_get_str(key_); ffStrbufSetS(&options->folders, yyjson_get_str(val));
if(ffStrEqualsIgnCase(key, "type")) continue;
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "folders"))
{
ffStrbufSetS(&options.folders, yyjson_get_str(val));
continue;
}
if (ffStrEqualsIgnCase(key, "showExternal"))
{
if (yyjson_get_bool(val))
options.showTypes |= FF_DISK_TYPE_EXTERNAL_BIT;
else
options.showTypes &= ~FF_DISK_TYPE_EXTERNAL_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "showHidden"))
{
if (yyjson_get_bool(val))
options.showTypes |= FF_DISK_TYPE_HIDDEN_BIT;
else
options.showTypes &= ~FF_DISK_TYPE_HIDDEN_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "showSubvolumes"))
{
if (yyjson_get_bool(val))
options.showTypes |= FF_DISK_TYPE_SUBVOLUME_BIT;
else
options.showTypes &= ~FF_DISK_TYPE_SUBVOLUME_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "showUnknown"))
{
if (yyjson_get_bool(val))
options.showTypes |= FF_DISK_TYPE_UNKNOWN_BIT;
else
options.showTypes &= ~FF_DISK_TYPE_UNKNOWN_BIT;
continue;
}
ffPrintError(FF_DISK_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
} }
}
ffPrintDisk(&options); if (ffStrEqualsIgnCase(key, "showExternal"))
{
if (yyjson_get_bool(val))
options->showTypes |= FF_DISK_TYPE_EXTERNAL_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_EXTERNAL_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "showHidden"))
{
if (yyjson_get_bool(val))
options->showTypes |= FF_DISK_TYPE_HIDDEN_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_HIDDEN_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "showSubvolumes"))
{
if (yyjson_get_bool(val))
options->showTypes |= FF_DISK_TYPE_SUBVOLUME_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_SUBVOLUME_BIT;
continue;
}
if (ffStrEqualsIgnCase(key, "showUnknown"))
{
if (yyjson_get_bool(val))
options->showTypes |= FF_DISK_TYPE_UNKNOWN_BIT;
else
options->showTypes &= ~FF_DISK_TYPE_UNKNOWN_BIT;
continue;
}
ffPrintError(FF_DISK_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
} }
+1 -1
View File
@@ -8,4 +8,4 @@ void ffPrintDisk(FFDiskOptions* options);
void ffInitDiskOptions(FFDiskOptions* options); void ffInitDiskOptions(FFDiskOptions* options);
bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const char* value); bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const char* value);
void ffDestroyDiskOptions(FFDiskOptions* options); void ffDestroyDiskOptions(FFDiskOptions* options);
void ffParseDiskJsonObject(yyjson_val* module); void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module);

Some files were not shown because too many files have changed in this diff Show More