Compare commits

..

46 Commits

Author SHA1 Message Date
Carter Li eea4150dbd Merge pull request #532 from fastfetch-cli/dev
Release v2.0.2
2023-08-22 05:26:33 -04:00
李通洲 afa736c37d Release v2.0.2 2023-08-22 16:17:05 +08:00
李通洲 643e632368 CMake: try fixing CI on FreeBSD 2023-08-22 16:14:24 +08:00
Carter Li ffe354ab07 Merge pull request #531 from fastfetch-cli/dev
Release v2.0.2
2023-08-22 03:57:27 -04:00
李通洲 f77090070c Image: code cleanup; no functional change 2023-08-22 15:32:19 +08:00
李通洲 fd5d2c84e8 Logo (Builtin): add Tuxedo OS 2023-08-21 22:46:50 +08:00
李通洲 ef6af84ea1 Fastfetch: fix presets not detected by file name (#529) 2023-08-21 22:14:44 +08:00
李通洲 f64bf73279 Windows: fix compiling for GCC 2023-08-21 20:28:27 +08:00
Carter Li 157be8443d Merge pull request #526 from fastfetch-cli/dev
Release v2.0.1 (stable)
2023-08-20 22:35:09 -04:00
李通洲 154e15e88f Release: v2.0.1 2023-08-21 10:05:41 +08:00
李通洲 159122eb98 Brightness (macOS): silence compiler warnings 2023-08-21 09:38:20 +08:00
李通洲 7b6e157a4d Doc: update bug_report.md 2023-08-21 09:26:07 +08:00
李通洲 c6eff111cc Fastfetch: refactor printVersion() 2023-08-21 09:22:03 +08:00
李通洲 f23384725f Version: add new module 2023-08-21 09:19:16 +08:00
李通洲 970863e7df Global: simplify code of module matching 2023-08-20 21:35:38 +08:00
李通洲 0b473e3bff Fastfetch: refactor the code of --list-modules 2023-08-20 20:51:55 +08:00
李通洲 5a43adb62b Doc: update changelog 2023-08-20 00:09:48 +08:00
李通洲 1a4a949dfe Logo (Builtin): add aerOS 2023-08-20 00:04:52 +08:00
李通洲 069c20be40 Brightness: don't make DDC/CI a slow operation 2023-08-19 02:16:04 -04:00
李通洲 c7f0172b25 CMake: Add option ENABLE_SYSTEM_YYJSON
Fix: #525
2023-08-19 11:11:50 +08:00
李通洲 125759dc75 Terminal: correctly detecting version and font on NixOS 2023-08-19 10:02:07 +08:00
李通洲 f0a10fcc6d Disk (BSD): improve disk type detection 2023-08-18 20:57:54 +08:00
李通洲 c70b9cb84e Revert "Disk (BSD): try detecting disk label"
Doesn't work

This reverts commit 55b9e274b6.
2023-08-18 21:21:34 +08:00
李通洲 5ebdd9a989 Logo (Builtin): add MOS
Ref: https://github.com/dylanaraps/neofetch/pull/2364
2023-08-18 13:44:48 +08:00
李通洲 77e0d9dba1 JsonConfig: prepare for module weather and public ip 2023-08-18 13:38:32 +08:00
李通洲 55b9e274b6 Disk (BSD): try detecting disk label 2023-08-18 09:52:21 +08:00
李通洲 67fe1e66b5 Windows: fix build 2023-08-17 17:15:30 +08:00
李通洲 ea2a26bd57 Battery (Linux): fix build 2023-08-17 16:13:54 +08:00
李通洲 55b279ab09 JsonConfig: remove useless checks 2023-08-17 16:10:05 +08:00
李通洲 e5e4c8bf88 Fastfetch: refactor command line option parsing code
1. improve performance
2. remove `-c`
3. rename `--recache` to `--logo-recache`, and remove `-r`
2023-08-17 16:10:05 +08:00
李通洲 c888254f70 Modules: major code refactor
Also fix some bugs found when refactoring
2023-08-17 16:10:02 +08:00
李通洲 75323d64f8 Chore: fix typo 2023-08-16 16:51:54 +08:00
李通洲 a0c4f2febd Global: support --bar-width 2023-08-16 16:51:41 +08:00
李通洲 4b714c7057 Doc: update changelog 2023-08-16 14:52:20 +08:00
李通洲 559bca4223 Global: add --bar-char-elapsed, --bar-char-total and --bar-border options 2023-08-16 14:41:56 +08:00
李通洲 8ed28673a9 Global: support --module-key-width per module 2023-08-16 13:21:15 +08:00
李通洲 ed9639c66b Disk (Linux): replace all \\x20 to real charactors in disk label 2023-08-15 21:11:52 +08:00
李通洲 98b9ef74cf Disk (Linux): fix label detection 2023-08-15 21:11:52 +08:00
李通洲 e6be90614a fastfetch: support --key-width 2023-08-15 21:11:52 +08:00
李通洲 20c2cdf7ba Monitor (Linux): fix EDID file reading
Its file length is always 0
2023-08-15 19:20:21 +08:00
李通洲 c70787bde9 Fastfetch: tidy 2023-08-15 16:52:35 +08:00
李通洲 8835f66b8c Fastfetch: unescape strings only when parsing .conf files
So that `NO_CONFIG=1 ./fastfetch --os-key \\\\ -s os -l none` prints `\\: *`
2023-08-15 16:41:04 +08:00
李通洲 2b2ebe0823 Logo (Builtin): update venom; add venom_small 2023-08-15 15:24:31 +08:00
李通洲 3ff3feb0e1 EdidHelper: silence compiler warnings 2023-08-14 20:48:37 +08:00
李通洲 ee4bc2302a Chore: move mk_wcwidch to 3rdparty folder 2023-08-14 20:48:37 +08:00
李通洲 cd4a512291 Chore: embed yyjson source code
Ref: https://github.com/fastfetch-cli/fastfetch/discussions/523
2023-08-14 20:48:37 +08:00
224 changed files with 19673 additions and 2461 deletions
+1 -6
View File
@@ -19,11 +19,6 @@ assignees: ''
# Often helpful information:
Output of `fastfetch --version`:
```
//paste here
```
The content of the configuration file you use (if any)
```
//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.
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`.
-->
```
+34 -2
View File
@@ -1,4 +1,36 @@
# 2.0.0 (beta)
# 2.0.2
Bugfixes:
* Workarund [a compiler bug of GCC](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85282) (Windows)
* Fix presets not detected by file name (#529)
Logo:
* Add Tuxedo OS
# 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.
@@ -32,7 +64,7 @@ Features:
* Support iTerm non-ascii font detection (Terminal, macOS)
* Add option `--title-color-user`, `--title-color-at` and `--title-color-host` (Title)
* 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`
* Better CPU and Host detection for Android (Android)
* Support yakuake terminal version & font detection (Terminal, Linux)
+26 -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
VERSION 2.0.0
VERSION 2.0.2
LANGUAGES C
DESCRIPTION "Fast system information tool"
HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
@@ -36,24 +36,6 @@ endif()
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 #
#####################
@@ -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_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_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(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_user.txt DATATEXT_CONFIG_USER)
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_color.txt DATATEXT_HELP_COLOR)
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
src/common/bar.c
src/common/commandoption.c
src/common/font.c
src/common/format.c
src/common/init.c
src/common/jsonconfig.c
src/common/library.c
src/common/modules.c
src/common/option.c
src/common/parsing.c
src/common/printing.c
@@ -295,6 +279,7 @@ set(LIBFASTFETCH_SRC
src/detection/packages/packages.c
src/detection/terminalfont/terminalfont.c
src/detection/terminalshell/terminalshell.c
src/detection/version/version.c
src/detection/vulkan/vulkan.c
src/logo/builtin.c
src/logo/image/im6.c
@@ -350,6 +335,7 @@ set(LIBFASTFETCH_SRC
src/modules/title/title.c
src/modules/uptime/uptime.c
src/modules/users/users.c
src/modules/version/version.c
src/modules/vulkan/vulkan.c
src/modules/wallpaper/wallpaper.c
src/modules/weather/weather.c
@@ -618,12 +604,29 @@ endif()
include(CheckFunctionExists)
check_function_exists(wcwidth 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()
add_library(libfastfetch OBJECT
${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)
if(WIN32)
@@ -822,6 +825,7 @@ elseif(WIN32)
)
elseif(BSD)
target_link_libraries(libfastfetch
PRIVATE "m"
PRIVATE "usbhid"
)
elseif(ANDROID)
@@ -847,7 +851,6 @@ target_include_directories(libfastfetch
target_link_libraries(libfastfetch
PRIVATE ${CMAKE_DL_LIBS}
PRIVATE yyjson
)
######################
@@ -862,7 +865,6 @@ target_compile_definitions(fastfetch
)
target_link_libraries(fastfetch
PRIVATE libfastfetch
PRIVATE yyjson
)
add_executable(flashfetch
@@ -873,7 +875,6 @@ target_compile_definitions(flashfetch
)
target_link_libraries(flashfetch
PRIVATE libfastfetch
PRIVATE yyjson
)
if(WIN32)
+3 -3
View File
@@ -96,14 +96,14 @@ All categories not listed here should work without needing a specific implementa
##### 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
<!-- `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)).filter(x => x != 'LAST').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, 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, TuxedoOS, 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
+96
View File
@@ -17,6 +17,12 @@
"title": "Color of the module key. Left empty to use `display.color.keys`",
"$ref": "#/$defs/colors"
},
"keyWidth": {
"title": "Width of the module key. Use 0 to use `display.keyWidth`",
"type": "integer",
"minimum": 0,
"default": 0
},
"format": {
"title": "Output format of the module",
"type": "string"
@@ -155,6 +161,11 @@
"title": "Whether to preserve the aspect ratio of the logo. Supported by iTerm image protocol",
"default": false
},
"recache": {
"type": "boolean",
"title": "If true, regenerate image logo cache",
"default": false
},
"chafa": {
"type": "object",
"title": "Chafa configuration. See chafa document for details",
@@ -221,6 +232,11 @@
"title": "Use multiple threads to detect values",
"default": true
},
"thread": {
"type": "boolean",
"title": "Alias of multithreading",
"default": true
},
"stat": {
"type": "boolean",
"title": "Show time usage (in ms) for individual modules",
@@ -309,6 +325,12 @@
"type": "boolean",
"default": true
},
"keyWidth": {
"title": "Align the width of keys to number of characters, 0 to disable",
"type": "integer",
"minimum": 0,
"default": 0
},
"binaryPrefix": {
"type": "string",
"title": "Set the binary prefix to used when printing bytes",
@@ -335,6 +357,33 @@
"enum": ["CELSIUS", "C", "FAHRENHEIT", "F", "KELVIN", "K"],
"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": {
"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",
@@ -509,6 +558,7 @@
"theme",
"uptime",
"users",
"version",
"vulkan",
"wallpaper",
"weather",
@@ -577,6 +627,7 @@
"theme",
"uptime",
"users",
"version",
"vulkan",
"wallpaper",
"wm",
@@ -590,6 +641,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -617,6 +671,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -640,6 +697,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -663,6 +723,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -716,6 +779,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -736,6 +802,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"title": "Text to print",
"type": "string"
@@ -772,6 +841,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -814,6 +886,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -851,6 +926,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -903,6 +981,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -931,6 +1012,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -961,6 +1045,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -1003,6 +1090,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -1044,6 +1134,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"format": {
"$ref": "#/$defs/format"
}
@@ -1077,6 +1170,9 @@
"keyColor": {
"$ref": "#/$defs/keyColor"
},
"keyWidth": {
"$ref": "#/$defs/keyWidth"
},
"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",
"gamepad",
"weather",
"version",
"break",
"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 "bar.h"
// green, yellow, red: print the color on nth (0~9) block
// 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)
void ffAppendPercentBar(FFstrbuf* buffer, double 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
// [ 5%, 15%) prints 1 block;
// ...
// [85%, 95%) prints 9 blocks;
// [95%,100%] prints 10 blocks
percent = (uint8_t)(percent + 5) / 10;
assert(percent <= 10);
uint32_t blocksPercent = (uint32_t) (percent / 100.0 * instance.config.barWidth + 0.5);
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);
uint32_t blocksRed = (uint32_t) (red / 100.0 * instance.config.barWidth + 0.5);
assert(blocksPercent <= instance.config.barWidth);
if(!instance.config.pipe)
ffStrbufAppendS(buffer, "\033[97m[ ");
else
ffStrbufAppendS(buffer, "[ ");
if(instance.config.barBorder)
{
if(!instance.config.pipe)
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 (i == green)
ffStrbufAppendS(buffer, "\033[32m");
else if (i == yellow)
ffStrbufAppendS(buffer, "\033[93m");
else if (i == red)
ffStrbufAppendS(buffer, "\033[91m");
if (i == blocksGreen)
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_GREEN "m");
else if (i == blocksYellow)
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_YELLOW "m");
else if (i == blocksRed)
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)
ffStrbufAppendS(buffer, "\033[97m");
for (uint8_t i = percent; i < 10; ++i)
ffStrbufAppendS(buffer, "-");
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m");
for (uint32_t i = blocksPercent; i < instance.config.barWidth; ++i)
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)
ffStrbufAppendS(buffer, "\033[97m ]" FASTFETCH_TEXT_MODIFIER_RESET);
else
ffStrbufAppendS(buffer, " ]");
ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET);
}
// if (green < yellow)
@@ -57,7 +63,7 @@ void ffAppendPercentBar(FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_
// [green, 100]: print green
// [yellow, green): print yellow
// [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);
@@ -71,23 +77,23 @@ void ffAppendPercentNum(FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_
if(green < yellow)
{
if (percent <= green)
ffStrbufAppendS(buffer, "\033[32m");
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_GREEN "m");
else if (percent <= yellow)
ffStrbufAppendS(buffer, "\033[93m");
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_YELLOW "m");
else
ffStrbufAppendS(buffer, "\033[91m");
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_RED "m");
}
else
{
if (percent >= green)
ffStrbufAppendS(buffer, "\033[32m");
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_GREEN "m");
else if (percent >= yellow)
ffStrbufAppendS(buffer, "\033[93m");
ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_YELLOW "m");
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)
{
+2 -2
View File
@@ -13,7 +13,7 @@ enum
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 ffAppendPercentNum(FFstrbuf* buffer, uint8_t percent, uint8_t green, uint8_t yellow, bool parentheses);
void ffAppendPercentBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, uint8_t red);
void ffAppendPercentNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t yellow, bool parentheses);
#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
instance.config.showErrors = false;
instance.config.recache = false;
instance.config.allowSlowOperations = false;
instance.config.pipe = !isatty(STDOUT_FILENO);
@@ -68,58 +67,69 @@ static void defaultConfig(void)
instance.config.multithreading = true;
instance.config.stat = false;
instance.config.noBuffer = false;
instance.config.keyWidth = 0;
ffInitTitleOptions(&instance.config.title);
ffInitOSOptions(&instance.config.os);
ffInitHostOptions(&instance.config.host);
ffStrbufInitStatic(&instance.config.barCharElapsed, "");
ffStrbufInitStatic(&instance.config.barCharTotal, "-");
instance.config.barWidth = 10;
instance.config.barBorder = true;
instance.config.percentType = 1;
ffInitBatteryOptions(&instance.config.battery);
ffInitBiosOptions(&instance.config.bios);
ffInitBluetoothOptions(&instance.config.bluetooth);
ffInitBoardOptions(&instance.config.board);
ffInitBreakOptions(&instance.config.break_);
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);
ffInitCPUUsageOptions(&instance.config.cpuUsage);
ffInitGPUOptions(&instance.config.gpu);
ffInitMemoryOptions(&instance.config.memory);
ffInitSwapOptions(&instance.config.swap);
ffInitChassisOptions(&instance.config.chassis);
ffInitColorsOptions(&instance.config.colors);
ffInitCommandOptions(&instance.config.command);
ffInitCursorOptions(&instance.config.cursor);
ffInitCustomOptions(&instance.config.custom);
ffInitDEOptions(&instance.config.de);
ffInitDateTimeOptions(&instance.config.dateTime);
ffInitDiskOptions(&instance.config.disk);
ffInitBatteryOptions(&instance.config.battery);
ffInitPowerAdapterOptions(&instance.config.powerAdapter);
ffInitDisplayOptions(&instance.config.display);
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);
ffInitLocaleOptions(&instance.config.locale);
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);
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);
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.libVulkan);
@@ -145,8 +155,6 @@ static void defaultConfig(void)
ffStrbufInit(&instance.config.libPulse);
ffStrbufInit(&instance.config.libnm);
ffStrbufInit(&instance.config.libDdcutil);
instance.config.percentType = 1;
}
void ffInitInstance(void)
@@ -272,63 +280,69 @@ static void destroyConfig(void)
ffStrbufDestroy(&instance.config.colorKeys);
ffStrbufDestroy(&instance.config.colorTitle);
ffStrbufDestroy(&instance.config.keyValueSeparator);
ffStrbufDestroy(&instance.config.barCharElapsed);
ffStrbufDestroy(&instance.config.barCharTotal);
#if defined(__linux__) || defined(__FreeBSD__)
ffStrbufDestroy(&instance.config.playerName);
ffStrbufDestroy(&instance.config.osFile);
#endif
ffDestroyTitleOptions(&instance.config.title);
ffDestroyOSOptions(&instance.config.os);
ffDestroyHostOptions(&instance.config.host);
ffDestroyBatteryOptions(&instance.config.battery);
ffDestroyBiosOptions(&instance.config.bios);
ffDestroyBluetoothOptions(&instance.config.bluetooth);
ffDestroyBoardOptions(&instance.config.board);
ffDestroyBreakOptions(&instance.config.break_);
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);
ffDestroyCPUUsageOptions(&instance.config.cpuUsage);
ffDestroyGPUOptions(&instance.config.gpu);
ffDestroyMemoryOptions(&instance.config.memory);
ffDestroySwapOptions(&instance.config.swap);
ffDestroyChassisOptions(&instance.config.chassis);
ffDestroyColorsOptions(&instance.config.colors);
ffDestroyCommandOptions(&instance.config.command);
ffDestroyCursorOptions(&instance.config.cursor);
ffDestroyCustomOptions(&instance.config.custom);
ffDestroyDEOptions(&instance.config.de);
ffDestroyDateTimeOptions(&instance.config.dateTime);
ffDestroyDiskOptions(&instance.config.disk);
ffDestroyBatteryOptions(&instance.config.battery);
ffDestroyPowerAdapterOptions(&instance.config.powerAdapter);
ffDestroyDisplayOptions(&instance.config.display);
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);
ffDestroyLocaleOptions(&instance.config.locale);
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);
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);
ffDestroyWeatherOptions(&instance.config.weather);
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.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));
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"))
{
ffOptionParseColor(yyjson_get_str(val), &moduleArgs->keyColor);
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 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";
}
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);
return true;
FFModuleBaseInfo* baseInfo = *modules;
if (ffStrEqualsIgnCase(type, baseInfo->name))
{
if (jsonVal) baseInfo->parseJsonObject(baseInfo, jsonVal);
baseInfo->printModule(baseInfo);
return true;
}
}
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': {
return
tryModule(type, module, FF_BATTERY_MODULE_NAME, ffParseBatteryJsonObject) ||
tryModule(type, module, FF_BIOS_MODULE_NAME, ffParseBiosJsonObject) ||
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 'b': case 'B': {
if (ffStrEqualsIgnCase(type, FF_CPUUSAGE_MODULE_NAME))
ffPrepareCPUUsage();
break;
}
case 'C': {
return
tryModule(type, module, FF_CHASSIS_MODULE_NAME, ffParseChassisJsonObject) ||
tryModule(type, module, FF_COMMAND_MODULE_NAME, ffParseCommandJsonObject) ||
tryModule(type, module, FF_COLORS_MODULE_NAME, ffParseColorsJsonObject) ||
tryModule(type, module, FF_CPU_MODULE_NAME, ffParseCPUJsonObject) ||
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 'p': case 'P': {
if (ffStrEqualsIgnCase(type, FF_PUBLICIP_MODULE_NAME))
{
if (module) ffParsePublicIpJsonObject(&cfg->publicIP, module);
ffPreparePublicIp(&cfg->publicIP);
}
break;
}
case 'D': {
return
tryModule(type, module, FF_DATETIME_MODULE_NAME, ffParseDateTimeJsonObject) ||
tryModule(type, module, FF_DE_MODULE_NAME, ffParseDEJsonObject) ||
tryModule(type, module, FF_DISPLAY_MODULE_NAME, ffParseDisplayJsonObject) ||
tryModule(type, module, FF_DISK_MODULE_NAME, ffParseDiskJsonObject) ||
false;
case 'w': case 'W': {
if (ffStrEqualsIgnCase(type, FF_WEATHER_MODULE_NAME))
{
if (module) ffParseWeatherJsonObject(&cfg->weather, module);
ffPrepareWeather(&cfg->weather);
}
break;
}
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);
assert(root);
@@ -240,7 +133,7 @@ static const char* printJsonConfig(void)
yyjson_arr_foreach(modules, idx, max, item)
{
uint64_t ms = 0;
if(__builtin_expect(instance.config.stat, false))
if(!prepare && instance.config.stat)
ms = ffTimeGetTick();
yyjson_val* module = item;
@@ -257,10 +150,12 @@ static const char* printJsonConfig(void)
else
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";
if(__builtin_expect(instance.config.stat, false))
if(!prepare && instance.config.stat)
{
char str[32];
int len = snprintf(str, sizeof str, "%" PRIu64 "ms", ffTimeGetTick() - ms);
@@ -431,8 +326,33 @@ const char* ffParseDisplayJsonConfig(void)
}
else if (ffStrEqualsIgnCase(key, "percentType"))
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"))
config->noBuffer = yyjson_get_bool(val);
else if (ffStrEqualsIgnCase(key, "keyWidth"))
config->keyWidth = (uint32_t) yyjson_get_uint(val);
else
return "Unknown display property";
}
@@ -515,9 +435,9 @@ const char* ffParseLibraryJsonConfig(void)
return NULL;
}
void ffPrintJsonConfig(void)
void ffPrintJsonConfig(bool prepare)
{
const char* error = printJsonConfig();
const char* error = printJsonConfig(prepare);
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);
const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair pairs[]);
void ffPrintJsonConfig();
const char* ffParseGeneralJsonConfig();
const char* ffParseDisplayJsonConfig();
const char* ffParseLibraryJsonConfig();
void ffPrintJsonConfig(bool prepare);
const char* ffParseGeneralJsonConfig(void);
const char* ffParseDisplayJsonConfig(void);
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);
return true;
}
else if(ffStrEqualsIgnCase(subKey, "format"))
{
ffOptionParseString(argumentKey, value, &result->outputFormat);
return true;
}
else if(ffStrEqualsIgnCase(subKey, "key-color"))
{
if(value == NULL)
@@ -44,9 +49,9 @@ bool ffOptionParseModuleArgs(const char* argumentKey, const char* subKey, const
ffOptionParseColor(value, &result->keyColor);
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 false;
@@ -175,6 +180,7 @@ void ffOptionInitModuleArg(FFModuleArgs* args)
ffStrbufInit(&args->key);
ffStrbufInit(&args->keyColor);
ffStrbufInit(&args->outputFormat);
args->keyWidth = 0;
}
void ffOptionDestroyModuleArg(FFModuleArgs* args)
+26
View File
@@ -2,11 +2,37 @@
#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
{
FFstrbuf key;
FFstrbuf keyColor;
FFstrbuf outputFormat;
uint32_t keyWidth;
} FFModuleArgs;
typedef struct FFKeyValuePair
+27 -53
View File
@@ -2,7 +2,7 @@
#include "common/printing.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();
@@ -16,14 +16,14 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFstrb
if (instance.config.brightColor)
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
if(customKeyColor != NULL && customKeyColor->length > 0)
ffPrintColor(customKeyColor);
if(moduleArgs && !(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_COLOR) && moduleArgs->keyColor.length > 0)
ffPrintColor(&moduleArgs->keyColor);
else
ffPrintColor(&instance.config.colorKeys);
}
//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);
@@ -33,10 +33,10 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFstrb
else
{
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
ffParseFormatString(&key, customKeyFormat, 1, (FFformatarg[]){
ffParseFormatString(&key, &moduleArgs->key, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex}
});
ffPrintUserString(key.chars);
ffStrbufWriteTo(&key, stdout);
}
if(!instance.config.pipe)
@@ -46,32 +46,37 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFstrb
if(!instance.config.pipe)
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);
ffPrintUserString(buffer.chars);
putchar('\n');
uint32_t keyWidth = moduleArgs && moduleArgs->keyWidth > 0 ? moduleArgs->keyWidth : instance.config.keyWidth;
if (keyWidth > 0)
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)
return;
ffPrintLogoAndKey(moduleName, moduleIndex, customKeyFormat, customKeyColor);
ffPrintLogoAndKey(moduleName, moduleIndex, moduleArgs, printType);
if(!instance.config.pipe)
fputs(FASTFETCH_TEXT_MODIFIER_ERROR, stdout);
@@ -84,11 +89,11 @@ static void printError(const char* moduleName, uint8_t moduleIndex, const FFstrb
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_start(arguments, message);
printError(moduleName, moduleIndex, customKeyFormat, customKeyColor, message, arguments);
printError(moduleName, moduleIndex, moduleArgs, printType, message, arguments);
va_end(arguments);
}
@@ -96,7 +101,7 @@ void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArg
{
va_list arguments;
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);
}
@@ -125,34 +130,3 @@ void ffPrintCharTimes(char c, uint32_t times)
if(remaining > 0)
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 "common/format.h"
void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor);
void ffPrintFormatString(const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments);
void ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments);
FF_C_PRINTF(5, 6) void ffPrintErrorString(const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customKeyColor, const char* message, ...);
typedef enum FFPrintType {
FF_PRINT_TYPE_DEFAULT = 0,
FF_PRINT_TYPE_NO_CUSTOM_KEY = 1 << 0,
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, ...);
void ffPrintColor(const FFstrbuf* colorValue);
void ffPrintCharTimes(char c, uint32_t times);
void ffPrintUserString(const char* str);
#endif
+3
View File
@@ -376,6 +376,7 @@
#--player-key Media Player
#--media-key Media
#--datetime-key Date Time
#--version-key Version
#--vulkan-key Vulkan
#--opengl-key OpenGL
#--opencl-key OpenCL
@@ -426,6 +427,7 @@
#--player-format
#--media-format
#--datetime-format
#--version-format
#--vulkan-format
#--opengl-format
#--opencl-format
@@ -473,6 +475,7 @@
#--player-key-color
#--media-key-color
#--datetime-key-color
#--version-key-color
#--vulkan-key-color
#--opengl-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-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-recache <?value>: If true, regenerate image logo cache
--file <file>: Short for --logo-type file --logo <file>
--file-raw <file>: Short for --logo-type file-raw --logo <file>
--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.
--color-keys <color>: Set the color of the keys
--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
-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
--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
@@ -68,6 +70,10 @@ Display options:
--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
--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
--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
@@ -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.
--<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
--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
// 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)
return "IOAVService is not available";
@@ -108,8 +108,10 @@ const char* ffDetectBrightness(FFlist* result)
detectWithDisplayServices(displayServer, result);
if (instance.config.allowSlowOperations && displayServer->displays.length > result->length)
#ifdef __aarch64__
if (displayServer->displays.length > result->length)
detectWithDdcci(result);
#endif
return NULL;
}
+3 -6
View File
@@ -139,12 +139,9 @@ const char* ffDetectBrightness(FFlist* result)
detectWithBacklight(result);
#ifdef FF_HAVE_DDCUTIL
if (instance.config.allowSlowOperations)
{
const FFDisplayServerResult* displayServer = ffConnectDisplayServer();
if (result->length < displayServer->displays.length)
detectWithDdcci(result);
}
const FFDisplayServerResult* displayServer = ffConnectDisplayServer();
if (result->length < displayServer->displays.length)
detectWithDdcci(result);
#endif
return NULL;
@@ -76,7 +76,7 @@ const char* ffDetectBrightness(FFlist* result)
if (hasBuiltinDisplay(displayServer))
detectWithWmi(result);
if (instance.config.allowSlowOperations && result->length < displayServer->displays.length)
if (result->length < displayServer->displays.length)
detectWithDdcci(displayServer, result);
return NULL;
}
+2
View File
@@ -35,6 +35,8 @@ const char* ffGetCpuUsageResult(double* result)
if(inUseAll2 != inUseAll1)
{
*result = (double)(inUseAll2 - inUseAll1) / (double)(totalAll2 - totalAll1) * 100;
inUseAll1 = inUseAll2;
totalAll1 = totalAll2;
return NULL;
}
else
+10 -10
View File
@@ -3,19 +3,19 @@
#include <sys/mount.h>
#ifdef __FreeBSD__
#include "util/stringUtils.h"
static void detectFsInfo(struct statfs* fs, FFDisk* disk)
{
if(
ffStrbufStartsWithS(&disk->mountpoint, "/boot") ||
ffStrbufStartsWithS(&disk->mountpoint, "/dev") ||
ffStrbufStartsWithS(&disk->mountpoint, "/var") ||
ffStrbufStartsWithS(&disk->mountpoint, "/tmp") ||
ffStrbufStartsWithS(&disk->mountpoint, "/proc") ||
ffStrbufStartsWithS(&disk->mountpoint, "/zroot") ||
ffStrbufStartsWithS(&disk->mountpoint, "/compat/linux/")
)
if(ffStrbufEqualS(&disk->filesystem, "zfs"))
{
disk->type = !ffStrStartsWith(fs->f_mntfromname, "zroot/") || ffStrStartsWith(fs->f_mntfromname, "zroot/ROOT/")
? FF_DISK_TYPE_REGULAR_BIT
: FF_DISK_TYPE_SUBVOLUME_BIT;
}
else if(!ffStrStartsWith(fs->f_mntfromname, "/dev/"))
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;
else
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();
//Try partlabel first
ffStrbufSetS(&basePath, "/dev/disk/by-partlabel/");
//Try label first
ffStrbufSetS(&basePath, "/dev/disk/by-label/");
detectNameFromPath(disk, &deviceStat, &basePath);
//Try label second
if(disk->name.length == 0)
{
ffStrbufSetS(&basePath, "/dev/disk/by-label/");
//Try partlabel second
ffStrbufSetS(&basePath, "/dev/disk/by-partlabel/");
detectNameFromPath(disk, &deviceStat, &basePath);
}
//Use the mountpoint as a last resort
if(disk->name.length == 0)
ffStrbufAppend(&disk->name, &disk->mountpoint);
// Basic\x20data\x20partition
for (uint32_t i = ffStrbufFirstIndexS(&disk->name, "\\x");
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__
+1 -1
View File
@@ -59,7 +59,7 @@ const char* ffDetectHost(FFHostResult* host)
ffStrbufAppendF(&host->productName, " - %s", wslDistroName);
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[]){
"wsl.exe",
"--version",
+4 -11
View File
@@ -3,7 +3,6 @@
#include "common/io/io.h"
#include "util/edidHelper.h"
#include "util/stringUtils.h"
#include "util/mallocHelper.h"
#include <dirent.h>
#include <sys/stat.h>
@@ -30,15 +29,9 @@ const char* ffDetectMonitor(FFlist* results)
ffStrbufAppendS(&drmDir, entry->d_name);
ffStrbufAppendS(&drmDir, "/edid");
struct stat fileStat;
if (stat(drmDir.chars, &fileStat) < 0 || fileStat.st_size == 0 || fileStat.st_size % 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))
uint8_t edidData[512];
ssize_t edidLength = ffReadFileData(drmDir.chars, sizeof(edidData), edidData);
if(edidLength <= 0 || edidLength % 128 != 0)
{
ffStrbufSubstrBefore(&drmDir, drmDirLength);
continue;
@@ -54,7 +47,7 @@ const char* ffDetectMonitor(FFlist* results)
ffStrbufInit(&display->name);
ffEdidGetName(edidData, &display->name);
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);
+1 -2
View File
@@ -62,7 +62,6 @@ FF_MAYBE_UNUSED static void detectTTY(FFTerminalFontResult* terminalFont)
#include "common/processing.h"
#include <stdlib.h>
#include <yyjson.h>
static const char* detectWTProfile(yyjson_val* profile, FFstrbuf* name, double* size)
{
@@ -355,7 +354,7 @@ static bool detectTerminalFontCommon(const FFTerminalShellResult* terminalShell,
#ifndef _WIN32
else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalExe, "/dev/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);
else if(ffStrbufStartsWithIgnCaseS(&terminalShell->terminalExe, "/dev/tty"))
detectTTY(terminalFont);
@@ -375,12 +375,19 @@ const FFTerminalShellResult* ffDetectTerminalShell()
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"))
ffStrbufInitStatic(&result.terminalPrettyName, "WezTerm");
else if(ffStrbufEqualS(&result.terminalProcessName, ".kitty-wrapped"))
ffStrbufInitStatic(&result.terminalPrettyName, "kitty"); // #510
#if defined(__linux__) || defined(__FreeBSD__)
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
+133 -259
View File
@@ -1,9 +1,11 @@
#include "fastfetch.h"
#include "common/commandoption.h"
#include "common/printing.h"
#include "common/parsing.h"
#include "common/io/io.h"
#include "common/time.h"
#include "common/jsonconfig.h"
#include "detection/version/version.h"
#include "util/stringUtils.h"
#include "logo/logo.h"
#include "fastfetch_datatext.h"
@@ -455,6 +457,17 @@ static inline void printCommandHelp(const char* command)
"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"))
{
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 bool parseJsoncFile(const char* path)
@@ -563,7 +589,7 @@ static bool parseJsoncFile(const char* path)
{
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);
}
return false;
@@ -584,6 +610,7 @@ static bool parseConfigFile(FFdata* data, const char* path)
char* line = NULL;
size_t len = 0;
ssize_t read;
FF_STRBUF_AUTO_DESTROY unescaped = ffStrbufCreate();
while ((read = getline(&line, &len, file)) != -1)
{
@@ -628,7 +655,42 @@ static bool parseConfigFile(FFdata* data, const char* path)
--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)
@@ -696,7 +758,7 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128);
if (ffPathExpandEnv(value, &absolutePath))
{
bool success = isJsonConfig ? parseJsoncFile(value) : parseConfigFile(data, absolutePath.chars);
bool success = isJsonConfig ? parseJsoncFile(absolutePath.chars) : parseConfigFile(data, absolutePath.chars);
if(success)
return;
@@ -711,7 +773,7 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
ffStrbufAppendS(&absolutePath, "fastfetch/presets/");
ffStrbufAppendS(&absolutePath, value);
bool success = isJsonConfig ? parseJsoncFile(value) : parseConfigFile(data, absolutePath.chars);
bool success = isJsonConfig ? parseJsoncFile(absolutePath.chars) : parseConfigFile(data, absolutePath.chars);
if(success)
return;
@@ -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
}
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)
{
///////////////////////
@@ -746,37 +815,7 @@ static void parseOption(FFdata* data, const char* key, const char* value)
}
else if(ffStrEqualsIgnCase(key, "-v") || ffStrEqualsIgnCase(key, "--version"))
{
#ifndef NDEBUG
#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
printVersion();
exit(0);
}
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");
if(ffStrEqualsIgnCase(subkey, "-modules"))
{
puts(FASTFETCH_DATATEXT_MODULES);
listModules();
exit(0);
}
else if(ffStrEqualsIgnCase(subkey, "-presets"))
@@ -893,8 +932,6 @@ static void parseOption(FFdata* data, const char* key, const char* value)
//General options//
///////////////////
else if(ffStrEqualsIgnCase(key, "-r") || ffStrEqualsIgnCase(key, "--recache"))
instance.config.recache = ffOptionParseBoolean(value);
else if(ffStrEqualsIgnCase(key, "--load-config"))
optionParseConfigFile(data, key, value);
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);
else if(ffStrEqualsIgnCase(key, "--separator"))
ffOptionParseString(key, value, &instance.config.keyValueSeparator);
else if(ffStrEqualsIgnCase(key, "--color-keys"))
else if(ffStrStartsWith(key, "--color"))
{
optionCheckString(key, value, &instance.config.colorKeys);
ffOptionParseColor(value, &instance.config.colorKeys);
}
else if(ffStrEqualsIgnCase(key, "--color-title"))
{
optionCheckString(key, value, &instance.config.colorTitle);
ffOptionParseColor(value, &instance.config.colorTitle);
const char* subkey = key + strlen("--color");
if(*subkey == '\0')
{
optionCheckString(key, value, &instance.config.colorKeys);
ffOptionParseColor(value, &instance.config.colorKeys);
ffStrbufSet(&instance.config.colorTitle, &instance.config.colorKeys);
}
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"))
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"))
{
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);
else if(ffStrEqualsIgnCase(key, "--no-buffer"))
instance.config.noBuffer = ffOptionParseBoolean(value);
///////////////////////
//Module args options//
///////////////////////
else if(ffParseOSCommandOptions(&instance.config.os, key, value)) {}
else if(ffParseHostCommandOptions(&instance.config.host, key, value)) {}
else if(ffParseOSCommandOptions(&instance.config.os, key, value)) {}
else if(ffParseBiosCommandOptions(&instance.config.bios, key, value)) {}
else if(ffParseBoardCommandOptions(&instance.config.board, key, value)) {}
else if(ffParseChassisCommandOptions(&instance.config.chassis, key, value)) {}
else if(ffParseCommandCommandOptions(&instance.config.command, key, value)) {}
else if(ffParseCustomCommandOptions(&instance.config.custom, key, value)) {}
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)) {}
else if(ffStrStartsWithIgnCase(key, "--bar"))
{
const char* subkey = key + strlen("--bar");
if(ffStrEqualsIgnCase(subkey, "-char-elapsed"))
ffOptionParseString(key, value, &instance.config.barCharElapsed);
else if(ffStrEqualsIgnCase(subkey, "-char-total"))
ffOptionParseString(key, value, &instance.config.barCharTotal);
else if(ffStrEqualsIgnCase(subkey, "-width"))
instance.config.barWidth = (uint8_t) ffOptionParseUInt32(key, value);
else if(ffStrEqualsIgnCase(subkey, "-border"))
instance.config.barBorder = ffOptionParseBoolean(value);
else
goto error;
}
///////////////////
//Library options//
@@ -1129,6 +1130,12 @@ static void parseOption(FFdata* data, const char* key, const char* value)
goto error;
}
///////////////////////
//Module args options//
///////////////////////
else if(ffParseModuleOptions(key, value)) {}
//////////////////
//Unknown option//
//////////////////
@@ -1175,6 +1182,13 @@ static void parseArguments(FFdata* data, int argc, const char** argv)
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 || (
*argv[i + 1] == '-' &&
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]))
{
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>");
if(!ffParseModuleCommand(line))
ffPrintErrorString(line, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "<no implementation provided>");
}
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(data.structure.length == 0)
@@ -1409,9 +1283,9 @@ int main(int argc, const char** argv)
if (!instance.config.noBuffer) fflush(stdout);
#endif
if (data.structure.length == 0 && instance.state.configDoc)
if (useJsonConfig)
{
ffPrintJsonConfig();
ffPrintJsonConfig(false);
}
else
{
+62 -53
View File
@@ -7,7 +7,12 @@
#include <stdint.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/FFlist.h"
@@ -44,7 +49,6 @@ typedef struct FFconfig
FFstrbuf keyValueSeparator;
bool showErrors;
bool recache;
bool allowSlowOperations;
bool disableLinewrap;
bool hideCursor;
@@ -53,11 +57,17 @@ typedef struct FFconfig
uint8_t sizeNdigits;
uint8_t sizeMaxPrefix;
FFTemperatureUnit temperatureUnit;
FFstrbuf barCharElapsed;
FFstrbuf barCharTotal;
uint8_t barWidth;
bool barBorder;
uint32_t percentType;
bool pipe; //disables logo and all escape sequences
bool multithreading;
bool stat;
bool noBuffer;
int32_t processingTimeout;
uint32_t keyWidth;
// Module options that cannot be put in module option structure
#if defined(__linux__) || defined(__FreeBSD__)
@@ -68,59 +78,61 @@ typedef struct FFconfig
int32_t wmiTimeout;
#endif
FFTitleOptions title;
FFOSOptions os;
FFHostOptions host;
FFBatteryOptions battery;
FFBiosOptions bios;
FFBluetoothOptions bluetooth;
FFBoardOptions board;
FFBreakOptions break_;
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;
FFCPUUsageOptions cpuUsage;
FFCustomOptions custom;
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;
FFChassisOptions chassis;
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 libVulkan;
@@ -146,10 +158,6 @@ typedef struct FFconfig
FFstrbuf libPulse;
FFstrbuf libnm;
FFstrbuf libDdcutil;
uint32_t percentType;
bool jsonConfig;
} FFconfig;
typedef struct FFstate
@@ -168,6 +176,7 @@ typedef struct FFinstance
FFstate state;
} FFinstance;
extern FFinstance instance; // Defined in `common/init.c`
extern FFModuleBaseInfo** ffModuleInfos[];
//////////////////////
// Init functions //
+1
View File
@@ -10,6 +10,7 @@
#define FASTFETCH_PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@
#define FASTFETCH_PROJECT_VERSION_TWEAK "@PROJECT_VERSION_TWEAK@"
#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_DESCRIPTION "@PROJECT_DESCRIPTION@"
#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_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_MODULES "@DATATEXT_MODULES@"
#define FASTFETCH_DATATEXT_HELP "@DATATEXT_HELP@"
#define FASTFETCH_DATATEXT_HELP_COLOR "@DATATEXT_HELP_COLOR@"
#define FASTFETCH_DATATEXT_HELP_FORMAT "@DATATEXT_HELP_FORMAT@"
+1 -1
View File
@@ -62,7 +62,7 @@ int main(void)
//ffPrintBluetooth(&instance.config.bluetooth);
//ffPrintSound(&instance.config.sound);
//ffPrintGamepad(&instance.config.gamepad);
ffPrintBreak();
ffPrintBreak(&instance.config.break_);
ffPrintColors(&instance.config.colors);
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 @@
:--==========================--:
.-=================================.
-==================================-
====================================
=======-....:==========:....:=======
=======: -======-. .=======
=======: :====- .=======
=======: :==: .=======
=======: .. .=======
=======: .: .: .=======
=======: .=- :=: .=======
=======: .===. .-==: .=======
=======: .==========: .=======
=======: :==========: :=======
====================================
-===================================
.==================================:
:--===========================-:.
+16
View File
@@ -0,0 +1,16 @@
#############################+
.%#######################%@@@+
. :#@%-
.#@%%%- =@@#.
*@%@@= +@@+
=@@%@+.#@%-
-@@%@@@#:
.#@%%@-
:#@@%@@=
=@@+=@@%@+
.#@@= -@@%@#
-%@#: :%@%@%:
*@@+ .#%%%%-
:%@%- .
+@@@%#%%%%%%%%%%%%%%%%%%%%%%%.
+######################*******
+19 -15
View File
@@ -1,15 +1,19 @@
::::::: :::::::
mMMMMMMm dMMMMMMm
/MMMMMMMo +MMMMMMM/
yMMMMMMN mMMMMMMy
NMMMMMMs oMMMMMMm
+MMMMMMN: NMMMMMM+
hMMMMMMy sMMMMMMy
:NMMMMMM::NMMMMMN:
oMMMMMMyyMMMMMM+
dMMMMMMMMMMMMh
/MMMMMMMMMMMN:
sMMMMMMMMMMo
mMMMMMMMMd
+MMMMMMMN:
::::::
`-`
-yys+/-`
`oyyyyy: /osyyyyso+:.
/yyyyy+`+yyyyyyyyyys/.
.-yyyyys.:+//+oyyyyyyyo.
`oy/`oyyyyy/ ./syyyyy:
syyys`:yyyyyo` :yyyyy:
/yyyyo .syyyyy- .yyyyy.
yyyyy. +yyyyy/ /yyyy/
`yyyyy :yyyyys` -yyyyo
yyyyy. `syyyyy- /yyyy/
/yyyyo /yyyyy+ .yyyyy.
syyyys. -yyyyys.:yyyy:
`oyyyyyo-` `oyyyyy:.sy:
:syyyyyyso+/++`/yyyyyo``
-oyyyyyyyyyyy-.syyyys.
-/+osyyyyso.`+yyyyy/
.-/+syo`
`.
+11
View File
@@ -0,0 +1,11 @@
++**
*===**====+*
*====* +===+
*==*+===* *===*
*===* *===+ *===*
*===* +===+ *===*
*===* +===* *===*
*===* *===+*==*
+===+ *===+=*
*+====**===*
**++
+37
View File
@@ -13,6 +13,15 @@ const FFlogo ffLogoUnknown = {
};
static const FFlogo A[] = {
// AerOS
{
.names = {"aerOS"},
.lines = FASTFETCH_DATATEXT_LOGO_AEROS,
.colors = {
FF_COLOR_FG_CYAN,
FF_COLOR_FG_CYAN,
},
},
// AIX
{
.names = {"aix"},
@@ -2332,6 +2341,15 @@ static const FFlogo M[] = {
.colorKeys = FF_COLOR_FG_256 "29",
.colorTitle = FF_COLOR_FG_WHITE,
},
// MOS
{
.names = {"MOS"},
.lines = FASTFETCH_DATATEXT_LOGO_MOS,
.colors = {
FF_COLOR_FG_CYAN,
FF_COLOR_FG_BLUE,
},
},
// Msys2
{
.names = {"Msys2"},
@@ -3639,6 +3657,15 @@ static const FFlogo T[] = {
FF_COLOR_FG_CYAN,
},
},
// TuxedoOS
{
.names = {"Tuxedo OS"},
.lines = FASTFETCH_DATATEXT_LOGO_TUXEDO_OS,
.colors = {
FF_COLOR_FG_WHITE,
FF_COLOR_FG_RED,
},
},
// Twister
{
.names = {"Twister"},
@@ -3899,6 +3926,16 @@ static const FFlogo V[] = {
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
{
.names = {"Vnux"},
+8 -18
View File
@@ -3,6 +3,7 @@
#include "common/printing.h"
#include <limits.h>
#include <math.h>
#ifdef __APPLE__
#include <sys/syslimits.h>
@@ -184,12 +185,6 @@ static inline bool checkAllocationResult(void* data, size_t length)
return true;
}
static inline uint32_t simpleCeil(double value)
{
uint32_t result = (uint32_t) value;
return value == (double) result ? result : result + 1;
}
static void writeCacheStrbuf(FFLogoRequestData* requestData, const FFstrbuf* value, const char* cacheFileName)
{
uint32_t cacheDirLength = requestData->cacheDir.length;
@@ -463,8 +458,8 @@ FFLogoImageResult ffLogoPrintImageImpl(FFLogoRequestData* requestData, const FFI
else if(requestData->logoPixelHeight == 0)
requestData->logoPixelHeight = (uint32_t) ((double) imageData.image->rows / (double) imageData.image->columns * requestData->logoPixelWidth);
requestData->logoCharacterWidth = simpleCeil((double) requestData->logoPixelWidth / requestData->characterPixelWidth);
requestData->logoCharacterHeight = simpleCeil((double) requestData->logoPixelHeight / requestData->characterPixelHeight);
requestData->logoCharacterWidth = (uint32_t) ceil((double) requestData->logoPixelWidth / requestData->characterPixelWidth);
requestData->logoCharacterHeight = (uint32_t) ceil((double) requestData->logoPixelHeight / requestData->characterPixelHeight);
if(requestData->logoPixelWidth == 0 || requestData->logoPixelHeight == 0 || requestData->logoCharacterWidth == 0 || requestData->logoCharacterHeight == 0)
{
@@ -608,8 +603,7 @@ static bool printCachedPixel(FFLogoRequestData* requestData)
instance.state.logoHeight = requestData->logoCharacterHeight + instance.config.logo.paddingTop;
//Go to upper left corner
fputs("\033[9999999D", stdout);
printf("\033[%uA", instance.state.logoHeight);
printf("\033[9999999D\033[%uA", instance.state.logoHeight);
return true;
}
@@ -674,8 +668,8 @@ static bool printImageIfExistsSlowPath(FFLogoType type, bool printError)
return false;
}
requestData.logoPixelWidth = simpleCeil((double) instance.config.logo.width * requestData.characterPixelWidth);
requestData.logoPixelHeight = simpleCeil((double) instance.config.logo.height * requestData.characterPixelHeight);
requestData.logoPixelWidth = (uint32_t) ceil((double) instance.config.logo.width * requestData.characterPixelWidth);
requestData.logoPixelHeight = (uint32_t) ceil((double) instance.config.logo.height * requestData.characterPixelHeight);
ffStrbufInit(&requestData.cacheDir);
ffStrbufAppend(&requestData.cacheDir, &instance.state.platform.cacheDir);
@@ -692,13 +686,9 @@ static bool printImageIfExistsSlowPath(FFLogoType type, bool printError)
}
ffStrbufRecalculateLength(&requestData.cacheDir);
ffStrbufEnsureEndsWithC(&requestData.cacheDir, '/');
ffStrbufAppendF(&requestData.cacheDir, "%u*%u/", requestData.logoPixelWidth, requestData.logoPixelHeight);
ffStrbufAppendF(&requestData.cacheDir, "%u", requestData.logoPixelWidth);
ffStrbufAppendC(&requestData.cacheDir, '*');
ffStrbufAppendF(&requestData.cacheDir, "%u", requestData.logoPixelHeight);
ffStrbufAppendC(&requestData.cacheDir, '/');
if(!instance.config.recache && printCached(&requestData))
if(!instance.config.logo.recache && printCached(&requestData))
{
ffStrbufDestroy(&requestData.cacheDir);
return true;
+8
View File
@@ -16,6 +16,7 @@ void ffInitLogoOptions(FFLogoOptions* options)
options->paddingRight = 4;
options->printRemaining = true;
options->preserveAspectRadio = false;
options->recache = false;
options->chafaFgOnly = false;
ffStrbufInitStatic(&options->chafaSymbols, "block+border+space-wide-inverted"); // Chafa default
@@ -113,6 +114,8 @@ logoType:
options->printRemaining = ffOptionParseBoolean(value);
else if(strcasecmp(subKey, "preserve-aspect-radio") == 0)
options->preserveAspectRadio = ffOptionParseBoolean(value);
else if(strcasecmp(subKey, "recache") == 0)
options->recache = ffOptionParseBoolean(value);
else
return false;
}
@@ -334,6 +337,11 @@ const char* ffParseLogoJsonConfig(void)
options->preserveAspectRadio = yyjson_get_bool(val);
continue;
}
else if (strcasecmp(key, "recache") == 0)
{
options->recache = yyjson_get_bool(val);
continue;
}
else if (strcasecmp(key, "chafa") == 0)
{
if (!yyjson_is_obj(val))
+1
View File
@@ -35,6 +35,7 @@ typedef struct FFLogoOptions
uint32_t paddingRight;
bool printRemaining;
bool preserveAspectRadio;
bool recache;
bool chafaFgOnly;
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)
{
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 =
!(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(result->capacity <= 20)
ffAppendPercentBar(&str, (uint8_t)result->capacity, 10, 10, 0);
ffAppendPercentBar(&str, result->capacity, 100, 100, 0);
else if(result->capacity <= 50)
ffAppendPercentBar(&str, (uint8_t)result->capacity, 10, 0, 10);
ffAppendPercentBar(&str, result->capacity, 100, 0, 100);
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)
@@ -38,7 +38,7 @@ static void printBattery(FFBatteryOptions* options, BatteryResult* result, uint8
if(str.length > 0)
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)
{
options->moduleName = FF_BATTERY_MODULE_NAME;
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BATTERY_MODULE_NAME, ffParseBatteryCommandOptions, ffParseBatteryJsonObject, ffPrintBattery);
ffOptionInitModuleArg(&options->moduleArgs);
options->temp = false;
@@ -147,41 +147,33 @@ void ffDestroyBatteryOptions(FFBatteryOptions* options)
#endif
}
void ffParseBatteryJsonObject(yyjson_val* module)
void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module)
{
FFBatteryOptions __attribute__((__cleanup__(ffDestroyBatteryOptions))) options;
ffInitBatteryOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
#ifdef __linux__
if (ffStrEqualsIgnCase(key, "dir"))
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
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);
ffStrbufSetS(&options->dir, yyjson_get_str(val));
continue;
}
}
#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);
bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
bool temp;
+12 -20
View File
@@ -30,7 +30,7 @@ void ffPrintBios(FFBiosOptions* options)
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);
if (bios.release.length)
printf(" (%s)", bios.release.chars);
@@ -55,7 +55,7 @@ exit:
void ffInitBiosOptions(FFBiosOptions* options)
{
options->moduleName = FF_BIOS_MODULE_NAME;
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BIOS_MODULE_NAME, ffParseBiosCommandOptions, ffParseBiosJsonObject, ffPrintBios);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -74,27 +74,19 @@ void ffDestroyBiosOptions(FFBiosOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseBiosJsonObject(yyjson_val* module)
void ffParseBiosJsonObject(FFBiosOptions* options, yyjson_val* module)
{
FFBiosOptions __attribute__((__cleanup__(ffDestroyBiosOptions))) options;
ffInitBiosOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
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);
bool ffParseBiosCommandOptions(FFBiosOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFBiosOptions;
+18 -26
View File
@@ -10,7 +10,7 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothDevice* de
{
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);
if(device->battery > 0)
@@ -75,7 +75,7 @@ void ffPrintBluetooth(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);
options->showDisconnected = false;
}
@@ -101,33 +101,25 @@ void ffDestroyBluetoothOptions(FFBluetoothOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseBluetoothJsonObject(yyjson_val* module)
void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module)
{
FFBluetoothOptions __attribute__((__cleanup__(ffDestroyBluetoothOptions))) options;
ffInitBluetoothOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "showDisconnected"))
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
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);
options->showDisconnected = yyjson_get_bool(val);
continue;
}
}
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);
bool ffParseBluetoothCommandOptions(FFBluetoothOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
bool showDisconnected;
+12 -20
View File
@@ -28,7 +28,7 @@ void ffPrintBoard(FFBoardOptions* options)
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);
if (result.version.length)
printf(" (%s)", result.version.chars);
@@ -51,7 +51,7 @@ exit:
void ffInitBoardOptions(FFBoardOptions* options)
{
options->moduleName = FF_BOARD_MODULE_NAME;
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BOARD_MODULE_NAME, ffParseBoardCommandOptions, ffParseBoardJsonObject, ffPrintBoard);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -70,27 +70,19 @@ void ffDestroyBoardOptions(FFBoardOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseBoardJsonObject(yyjson_val* module)
void ffParseBoardJsonObject(FFBoardOptions* options, yyjson_val* module)
{
FFBoardOptions __attribute__((__cleanup__(ffDestroyBoardOptions))) options;
ffInitBoardOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
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);
bool ffParseBoardCommandOptions(FFBoardOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFBoardOptions;
+18 -3
View File
@@ -1,13 +1,28 @@
#include "common/printing.h"
#include "modules/break/break.h"
void ffPrintBreak(void)
void ffPrintBreak(FF_MAYBE_UNUSED FFBreakOptions* options)
{
ffLogoPrintLine();
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"
void ffPrintBreak();
void ffParseBreakJsonObject(yyjson_val* module);
void ffPrintBreak(FFBreakOptions* options);
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();
uint32_t index = 0;
FF_LIST_FOR_EACH(FFBrightnessResult, item, result)
{
if(options->moduleArgs.key.length == 0)
@@ -35,7 +36,9 @@ void ffPrintBrightness(FFBrightnessOptions* options)
}
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}
});
}
@@ -44,11 +47,11 @@ void ffPrintBrightness(FFBrightnessOptions* options)
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)
{
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)
@@ -56,14 +59,14 @@ void ffPrintBrightness(FFBrightnessOptions* options)
if(str.length > 0)
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);
}
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_STRBUF, &item->name},
});
@@ -71,12 +74,13 @@ void ffPrintBrightness(FFBrightnessOptions* options)
ffStrbufClear(&key);
ffStrbufDestroy(&item->name);
++index;
}
}
void ffInitBrightnessOptions(FFBrightnessOptions* options)
{
options->moduleName = FF_BRIGHTNESS_MODULE_NAME;
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BRIGHTNESS_MODULE_NAME, ffParseBrightnessCommandOptions, ffParseBrightnessJsonObject, ffPrintBrightness);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -95,27 +99,19 @@ void ffDestroyBrightnessOptions(FFBrightnessOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseBrightnessJsonObject(yyjson_val* module)
void ffParseBrightnessJsonObject(FFBrightnessOptions* options, yyjson_val* module)
{
FFBrightnessOptions __attribute__((__cleanup__(ffDestroyBrightnessOptions))) options;
ffInitBrightnessOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
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);
bool ffParseBrightnessCommandOptions(FFBrightnessOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFBrightnessOptions;
+12 -20
View File
@@ -29,7 +29,7 @@ void ffPrintChassis(FFChassisOptions* options)
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);
if (result.version.length)
printf(" (%s)", result.version.chars);
@@ -52,7 +52,7 @@ exit:
void ffInitChassisOptions(FFChassisOptions* options)
{
options->moduleName = FF_CHASSIS_MODULE_NAME;
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CHASSIS_MODULE_NAME, ffParseChassisCommandOptions, ffParseChassisJsonObject, ffPrintChassis);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -71,27 +71,19 @@ void ffDestroyChassisOptions(FFChassisOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseChassisJsonObject(yyjson_val* module)
void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module)
{
FFChassisOptions __attribute__((__cleanup__(ffDestroyChassisOptions))) options;
ffInitChassisOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
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);
bool ffParseChassisCommandOptions(FFChassisOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFChassisOptions;
+33 -41
View File
@@ -57,7 +57,7 @@ void ffPrintColors(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->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;
ffInitColorsOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffStrEqualsIgnCase(key, "symbol"))
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffStrEqualsIgnCase(key, "symbol"))
{
int value;
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
{ "block", FF_COLORS_SYMBOL_BLOCK },
{ "circle", FF_COLORS_SYMBOL_CIRCLE },
{ "diamond", FF_COLORS_SYMBOL_DIAMOND },
{ "triangle", FF_COLORS_SYMBOL_TRIANGLE },
{ "square", FF_COLORS_SYMBOL_SQUARE },
{ "star", FF_COLORS_SYMBOL_STAR },
{},
});
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);
int value;
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
{ "block", FF_COLORS_SYMBOL_BLOCK },
{ "circle", FF_COLORS_SYMBOL_CIRCLE },
{ "diamond", FF_COLORS_SYMBOL_DIAMOND },
{ "triangle", FF_COLORS_SYMBOL_TRIANGLE },
{ "square", FF_COLORS_SYMBOL_SQUARE },
{ "star", FF_COLORS_SYMBOL_STAR },
{},
});
if (error)
ffPrintErrorString(FF_COLORS_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Invalid %s value: %s", key, error);
else
options->symbol = (FFColorsSymbol) value;
continue;
}
}
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 ffDestroyColorsOptions(FFColorsOptions* options);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFColorsSymbol symbol;
uint32_t paddingLeft;
} FFColorsOptions;
+24 -32
View File
@@ -30,13 +30,13 @@ void ffPrintCommand(FFCommandOptions* options)
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);
}
void ffInitCommandOptions(FFCommandOptions* options)
{
options->moduleName = FF_COMMAND_MODULE_NAME;
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COMMAND_MODULE_NAME, ffParseCommandCommandOptions, ffParseCommandJsonObject, ffPrintCommand);
ffOptionInitModuleArg(&options->moduleArgs);
ffStrbufInitStatic(&options->shell,
@@ -79,39 +79,31 @@ void ffDestroyCommandOptions(FFCommandOptions* options)
ffStrbufDestroy(&options->text);
}
void ffParseCommandJsonObject(yyjson_val* module)
void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module)
{
FFCommandOptions __attribute__((__cleanup__(ffDestroyCommandOptions))) options;
ffInitCommandOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "shell"))
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
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);
ffStrbufSetS(&options->shell, yyjson_get_str(val));
continue;
}
}
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);
bool ffParseCommandCommandOptions(FFCommandOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
FFstrbuf shell;
+18 -26
View File
@@ -30,7 +30,7 @@ void ffPrintCPU(FFCPUOptions* options)
{
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();
@@ -79,7 +79,7 @@ void ffPrintCPU(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);
options->temp = false;
}
@@ -105,33 +105,25 @@ void ffDestroyCPUOptions(FFCPUOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseCPUJsonObject(yyjson_val* module)
void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module)
{
FFCPUOptions __attribute__((__cleanup__(ffDestroyCPUOptions))) options;
ffInitCPUOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "temp"))
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
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);
options->temp = yyjson_get_bool(val);
continue;
}
}
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);
bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
bool temp;
+14 -22
View File
@@ -21,16 +21,16 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
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();
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(str.length > 0)
ffStrbufAppendC(&str, ' ');
ffAppendPercentNum(&str, (uint8_t) percentage, 50, 80, str.length > 0);
ffAppendPercentNum(&str, percentage, 50, 80, str.length > 0);
}
ffStrbufPutTo(&str, stdout);
}
@@ -44,7 +44,7 @@ void ffPrintCPUUsage(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);
}
@@ -63,27 +63,19 @@ void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseCPUUsageJsonObject(yyjson_val* module)
void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module)
{
FFCPUUsageOptions __attribute__((__cleanup__(ffDestroyCPUUsageOptions))) options;
ffInitCPUUsageOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
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);
bool ffParseCPUUsageCommandOptions(FFCPUUsageOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFCPUUsageOptions;
+12 -20
View File
@@ -28,7 +28,7 @@ void ffPrintCursor(FFCursorOptions* options)
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);
if(result.size.length > 0)
@@ -52,7 +52,7 @@ void ffPrintCursor(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);
}
@@ -71,27 +71,19 @@ void ffDestroyCursorOptions(FFCursorOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseCursorJsonObject(yyjson_val* module)
void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module)
{
FFCursorOptions __attribute__((__cleanup__(ffDestroyCursorOptions))) options;
ffInitCursorOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
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);
bool ffParseCursorCommandOptions(FFCursorOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFCursorOptions;
+13 -21
View File
@@ -12,14 +12,14 @@ void ffPrintCustom(FFCustomOptions* options)
return;
}
ffPrintLogoAndKey(options->moduleArgs.key.length == 0 ? NULL : FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor);
ffPrintUserString(options->moduleArgs.outputFormat.chars);
ffPrintLogoAndKey(options->moduleArgs.key.length == 0 ? NULL : FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&options->moduleArgs.outputFormat, stdout);
puts(FASTFETCH_TEXT_MODIFIER_RESET);
}
void ffInitCustomOptions(FFCustomOptions* options)
{
options->moduleName = FF_CUSTOM_MODULE_NAME;
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CUSTOM_MODULE_NAME, ffParseCustomCommandOptions, ffParseCustomJsonObject, ffPrintCustom);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -38,27 +38,19 @@ void ffDestroyCustomOptions(FFCustomOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseCustomJsonObject(yyjson_val* module)
void ffParseCustomJsonObject(FFCustomOptions* options, yyjson_val* module)
{
FFCustomOptions __attribute__((__cleanup__(ffDestroyCustomOptions))) options;
ffInitCustomOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
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);
bool ffParseCustomCommandOptions(FFCustomOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFCustomOptions;
+12 -20
View File
@@ -43,7 +43,7 @@ void ffPrintDateTime(FFDateTimeOptions* options)
}
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
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)
{
options->moduleName = FF_DATETIME_MODULE_NAME;
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DATETIME_MODULE_NAME, ffParseDateTimeCommandOptions, ffParseDateTimeJsonObject, ffPrintDateTime);
ffOptionInitModuleArg(&options->moduleArgs);
}
@@ -70,27 +70,19 @@ void ffDestroyDateTimeOptions(FFDateTimeOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseDateTimeJsonObject(yyjson_val* module)
void ffParseDateTimeJsonObject(FFDateTimeOptions* options, yyjson_val* module)
{
FFDateTimeOptions __attribute__((__cleanup__(ffDestroyDateTimeOptions))) options;
ffInitDateTimeOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
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);
bool ffParseDateTimeCommandOptions(FFDateTimeOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFDateTimeOptions;
+12 -20
View File
@@ -18,7 +18,7 @@ void ffPrintDE(FFDEOptions* options)
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);
@@ -42,7 +42,7 @@ void ffPrintDE(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);
}
@@ -61,27 +61,19 @@ void ffDestroyDEOptions(FFDEOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseDEJsonObject(yyjson_val* module)
void ffParseDEJsonObject(FFDEOptions* options, yyjson_val* module)
{
FFDEOptions __attribute__((__cleanup__(ffDestroyDEOptions))) options;
ffInitDEOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
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);
bool ffParseDECommandOptions(FFDEOptions* options, const char* key, const char* value);
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
{
const char* moduleName;
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
} FFDEOptions;
+61 -69
View File
@@ -34,8 +34,9 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
}
else
{
ffParseFormatString(&key, &options->moduleArgs.key, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->mountpoint}
ffParseFormatString(&key, &options->moduleArgs.key, 2, (FFformatarg[]){
{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();
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)
{
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();
@@ -57,7 +58,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
{
if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
{
ffAppendPercentBar(&str, bytesPercentage, 0, 5, 8);
ffAppendPercentBar(&str, bytesPercentage, 0, 50, 80);
ffStrbufAppendC(&str, ' ');
}
@@ -66,7 +67,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
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, ' ');
}
}
@@ -95,7 +96,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
bool isExternal = !!(disk->type & FF_DISK_TYPE_EXTERNAL_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, &totalPretty},
{FF_FORMAT_ARG_TYPE_UINT8, &bytesPercentage},
@@ -183,10 +184,9 @@ void ffPrintDisk(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);
ffStrbufInit(&options->folders);
@@ -259,69 +259,61 @@ void ffDestroyDiskOptions(FFDiskOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseDiskJsonObject(yyjson_val* module)
void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
{
FFDiskOptions __attribute__((__cleanup__(ffDestroyDiskOptions))) options;
ffInitDiskOptions(&options);
if (module)
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
{
yyjson_val *key_, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key_, val)
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
continue;
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
continue;
if (ffStrEqualsIgnCase(key, "folders"))
{
const char* key = yyjson_get_str(key_);
if(ffStrEqualsIgnCase(key, "type"))
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);
ffStrbufSetS(&options->folders, yyjson_get_str(val));
continue;
}
}
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);
}
}

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