Compare commits

...

217 Commits

Author SHA1 Message Date
Linus Dierheimer 779dbab647 Release 1.6.4 2022-08-22 00:13:13 +02:00
Linus Dierheimer 47373998d5 replace gethostbyname with getaddrinfo
#217
2022-08-21 23:35:22 +02:00
Linus Dierheimer 11809e30b5 Parse config files faster 2022-08-21 21:08:11 +02:00
Linus Dierheimer 35253e085c Unified storage of --set and --set-keyless values 2022-08-20 18:17:00 +02:00
Linus Dierheimer 112e83b7c3 Provide apk count to package format string 2022-08-18 22:02:21 +02:00
Linus Dierheimer c74b34aa39 Merge pull request #216 from mxkrsv/apk-support
Add APK (Alpine Package Keeper) support
2022-08-18 21:56:20 +02:00
Maxim Karasev b2e0034c34 Add APK (Alpine Package Keeper) support 2022-08-18 22:28:40 +03:00
Linus Dierheimer e3cdf9d9fd Reset color after custom module 2022-08-18 11:45:44 +02:00
Linus Dierheimer 6cdb694e33 Do simple \ replacement in user strings 2022-08-18 11:36:30 +02:00
Linus Dierheimer 83016289e9 --set-keyless option 2022-08-18 10:44:21 +02:00
Linus Dierheimer f9562d7132 Merge pull request #214 from jonathanspw/master
add AlmaLinux logo
2022-08-17 09:19:38 +02:00
jonathanspw 2f66bc2c95 add AlmaLinux logo 2022-08-16 20:10:47 -05:00
Linus Dierheimer d7c848225c Update CHANGELOG.md 2022-08-12 21:52:29 +02:00
Linus Dierheimer 8404ae8e70 Merge pull request #212 from ceamac/bugs/install-presets
Fix installation of presets/ directory
2022-08-12 21:50:49 +02:00
Viorel d75f72c8fe Fix installation of presets/ directory 2022-08-12 22:35:31 +03:00
Linus Dierheimer 9fa00081e3 Release 1.6.2 2022-08-12 16:01:52 +02:00
Linus Dierheimer fca37b59c8 Print xbps package count once again
#209
2022-08-12 09:40:02 +02:00
Linus Dierheimer 2fe7476c67 Better xbps package count
#209
2022-08-07 19:42:16 +02:00
Linus Dierheimer 03cbd64d8a Merge pull request #208 from hervyqa/langitketujuh
Add LangitKetujuh Linux logo
2022-08-03 13:03:06 +02:00
Hervy Qurrotul Ainur Rozi f65aeed96f Add LangitKetujuh Linux logo 2022-08-03 16:46:14 +07:00
Linus Dierheimer b63f419cde Merge pull request #207 from draumaz/master
Add KISS Linux logo
2022-08-02 15:14:41 +02:00
draumaz 99aa2f7b45 swap order 2022-08-02 12:29:44 +00:00
draumaz b251c32c12 fix colors, update README 2022-08-02 12:24:15 +00:00
draumaz 034e23d7e3 Merge branch 'LinusDierheimer:master' into master 2022-08-02 05:13:30 -07:00
Linus Dierheimer bba912d42e Add missing include 2022-08-02 10:24:54 +02:00
draumaz 597652c35a one more backslash 2022-08-02 05:56:20 +00:00
draumaz 7f67846ad9 add KISS Linux logo 2022-08-02 05:51:15 +00:00
Linus Dierheimer bc2e292e22 Update issue templates 2022-07-31 17:44:07 +02:00
Linus Dierheimer 75dc228120 Update issue templates 2022-07-31 17:39:54 +02:00
Linus Dierheimer bc783f6efd Update issue templates 2022-07-31 17:33:03 +02:00
Linus Dierheimer 85e1d2b40c Add logo request template 2022-07-31 17:31:30 +02:00
Linus Dierheimer 3338189354 Rosa Linux logo 2022-07-31 17:22:03 +02:00
Linus Dierheimer d4c836fd25 Handle empty xdg env vars better 2022-07-30 23:30:46 +02:00
Linus Dierheimer 6787f1eba8 Merge branches 'master' and 'master' of github.com:LinusDierheimer/fastfetch 2022-07-27 21:56:42 +02:00
Linus Dierheimer eedc277bcf Respect target dir config during installation 2022-07-27 21:56:28 +02:00
Linus Dierheimer d4b32eaaec Merge pull request #205 from licy183/fix-android-header
Fix build error on Android
2022-07-27 19:31:29 +02:00
Linus Dierheimer 910f63f0ad Update changelog 2022-07-27 19:31:14 +02:00
Linus Dierheimer 9a0aa2ac72 Fix compilation issues
1) when building for android
2) when building without wayland
2022-07-27 19:28:55 +02:00
Chongyun Lee dce81055fe Release 1.6.1 2022-07-28 01:28:17 +08:00
Chongyun Lee 66a4fc1600 Fix build error on Android
host.c has an #elif, but actually #else is needed.
2022-07-27 22:50:11 +08:00
Linus Dierheimer 159a114bb7 Release 1.6.0
tag correctly
2022-07-26 22:38:40 +02:00
Linus Dierheimer ac08b46e71 Release 1.6.0
this time with correct packaging the second
2022-07-26 22:27:13 +02:00
Linus Dierheimer ceb92dafd7 Release 1.6.0
this time with correct packaging
2022-07-26 22:13:09 +02:00
Linus Dierheimer 31eeb6dd08 Release 1.6.0 2022-07-26 20:35:15 +02:00
Linus Dierheimer c021689a2b Better nix package sorting
#195
2022-07-26 19:15:00 +02:00
Linus Dierheimer 2ac2762c9f Print nix-default packages
#195
2022-07-26 19:03:15 +02:00
Linus Dierheimer 27dd097671 Improved Nix package detection
#195
2022-07-26 18:36:10 +02:00
Linus Dierheimer c7bf471e29 Refactor: move vulkan detection to own header 2022-07-26 18:18:14 +02:00
Linus Dierheimer 298bc10e5f Refactor: move media detection to own header 2022-07-26 18:15:45 +02:00
Linus Dierheimer 676485ef74 Refactor: move temps detection to own header 2022-07-26 18:13:12 +02:00
Linus Dierheimer fb6da20b0c Refactor: move date/time detection to own header 2022-07-26 18:09:25 +02:00
Linus Dierheimer 0c81d3e894 Refactor: move terminal/shell detection to own header 2022-07-26 18:06:30 +02:00
Linus Dierheimer 5c1aa20042 Refactor: move wm/de detection to own header 2022-07-26 17:56:42 +02:00
Linus Dierheimer 46a27c4e39 Refactor: move gtk detection to own header 2022-07-26 17:47:08 +02:00
Linus Dierheimer 128302596e Refactor: move qt detection to own header 2022-07-26 17:42:28 +02:00
Linus Dierheimer 7a15dee2be Refactor: move os detection to own header 2022-07-26 17:33:51 +02:00
Linus Dierheimer 000bd37f1d Refactor: move title detection to own header 2022-07-26 17:29:09 +02:00
Linus Dierheimer 707e0f930d Refactor: don't include FFvaluestore global 2022-07-25 19:54:33 +02:00
Linus Dierheimer 7676a313c5 Refactor: move threading functions to init 2022-07-25 15:01:11 +02:00
Linus Dierheimer 6e0d76a2fb Refactor: move networking functions to own header 2022-07-25 14:48:59 +02:00
Linus Dierheimer 4c7b7e4a4d Refactor: move processing functions to own header 2022-07-25 14:45:41 +02:00
Linus Dierheimer 4d34091573 Refactor: move format functions to own header 2022-07-25 14:26:08 +02:00
Linus Dierheimer c971e28aca Refactor: move setting functions to own header 2022-07-25 14:20:07 +02:00
Linus Dierheimer c41a29a5c1 Refactor: move parsing functions to own header 2022-07-25 13:59:19 +02:00
Linus Dierheimer 5c73125693 Refactor: move font functions to own header 2022-07-25 13:44:55 +02:00
Linus Dierheimer cea48474a1 Refactor: move caching functions to own header 2022-07-25 13:36:58 +02:00
Linus Dierheimer 536f914f3e Refactor: move printing functions to own header 2022-07-25 13:15:01 +02:00
Linus Dierheimer 778856dd57 Refactor: move property functions to own header 2022-07-25 12:24:23 +02:00
Linus Dierheimer 4a43144991 Refactor: move io functions to own header 2022-07-25 11:48:48 +02:00
Linus Dierheimer ac96cfc748 Refactor: move FFInitState to settings.c 2022-07-25 11:24:50 +02:00
Linus Dierheimer f18ffe3239 Refactor: move library functions and macros to own header 2022-07-25 11:20:38 +02:00
Linus Dierheimer 986bbeebb3 Don't segfault if invalid structure is given
#204
2022-07-25 11:00:41 +02:00
Linus Dierheimer b9d360af97 --title-fqdn option
#203
2022-07-22 19:36:00 +02:00
Linus Dierheimer ec1981c545 Use [QT] instead of [Plasma]
#198 #199
2022-07-22 17:18:36 +02:00
Linus Dierheimer f7e7d8e9f2 Update README.md 2022-07-22 13:42:26 +02:00
Linus Dierheimer ad9fc5845a GTK: Fix detection on XFCE DE
#198 #199
2022-07-22 12:23:35 +02:00
Linus Dierheimer a6b169f3e2 Disk: Print one decimal point if < 100GiB
#202
2022-07-22 11:47:20 +02:00
Linus Dierheimer 8aff9939bc GTK: prefer dconf over config files on certain DEs
#198 #199
2022-07-22 11:24:29 +02:00
Linus Dierheimer 0b8f51188b gh actions: configure correct path for packaging
the follow up
2022-07-21 22:58:38 +02:00
Linus Dierheimer 3c99a82619 gh actions: configure correct path for packaging 2022-07-21 22:55:47 +02:00
Linus Dierheimer d5f3ff1cfe Update README.md 2022-07-21 20:20:40 +02:00
Linus Dierheimer 011c033091 Update README.md 2022-07-21 20:18:34 +02:00
Linus Dierheimer 63bf22fb00 Load system config
#196
2022-07-21 14:37:13 +02:00
Linus Dierheimer f74973db65 Special NixOS OS output
#194
2022-07-21 11:33:19 +02:00
Linus Dierheimer 85656fd515 Fix Mutter detection
#200
2022-07-20 21:32:17 +02:00
Linus Dierheimer 23bf7a407b Fix alacritty term font size
#197
2022-07-20 20:56:02 +02:00
Linus Dierheimer e570cacbc9 Fix typos
#201
2022-07-20 20:44:16 +02:00
Linus Dierheimer a96f79795b Merge pull request #193 from Izorkin/update-nixos-logo
Update old nixos logo
2022-07-19 12:09:25 +02:00
Izorkin 2d51d935c8 update old nixos logo 2022-07-19 12:57:15 +03:00
Linus Dierheimer 9d395f7235 don't print GPU in WSL 2022-07-17 16:11:08 +02:00
Linus Dierheimer 5f16394916 Add alacritty to readme 2022-07-12 16:49:39 +02:00
Linus Dierheimer 6581c9d378 Merge pull request #191 from x-zvf/alacritty-term-support
[enhancement] Add best effort terminal font detection for alacritty.
2022-07-12 16:46:22 +02:00
Péter Bohner (xzvf) 67ac7eef59 buxfix: missing fontSize/fontName would overwrite the other 2022-07-12 16:43:21 +02:00
Péter Bohner (xzvf) b95e83e9e5 Use ffStrbufAppend instead of ffStrbugInitCopy 2022-07-12 16:41:20 +02:00
Péter Bohner (xzvf) e9d9b942fa Cleanup diff 2022-07-12 16:34:35 +02:00
Péter Bohner (xzvf) c95ad74ea2 Refactor to use ffFontInitCopy and detect font size
printAlacritty now usese ffFontInitCopy instead of ffFontInitPango
and also detects font size.
2022-07-12 16:31:19 +02:00
Péter Bohner (xzvf) 85b0be5213 Add best effort terminal font detection for alacritty.
Alacritty's config files are technically YML files, so
simply looking for a prop value "family:" may break some of the time,
but is in fact better than what neofetch does and much easier
to implement then writing a YML parser :)
2022-07-12 14:38:06 +02:00
Linus Dierheimer da671d6cfe Start cleaning up of config struct 2022-07-10 18:28:17 +02:00
Linus Dierheimer 18af9ab902 Wayland: don't destroy proxies our self 2022-07-08 11:48:43 +02:00
Linus Dierheimer 558fbc20e2 Don't detect guake-wrapped as terminal 2022-07-08 11:24:11 +02:00
Linus Dierheimer d9bbbd4fa8 Merge pull request #189 from x-zvf/alacritty-term-support
Fix memory leak in ffParsePropFileValues
2022-07-08 10:46:11 +02:00
Péter Bohner (xzvf) 292a809703 ffParsePropValues: Hoisted fopen call to simplify error handling 2022-07-08 09:09:59 +02:00
Péter Bohner (xzvf) fa13826043 Revert "Coalesce cleanup in ffParsePropFileValues"
This reverts commit 7bc85b2397.
2022-07-08 09:05:00 +02:00
Péter Bohner (xzvf) 7bc85b2397 Coalesce cleanup in ffParsePropFileValues 2022-07-07 15:19:56 +02:00
Péter Bohner (xzvf) 1863d8377a Fix memory leak in ffParseProfFileValues, if more than 4 queries are passed (unsetValues is on the heap) and the file
is not found.
2022-07-07 14:35:59 +02:00
xzvf f9e17f44b1 Merge branch 'LinusDierheimer:master' into master 2022-07-04 20:10:01 +02:00
Linus Dierheimer 02cc214dfc Release 1.5.6
Bugfix: Don't segfault when connecting to some wayland compositors
See https://github.com/LinusDierheimer/fastfetch/issues/188
2022-07-03 16:16:39 +02:00
Linus Dierheimer 609fa14f4f Wayland: use a single, common stub listener 2022-07-03 16:10:17 +02:00
Linus Dierheimer 7d6f92a446 Wayland: only use required stub listeners 2022-06-30 12:22:46 +02:00
Linus Dierheimer bc76ebfb3f Wayland: add stub listeners 2022-06-30 12:16:38 +02:00
Linus Dierheimer c2da7b19f9 Song: Don't show album by default 2022-06-29 12:47:57 +02:00
Linus Dierheimer 41b024d3b1 Refactor wayland code the third 2022-06-29 11:08:42 +02:00
Linus Dierheimer 9b62d17d8d Refactor wayland code the second 2022-06-28 21:41:13 +02:00
Linus Dierheimer 1861d55f7d Refactor wayland code 2022-06-28 11:57:08 +02:00
Linus Dierheimer 3b2a6e4a6e Don't load sqlite3 id db path doesn't exist 2022-06-27 15:38:34 +02:00
Linus Dierheimer 8ab7a8ba37 Release 1.5.5
Feature: Detect wayland WM much faster
Bugfix: Wayland backend for resolution working once again
Bugfix: Plasma values are no longer victims to race conditions
2022-06-26 13:41:55 +02:00
Linus Dierheimer 22a3ab4a81 Detect wayland WM _much_ faster 2022-06-26 13:35:16 +02:00
Linus Dierheimer 44d6780545 Merge pull request #185 from artixnous/master
Fix misaligned Artix logo
2022-06-25 17:41:16 +02:00
nous 5820c9bbff Update builtin.c 2022-06-25 13:26:07 +03:00
Linus Dierheimer 3ba486a5b8 Wayland: switch to wl_proxy_marshal_constructor_versioned 2022-06-23 15:59:59 +02:00
Linus Dierheimer 2d2ba4c5b3 Wayland: switch to wl_proxy_marshal_flags 2022-06-23 15:51:29 +02:00
Linus Dierheimer 94ad782caa No unneeded casts 2022-06-23 10:44:53 +02:00
Linus Dierheimer b079e86c5e update bug_report.yml 2022-06-23 10:36:53 +02:00
Linus Dierheimer 91ba03d988 Add warning about public IP to bug_report.yml 2022-06-23 10:35:46 +02:00
Linus Dierheimer c440fdfca8 Uses instance->state.configDirs consistenlty (in particular thread save) troughout the project 2022-06-22 20:14:10 +02:00
Linus Dierheimer af0c72aa61 Methods for caching generic data 2022-06-20 16:35:15 +02:00
Linus Dierheimer 8fa09ca093 Refactored read methods 2022-06-20 16:27:33 +02:00
Linus Dierheimer 6e731c80d0 Refactored write methods 2022-06-19 18:22:00 +02:00
Linus Dierheimer 45eae78980 Better ordering in initCacheDir 2022-06-19 18:21:41 +02:00
Linus Dierheimer fb35a6e889 Release 1.5.4
Feature: Better WSL / WSLg support
Feature: --<module>-error arguments
Bugfix: Show GiB instad of GB
Feature: Export much more information to host format string
Feature: Expose CPU temp to cpu format string
Feature: Expose GPU temp to gpi format string
Bugfix: Print last line of logo, if it is higher than the infos
Logo: Alpine Linux
Refactor: Cleaned up header includes
Refactor: Build libfastfetch as OBJECT lib, as the linked binary is never needed
Feature: Detect termux as terminal
2022-06-18 23:39:48 +02:00
Linus Dierheimer 26d17250b6 Detect WSLg 2022-06-18 14:55:56 +02:00
Linus Dierheimer 9176797327 Detect Windows Terminal better 2022-06-18 14:51:10 +02:00
Linus Dierheimer 9d3f762c20 Better fallback for wayland detection 2022-06-18 15:27:46 +02:00
Linus Dierheimer fe71291769 Clean up includes 2022-06-18 14:25:31 +02:00
Linus Dierheimer f35dc9f46a Detect termux 2022-06-18 00:45:28 +02:00
Linus Dierheimer a6209187ae Fix build on Android part 4 2022-06-18 00:41:43 +02:00
Linus Dierheimer af2f97e0c9 Fix build on Android part 3 2022-06-18 00:22:07 +02:00
Linus Dierheimer 0691112e5e Fix build on Android part 2 2022-06-18 00:20:22 +02:00
Linus Dierheimer e61b31acab Fix build on Android 2022-06-18 00:15:23 +02:00
Linus Dierheimer 5d853f3b17 GPU temp detection 2022-06-17 23:38:33 +02:00
Linus Dierheimer 20e2f1e19d Detect CPU temp only if a custom format string is given 2022-06-17 20:41:11 +02:00
Linus Dierheimer ad28b3aac5 rename date-time to datetime 2022-06-17 20:40:51 +02:00
Linus Dierheimer eb0bbd0796 Detect WSL as host name 2022-06-17 20:01:02 +02:00
Linus Dierheimer da77a7936f Detect WSL as host 2022-06-17 19:59:01 +02:00
Linus Dierheimer eac875b8b1 Update bash completion to include --<module>-error options 2022-06-17 18:28:37 +02:00
Linus Dierheimer 97d2096df8 Delete performance test
I never really used it, and it didn't even build any more
2022-06-17 18:19:53 +02:00
Linus Dierheimer 6e3e717224 --<module>-error options 2022-06-17 18:15:36 +02:00
Linus Dierheimer aae182c889 Merge pull request #180 from draumaz/master
Add Alpine Linux logos
2022-06-17 10:44:54 +02:00
draumaz 5c7b9d223a Merge pull request #1 from draumaz/workbench
Merge Alpine Linux logos
2022-06-17 04:12:50 +00:00
draumaz c80f8cf422 further fixes 2022-06-16 21:11:14 -07:00
draumaz b150e8d106 whoops 2022-06-16 21:10:23 -07:00
draumaz bb897f03f0 add small logo 2022-06-16 21:08:39 -07:00
draumaz 517d80eadc update getAll function 2022-06-16 21:03:39 -07:00
draumaz 36964d6b1d Initial Alpine addition 2022-06-16 21:02:20 -07:00
Linus Dierheimer 5e96ba8384 Fix cpu temp detection the second 2022-06-16 14:55:02 +02:00
Linus Dierheimer 481affa50a Fix cpu temp detection 2022-06-16 14:39:01 +02:00
Linus Dierheimer a33e296656 Merge pull request #178 from Samisafool/patch-1
fix spelling of temperature
2022-06-16 14:17:07 +02:00
Samisafool 85a36ae7ef fix spelling of temperature 2022-06-16 17:10:59 +05:30
Linus Dierheimer 1eff343733 Finish exposing temperatur to cpu format 2022-06-16 13:36:00 +02:00
Linus Dierheimer acdbf6933c Merge pull request #177 from x-zvf/feature-cpu-temp
Add CPU package temperature to CPU module.
2022-06-16 13:21:34 +02:00
xzvf ea53833466 Remove unnecessary checks for content->length 2022-06-16 13:18:38 +02:00
xzvf c491c11988 update DEVELOPMENT.md 2022-06-16 13:15:48 +02:00
xzvf dcaeab7e96 Rewrite to use ffDetectTemps. 2022-06-16 13:14:03 +02:00
xzvf bccd1cf960 Merge pull request #1 from LinusDierheimer/master
build temps file
2022-06-16 13:14:03 +02:00
xzvf 5b030de20a Quality of life improvement: make run.sh not run ff, if the build fails 2022-06-16 13:14:03 +02:00
xzvf fa9b38eb2d Merge pull request #1 from LinusDierheimer/master
build temps file
2022-06-16 12:54:28 +02:00
Linus Dierheimer 716522e29a build temps file 2022-06-15 23:15:49 +02:00
Linus Dierheimer 921e4a6c8d Merge pull request #176 from x-zvf/fix-run-sh-script
Quality of life improvement: make run.sh not run ff, if the build fails
2022-06-15 16:43:59 +02:00
xzvf 7d43118abb Quality of life improvement: make run.sh not run ff, if the build fails 2022-06-15 16:28:07 +02:00
xzvf d8bb36f119 Add CPU package temperature to CPU module.
This is done by looking for a specified thermal zone in
/sys/class/thermal/thermal_zone*/ .
Unfortunately there is no better way to find the
temperature, then to check all registered zones.
This still needs to be extended to support other hardware,
right now only x86 CPUs and Raspberry pi are tested.
Maybe the FF_CPU_THERMAL_ZONES array could be user configurable,
but I could not figure out how to add an array as a config parameter.
2022-06-15 16:21:50 +02:00
Linus Dierheimer ae8b5bde65 Fix printing of remaining logo 2022-06-15 11:07:22 +02:00
Linus Dierheimer 3d8a071781 Update verbose 2022-06-14 20:07:42 +02:00
Linus Dierheimer 4cf912e535 Disk: Change GB to GiB 2022-06-14 17:17:22 +02:00
Linus Dierheimer e1b5445783 Export much more values to host format string 2022-06-14 17:10:46 +02:00
Linus Dierheimer a04daf1fff Clean up git ignore 2022-06-13 21:28:49 +02:00
Linus Dierheimer df0a4c0d46 Remove unneeded property set from CMakeLists.txt 2022-06-11 14:17:10 +02:00
Linus Dierheimer d70e160d72 Merge branch 'master' of github.com:LinusDierheimer/fastfetch 2022-06-10 23:02:11 +02:00
Linus Dierheimer 8c52cd0d91 Change libfastfetch target to be OBJECT library 2022-06-10 23:01:56 +02:00
Linus Dierheimer 4622d7a300 Change libfatsfetch target to be OBJECT library 2022-06-10 22:58:35 +02:00
Linus Dierheimer 09f7180dd5 Merge pull request #169 from ADawesomeguy/patch-1
fix: correct "hout" to "hour"
2022-06-10 22:37:07 +02:00
Abheek Dhawan 6ae8b46f68 fix: correct "hout" to "hour" 2022-06-10 15:12:39 -05:00
Linus Dierheimer 2d0ffb55b7 Release 1.5.3
Enable LTO by default
Fix compile bug when LTO enabled
2022-06-08 17:18:02 +02:00
Linus Dierheimer 22a8cfdcfe Remove obsolete strbuf function 2022-06-08 17:14:11 +02:00
Linus Dierheimer 63041aa24b Enable link time optimization 2022-06-08 16:25:14 +02:00
Linus Dierheimer 242df5f2f0 Explicitly set c standard to 11 2022-06-08 15:52:55 +02:00
Linus Dierheimer ec1bbd118f Update README.md 2022-06-08 12:11:00 +02:00
Linus Dierheimer fe624123dc Merge pull request #168 from Yureien/master
Fix build if ImageMagick is not installed
2022-06-08 12:08:10 +02:00
Linus Dierheimer 8577be3d6d Update packaging section in README 2022-06-08 12:07:06 +02:00
Soham Sen d185dc74b8 Bumped version to 1.5.2 2022-06-08 15:32:52 +05:30
Soham Sen 54c09cab18 Fix build if ImageMagick is not installed 2022-06-08 15:22:34 +05:30
Linus Dierheimer dbe24c7508 Fix --print-logos 2022-06-08 11:28:26 +02:00
Linus Dierheimer d23d4ef5a0 Relase 1.5.0
Module: Vulkan
Module: OpenGL
Module: OpenCL
Feature: Detect Bedrock linux
Feature: Detect packages on Bedrock linux
Feature: --pipe option
Logo: Bedrock linux
Bugfix: Locale detection on Ubuntu and deriviates
Bugfix: bolt keys and title, if main color is not set
2022-06-08 11:17:08 +02:00
Linus Dierheimer daac1b783c Refactored logo choosing logic 2022-06-08 10:59:33 +02:00
Linus Dierheimer 2e98dd7710 Move ffPrintLogoAndKey to printing.c 2022-06-06 14:30:06 +02:00
Linus Dierheimer 9d6d2ca5a4 Add osmesa to help texts 2022-06-06 14:24:14 +02:00
Linus Dierheimer e4a1a836fe Fix keys not being bolt if main color is not set 2022-06-06 14:20:05 +02:00
Linus Dierheimer 1e3cabff2d --pipe option 2022-06-06 14:02:21 +02:00
Linus Dierheimer 008cf3b83d OpenCL module 2022-06-05 00:18:40 +02:00
Linus Dierheimer 3daede53eb Don't cache OS 2022-06-04 22:43:57 +02:00
Linus Dierheimer 36d9b5a9bd Finish OpenGL module 2022-06-04 19:30:26 +02:00
Linus Dierheimer 1826e23c29 OpenGL module 2022-06-04 15:21:34 +02:00
Linus Dierheimer 43b3998b9d Fix bedrock linux detection 2022-06-03 01:48:50 +02:00
Linus Dierheimer c55cc9c732 ffParsePropFileValues: only allocate storage on the heap if numQuerys > 4 2022-06-03 00:24:53 +02:00
Linus Dierheimer 0244e5ebd7 removed unused code 2022-06-02 23:24:50 +02:00
Linus Dierheimer ea6805de82 Escape bedrock option 2022-06-02 23:06:49 +02:00
Linus Dierheimer 9aba57cdea Bedrock package support 2022-06-02 22:58:19 +02:00
Linus Dierheimer 0dffd8debf Vulkan module 2022-06-01 00:04:58 +02:00
Linus Dierheimer 032ba375b6 Enable chafa only if ImageMagick is found 2022-05-29 16:23:56 +02:00
Linus Dierheimer 743bc07bad Correctly detect locale on ubuntu systems 2022-05-29 16:17:36 +02:00
Linus Dierheimer 044e5496fd Fix bedrock logo 2022-05-25 14:28:08 +02:00
Linus Dierheimer 102b2d33c7 Bedrock linux detection 2022-05-25 14:06:59 +02:00
Linus Dierheimer afc144fa01 Merge branch 'master' of github.com:LinusDierheimer/fastfetch 2022-05-25 14:00:36 +02:00
Linus Dierheimer ededa4d6dd Bedrock linux logo 2022-05-25 14:00:18 +02:00
Linus Dierheimer af4596b666 Bedrock linux 2022-05-25 13:59:40 +02:00
Linus Dierheimer 8c910089cc Detect KDE plasma version more reliable 2022-05-24 13:58:38 +02:00
Linus Dierheimer e79af7ba79 Relase 1.4.2
Bugfix: RPM package count on SUSE platforms
Bugfix: Prepend /var with TARGET_DIR_ROOT
2022-05-24 13:41:23 +02:00
Linus Dierheimer 960364bd47 Use librpm as rpm fallback 2022-05-24 13:36:33 +02:00
125 changed files with 4737 additions and 2493 deletions
+3 -1
View File
@@ -25,6 +25,9 @@ Output of `fastfetch --load-config devinfo`:
```
Output of `fastfetch --load-config devinfo-verbose`:
<!--
Note that this output will contain you public IP. If it is not relevant for the issue, feel free to remove it before uploading.
-->
```
//paste here
```
@@ -38,4 +41,3 @@ Output of `fastfetch --list-features`:
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 `fastfetch --show-errors --recache --multithreading false --disable-linewrap false`.
-->
+18
View File
@@ -0,0 +1,18 @@
---
name: Logo request
about: Request a new logo
title: ''
labels: logo request
assignees: ''
---
# OS
```
paste content of /etc/os-release here. If this file doesn't exist, describe a way to identify the distro.
```
# Ascii
```
paste ascii art here. If you leave this empty, i will try to find the logo myself.
```
+1 -1
View File
@@ -13,7 +13,7 @@ jobs:
uses: actions/checkout@v2
- name: install required packages
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev rpm librpm-dev libzstd-dev libegl-dev libglx-dev libosmesa6-dev ocl-icd-opencl-dev
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
+2 -2
View File
@@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v2
- name: install required packages
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev
run: sudo apt-get update && sudo apt-get install -y libpci-dev libvulkan-dev libwayland-dev libxrandr-dev libxcb-randr0-dev libdconf-dev libdbus-1-dev libmagickcore-dev libxfconf-0-dev libsqlite3-dev rpm librpm-dev libzstd-dev libegl-dev libglx-dev libosmesa6-dev ocl-icd-opencl-dev
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
@@ -24,7 +24,7 @@ jobs:
- name: configure project
# We reuse the build binary only for the releases.
# We set tweak version to off, because it is wrong, as git tag will happen after this step. Releases don't have a tweak, so this is ok.
run: cmake -DSET_TWEAK=Off -DBUILD_TESTS=On .
run: cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DCMAKE_INSTALL_PREFIX=/usr .
- name: build project
run: cmake --build . -j$(nproc) --target package
-2
View File
@@ -5,5 +5,3 @@
cscope.*
tags
fastfetch.kdev4
**/*.deb
packaging/deb/fastfetch
+57
View File
@@ -0,0 +1,57 @@
# 1.6.4
Releasing this, so fedora can package fastfetch. Thanks to @jonathanspw for doing that!
Features:
* --set-keyless option (#215)
* Replace `\n`, `\t`, `\e` and `\\` in user provided strings, just like c would do it (#215)
* APK (Alpine Package Keeper) support (@mxkrsv, #216)
Logos:
* Alma Linux (@jonathanspw, #214)
Bugfixes:
* replace deprecated gethostbyname call with getaddrinfo (#217)
# 1.6.3
Fixes installing presets in their own directory (@ceamac, #212)
# 1.6.2
Releasing this, so void linux can package fastfetch.
Logos:
* Rosa linux (#206)
* KISS linux (@draumaz, #207)
* LangitKetujuh (@hervyqa, #208)
Bugfixes:
* Using musl as libc does work now (#210)
* XBPS packages are once again printed (#209)
* configured target dirs are applied to install directories too
* empty XDG_* env vars don't cause a crash anymore
# 1.6.1
Fixes build on android (#205)
# 1.6.0
Features:
* Detect QT on more DEs than just KDE Plasma. The [Plasma] category was therefore renamed to [QT]
* Alacritty font detection
* Load `/etc/fastfetch/config.conf` before user config
* Disk: print one decimal point if size < 100GB
* `--title-fqdn` option, to print fully qualified domain name instead of host name in title
Logos:
* updated old NixOS logo
Bugfixes:
* Correctly detect GTK on DEs that store their settings in dconf
* Correctly detect NixOS packages
* Mutter WM detected once again
* Show full NixOS version in OS output
* Don't segfault if an invalid structure is given
* WSL doesn't output GPU anymore, as the name is always meaningless
+162 -68
View File
@@ -1,20 +1,13 @@
cmake_minimum_required(VERSION 3.1.0) # Threads::Threads
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs
project(fastfetch
VERSION 1.4.1
VERSION 1.6.4
LANGUAGES C
)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
# This is set to off by github actions for release builds
OPTION(SET_TWEAK "Add tweak to project version" ON)
# Also create test executables
OPTION(BUILD_TESTS "Build tests" OFF)
#####################
# Configure options #
#####################
OPTION(ENABLE_LIBPCI "Enable libpci" ON)
OPTION(ENABLE_VULKAN "Enable vulkan" ON)
@@ -28,19 +21,49 @@ OPTION(ENABLE_DCONF "Enable dconf" ON)
OPTION(ENABLE_DBUS "Enable dbus-1" ON)
OPTION(ENABLE_XFCONF "Enable libxfconf-0" ON)
OPTION(ENABLE_SQLITE3 "Enable sqlite3" ON)
OPTION(ENABLE_RPM "Enable rpm" ON)
OPTION(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON)
OPTION(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON)
OPTION(ENABLE_ZLIB "Enable zlib" ON)
OPTION(ENABLE_CHAFA "Enable chafa" ON)
OPTION(ENABLE_EGL "Enable egl" ON)
OPTION(ENABLE_GLX "Enable glx" ON)
OPTION(ENABLE_OSMESA "Enable osmesa" ON)
OPTION(ENABLE_OPENCL "Enable opencl" ON)
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
#############################
# Compile time dependencies #
#############################
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
####################
# Compiler options #
####################
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wconversion")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,-O3")
# These variables are mainly here for android, which has a different root fs structure.
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)
if(IPO_SUPPORTED)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
#######################
# Target FS structure #
#######################
if(NOT TARGET_DIR_ROOT)
if(NOT ANDROID)
set(TARGET_DIR_ROOT "")
@@ -65,15 +88,10 @@ if(NOT TARGET_DIR_HOME)
endif()
endif()
function(fastfetch_load_text FILENAME OUTVAR)
file(READ "${FILENAME}" TEMP)
string(REPLACE "\n" "\\n" TEMP "${TEMP}")
string(REPLACE "\"" "\\\"" TEMP "${TEMP}")
string(REPLACE "$\\" "" TEMP "${TEMP}")
set("${OUTVAR}" "${TEMP}" PARENT_SCOPE)
endfunction(fastfetch_load_text)
#################
# Tweak version #
#################
# Track commits between version bumps for output in --version
if (SET_TWEAK AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND git describe --tags
@@ -84,24 +102,42 @@ if (SET_TWEAK AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
string(REGEX MATCH "-[0-9]+" PROJECT_VERSION_TWEAK "${PROJECT_VERSION_TWEAK}")
endif()
#############
# Text data #
#############
function(fastfetch_load_text FILENAME OUTVAR)
file(READ "${FILENAME}" TEMP)
string(REPLACE "\n" "\\n" TEMP "${TEMP}")
string(REPLACE "\"" "\\\"" TEMP "${TEMP}")
string(REPLACE "$\\" "" TEMP "${TEMP}")
set("${OUTVAR}" "${TEMP}" PARENT_SCOPE)
endfunction(fastfetch_load_text)
fastfetch_load_text(src/data/structure.txt DATATEXT_STRUCTURE)
fastfetch_load_text(src/data/config.txt DATATEXT_CONFIG)
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/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)
fastfetch_load_text(src/data/help_config.txt DATATEXT_HELP_CONFIG)
######################
# Configure config.h #
######################
configure_file(src/fastfetch_config.h.in fastfetch_config.h)
# Init CMake targets
#######################
# libfastfetch target #
#######################
add_library(libfastfetch STATIC
add_library(libfastfetch OBJECT
src/util/FFstrbuf.c
src/util/FFlist.c
src/util/FFvaluestore.c
src/common/init.c
src/common/threading.c
src/common/io.c
src/common/printing.c
src/common/caching.c
@@ -119,11 +155,14 @@ add_library(libfastfetch STATIC
src/logo/image/im7.c
src/logo/image/im6.c
src/detection/os.c
src/detection/plasma.c
src/detection/qt.c
src/detection/gtk.c
src/detection/terminalShell.c
src/detection/vulkan.c
src/detection/media.c
src/detection/datetime.c
src/detection/temps.c
src/detection/title.c
src/detection/displayserver/displayServer.c
src/detection/displayserver/wayland.c
src/detection/displayserver/xcb.c
@@ -157,6 +196,7 @@ add_library(libfastfetch STATIC
src/modules/disk.c
src/modules/battery.c
src/modules/locale.c
src/modules/vulkan.c
src/modules/localip.c
src/modules/publicip.c
src/modules/player.c
@@ -165,6 +205,8 @@ add_library(libfastfetch STATIC
src/modules/date.c
src/modules/time.c
src/modules/colors.c
src/modules/opengl.c
src/modules/opencl.c
)
if(ENABLE_LIBPCI)
@@ -275,6 +317,15 @@ if(ENABLE_SQLITE3)
endif()
endif()
if(ENABLE_RPM)
pkg_check_modules(RPM rpm)
if(RPM_FOUND)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_RPM=1)
else()
message(WARNING "Package rpm not found. Building without support.")
endif()
endif()
if(ENABLE_IMAGEMAGICK7)
pkg_check_modules(IMAGEMAGICK7 MagickCore-7.Q16HDRI)
if(NOT IMAGEMAGICK7_FOUND)
@@ -323,11 +374,51 @@ if(ENABLE_ZLIB)
endif()
if(ENABLE_CHAFA)
pkg_check_modules(CHAFA chafa>=1.10)
if(CHAFA_FOUND)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_CHAFA=1)
if(IMAGEMAGICK6_FOUND OR IMAGEMAGICK7_FOUND)
pkg_check_modules(CHAFA chafa>=1.10)
if(CHAFA_FOUND)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_CHAFA=1)
else()
message(WARNING "Package chafa>=1.10 not found. Building without support.")
endif()
else()
message(WARNING "Package chafa>=1.10 not found. Building without support.")
message(WARNING "Chafa not enabled, because neither ImageMagick6 nor ImageMagick7 were found. Building without support.")
endif()
endif()
if(ENABLE_EGL)
pkg_check_modules(EGL egl)
if(EGL_FOUND)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_EGL=1)
else()
message(WARNING "Package egl not found. Building without support.")
endif()
endif()
if(ENABLE_GLX)
pkg_check_modules(GLX glx)
if(GLX_FOUND)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_GLX=1)
else()
message(WARNING "Package glx not found. Building without support.")
endif()
endif()
if(ENABLE_OSMESA)
pkg_check_modules(OSMESA osmesa)
if(OSMESA_FOUND)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_OSMESA=1)
else()
message(WARNING "Package osmesa not found. Building without support.")
endif()
endif()
if(ENABLE_OPENCL)
pkg_check_modules(OPENCL OpenCL)
if(OPENCL_FOUND)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_OPENCL=1)
else()
message(WARNING "Package opencl not found. Building without support.")
endif()
endif()
@@ -347,10 +438,16 @@ target_include_directories(libfastfetch
PRIVATE ${DBUS_INCLUDE_DIRS}
PRIVATE ${XFCONF_INCLUDE_DIRS}
PRIVATE ${SQLITE3_INCLUDE_DIRS}
PRIVATE ${RPM_INCLUDE_DIRS}
PRIVATE ${IMAGEMAGICK7_INCLUDE_DIRS}
PRIVATE ${IMAGEMAGICK6_INCLUDE_DIRS}
PRIVATE ${ZLIB_INCLUDE_DIRS}
PRIVATE ${CHAFA_INCLUDE_DIRS}
PRIVATE ${VULKAN_INCLUDE_DIRS}
PRIVATE ${EGL_INCLUDE_DIRS}
PRIVATE ${GLX_INCLUDE_DIRS}
PRIVATE ${OSMESA_INCLUDE_DIRS}
PRIVATE ${OPENCL_INCLUDE_DIRS}
)
target_link_libraries(libfastfetch
@@ -358,7 +455,9 @@ target_link_libraries(libfastfetch
PRIVATE Threads::Threads
)
set_target_properties(libfastfetch PROPERTIES OUTPUT_NAME "fastfetch")
######################
# Executable targets #
######################
add_executable(fastfetch
src/fastfetch.c
@@ -374,16 +473,11 @@ target_link_libraries(flashfetch
PRIVATE libfastfetch
)
# Testing
###################
# Testing targets #
###################
if (BUILD_TESTS)
add_executable(fastfetch-test-performance
tests/performance.c
)
target_link_libraries(fastfetch-test-performance
PRIVATE libfastfetch
)
add_executable(fastfetch-test-strbuf
tests/strbuf.c
)
@@ -395,39 +489,54 @@ if (BUILD_TESTS)
add_test(NAME test-strbuf COMMAND fastfetch-test-strbuf)
endif()
# Installation
##################
# install target #
##################
#https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT.html
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${TARGET_DIR_USR}" CACHE PATH "..." FORCE)
endif()
if(NOT CMAKE_INSTALL_SYSCONFDIR)
set(CMAKE_INSTALL_SYSCONFDIR "${TARGET_DIR_ROOT}/etc")
endif()
include(GNUInstallDirs)
install(
TARGETS fastfetch
DESTINATION ${CMAKE_INSTALL_BINDIR}
TARGETS fastfetch flashfetch
DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
install(
TARGETS flashfetch
DESTINATION ${CMAKE_INSTALL_BINDIR}
FILES "${CMAKE_SOURCE_DIR}/src/data/config_system.txt"
DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/${CMAKE_PROJECT_NAME}"
RENAME "config.conf"
)
install(
FILES completions/bash
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/bash-completion/completions
RENAME ${CMAKE_PROJECT_NAME}
FILES "${CMAKE_SOURCE_DIR}/completions/bash"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/bash-completion/completions"
RENAME "${CMAKE_PROJECT_NAME}"
)
install(
DIRECTORY presets
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${CMAKE_PROJECT_NAME}
DIRECTORY "${CMAKE_SOURCE_DIR}/presets"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${CMAKE_PROJECT_NAME}"
)
install(
FILES ./LICENSE
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/licenses/${CMAKE_PROJECT_NAME}
FILES "${CMAKE_SOURCE_DIR}/LICENSE"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${CMAKE_PROJECT_NAME}"
)
# Packaging
##################
# package target #
##################
set(CPACK_GENERATOR "DEB;RPM;TGZ;ZIP")
set(CPACK_SET_DESTDIR ON)
set(CPACK_PACKAGE_CONTACT "Linus Dierheimer <Linus@Dierheimer.de>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Neofetch clone written in C")
@@ -440,21 +549,6 @@ set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/LinusDierheimer")
set(CPACK_DEBIAN_PACKAGE_SECTION, "utils")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6")
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "\
libpci3, \
libvulkan1, \
libwayland-client0, \
libxcb-randr0, \
xcb, \
libxrandr2, \
libx11-6, \
libdconf1, \
libglib2.0-0, \
libdbus-1-3, \
libxfconf-0-3, \
libmagickcore-6.q16hdri-6, \
zlib1g \
")
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
-4
View File
@@ -11,11 +11,7 @@ Here i just add things that are easy to forget.
- `libffdetect`: contains all the detection stuff. To be used by anything that needs system information
- `libffprint`: contains the printing functions, logos, format etc
- `fastfetch` and `flashfetch`: Executables, that initialize the config of libffprint. Fist one at runtime, second one at compile time
- [ ] Support for printing images as ascii art logos (using imlib2 and libcaca probably)
- [ ] Better OS output for all possible combinations of /etc/os-release variables.
- [ ] Expose temperatures to CPU format string
- [ ] Expose temperatures to GPU format string
- [ ] Fallback GPU detection using GL (multi GPU suport somehow possible?)
- [ ] Find wayland compositor by looking at \${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY:-wayland-0}
- [ ] Make LocalIP module more configurable
- [ ] Automatic migrate old config files to newer versions
+33 -27
View File
@@ -19,33 +19,38 @@ There are some presets defined for fastfech in [`presets`](presets), you can can
Fastfetch dynamically loads needed libraries if they are available. Therefore its only hard dependencies are `libc` (any implementation of the c standard library), `libdl` and `libpthread`. They are all shipped with [`glibc`](https://www.gnu.org/software/libc/), which is already installed on most linux distributions, so you probably don't have to worry about it.
The following libraries are used if present at runtime:
* [`libpci`](https://github.com/pciutils/pciutils): GPU output.
* [`libvulkan`](https://www.vulkan.org/): Fallback for GPU output.
* [`libxcb-randr`](https://xcb.freedesktop.org/),
[`libXrandr`](https://gitlab.freedesktop.org/xorg/lib/libxrandr),
[`libxcb`](https://xcb.freedesktop.org/),
[`libX11`](https://gitlab.freedesktop.org/xorg/lib/libx11): At least one of them sould be present in X11 sessions for better resolution detection and faster WM detection. The `*randr` ones provide multi monitor support. The `libxcb*` ones usually have better performance.
* [`libwayland-client`](https://wayland.freedesktop.org/): Better resolution performance and output in wayland sessions. Supports different refresh rates per monitor.
* [`libGIO`](https://developer.gnome.org/gio/unstable/): Needed for values that are only stored GSettings.
* [`libDConf`](https://developer.gnome.org/dconf/unstable/): Needed for values that are only stored in DConf + Fallback for GSettings.
* [`libmagickcore` (ImageMagick)](https://www.imagemagick.org/): Images in terminal using sixel or kitty graphics protocol.
* [`libchafa`](https://github.com/hpjansson/chafa): Image output as ascii art.
* [`libZ`](https://www.zlib.net/): Faster image output when using kitty graphics protocol.
* [`libDBus`](https://www.freedesktop.org/wiki/Software/dbus): Needed for detecting current media player and song.
* [`libXFConf`](https://gitlab.xfce.org/xfce/xfconf): Needed for XFWM theme and XFCE Terminal font.
* [`libsqlite3`](https://www.sqlite.org/index.html): Needed for rpm package count.
* [`libpci`](https://github.com/pciutils/pciutils): GPU output.
* [`libvulkan`](https://www.vulkan.org/): Vulkan module & fallback for GPU output.
* [`libxcb-randr`](https://xcb.freedesktop.org/),
[`libXrandr`](https://gitlab.freedesktop.org/xorg/lib/libxrandr),
[`libxcb`](https://xcb.freedesktop.org/),
[`libX11`](https://gitlab.freedesktop.org/xorg/lib/libx11): At least one of them sould be present in X11 sessions for better resolution detection and faster WM detection. The `*randr` ones provide multi monitor support The `libxcb*` ones usually have better performance.
* [`libwayland-client`](https://wayland.freedesktop.org/): Better resolution performance and output in wayland sessions. Supports different refresh rates per monitor.
* [`libGIO`](https://developer.gnome.org/gio/unstable/): Needed for values that are only stored GSettings.
* [`libDConf`](https://developer.gnome.org/dconf/unstable/): Needed for values that are only stored in DConf + Fallback for GSettings.
* [`libmagickcore` (ImageMagick)](https://www.imagemagick.org/): Images in terminal using sixel or kitty graphics protocol.
* [`libchafa`](https://github.com/hpjansson/chafa): Image output as ascii art.
* [`libZ`](https://www.zlib.net/): Faster image output when using kitty graphics protocol.
* [`libDBus`](https://www.freedesktop.org/wiki/Software/dbus): Needed for detecting current media player and song.
* [`libEGL`](https://www.khronos.org/registry/EGL/),
[`libGLX`](https://dri.freedesktop.org/wiki/GLX/),
[`libOSMesa`](https://docs.mesa3d.org/osmesa.html): At least one of them is needed by the OpenGL module for gl context creation.
* [`libOpenCL`](https://www.khronos.org/opencl/): OpenCL module
* [`libXFConf`](https://gitlab.xfce.org/xfce/xfconf): Needed for XFWM theme and XFCE Terminal font.
* [`libsqlite3`](https://www.sqlite.org/index.html): Needed for rpm package count.
* [`librpm`](http://rpm.org/): Slower fallback for rpm package count. Needed on openSUSE.
## Support status
All categories not listed here should work without needing a specific implementation.
##### Available Modules
```
Title, Separator, OS, Host, Kernel, Uptime, Processes, Packages, Shell, Resolution, DE, WM, WMTheme, Theme, Icons, Font, Cursor, Terminal, Terminal Font, CPU, CPUUsage, GPU, Memory, Disk, Battery, Player, Song, LocalIP, PublicIP, DateTime, Date, Time, Locale, Colors, Break, Custom
Title, Separator, OS, Host, Kernel, Uptime, Processes, Packages, Shell, Resolution, DE, WM, WMTheme, Theme, Icons, Font, Cursor, Terminal, Terminal Font, CPU, CPUUsage, GPU, Memory, Disk, Battery, Player, Song, Vulkan, OpenGL, OpenCL, LocalIP, PublicIP, DateTime, Date, Time, Locale, Colors, Break, Custom
```
##### Logos
```
Android, Arch, Arco, Artix, CachyOS, CentOS, Debian, Devuan, Deepin, Endeavour, Fedora, Garuda, Gentoo, KDE Neon, Kubuntu, Linux, Manjaro, Mint, NixOS, OpenSUSE, OpenSUSE Tumbleweed, OpenSUSE LEAP, Pop!_OS, RebornOS, RedstarOS, Rocky, Ubuntu, Void, Zorin
AlmaLinux, Alpine, Android, Arch, Arco, Artix, Bedrock, CachyOS, CentOS, Debian, Devuan, Deepin, Endeavour, Fedora, Garuda, Gentoo, KDE Neon, KISS, Kubuntu, LangitKetujuh, Linux, Manjaro, Mint, NixOS, OpenSUSE, OpenSUSE Tumbleweed, OpenSUSE LEAP, Pop!_OS, RebornOS, RedstarOS, Rocky, Rosa, Ubuntu, Void, Zorin
```
* Most of the logos have a small variant. Access it by appending _small to the logo name.
* Some logos have an old variant. Access it by appending _old to the logo name.
@@ -55,7 +60,7 @@ Android, Arch, Arco, Artix, CachyOS, CentOS, Debian, Devuan, Deepin, Endeavour,
##### Package managers
```
Pacman, dpkg, rpm, emerge, xbps, nix, Flatpak, Snap
Pacman, dpkg, rpm, emerge, xbps, nix, Flatpak, Snap, apk
```
##### WM themes
@@ -70,7 +75,7 @@ KDE Plasma, Gnome, Cinnamon, Mate, XFCE4, LXQt
##### Terminal fonts
```
konsole, gnome-terminal-server, tilix, xfce4-terminal, lxterminal, TTY
konsole, gnome-terminal-server, tilix, xfce4-terminal, alacritty, lxterminal, TTY
```
## Building
@@ -80,20 +85,21 @@ fastfetch uses [`cmake`](https://cmake.org/) and [`pkg-config`](https://www.free
mkdir -p build
cd build
cmake ..
cmake --build . -j$(nproc) --target fastfetch --target flashfetch
cmake --build . --target fastfetch --target flashfetch
```
If pkg-config fails to find the headers for a library listed in [dependencies](#dependencies), fastfetch will simply build without support for that specific feature. This means, it won't look for it at runtime and just act like it isn't available.
## Packaging
* [AUR](https://aur.archlinux.org/packages/fastfetch-git/): Packaged by me. Will install the fastfetch binary, bash completion and the presets. Git version
* [Manjaro Repositories](https://gitlab.manjaro.org/packages/community/fastfetch): Packaged by a manjaro maintainer. Usually a bit outdated.
* [Gentoo (Guru)](https://github.com/gentoo/guru/tree/master/app-misc/fastfetch): Packed by some other guy. May be out of date some times.
* DEB / RPM: Run `cmake -B build && cmake --build build --target package` to build the packages in build.
* Manually:
* Build: Follow the [build instructions](#building).
* Install: `sudo cmake --install build --prefix /usr/local`
### Repositories
[![Packaging status](https://repology.org/badge/vertical-allrepos/fastfetch.svg?header=)](https://repology.org/project/fastfetch/versions)
### Manual
* DEB / RPM package: `cmake --build . --target package`
* Install directly: `cmake --install . --prefix /usr/local`
## FAQ
+53 -1
View File
@@ -108,7 +108,8 @@ __fastfetch_completion()
"--list-presets"
"--list-features"
"--print-logos"
"--print-config"
"--print-config-system"
"--print-config-user"
"--print-structure"
)
@@ -130,6 +131,9 @@ __fastfetch_completion()
"--localip-show-ipv4"
"--localip-show-ipv6"
"--localip-show-loop"
"--escape-bedrock"
"--pipe"
"--title-fqdn"
)
local FF_OPTIONS_STRING=(
@@ -152,6 +156,8 @@ __fastfetch_completion()
"-s"
"--structure"
"--set"
"--set-keyless"
"--gl"
"--os-format"
"--os-key"
"--host-format"
@@ -216,6 +222,47 @@ __fastfetch_completion()
"--date-key"
"--time-format"
"--time-key"
"--vulkan-key"
"--vulkan-format"
"--opengl-key"
"--opengl-format"
"--opencl-key"
"--opencl-format"
"--os-error"
"--host-error"
"--kernel-error"
"--uptime-error"
"--processes-error"
"--packages-error"
"--shell-error"
"--resolution-error"
"--de-error"
"--wm-error"
"--wm-theme-error"
"--theme-error"
"--icons-error"
"--font-error"
"--cursor-error"
"--terminal-error"
"--terminal-font-error"
"--cpu-error"
"--cpu-usage-error"
"--gpu-error"
"--memory-error"
"--disk-error"
"--battery-error"
"--locale-error"
"--disk-error"
"--local-ip-error"
"--public-ip-error"
"--player-error"
"--song-error"
"--datetime-error"
"--date-error"
"--time-error"
"--vulkan-error"
"--opengl-error"
"--opencl-error"
)
local FF_OPTIONS_PATH=(
@@ -232,9 +279,14 @@ __fastfetch_completion()
"--lib-DBus"
"--lib-XFConf"
"--lib-sqlite3"
"--lib-rpm"
"--lib-imagemagick"
"--lib-z"
"--lib-chafa"
"--lib-egl"
"--lib-glx"
"--lib-osmesa"
"--lib-opencl"
"--battery-dir"
"--load-config"
)
+1 -1
View File
@@ -1 +1 @@
--structure Title:Separator:OS:Host:Kernel:Uptime:Processes:Packages:Shell:Resolution:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:GPU:Memory:Disk:Battery:Player:Song:PublicIP:LocalIP:DateTime:Locale:Break:Colors
--structure Title:Separator:OS:Host:Kernel:Uptime:Processes:Packages:Shell:Resolution:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:GPU:Memory:Disk:Battery:Player:Song:PublicIP:LocalIP:DateTime:Locale:Vulkan:OpenGL:OpenCL:Break:Colors
+6 -3
View File
@@ -1,7 +1,7 @@
--load-config all
--os-format "System: {}; Name: {}; Pretty name: {}; ID: {}; ID like: {}; Variant: {}; Variant ID: {}; Version: {}; Version ID: {}; Version codename: {}; Build ID: {}; Architecture: {}"
--host-format "Family: {}; Name: {}; Version: {}"
--host-format "Family: "product_family: {}; product_name: {}; product_version: {}; product_sku: {}; bios_date: {}; bios_release: {}; bios_vendor: {}; bios_version: {}; board_name: {}; board_vendor: {}; board_version: {}; chassis_type: {}; chassis_vendor: {}; chassis_version: {}; sys_vendor: {}"
--kernel-format "Sysname: {}; Release: {}; Version: {}"
--uptime-format "Days: {}; Hours: {}; Minutes: {}; Seconds: {}"
--processes-format "Count: {}"
@@ -17,12 +17,15 @@
--cursor-format "Theme: {}; Size: {}"
--terminal-format "Process: {}; Path: {}; Exe: {}"
--terminal-font-format "Raw: {}; Name: {}; Size: {}; Styles: {}; Pretty: {}"
--cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; bios: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}"
--cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; temperature: {}; bios: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}"
--cpu-usage-format "Percentage: {}"
--gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}"
--gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}; Temperature: {}"
--memory-format "Used: {}; Total: {}; Percentage: {}"
--disk-format "Used: {}; Total: {}; Files: {}; Percentage: {}"
--battery-format "Manufactor: {}; Model: {}; Technology: {}; Capacaty: {}; Status: {}"
--player-format "Name: {}"
--song-format "Song: {}; Artist: {}; Album: {}"
--datetime-format "year: {}; yearShort: {}; month: {}; monthPretty: {}; monthName: {}; monthNameShort: {}; weekNumber: {}; weekday: {}; weekdayShort: {}; dayInYear: {}; dayInMonth: {}; dayInWeek: {}; hour: {}; hourPretty: {}; hour12: {}; hour12Pretty: {}; minute: {}; minutePretty: {}; second: {}; secondPretty: {}"
--vulkan-format "driver: {}; Api Version: {}; Conformance Version: {}"
--opengl-format "version: {}; renderer: {}; vendor: {}"
--opencl-format "version: {}; device: {}; vendor: {}"
+5
View File
@@ -1,4 +1,9 @@
#!/bin/env sh
# make the script exit if any of the commands fail,
# making fastfetch not run if the build failed.
set -e
mkdir -p build/
cd build/
cmake ..
+46 -20
View File
@@ -1,9 +1,16 @@
#include "fastfetch.h"
#include "common/caching.h"
#include "common/io.h"
#include "common/printing.h"
#include <stdlib.h>
#define FF_CACHE_VALUE_EXTENSION "ffcv"
#define FF_CACHE_SPLIT_EXTENSION "ffcs"
static void getCacheFilePath(FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer)
#define FF_CACHE_EXTENSION_DATA "ffcd"
static void getCacheFilePath(const FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer)
{
ffStrbufAppend(buffer, &instance->state.cacheDir);
ffStrbufAppendS(buffer, moduleName);
@@ -20,7 +27,7 @@ static void readCacheFile(FFinstance* instance, const char* moduleName, const ch
FFstrbuf path;
ffStrbufInitA(&path, 64);
getCacheFilePath(instance, moduleName, extension, &path);
ffAppendFileContent(path.chars, buffer);
ffAppendFileBuffer(path.chars, buffer);
ffStrbufDestroy(&path);
}
@@ -29,15 +36,12 @@ static void writeCacheFile(FFinstance* instance, const char* moduleName, const c
FFstrbuf path;
ffStrbufInitA(&path, 64);
getCacheFilePath(instance, moduleName, extension, &path);
ffWriteFileContent(path.chars, content);
ffWriteFileBuffer(path.chars, content);
ffStrbufDestroy(&path);
}
void ffCacheValidate(FFinstance* instance)
{
if(instance->config.recache)
return;
FFstrbuf content;
ffStrbufInit(&content);
readCacheFile(instance, "cacheversion", "ffv", &content);
@@ -80,7 +84,7 @@ void ffCacheClose(FFcache* cache)
fclose(cache->split);
}
static bool printCachedValue(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat)
static bool printCachedValue(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs)
{
FFstrbuf content;
ffStrbufInitA(&content, 512);
@@ -98,7 +102,7 @@ static bool printCachedValue(FFinstance* instance, const char* moduleName, const
{
uint32_t nullByteIndex = ffStrbufNextIndexC(&content, startIndex, '\0');
uint8_t moduleIndex = (moduleCounter == 1 && nullByteIndex == content.length) ? 0 : moduleCounter;
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
ffPrintLogoAndKey(instance, moduleName, moduleIndex, &moduleArgs->key);
puts(content.chars + startIndex);
startIndex = nullByteIndex + 1;
++moduleCounter;
@@ -109,7 +113,7 @@ static bool printCachedValue(FFinstance* instance, const char* moduleName, const
return moduleCounter > 1;
}
static bool printCachedFormat(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numArgs)
static bool printCachedFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs)
{
FFstrbuf content;
ffStrbufInitA(&content, 512);
@@ -137,7 +141,7 @@ static bool printCachedFormat(FFinstance* instance, const char* moduleName, cons
if(argumentCounter == numArgs)
{
uint8_t moduleIndex = (moduleCounter == 1 && nullByteIndex == content.length) ? 0 : moduleCounter;
ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, formatString, NULL, numArgs, arguments);
ffPrintFormat(instance, moduleName, moduleIndex, moduleArgs, numArgs, arguments);
++moduleCounter;
argumentCounter = 0;
}
@@ -151,27 +155,27 @@ static bool printCachedFormat(FFinstance* instance, const char* moduleName, cons
return moduleCounter > 1;
}
bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numArgs)
bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs)
{
if(instance->config.recache)
return false;
if(formatString == NULL || formatString->length == 0)
return printCachedValue(instance, moduleName, customKeyFormat);
if(moduleArgs->outputFormat.length == 0)
return printCachedValue(instance, moduleName, moduleArgs);
else
return printCachedFormat(instance, moduleName, customKeyFormat, formatString, numArgs);
return printCachedFormat(instance, moduleName, moduleArgs, numArgs);
}
void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, FFcache* cache, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments)
void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFcache* cache, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments)
{
if(formatString == NULL || formatString->length == 0)
if(moduleArgs->outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
ffPrintLogoAndKey(instance, moduleName, moduleIndex, &moduleArgs->key);
ffStrbufPutTo(value, stdout);
}
else
{
ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, formatString, NULL, numArgs, arguments);
ffPrintFormat(instance, moduleName, moduleIndex, moduleArgs, numArgs, arguments);
}
if(cache->value != NULL)
@@ -194,10 +198,32 @@ void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8
}
}
void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments)
void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments)
{
FFcache cache;
ffCacheOpenWrite(instance, moduleName, &cache);
ffPrintAndAppendToCache(instance, moduleName, 0, customKeyFormat, &cache, value, formatString, numArgs, arguments);
ffPrintAndAppendToCache(instance, moduleName, 0, moduleArgs, &cache, value, numArgs, arguments);
ffCacheClose(&cache);
}
void ffCachingWriteData(const FFinstance* instance, const char* moduleName, size_t dataSize, const void* data)
{
FFstrbuf path;
ffStrbufInitA(&path, 128);
getCacheFilePath(instance, moduleName, FF_CACHE_EXTENSION_DATA, &path);
ffWriteFileData(path.chars, dataSize, data);
ffStrbufDestroy(&path);
}
bool ffCachingReadData(const FFinstance* instance, const char* moduleName, size_t dataSize, void* data)
{
if(instance->config.recache)
return false;
FFstrbuf path;
ffStrbufInitA(&path, 128);
getCacheFilePath(instance, moduleName, FF_CACHE_EXTENSION_DATA, &path);
ssize_t result = ffReadFileData(path.chars, dataSize, data);
ffStrbufDestroy(&path);
return result > 0 && (size_t) result == dataSize;
}
+27
View File
@@ -0,0 +1,27 @@
#pragma once
#ifndef FF_INCLUDED_common_caching
#define FF_INCLUDED_common_caching
#include "fastfetch.h"
#include "common/format.h"
typedef struct FFcache
{
FILE* value;
FILE* split;
} FFcache;
void ffCacheValidate(FFinstance* instance);
void ffCacheOpenWrite(FFinstance* instance, const char* moduleName, FFcache* cache);
void ffCacheClose(FFcache* cache);
bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs);
void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFcache* cache, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments);
void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments);
void ffCachingWriteData(const FFinstance* instance, const char* moduleName, size_t dataSize, const void* data);
bool ffCachingReadData(const FFinstance* instance, const char* moduleName, size_t dataSize, void* data);
#endif
+10 -1
View File
@@ -1,4 +1,5 @@
#include "fastfetch.h"
#include "common/font.h"
#include <string.h>
@@ -188,13 +189,21 @@ void ffFontInitPango(FFfont* font, const char* data)
fontInitPretty(font);
}
void ffFontInitCopy(FFfont* font, const char* name)
void ffFontInitValues(FFfont* font, const char* name, const char* size)
{
fontInit(font);
ffStrbufAppendS(&font->name, name);
ffStrbufAppendS(&font->size, size);
fontInitPretty(font);
}
void ffFontInitCopy(FFfont* font, const char* name)
{
ffFontInitValues(font, name, NULL);
}
void ffFontDestroy(FFfont* font)
{
ffStrbufDestroy(&font->pretty);
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#ifndef FF_INCLUDED_common_font
#define FF_INCLUDED_common_font
#include "util/FFstrbuf.h"
#include "util/FFlist.h"
typedef struct FFfont
{
FFstrbuf pretty;
FFstrbuf name;
FFstrbuf size;
FFlist styles;
} FFfont;
void ffFontInitQt(FFfont* font, const char* data);
void ffFontInitPango(FFfont* font, const char* data);
void ffFontInitCopy(FFfont* font, const char* name);
void ffFontInitValues(FFfont* font, const char* name, const char* size);
void ffFontDestroy(FFfont* font);
#endif
+3 -33
View File
@@ -1,4 +1,5 @@
#include "fastfetch.h"
#include "common/format.h"
void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg)
{
@@ -32,15 +33,6 @@ void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg)
}
}
static inline bool placeholderValueIsForError(const FFstrbuf* placeholderValue)
{
return
ffStrbufIgnCaseCompS(placeholderValue, "e") == 0 ||
ffStrbufIgnCaseCompS(placeholderValue, "error") == 0 ||
ffStrbufIgnCaseCompS(placeholderValue, "0") == 0
;
}
static inline uint32_t getArgumentIndex(const FFstrbuf* placeholderValue)
{
uint32_t result = UINT32_MAX;
@@ -72,6 +64,7 @@ static inline bool formatArgSet(const FFformatarg* arg)
{
return arg->value != NULL && (
(arg->type == FF_FORMAT_ARG_TYPE_DOUBLE && *(double*)arg->value > 0) ||
(arg->type == FF_FORMAT_ARG_TYPE_DOUBLE && *(double*)arg->value == *(double*)arg->value) || //NaN
(arg->type == FF_FORMAT_ARG_TYPE_INT && *(int*)arg->value > 0) ||
(arg->type == FF_FORMAT_ARG_TYPE_STRBUF && ((FFstrbuf*)arg->value)->length > 0) ||
(arg->type == FF_FORMAT_ARG_TYPE_STRING && *(const char*)arg->value != '\0') ||
@@ -81,7 +74,7 @@ static inline bool formatArgSet(const FFformatarg* arg)
);
}
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments)
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t numArgs, const FFformatarg* arguments)
{
uint32_t argCounter = 0;
@@ -128,13 +121,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFst
while(i < formatstr->length && formatstr->chars[i] != '}')
ffStrbufAppendC(&placeholderValue, formatstr->chars[i++]);
// test for error, if so print it
if(placeholderValueIsForError(&placeholderValue)) {
ffStrbufAppend(buffer, error);
ffStrbufDestroy(&placeholderValue);
continue;
}
// test if for stop, if so break the loop
if(placeholderValue.length == 1 && placeholderValue.chars[0] == '-')
{
@@ -186,14 +172,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFst
{
ffStrbufSubstrAfter(&placeholderValue, 0);
// continue if an error is set
if(placeholderValueIsForError(&placeholderValue) && error != NULL && error->length > 0)
{
++numOpenIfs;
ffStrbufDestroy(&placeholderValue);
continue;
}
uint32_t index = getArgumentIndex(&placeholderValue);
// testing for an invalid index
@@ -223,14 +201,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFst
{
ffStrbufSubstrAfter(&placeholderValue, 0);
//continue if an error os not set
if(placeholderValueIsForError(&placeholderValue) && (error == NULL || error->length == 0))
{
++numOpenNotIfs;
ffStrbufDestroy(&placeholderValue);
continue;
}
uint32_t index = getArgumentIndex(&placeholderValue);
// testing for an invalid index
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#ifndef FF_INCLUDED_common_format
#define FF_INCLUDED_common_format
typedef enum FFformatargtype
{
FF_FORMAT_ARG_TYPE_NULL = 0,
FF_FORMAT_ARG_TYPE_UINT,
FF_FORMAT_ARG_TYPE_UINT16,
FF_FORMAT_ARG_TYPE_UINT8,
FF_FORMAT_ARG_TYPE_INT,
FF_FORMAT_ARG_TYPE_STRING,
FF_FORMAT_ARG_TYPE_STRBUF,
FF_FORMAT_ARG_TYPE_DOUBLE,
FF_FORMAT_ARG_TYPE_LIST
} FFformatargtype;
typedef struct FFformatarg
{
FFformatargtype type;
const void* value;
} FFformatarg;
void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg);
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t numArgs, const FFformatarg* arguments);
#endif
+192 -97
View File
@@ -1,8 +1,15 @@
#include "fastfetch.h"
#include "common/caching.h"
#include "common/parsing.h"
#include "detection/qt.h"
#include "detection/gtk.h"
#include "detection/displayserver.h"
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <signal.h>
#include <pthread.h>
static bool strbufEqualsAdapter(const void* first, const void* second)
{
@@ -14,18 +21,14 @@ static void initConfigDirs(FFstate* state)
ffListInit(&state->configDirs, sizeof(FFstrbuf));
const char* xdgConfigHome = getenv("XDG_CONFIG_HOME");
if(xdgConfigHome != NULL)
if(ffStrSet(xdgConfigHome))
{
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs);
ffStrbufInitA(buffer, 64);
ffStrbufAppendS(buffer, xdgConfigHome);
ffStrbufTrimRight(buffer, '/');
ffStrbufEnsureEndsWithC(buffer, '/');
}
FFstrbuf xdgConfigDirs;
ffStrbufInitA(&xdgConfigDirs, 64);
ffStrbufAppendS(&xdgConfigDirs, getenv("XDG_CONFIG_DIRS"));
#define FF_ENSURE_ONLY_ONCE_IN_LIST(element) \
if(ffListFirstIndexComp(&state->configDirs, element, strbufEqualsAdapter) < state->configDirs.length - 1) \
--state->configDirs.length;
@@ -33,24 +36,35 @@ static void initConfigDirs(FFstate* state)
FFstrbuf* userConfigHome = ffListAdd(&state->configDirs);
ffStrbufInitA(userConfigHome, 64);
ffStrbufAppendS(userConfigHome, state->passwd->pw_dir);
ffStrbufAppendS(userConfigHome, "/.config");
ffStrbufAppendS(userConfigHome, "/.config/");
FF_ENSURE_ONLY_ONCE_IN_LIST(userConfigHome)
FFstrbuf* userHome = ffListAdd(&state->configDirs);
ffStrbufInitA(userHome, 64);
ffStrbufAppendS(userHome, state->passwd->pw_dir);
ffStrbufEnsureEndsWithC(userHome, '/');
FF_ENSURE_ONLY_ONCE_IN_LIST(userHome)
FFstrbuf xdgConfigDirs;
ffStrbufInitA(&xdgConfigDirs, 64);
ffStrbufAppendS(&xdgConfigDirs, getenv("XDG_CONFIG_DIRS"));
uint32_t startIndex = 0;
while (startIndex < xdgConfigDirs.length)
{
uint32_t colonIndex = ffStrbufNextIndexC(&xdgConfigDirs, startIndex, ':');
xdgConfigDirs.chars[colonIndex] = '\0';
if(!ffStrSet(xdgConfigDirs.chars + startIndex))
{
startIndex = colonIndex + 1;
continue;
}
FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs);
ffStrbufInitA(buffer, 64);
ffStrbufAppendS(buffer, xdgConfigDirs.chars + startIndex);
ffStrbufTrimRight(buffer, '/');
ffStrbufEnsureEndsWithC(buffer, '/');
FF_ENSURE_ONLY_ONCE_IN_LIST(buffer);
startIndex = colonIndex + 1;
@@ -58,12 +72,12 @@ static void initConfigDirs(FFstate* state)
FFstrbuf* systemConfigHome = ffListAdd(&state->configDirs);
ffStrbufInitA(systemConfigHome, 64);
ffStrbufAppendS(systemConfigHome, FASTFETCH_TARGET_DIR_ROOT"/etc/xdg");
ffStrbufAppendS(systemConfigHome, FASTFETCH_TARGET_DIR_ROOT"/etc/xdg/");
FF_ENSURE_ONLY_ONCE_IN_LIST(systemConfigHome)
FFstrbuf* systemConfig = ffListAdd(&state->configDirs);
ffStrbufInitA(systemConfig, 64);
ffStrbufAppendS(systemConfig, FASTFETCH_TARGET_DIR_ROOT"/etc");
ffStrbufAppendS(systemConfig, FASTFETCH_TARGET_DIR_ROOT"/etc/");
FF_ENSURE_ONLY_ONCE_IN_LIST(systemConfig)
#undef FF_ENSURE_ONLY_ONCE_IN_LIST
@@ -80,8 +94,8 @@ static void initCacheDir(FFstate* state)
ffStrbufAppendS(&state->cacheDir, state->passwd->pw_dir);
ffStrbufAppendS(&state->cacheDir, "/.cache/");
}
else if(!ffStrbufEndsWithC(&state->cacheDir, '/'))
ffStrbufAppendC(&state->cacheDir, '/');
else
ffStrbufEnsureEndsWithC(&state->cacheDir, '/');
mkdir(state->cacheDir.chars, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder, but who knows
@@ -102,17 +116,24 @@ static void initState(FFstate* state)
initCacheDir(state);
}
static void initModuleArg(FFModuleArgs* args)
{
ffStrbufInitA(&args->key, 0);
ffStrbufInitA(&args->outputFormat, 0);
ffStrbufInitA(&args->errorFormat, 0);
}
static void defaultConfig(FFinstance* instance)
{
ffStrbufInit(&instance->config.logoSource);
instance->config.logoType = FF_LOGO_TYPE_AUTO;
ffStrbufInit(&instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_AUTO;
for(uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i)
ffStrbufInit(&instance->config.logoColors[i]);
instance->config.logoWidth = 0;
instance->config.logoHeight = 0; //preserve aspect ratio
instance->config.logoPaddingLeft = 0;
instance->config.logoPaddingRight = 4;
instance->config.logoPrintRemaining = true;
ffStrbufInit(&instance->config.logo.colors[i]);
instance->config.logo.width = 0;
instance->config.logo.height = 0; //preserve aspect ratio
instance->config.logo.paddingLeft = 0;
instance->config.logo.paddingRight = 4;
instance->config.logo.printRemaining = true;
ffStrbufInit(&instance->config.mainColor);
ffStrbufInit(&instance->config.separator);
@@ -124,69 +145,45 @@ static void defaultConfig(FFinstance* instance)
instance->config.allowSlowOperations = false;
instance->config.disableLinewrap = true;
instance->config.hideCursor = true;
instance->config.escapeBedrock = true;
instance->config.glType = FF_GL_TYPE_AUTO;
instance->config.pipe = false;
instance->config.multithreading = true;
ffStrbufInitA(&instance->config.osFormat, 0);
ffStrbufInitA(&instance->config.osKey, 0);
ffStrbufInitA(&instance->config.hostFormat, 0);
ffStrbufInitA(&instance->config.hostKey, 0);
ffStrbufInitA(&instance->config.kernelFormat, 0);
ffStrbufInitA(&instance->config.kernelKey, 0);
ffStrbufInitA(&instance->config.uptimeFormat, 0);
ffStrbufInitA(&instance->config.uptimeKey, 0);
ffStrbufInitA(&instance->config.processesFormat, 0);
ffStrbufInitA(&instance->config.processesKey, 0);
ffStrbufInitA(&instance->config.packagesFormat, 0);
ffStrbufInitA(&instance->config.packagesKey, 0);
ffStrbufInitA(&instance->config.shellFormat, 0);
ffStrbufInitA(&instance->config.shellKey, 0);
ffStrbufInitA(&instance->config.resolutionFormat, 0);
ffStrbufInitA(&instance->config.resolutionKey, 0);
ffStrbufInitA(&instance->config.deFormat, 0);
ffStrbufInitA(&instance->config.deKey, 0);
ffStrbufInitA(&instance->config.wmFormat, 0);
ffStrbufInitA(&instance->config.wmKey, 0);
ffStrbufInitA(&instance->config.wmThemeFormat, 0);
ffStrbufInitA(&instance->config.wmThemeKey, 0);
ffStrbufInitA(&instance->config.themeFormat, 0);
ffStrbufInitA(&instance->config.themeKey, 0);
ffStrbufInitA(&instance->config.iconsFormat, 0);
ffStrbufInitA(&instance->config.iconsKey, 0);
ffStrbufInitA(&instance->config.fontFormat, 0);
ffStrbufInitA(&instance->config.fontKey, 0);
ffStrbufInitA(&instance->config.cursorKey, 0);
ffStrbufInitA(&instance->config.cursorFormat, 0);
ffStrbufInitA(&instance->config.terminalFormat, 0);
ffStrbufInitA(&instance->config.terminalKey, 0);
ffStrbufInitA(&instance->config.termFontFormat, 0);
ffStrbufInitA(&instance->config.termFontKey, 0);
ffStrbufInitA(&instance->config.cpuFormat, 0);
ffStrbufInitA(&instance->config.cpuKey, 0);
ffStrbufInitA(&instance->config.cpuUsageFormat, 0);
ffStrbufInitA(&instance->config.cpuUsageKey, 0);
ffStrbufInitA(&instance->config.gpuFormat, 0);
ffStrbufInitA(&instance->config.gpuKey, 0);
ffStrbufInitA(&instance->config.memoryFormat, 0);
ffStrbufInitA(&instance->config.memoryKey, 0);
ffStrbufInitA(&instance->config.diskFormat, 0);
ffStrbufInitA(&instance->config.diskKey, 0);
ffStrbufInitA(&instance->config.batteryFormat, 0);
ffStrbufInitA(&instance->config.batteryKey, 0);
ffStrbufInitA(&instance->config.localeFormat, 0);
ffStrbufInitA(&instance->config.localeKey, 0);
ffStrbufInitA(&instance->config.localIpKey, 0);
ffStrbufInitA(&instance->config.localIpFormat, 0);
ffStrbufInitA(&instance->config.publicIpKey, 0);
ffStrbufInitA(&instance->config.publicIpFormat, 0);
ffStrbufInitA(&instance->config.playerKey, 0);
ffStrbufInitA(&instance->config.playerFormat, 0);
ffStrbufInitA(&instance->config.songKey, 0);
ffStrbufInitA(&instance->config.songFormat, 0);
ffStrbufInitA(&instance->config.dateTimeKey, 0);
ffStrbufInitA(&instance->config.dateTimeFormat, 0);
ffStrbufInitA(&instance->config.dateKey, 0);
ffStrbufInitA(&instance->config.dateFormat, 0);
ffStrbufInitA(&instance->config.timeKey, 0);
ffStrbufInitA(&instance->config.timeFormat, 0);
initModuleArg(&instance->config.os);
initModuleArg(&instance->config.host);
initModuleArg(&instance->config.kernel);
initModuleArg(&instance->config.uptime);
initModuleArg(&instance->config.processes);
initModuleArg(&instance->config.packages);
initModuleArg(&instance->config.shell);
initModuleArg(&instance->config.resolution);
initModuleArg(&instance->config.de);
initModuleArg(&instance->config.wm);
initModuleArg(&instance->config.wmTheme);
initModuleArg(&instance->config.theme);
initModuleArg(&instance->config.icons);
initModuleArg(&instance->config.font);
initModuleArg(&instance->config.cursor);
initModuleArg(&instance->config.terminal);
initModuleArg(&instance->config.terminalFont);
initModuleArg(&instance->config.cpu);
initModuleArg(&instance->config.cpuUsage);
initModuleArg(&instance->config.gpu);
initModuleArg(&instance->config.memory);
initModuleArg(&instance->config.disk);
initModuleArg(&instance->config.battery);
initModuleArg(&instance->config.locale);
initModuleArg(&instance->config.localIP);
initModuleArg(&instance->config.publicIP);
initModuleArg(&instance->config.player);
initModuleArg(&instance->config.song);
initModuleArg(&instance->config.dateTime);
initModuleArg(&instance->config.date);
initModuleArg(&instance->config.time);
initModuleArg(&instance->config.vulkan);
initModuleArg(&instance->config.openGL);
initModuleArg(&instance->config.openCL);
ffStrbufInitA(&instance->config.libPCI, 0);
ffStrbufInitA(&instance->config.libVulkan, 0);
@@ -200,9 +197,16 @@ static void defaultConfig(FFinstance* instance)
ffStrbufInitA(&instance->config.libDBus, 0);
ffStrbufInitA(&instance->config.libXFConf, 0);
ffStrbufInitA(&instance->config.libSQLite3, 0);
ffStrbufInitA(&instance->config.librpm, 0);
ffStrbufInitA(&instance->config.libImageMagick, 0);
ffStrbufInitA(&instance->config.libZ, 0);
ffStrbufInitA(&instance->config.libChafa, 0);
ffStrbufInitA(&instance->config.libEGL, 0);
ffStrbufInitA(&instance->config.libGLX, 0);
ffStrbufInitA(&instance->config.libOSMesa, 0);
ffStrbufInitA(&instance->config.libOpenCL, 0);
instance->config.titleFQDN = false;
ffStrbufInitA(&instance->config.diskFolders, 0);
@@ -227,29 +231,101 @@ void ffInitInstance(FFinstance* instance)
defaultConfig(instance);
}
static void resetConsole(bool disableLinewrap, bool hideCursor)
static inline void* detectPlasmaThreadMain(void* instance)
{
if(disableLinewrap)
fputs("\033[?7h", stdout);
ffDetectQt((FFinstance*)instance);
return NULL;
}
if(hideCursor)
fputs("\033[?25h", stdout);
static inline void* detectGTK2ThreadMain(void* instance)
{
ffDetectGTK2((FFinstance*)instance);
return NULL;
}
static inline void* detectGTK3ThreadMain(void* instance)
{
ffDetectGTK3((FFinstance*)instance);
return NULL;
}
static inline void* detectGTK4ThreadMain(void* instance)
{
ffDetectGTK4((FFinstance*)instance);
return NULL;
}
static inline void* connectDisplayServerThreadMain(void* instance)
{
ffConnectDisplayServer((FFinstance*)instance);
return NULL;
}
static inline void* startThreadsThreadMain(void* instance)
{
pthread_t dsThread;
pthread_create(&dsThread, NULL, connectDisplayServerThreadMain, instance);
pthread_detach(dsThread);
pthread_t gtk2Thread;
pthread_create(&gtk2Thread, NULL, detectGTK2ThreadMain, instance);
pthread_detach(gtk2Thread);
pthread_t gtk3Thread;
pthread_create(&gtk3Thread, NULL, detectGTK3ThreadMain, instance);
pthread_detach(gtk3Thread);
pthread_t gtk4Thread;
pthread_create(&gtk4Thread, NULL, detectGTK4ThreadMain, instance);
pthread_detach(gtk4Thread);
pthread_t plasmaThread;
pthread_create(&plasmaThread, NULL, detectPlasmaThreadMain, instance);
pthread_detach(plasmaThread);
return NULL;
}
void startDetectionThreads(FFinstance* instance)
{
//Android needs none of the things that are detected here
//And using gsettings sometimes hangs the program in android for some unknown reason,
//and since we don't need it we just never call it.
#ifdef __ANDROID__
return;
#endif
pthread_t startThreadsThread;
pthread_create(&startThreadsThread, NULL, startThreadsThreadMain, instance);
pthread_detach(startThreadsThread);
}
static volatile bool ffDisableLinewrap = true;
static volatile bool ffHideCursor = true;
static void resetConsole()
{
if(ffDisableLinewrap)
fputs("\033[?7h", stdout);
if(ffHideCursor)
fputs("\033[?25h", stdout);
}
static void exitSignalHandler(int signal)
{
FF_UNUSED(signal);
resetConsole(ffDisableLinewrap, ffHideCursor);
resetConsole();
exit(0);
}
void ffStart(FFinstance* instance)
{
ffDisableLinewrap = instance->config.disableLinewrap;
ffHideCursor = instance->config.hideCursor;
if(instance->config.multithreading)
startDetectionThreads(instance);
ffDisableLinewrap = instance->config.disableLinewrap && !instance->config.pipe;
ffHideCursor = instance->config.hideCursor && !instance->config.pipe;
struct sigaction action = {};
action.sa_handler = exitSignalHandler;
@@ -259,24 +335,28 @@ void ffStart(FFinstance* instance)
sigaction(SIGQUIT, &action, NULL);
//We do the cache validation here, so we can skip it if --recache is given
ffCacheValidate(instance);
if(!instance->config.recache)
ffCacheValidate(instance);
//reset everything to default before we start printing
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
if(!instance->config.pipe)
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
if(instance->config.hideCursor)
if(ffHideCursor)
fputs("\033[?25l", stdout);
if(instance->config.disableLinewrap)
if(ffDisableLinewrap)
fputs("\033[?7l", stdout);
ffPrintLogo(instance);
ffLogoPrint(instance);
}
void ffFinish(FFinstance* instance)
{
ffPrintRemainingLogo(instance);
resetConsole(instance->config.disableLinewrap, instance->config.hideCursor);
if(instance->config.logo.printRemaining)
ffLogoPrintRemaining(instance);
resetConsole();
}
//Must be in a file compiled with the libfastfetch target, because the FF_HAVE* macros are not defined for the executable targets
@@ -331,6 +411,21 @@ void ffListFeatures()
#ifdef FF_HAVE_SQLITE3
"sqlite3\n"
#endif
#ifdef FF_HAVE_RPM
"rpm\n"
#endif
#ifdef FF_HAVE_EGL
"egl\n"
#endif
#ifdef FF_HAVE_GLX
"glx\n"
#endif
#ifdef FF_HAVE_OSMESA
"osmesa\n"
#endif
#ifdef FF_HAVE_OPENCL
"opencl\n"
#endif
""
, stdout);
}
+38 -16
View File
@@ -1,17 +1,12 @@
#include "fastfetch.h"
#include "common/io.h"
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdarg.h>
#include <termios.h>
#include <poll.h>
bool ffWriteFDContent(int fd, const FFstrbuf* content)
{
return write(fd, content->chars, content->length) != -1;
}
static void createSubfolders(const char* fileName)
{
FFstrbuf path;
@@ -28,7 +23,13 @@ static void createSubfolders(const char* fileName)
ffStrbufDestroy(&path);
}
bool ffWriteFileContent(const char* fileName, const FFstrbuf* content)
bool ffWriteFDBuffer(int fd, const FFstrbuf* content)
{
return write(fd, content->chars, content->length) != -1;
}
bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
{
int openFlagsModes = O_WRONLY | O_CREAT | O_TRUNC;
int openFlagsRights = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
@@ -42,14 +43,19 @@ bool ffWriteFileContent(const char* fileName, const FFstrbuf* content)
return false;
}
bool ret = ffWriteFDContent(fd, content);
bool ret = write(fd, data, dataSize) != -1;
close(fd);
return ret;
}
void ffAppendFDContent(int fd, FFstrbuf* buffer)
bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer)
{
return ffWriteFileData(fileName, buffer->length, buffer->chars);
}
bool ffAppendFDBuffer(int fd, FFstrbuf* buffer)
{
ssize_t readed = 0;
@@ -61,7 +67,7 @@ void ffAppendFDContent(int fd, FFstrbuf* buffer)
(uint32_t) readed == free
) {
buffer->length += (uint32_t) readed;
ffStrbufEnsureCapacity(buffer, (buffer->allocated * 2) - 1); // -1 for null terminator
ffStrbufEnsureFree(buffer, buffer->allocated - 1); // Doubles capacity every round. -1 for the null byte.
free = ffStrbufGetFree(buffer);
}
@@ -73,24 +79,40 @@ void ffAppendFDContent(int fd, FFstrbuf* buffer)
ffStrbufTrimRight(buffer, '\n');
ffStrbufTrimRight(buffer, ' ');
return readed >= 0;
}
bool ffAppendFileContent(const char* fileName, FFstrbuf* buffer)
ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data)
{
int fd = open(fileName, O_RDONLY);
if(fd == -1)
return -1;
ssize_t readed = read(fd, data, dataSize);
close(fd);
return readed;
}
bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer)
{
int fd = open(fileName, O_RDONLY);
if(fd == -1)
return false;
ffAppendFDContent(fd, buffer);
bool ret = ffAppendFDBuffer(fd, buffer);
close(fd);
return true;
return ret;
}
bool ffGetFileContent(const char* fileName, FFstrbuf* buffer)
bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer)
{
ffStrbufClear(buffer);
return ffAppendFileContent(fileName, buffer);
return ffAppendFileBuffer(fileName, buffer);
}
// Not thread safe!
+24
View File
@@ -0,0 +1,24 @@
#pragma once
#ifndef FF_INCLUDED_common_io
#define FF_INCLUDED_common_io
#include <sys/types.h> //mode_t
bool ffWriteFDBuffer(int fd, const FFstrbuf* content);
bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data);
bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer);
bool ffAppendFDBuffer(int fd, FFstrbuf* buffer);
ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data);
bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer);
bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer);
bool ffFileExists(const char* fileName, mode_t mode);
// Not thread safe!
void ffSuppressIO(bool suppress);
void ffGetTerminalResponse(const char* request, const char* format, ...);
#endif
+1
View File
@@ -1,4 +1,5 @@
#include "fastfetch.h"
#include "common/library.h"
#include <stdarg.h>
+29
View File
@@ -0,0 +1,29 @@
#pragma once
#ifndef FF_INCLUDED_common_library
#define FF_INCLUDED_common_library
#include <dlfcn.h>
#define FF_LIBRARY_SYMBOL(symbolName) \
__typeof__(&symbolName) ff ## symbolName;
#define FF_LIBRARY_LOAD(libraryObjectName, userLibraryName, returnValue, ...) \
void* libraryObjectName = ffLibraryLoad(&userLibraryName, __VA_ARGS__, NULL);\
if(libraryObjectName == NULL) \
return returnValue;
#define FF_LIBRARY_LOAD_SYMBOL_ADRESS(library, symbolMapping, symbolName, returnValue) \
symbolMapping = dlsym(library, #symbolName); \
if(symbolMapping == NULL) \
{ \
dlclose(library); \
return returnValue; \
}
#define FF_LIBRARY_LOAD_SYMBOL(library, symbolName, returnValue) \
__typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADRESS(library, ff ## symbolName, symbolName, returnValue);
void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...);
#endif
+2 -2
View File
@@ -1,7 +1,8 @@
#include "fastfetch.h"
#include "common/networking.h"
#include <sys/types.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netdb.h>
@@ -10,7 +11,6 @@ void ffNetworkingGetHttp(const char* host, const char* path, uint32_t timeout, F
struct addrinfo hints = {0};
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
struct addrinfo* addr;
+10
View File
@@ -0,0 +1,10 @@
#pragma once
#ifndef FF_INCLUDED_common_networking
#define FF_INCLUDED_common_networking
#include "util/FFstrbuf.h"
void ffNetworkingGetHttp(const char* host, const char* path, uint32_t timeout, FFstrbuf* buffer);
#endif
+27
View File
@@ -1,4 +1,5 @@
#include "fastfetch.h"
#include "common/parsing.h"
bool ffStrSet(const char* str)
{
@@ -39,6 +40,32 @@ void ffParseSemver(FFstrbuf* buffer, const FFstrbuf* major, const FFstrbuf* mino
ffStrbufAppend(buffer, patch);
}
int8_t ffVersionCompare(const FFVersion* version1, const FFVersion* version2)
{
if(version1->major != version2->major)
return version1->major > version2->major ? 1 : -1;
if(version1->minor != version2->minor)
return version1->minor > version2->minor ? 1 : -1;
if(version1->patch != version2->patch)
return version1->patch > version2->patch ? 1 : -1;
return 0;
}
void ffVersionToPretty(const FFVersion* version, FFstrbuf* pretty)
{
if(version->major > 0 || version->minor > 0 || version->patch > 0)
ffStrbufAppendF(pretty, "%u", version->major);
if(version->minor > 0 || version->patch > 0)
ffStrbufAppendF(pretty, ".%u", version->minor);
if(version->patch > 0)
ffStrbufAppendF(pretty, ".%u", version->patch);
}
void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, const FFstrbuf* gtk4)
{
if(gtk2->length > 0 && gtk3->length > 0 && gtk4->length > 0)
+24
View File
@@ -0,0 +1,24 @@
#pragma once
#ifndef FF_INCLUDED_parsing_h
#define FF_INCLUDED_parsing_h
#include <stdint.h>
typedef struct FFVersion
{
uint32_t major;
uint32_t minor;
uint32_t patch;
} FFVersion;
#define FF_VERSION_INIT ((FFVersion) {0})
bool ffStrSet(const char* str);
void ffParseSemver(FFstrbuf* buffer, const FFstrbuf* major, const FFstrbuf* minor, const FFstrbuf* patch);
void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, const FFstrbuf* gtk4);
void ffVersionToPretty(const FFVersion* version, FFstrbuf* pretty);
int8_t ffVersionCompare(const FFVersion* version1, const FFVersion* version2);
#endif
+125 -24
View File
@@ -1,55 +1,125 @@
#include "fastfetch.h"
#include "common/printing.h"
void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numFormatArgs, const char* message, ...)
void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat)
{
if(!instance->config.showErrors)
ffLogoPrintLine(instance);
//This is used by --set-keyless, in this case we wan't neither the module name nor the separator
if(moduleName == NULL)
return;
va_list arguments;
va_start(arguments, message);
if(formatString == NULL || formatString->length == 0)
if(!instance->config.pipe)
{
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
fputs(FASTFETCH_TEXT_MODIFIER_ERROR, stdout);
vprintf(message, arguments);
puts(FASTFETCH_TEXT_MODIFIER_RESET);
fputs(FASTFETCH_TEXT_MODIFIER_RESET FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
ffPrintColor(&instance->config.mainColor);
}
//NULL check is required for modules with custom keys, e.g. disk with the folder path
if(customKeyFormat == NULL || customKeyFormat->length == 0)
{
fputs(moduleName, stdout);
if(moduleIndex > 0)
printf(" %hhu", moduleIndex);
}
else
{
FF_STRBUF_CREATE(error);
ffStrbufAppendVF(&error, message, arguments);
// calloc sets all to 0 and FF_FORMAT_ARG_TYPE_NULL also has value 0 so we don't need to explictly set it
FFformatarg* nullArgs = calloc(numFormatArgs, sizeof(FFformatarg));
ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, formatString, &error, numFormatArgs, nullArgs);
free(nullArgs);
ffStrbufDestroy(&error);
FFstrbuf key;
ffStrbufInit(&key);
ffParseFormatString(&key, customKeyFormat, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex}
});
ffPrintUserString(key.chars);
ffStrbufDestroy(&key);
}
va_end(arguments);
if(!instance->config.pipe)
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
ffStrbufWriteTo(&instance->config.separator, stdout);
if(!instance->config.pipe)
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
}
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments)
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments)
{
FFstrbuf buffer;
ffStrbufInitA(&buffer, 256);
ffParseFormatString(&buffer, formatString, error, numArgs, arguments);
ffParseFormatString(&buffer, format, numArgs, arguments);
if(buffer.length > 0)
{
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
ffStrbufPutTo(&buffer, stdout);
ffPrintUserString(buffer.chars);
putchar('\n');
}
ffStrbufDestroy(&buffer);
}
void ffPrintFormat(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments)
{
ffPrintFormatString(instance, moduleName, moduleIndex, &moduleArgs->key, &moduleArgs->outputFormat, numArgs, arguments);
}
static void printError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customErrorFormat, const char* message, va_list arguments)
{
bool hasCustomErrorFormat = customErrorFormat != NULL && customErrorFormat->length > 0;
if(!hasCustomErrorFormat && !instance->config.showErrors)
return;
if(hasCustomErrorFormat)
{
FFstrbuf error;
ffStrbufInit(&error);
ffStrbufAppendVF(&error, message, arguments);
ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, customErrorFormat, 1, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &error}
});
ffStrbufDestroy(&error);
}
else
{
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
if(!instance->config.pipe)
fputs(FASTFETCH_TEXT_MODIFIER_ERROR, stdout);
vprintf(message, arguments);
if(!instance->config.pipe)
puts(FASTFETCH_TEXT_MODIFIER_RESET);
}
}
void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customErrorFormat, const char* message, ...)
{
va_list arguments;
va_start(arguments, message);
printError(instance, moduleName, moduleIndex, customKeyFormat, customErrorFormat, message, arguments);
va_end(arguments);
}
void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...)
{
va_list arguments;
va_start(arguments, message);
printError(instance, moduleName, moduleIndex, &moduleArgs->key, &moduleArgs->errorFormat, message, arguments);
va_end(arguments);
}
void ffPrintColor(const FFstrbuf* colorValue)
{
//If the color is not set, this would reset in \033[m, which resets everything.
//So we only print it, if the main color is at least one char.
if(colorValue->length == 0)
return;
fputs("\033[", stdout);
ffStrbufWriteTo(colorValue, stdout);
fputc('m', stdout);
@@ -60,3 +130,34 @@ void ffPrintCharTimes(char c, uint32_t times)
for(uint32_t i = 0; i < times; i++)
putchar(c);
}
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;
}
}
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#ifndef FF_INCLUDED_common_printing
#define FF_INCLUDED_common_printing
#include "fastfetch.h"
#include "common/format.h"
void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat);
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments);
void ffPrintFormat(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments);
void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customErrorFormat, const char* message, ...);
void ffPrintError(FFinstance* instance, 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
+4 -2
View File
@@ -1,6 +1,8 @@
#include "fastfetch.h"
#include "common/processing.h"
#include "common/io.h"
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
@@ -29,6 +31,6 @@ void ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
//Parent
close(pipes[1]);
waitpid(childPid, NULL, 0);
ffAppendFDContent(pipes[0], buffer);
ffAppendFDBuffer(pipes[0], buffer);
close(pipes[0]);
}
+10
View File
@@ -0,0 +1,10 @@
#pragma once
#ifndef FF_INCLUDED_common_processing
#define FF_INCLUDED_common_processing
#include "util/FFstrbuf.h"
void ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[]);
#endif
+30 -25
View File
@@ -1,4 +1,7 @@
#include "fastfetch.h"
#include "common/properties.h"
#include <stdlib.h>
static bool parsePropLinePointer(const char** line, const char* start, FFstrbuf* buffer)
{
@@ -86,27 +89,30 @@ bool ffParsePropLines(const char* lines, const char* start, FFstrbuf* buffer)
// The following functions return true if the file was found, independently if start was found
// Buffers which already contain content are not overwritten
// The last occurence of start in the first file will be the one used
// The *Values methods always return true, if all properties were already found before, without testing if the file exists
bool ffParsePropFileValues(const char* filename, uint32_t numQueries, FFpropquery* queries)
{
bool* searchedValues = malloc(sizeof(bool) * numQueries);
FILE* file = fopen(filename, "r");
if(file == NULL)
return false;
bool valueStorage[4];
bool* unsetValues;
if(numQueries > sizeof(valueStorage) / sizeof(valueStorage[0]))
unsetValues = malloc(sizeof(bool) * numQueries);
else
unsetValues = valueStorage;
bool allSet = true;
for(uint32_t i = 0; i < numQueries; i++)
{
if((searchedValues[i] = queries[i].buffer->length == 0))
if((unsetValues[i] = queries[i].buffer->length == 0))
allSet = false;
}
if(allSet)
{
free(searchedValues);
return true;
}
FILE* file = fopen(filename, "r");
if(file == NULL)
return false;
goto done;
char* line = NULL;
size_t len = 0;
@@ -115,7 +121,7 @@ bool ffParsePropFileValues(const char* filename, uint32_t numQueries, FFpropquer
{
for(uint32_t i = 0; i < numQueries; i++)
{
if(!searchedValues[i])
if(!unsetValues[i])
continue;
uint32_t currentLength = queries[i].buffer->length;
@@ -125,13 +131,13 @@ bool ffParsePropFileValues(const char* filename, uint32_t numQueries, FFpropquer
}
}
free(searchedValues);
if(line != NULL)
free(line);
done:
fclose(file);
if(unsetValues != valueStorage)
free(unsetValues);
return true;
}
@@ -164,21 +170,18 @@ bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativ
{
bool foundAFile = false;
FFstrbuf baseDir;
ffStrbufInitA(&baseDir, 64);
for(uint32_t i = 0; i < instance->state.configDirs.length; i++)
{
FFstrbuf* baseDir = (FFstrbuf*) ffListGet(&instance->state.configDirs, i);
uint32_t baseDirLength = baseDir->length;
//We need to copy the config dir each time, because it used by multiple threads, so we can't directly write to it.
ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i));
ffStrbufAppendS(&baseDir, relativeFile);
if(*relativeFile != '/')
ffStrbufAppendC(baseDir, '/');
ffStrbufAppendS(baseDir, relativeFile);
if(ffParsePropFileValues(baseDir->chars, numQueries, queries))
if(ffParsePropFileValues(baseDir.chars, numQueries, queries))
foundAFile = true;
ffStrbufSubstrBefore(baseDir, baseDirLength);
bool allSet = true;
for(uint32_t k = 0; k < numQueries; k++)
{
@@ -193,6 +196,8 @@ bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativ
break;
}
ffStrbufDestroy(&baseDir);
return foundAFile;
}
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#ifndef FF_INCLUDED_common_properties
#define FF_INCLUDED_common_properties
#include "util/FFstrbuf.h"
typedef struct FFpropquery
{
const char* start;
FFstrbuf* buffer;
} FFpropquery;
bool ffParsePropLine(const char* line, const char* start, FFstrbuf* buffer);
bool ffParsePropLines(const char* lines, const char* start, FFstrbuf* buffer);
bool ffParsePropFileValues(const char* filename, uint32_t numQueries, FFpropquery* queries);
bool ffParsePropFile(const char* filename, const char* start, FFstrbuf* buffer);
bool ffParsePropFileHomeValues(const FFinstance* instance, const char* relativeFile, uint32_t numQueries, FFpropquery* queries);
bool ffParsePropFileHome(const FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer);
bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativeFile, uint32_t numQueries, FFpropquery* queries);
bool ffParsePropFileConfig(const FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer);
#endif
+16 -2
View File
@@ -1,8 +1,18 @@
#include "fastfetch.h"
#include "common/settings.h"
#include "common/library.h"
#include "common/io.h"
#include <pthread.h>
#include <string.h>
typedef enum FFInitState
{
FF_INITSTATE_UNINITIALIZED = 0,
FF_INITSTATE_SUCCESSFUL = 1,
FF_INITSTATE_FAILED = 2
} FFInitState;
#define FF_LIBRARY_DATA_LOAD_INIT(dataObject, userLibraryName, ...) \
static dataObject data; \
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; \
@@ -270,6 +280,7 @@ FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, con
#ifdef FF_HAVE_SQLITE3
#include <sqlite3.h>
#include <sys/stat.h>
typedef struct SQLiteData
{
@@ -297,8 +308,11 @@ static const SQLiteData* getSQLiteData(const FFinstance* instance)
FF_LIBRARY_DATA_LOAD_RETURN
}
int ffSettingsGetSQLite3Int(FFinstance* instance, const char* dbPath, const char* query)
int ffSettingsGetSQLite3Int(const FFinstance* instance, const char* dbPath, const char* query)
{
if(!ffFileExists(dbPath, S_IFREG))
return 0;
const SQLiteData* data = getSQLiteData(instance);
if(data == NULL)
return 0;
@@ -329,7 +343,7 @@ int ffSettingsGetSQLite3Int(FFinstance* instance, const char* dbPath, const char
return result;
}
#else //FF_HAVE_SQLITE3
int ffSettingsGetSQLite3Int(FFinstance* instance, const char* dbPath, const char* query)
int ffSettingsGetSQLite3Int(const FFinstance* instance, const char* dbPath, const char* query)
{
FF_UNUSED(instance, dbPath, query)
return 0;
+39
View File
@@ -0,0 +1,39 @@
#pragma once
#ifndef FF_INCLUDED_common_settings
#define FF_INCLUDED_common_settings
#include "fastfetch.h"
typedef enum FFvarianttype
{
FF_VARIANT_TYPE_STRING,
FF_VARIANT_TYPE_BOOL,
FF_VARIANT_TYPE_INT
} FFvarianttype;
typedef union FFvariant
{
const char* strValue;
int32_t intValue;
struct
{
bool boolValueSet;
bool boolValue;
};
} FFvariant;
#define FF_VARIANT_NULL ((FFvariant){.strValue = NULL})
FFvariant ffSettingsGetDConf(FFinstance* instance, const char* key, FFvarianttype type);
FFvariant ffSettingsGetGSettings(FFinstance* instance, const char* schemaName, const char* path, const char* key, FFvarianttype type);
FFvariant ffSettingsGet(FFinstance* instance, const char* dconfKey, const char* gsettingsSchemaName, const char* gsettingsPath, const char* gsettingsKey, FFvarianttype type);
FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, const char* propertyName, FFvarianttype type);
int ffSettingsGetSQLite3Int(const FFinstance* instance, const char* dbPath, const char* query);
#ifdef __ANDROID__
bool ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result);
#endif
#endif
-72
View File
@@ -1,72 +0,0 @@
#include "fastfetch.h"
#include <pthread.h>
static inline void* detectPlasmaThreadMain(void* instance)
{
ffDetectPlasma((FFinstance*)instance);
return NULL;
}
static inline void* detectGTK2ThreadMain(void* instance)
{
ffDetectGTK2((FFinstance*)instance);
return NULL;
}
static inline void* detectGTK3ThreadMain(void* instance)
{
ffDetectGTK3((FFinstance*)instance);
return NULL;
}
static inline void* detectGTK4ThreadMain(void* instance)
{
ffDetectGTK4((FFinstance*)instance);
return NULL;
}
static inline void* connectDisplayServerThreadMain(void* instance)
{
ffConnectDisplayServer((FFinstance*)instance);
return NULL;
}
static inline void* startThreadsThreadMain(void* instance)
{
pthread_t dsThread;
pthread_create(&dsThread, NULL, connectDisplayServerThreadMain, instance);
pthread_detach(dsThread);
pthread_t gtk2Thread;
pthread_create(&gtk2Thread, NULL, detectGTK2ThreadMain, instance);
pthread_detach(gtk2Thread);
pthread_t gtk3Thread;
pthread_create(&gtk3Thread, NULL, detectGTK3ThreadMain, instance);
pthread_detach(gtk3Thread);
pthread_t gtk4Thread;
pthread_create(&gtk4Thread, NULL, detectGTK4ThreadMain, instance);
pthread_detach(gtk4Thread);
pthread_t plasmaThread;
pthread_create(&plasmaThread, NULL, detectPlasmaThreadMain, instance);
pthread_detach(plasmaThread);
return NULL;
}
void ffStartDetectionThreads(FFinstance* instance)
{
//Android needs none of the things that are detected here
//And using gsettings sometimes hangs the program in android for some unknown reason,
//and since we don't need it we just never call it.
#ifdef __ANDROID__
return;
#endif
pthread_t startThreadsThread;
pthread_create(&startThreadsThread, NULL, startThreadsThreadMain, instance);
pthread_detach(startThreadsThread);
}
+16
View File
@@ -0,0 +1,16 @@
# Fastfetch system configuration
# This file sets the defaults for all users of the system.
# For more information about configuration files work,
# see the file ~/.config/fastfetch/config.conf, generated during first
# All options that can be put there (or passed as argument) can be put here too.
# This file was shipped with $"FASTFETCH_PROJECT_VERSION$".
# Use fastfetch --print-config-system > /etc/fastfetch/config.conf to overwrite this file with the current defaults
# User config option
# Sets if fastfetch should load user provided configuration.
# If this is off, fastfetch ignores the user config file and any passed arguments
# Must be true or false
# Default is true.
#--load-user-config true
@@ -6,7 +6,7 @@
# Empty lines or lines starting with # are ignored.
# This file was shipped with $"FASTFETCH_PROJECT_VERSION$".
# Use fastfetch --print-config > ~/.config/fastfetch/config.conf to overwrite this with the current defaults
# Use fastfetch --print-config-user > ~/.config/fastfetch/config.conf to overwrite this file with the current defaults
# Below some often usefull options are listed. Uncomment and modify them so they take affect.
# Note that there are a lot more options than the ones listed here, take a look at "fastfetch --help".
@@ -120,6 +120,12 @@
# Use "fastfetch --help color" to learn more and see examples.
#--color magenta
# Title FQDN option:
# Sets if the title should use the fully qualified domain name.
# Must be true or false.
# Default is false.
#--title-fqdn false
# Separator option:
# Sets the string placed between a key and its value.
# Can be any string.
@@ -151,6 +157,18 @@
# Default is the first match starting with org.mpris.MediaPlayer2.
#--player-name spotify
# Escape bedrock option
# Sets if fastfetch should escape the bedrock jail, if it detectes that it is running in one
# Must be true or false.
# Default is true.
#--escape-bedrock true
# GL option
# Sets with opengl context creation library to use
# Must be either auto, egl, glx or osmesa
# Default is auto.
#--gl auto
# Key options:
# Sets the displayed key of a module
# Can be any string. Some of theme take an argument like a format string. See "fastfetch --help format" for help.
@@ -183,6 +201,9 @@
#--player-key Media Player
#--song-key Song
#--datetime-key Date Time
#--vulkan-key Vulkan
#--opengl-key OpenGL
#--opencl-key OpenCL
# Format options:
# Sets the format string for module values.
@@ -218,6 +239,47 @@
#--player-format
#--song-format
#--datetime-format
#--vulkan-format
#--opengl-format
#--opencl-format
# Error options:
# Sets the format string to use if an error occured
# For information on format strings, see "fastfetch --help format".
# Each of them take the error as first and only argument.
# If one of them is set, the module will appear, even if --show-errors is not given.
#--os-error
#--host-error
#--kernel-error
#--uptime-error
#--processes-error
#--packages-error
#--shell-error
#--resolution-error
#--de-error
#--wm-error
#--wm-theme-error
#--theme-error
#--icons-error
#--font-error
#--cursor-error
#--terminal-error
#--terminal-font-error
#--cpu-error
#--cpu-usage-error
#--gpu-error
#--memory-error
#--disk-error
#--battery-error
#--locale-error
#--local-ip-error
#--public-ip-error
#--player-error
#--song-error
#--datetime-error
#--vulkan-error
#--opengl-error
#--opencl-error
# Library options:
# Sets an user specific path to a library to load.
@@ -234,6 +296,11 @@
#--lib-DBus /usr/lib/libdbus-1.so
#--lib-XFConf /usr/lib/libxfconf-0.so
#--lib-sqlite3 /usr/lib/libsqlite3.so
#--lib-rpm /usr/lib/librpm.so
#--lib-imagemagick /usr/lib/libMagickCore-7.Q16HDRI.so
#--lib-z /usr/lib/libz.so
#--lib-chafa /usr/lib/libchafa.so
#--lib-egl /usr/lib/libEGL.so
#--lib-glx /usr/lib/libGLX.so
#--lib-osmesa /usr/lib/libOSMesa.so
#--lib-opencl /usr/lib/libOpenCL.so
+31 -74
View File
@@ -1,16 +1,17 @@
Usage: fastfetch <options>
Informative options:
-h,--help: shows this message and exits
-h,--help <command>: shows help for a specific command and exits
-v,--version: prints the version of fastfetch and exits
--list-logos: list available logos and exits
--list-modules: lists available modules and exits
--list-presets: list presets fastfetch knows about and exits. They can be loaded with --load-config. (+)
--list-features: list the supported features fastfetch was compiled with and exits. Mainly for development.
--print-logos: show available logos and exits
--print-config: prints the default config and exits
--print-structure: prints the default stucture and exits
-h,--help: shows this message and exits
-h,--help <command>: shows help for a specific command and exits
-v,--version: prints the version of fastfetch and exits
--list-logos: list available logos and exits
--list-modules: lists available modules and exits
--list-presets: list presets fastfetch knows about and exits. They can be loaded with --load-config. (+)
--list-features: list the supported features fastfetch was compiled with and exits. Mainly for development.
--print-logos: show available logos and exits
--print-config-system: prints the default system config and exits
--print-config-user: prints the default user config and exits
--print-structure: prints the default stucture and exits
General options:
-r,--recache <?value>: generate new cached values
@@ -18,6 +19,8 @@ General options:
--load-config <file>: load a config file or a preset (+)
--multithreading <?value>: use multiple threads to detect values
--allow-slow-operations <?value>: allow operations that are usually very slow for more detailed output
--escape-bedrock <?value>: on bedrock linux, sets if it should escape the bedrock jail or not
--pipe <?value>: disable logo and all escape sequences
Logo options:
-l,--logo <logo>: set the logo to use. The type is specified by --logo-type. If default: the name of a builtin logo or a path to a file
@@ -40,75 +43,22 @@ Display options:
-c,--color <color>: sets the color of the keys. Must be a linux console color code or the name of a color (+)
--separator <str>: sets 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
--show-errors <?value>: print occuring errors
--disable-linewrap <?value>: weather to disable linewrap during the run
--hide-cursor <?value>: weather to hide the cursor during the run
Format options: Provide the format string for custom output. Use fastfetch --help *-format for specific help.
--os-format <format>
--host-format <format>
--kernel-format <format>
--uptime-format <format>
--processes-format <format>
--packages-format <format>
--shell-format <format>
--resolution-format <format>
--de-format <format>
--wm-format <format>
--wm-theme-format <format>
--theme-format <format>
--icons-format <format>
--font-format <format>
--cursor-format <format>
--terminal-format <format>
--terminal-font-format <format>
--cpu-format <format>
--cpu-usage-format <format>
--gpu-format <format>
--memory-format <format>
--disk-format <format>
--battery-format <format>
--locale-format <format>
--local-ip-format <format>
--public-ip-format <format>
--player-format <format>
--song-format <format>
--datetime-format <format>
--time-format <format>
--date-format <format>
General module options:
--<module>-format <format>: Sets the format string to use for each specific module.
To see how a format string works, use fastfetch --help format.
To see help about a specific format string, use fastfetch --help <module>-format.
Key options: Provide a custom key for an output
--os-key <key>
--host-key <key>
--kernel-key <key>
--uptime-key <key>
--processes-key <key>
--packages-key <key>
--shell-key <key>
--resolution-key <key>: takes the resolution index as argument
--de-key <key>
--wm-key <key>
--wm-theme-key <key>
--theme-key <key>
--icons-key <key>
--font-key <key>
--cursor-key <key>
--terminal-key <key>
--terminal-font-key <key>
--cpu-key <key>
--cpu-usage-key <key>
--gpu-key <key>: takes the gpu index as format argument
--memory-key <key>
--disk-key <key>: takes the mount path as format argument
--battery-key <key>: takes the battery index as format argument
--locale-key <key>
--local-ip-key <key>: takes the name of this network interface as format argument
--public-ip-key <key>
--player-key <key>
--song-key <key>
--datetime-key <key>
--time-key <key>
--date-key <key>
--<module>-key <key>: Sets the key to use for each specific module.
For modules which print multiple lines, the string is parsed as a format string with the index as first character.
--<module>-error <format>: Sets the error format string to use for each specific module.
The error is given as the first and only argument.
Setting this for a module will cause it to appear, even if --show-errors is not given.
Library options: Set the path of a library to load
--lib-PCI <path>
@@ -123,11 +73,17 @@ Library options: Set the path of a library to load
--lib-DBus <path>
--lib-XFConf <path>
--lib-sqlite3 <path>
--lib-rpm <path>
--lib-imagemagick <path>
--lib-z <path>
--lib-chafa <path>
--lib-egl <path>
--lib-glx <path>
--lib-osmesa <path>
--lib-opencl <path>
Module specific options:
--title-fqdn <?value>: sets if the title should use fully qualified domain name. Default is false.
--separator-string <str>: Set the string printed by the separator module
--os-file <path>: Set the path to the file containing OS informations
--disk-folders <folders>: A colon separated list of folder paths for the disk output. Default is "/:/home"
@@ -137,6 +93,7 @@ Module specific options:
--localip-show-loop <?value>: Show loop back addresses (127.0.0.1) in local ip module. Default is false
--public-ip-timeout: Time in milliseconds to wait for the public ip server to respond. Default is disabled (0)
--player-name: The name of the player to use
--gl <value>: Sets the opengl context creation library to use. Must be auto, egl, glx or osmesa. Default is auto
Parsing is not case sensitive. E.g. "--lib-PCI" is equal to "--Lib-Pci"
If a value starts with a ?, it is optional. "true" will be used if not set.
-6
View File
@@ -19,24 +19,18 @@ If a "{?}" is found without an opener, it is printed as is.
To only print something if a variable is not set, do the same as with if, just replace every '?' with a '!'.
For example to print a fallback for a second value if it is not set, use "{?2}{2}{?}{/2}Second value fallback{/}"
There is a special variable set if an error occured during detection. You can access it with "{e}", "{error}" o
You can use ifs and not ifs with it like with an index. For example use "{?e}some text{?}", to print a text if an
To stop formatting at any point in the format string, use "{-}".
For example to print an error instead of the normal output if it occured, prefix the format string with "{?e}{e}{-
To print something with color, start a placeholder with a '#' and then the linux terminal color encoding.
"\\033[" at the start, and an 'm' at the end is automatically added, so don't do that.
A "{#}" is equivalent to a "{#0}" and resets everything to normal.
For example to print something pink and underline, use "{#4;35}...{#}".
If not in a format string, fastfetch wraps errors with "{#1;31}error{#}", so you might want to do that to if you
Information about what the numbers mean can be found here: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Sele
Which escape codes are supported and how they look is defined by your terminal.
If a format string evaluates to an empty value, the whole line in the output will be discarded.
You can therefore use --host-format " " to disable host output.
Note that --host-format "" would evaluate as not set, and therefore use the built-in host format
This can be used to print nothing if an error occured: prefix the format string with "{?e}{-}{?}...".
Format string is also the way to go to set a fixed value - just use one without placeholders.
For example when running in headless mode, you could use "--resolution-format "Preferred".
+3
View File
@@ -17,6 +17,8 @@ Locale
LocalIP
Memory
OS
OpenCL
OpenGL
Packages
Player
Processes
@@ -31,5 +33,6 @@ Theme
Time
Title
Uptime
Vulkan
WM
WMTheme
+1 -1
View File
@@ -1,7 +1,7 @@
#include "fastfetch.h"
#include "detection/datetime.h"
#include <time.h>
#include <pthread.h>
const FFDateTimeResult* ffDetectDateTime(const FFinstance* instance)
+35
View File
@@ -0,0 +1,35 @@
#pragma once
#ifndef FF_INCLUDED_detection_datetime
#define FF_INCLUDED_detection_datetime
#include "fastfetch.h"
typedef struct FFDateTimeResult
{
//Examples for 21.02.2022 - 15:18:37
uint16_t year; //2022
uint8_t yearShort; //22
uint8_t month; //2
FFstrbuf monthPretty; //02
FFstrbuf monthName; //February
FFstrbuf monthNameShort; //Feb
uint8_t week; //8
FFstrbuf weekday; //Monday
FFstrbuf weekdayShort; //Mon
uint16_t dayInYear; //52
uint8_t dayInMonth; //21
uint8_t dayInWeek; //1
uint8_t hour; //15
FFstrbuf hourPretty; //15
uint8_t hour12; //3
FFstrbuf hour12Pretty; //03
uint8_t minute; //18
FFstrbuf minutePretty; //18
uint8_t second; //37
FFstrbuf secondPretty; //37
} FFDateTimeResult;
const FFDateTimeResult* ffDetectDateTime(const FFinstance* instance);
#endif
+29
View File
@@ -0,0 +1,29 @@
#pragma once
#ifndef FF_INCLUDED_detection_displayserver
#define FF_INCLUDED_detection_displayserver
#include "fastfetch.h"
typedef struct FFResolutionResult
{
uint32_t width;
uint32_t height;
uint32_t refreshRate;
} FFResolutionResult;
typedef struct FFDisplayServerResult
{
FFstrbuf wmProcessName;
FFstrbuf wmPrettyName;
FFstrbuf wmProtocolName;
FFstrbuf deProcessName;
FFstrbuf dePrettyName;
FFstrbuf deVersion;
FFlist resolutions; //List of FFResolutionResult
} FFDisplayServerResult;
const FFDisplayServerResult* ffConnectDisplayServer(const FFinstance* instance);
#endif
@@ -1,4 +1,5 @@
#include "displayServer.h"
#include <pthread.h>
#include <dirent.h>
@@ -4,6 +4,7 @@
#define FASTFETCH_INCLUDED_DISPLAYSERVER
#include "fastfetch.h"
#include "detection/displayserver.h"
#define FF_DISPLAYSERVER_PROTOCOL_WAYLAND "Wayland"
#define FF_DISPLAYSERVER_PROTOCOL_X11 "X11"
+84 -69
View File
@@ -1,50 +1,53 @@
#define _GNU_SOURCE //required for struct ucred
#include "displayServer.h"
#include <stdlib.h>
#include <string.h>
#ifdef FF_HAVE_WAYLAND
#include <wayland-client.h>
#include "common/library.h"
#include "common/io.h"
#include <pthread.h>
#include <wayland-client.h>
#include <sys/socket.h>
typedef struct WaylandData
{
const FFinstance* instance;
FFlist* results;
FF_LIBRARY_SYMBOL(wl_proxy_marshal_constructor_versioned)
FF_LIBRARY_SYMBOL(wl_proxy_add_listener)
FF_LIBRARY_SYMBOL(wl_proxy_destroy)
const struct wl_interface* ffwl_output_interface;
struct wl_output_listener output_listener;
} WaylandData;
static void waylandGlobalRemoveListener(void* data, struct wl_registry* wl_registry, uint32_t name){
FF_UNUSED(data, wl_registry, name);
static void waylandDetectWM(int fd, FFDisplayServerResult* result)
{
struct ucred ucred;
socklen_t len = sizeof(struct ucred);
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1)
return;
FFstrbuf procPath;
ffStrbufInit(&procPath);
ffStrbufAppendF(&procPath, "/proc/%d/cmdline", ucred.pid); //We check the cmdline for the process name, because it is not trimmed.
ffReadFileBuffer(procPath.chars, &result->wmProcessName);
ffStrbufSubstrBeforeFirstC(&result->wmProcessName, '\0'); //Trim the arguments
ffStrbufSubstrAfterLastC(&result->wmProcessName, '/'); //Trim the path
ffStrbufDestroy(&procPath);
}
static void waylandOutputGeometryListener(void* data, struct wl_output* wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char* make, const char* model, int32_t transform)
static void stubListener(void* data, ...)
{
FF_UNUSED(data, wl_output, x, y, physical_width, physical_height, subpixel, make, model, transform);
}
static void waylandOutputDoneListener(void* data, struct wl_output* wl_output)
{
FF_UNUSED(data, wl_output);
}
static void waylandOutputScaleListener(void* data, struct wl_output* wl_output, int32_t factor)
{
FF_UNUSED(data, wl_output, factor);
(void) data;
}
static void waylandOutputModeListener(void* data, struct wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refreshRate)
{
if(!(flags & WL_OUTPUT_MODE_CURRENT))
return;
FF_UNUSED(output);
WaylandData* wldata = (WaylandData*) data;
WaylandData* wldata = data;
wldata->ffwl_proxy_destroy((struct wl_proxy*) output);
if(width <= 0 || height <= 0)
if(!(flags & WL_OUTPUT_MODE_CURRENT) || width <= 0 || height <= 0)
return;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -61,92 +64,106 @@ static void waylandOutputModeListener(void* data, struct wl_output* output, uint
static void waylandGlobalAddListener(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
{
if(strcmp(interface, "wl_output") == 0)
{
WaylandData* wldata = (WaylandData*) data;
WaylandData* wldata = data;
struct wl_output* output = (struct wl_output*) wldata->ffwl_proxy_marshal_constructor_versioned((struct wl_proxy *) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, name, wldata->ffwl_output_interface->name, version, NULL);
if(strcmp(interface, wldata->ffwl_output_interface->name) == 0)
{
struct wl_proxy* output = wldata->ffwl_proxy_marshal_constructor_versioned((struct wl_proxy*) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, name, wldata->ffwl_output_interface->name, version, NULL);
if(output == NULL)
return;
wldata->ffwl_proxy_add_listener((struct wl_proxy*) output, (void(**)(void)) &wldata->output_listener, data);
//Needs to be static, because the scope of the function will already be lost when calling the listener
static struct wl_output_listener outputListener = {
.mode = waylandOutputModeListener,
.geometry = (void*) stubListener,
//https://lists.freedesktop.org/archives/wayland-devel/2013-July/010278.html
#if WAYLAND_VERSION_MINOR >= 2
.done = (void*) stubListener,
.scale = (void*) stubListener,
#endif
//https://lists.freedesktop.org/archives/wayland-devel/2021-December/042064.html
#if WAYLAND_VERSION_MINOR >= 20
.name = (void*) stubListener,
.description = (void*) stubListener,
#endif
};
wldata->ffwl_proxy_add_listener(output, (void(**)(void)) &outputListener, data);
}
}
void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* result)
bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result)
{
if(getenv("XDG_RUNTIME_DIR") == NULL)
return;
FF_LIBRARY_LOAD(wayland, instance->config.libWayland, false, "libwayland-client.so", 1)
FF_LIBRARY_LOAD(wayland, instance->config.libWayland, , "libwayland-client.so", 1)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_connect,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_dispatch,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_roundtrip,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_proxy_marshal_constructor,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_disconnect,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_registry_interface,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_connect, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_get_fd, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_dispatch, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_roundtrip, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_proxy_marshal_constructor, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_disconnect, false)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_registry_interface, false)
WaylandData data;
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_constructor_versioned, wl_proxy_marshal_constructor_versioned,)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_add_listener, wl_proxy_add_listener,)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_output_interface, wl_output_interface,)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_destroy, wl_proxy_destroy,)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_constructor_versioned, wl_proxy_marshal_constructor_versioned, false)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_add_listener, wl_proxy_add_listener, false)
FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_output_interface, wl_output_interface, false)
struct wl_display* display = ffwl_display_connect(NULL);
if(display == NULL)
{
dlclose(wayland);
return;
return false;
}
struct wl_registry* registry = (struct wl_registry*) ffwl_proxy_marshal_constructor((struct wl_proxy*) display, WL_DISPLAY_GET_REGISTRY, ffwl_registry_interface, NULL);
waylandDetectWM(ffwl_display_get_fd(display), result);
struct wl_proxy* registry = ffwl_proxy_marshal_constructor((struct wl_proxy*) display, WL_DISPLAY_GET_REGISTRY, ffwl_registry_interface, NULL);
if(registry == NULL)
{
ffwl_display_disconnect(display);
dlclose(wayland);
return;
return false;
}
data.instance = instance;
data.results = &result->resolutions;
struct wl_registry_listener regestry_listener;
regestry_listener.global = waylandGlobalAddListener;
regestry_listener.global_remove = waylandGlobalRemoveListener;
struct wl_registry_listener registry_listener = {
.global = waylandGlobalAddListener,
.global_remove = (void*) stubListener
};
data.output_listener.geometry = waylandOutputGeometryListener;
data.output_listener.mode = waylandOutputModeListener;
data.output_listener.done = waylandOutputDoneListener;
data.output_listener.scale = waylandOutputScaleListener;
data.ffwl_proxy_add_listener((struct wl_proxy*) registry, (void(**)(void)) &regestry_listener, &data);
data.ffwl_proxy_add_listener(registry, (void(**)(void)) &registry_listener, &data);
ffwl_display_dispatch(display);
ffwl_display_roundtrip(display);
data.ffwl_proxy_destroy((struct wl_proxy*) registry);
ffwl_display_disconnect(display);
ffwl_display_disconnect(display); //This will also destroy our wl_registry and wl_output proxies
dlclose(wayland);
//We successfully connected to wayland and detected the resolution.
//So we can set set the session type to wayland.
//This is used as an indicator that we are running wayland by the x11 backends.
ffStrbufSetS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND);
return true;
}
#else
#endif
void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* result)
{
FF_UNUSED(instance);
//We try to detect wayland already here, so the x11 methods only to resolution detection.
//Wayland requires this to be set
if(getenv("XDG_RUNTIME_DIR") == NULL)
return;
#ifdef FF_HAVE_WAYLAND
if(detectWayland(instance, result))
return;
#else
FF_UNUSED(instance);
#endif
const char* xdgSessionType = getenv("XDG_SESSION_TYPE");
//If XDG_SESSION_TYPE is set, and doesn't contain "wayland", we are probably not running in a wayland session.
@@ -158,9 +175,7 @@ void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* resul
if(xdgSessionType == NULL && getenv("WAYLAND_DISPLAY") == NULL && getenv("WAYLAND_SOCKET") == NULL)
return;
//We are probably running a wayland compositor at this point, but fastfetch was compiled without the required library.
//Set the protocol name and use DRM for resolution detection.
//We are probably running a wayland compositor at this point,
//but fastfetch was compiled without the required library, or loading the library failed.
ffStrbufSetS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND);
}
#endif
+42 -11
View File
@@ -1,8 +1,15 @@
#include "displayServer.h"
#include <dirent.h>
#include "common/io.h"
#include "common/properties.h"
#include "common/parsing.h"
#include "common/processing.h"
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <dirent.h>
#include <sys/stat.h>
static const char* parseEnv()
{
@@ -40,6 +47,11 @@ static const char* parseEnv()
if(getenv("TDE_FULL_SESSION") != NULL)
return "Trinity";
if(
getenv("WAYLAND_DISPLAY") != NULL &&
ffFileExists("/mnt/wslg/", S_IFDIR)
) return "WSLg";
return NULL;
}
@@ -48,8 +60,23 @@ static void applyPrettyNameIfWM(FFDisplayServerResult* result, const char* proce
if(!ffStrSet(processName))
return;
if(strcasecmp(processName, "kwin_wayland") == 0 || strcasecmp(processName, "kwin_x11") == 0 || strcasecmp(processName, "kwin") == 0)
ffStrbufSetS(&result->wmPrettyName, "KWin");
if(
strcasecmp(processName, "kwin_wayland") == 0 ||
strcasecmp(processName, "kwin_wayland_wrapper") == 0 ||
strcasecmp(processName, "kwin_x11") == 0 ||
strcasecmp(processName, "kwin_x11_wrapper") == 0 ||
strcasecmp(processName, "kwin") == 0
) ffStrbufSetS(&result->wmPrettyName, "KWin");
else if(
strcasecmp(processName, "gnome-shell") == 0 ||
strcasecmp(processName, "gnome shell") == 0 ||
strcasecmp(processName, "gnome-session-binary") == 0 ||
strcasecmp(processName, "Mutter") == 0
) ffStrbufSetS(&result->wmPrettyName, "Mutter");
else if(
strcasecmp(processName, "cinnamon-session") == 0 ||
strcasecmp(processName, "Muffin") == 0
) ffStrbufSetS(&result->wmPrettyName, "Muffin");
else if(strcasecmp(processName, "sway") == 0)
ffStrbufSetS(&result->wmPrettyName, "Sway");
else if(strcasecmp(processName, "weston") == 0)
@@ -64,10 +91,6 @@ static void applyPrettyNameIfWM(FFDisplayServerResult* result, const char* proce
ffStrbufSetS(&result->wmPrettyName, "Marco");
else if(strcasecmp(processName, "xmonad") == 0)
ffStrbufSetS(&result->wmPrettyName, "XMonad");
else if(strcasecmp(processName, "gnome-session-binary") == 0 || strcasecmp(processName, "Mutter") == 0)
ffStrbufSetS(&result->wmPrettyName, "Mutter");
else if(strcasecmp(processName, "cinnamon-session") == 0 || strcasecmp(processName, "Muffin") == 0)
ffStrbufSetS(&result->wmPrettyName, "Muffin");
else if( // WMs where the pretty name matches the process name
strcasecmp(processName, "dwm") == 0 ||
strcasecmp(processName, "bspwm") == 0 ||
@@ -98,7 +121,15 @@ static void getKDE(FFDisplayServerResult* result)
{
ffStrbufSetS(&result->deProcessName, "plasmashell");
ffStrbufSetS(&result->dePrettyName, "KDE Plasma");
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
if(result->deVersion.length == 0)
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/xsessions/plasma5.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
if(result->deVersion.length == 0)
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/wayland-sessions/plasmawayland.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
if(result->deVersion.length == 0)
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/wayland-sessions/plasmawayland5.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
applyBetterWM(result, getenv("KDEWM"));
}
@@ -321,7 +352,7 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re
//Don't check for processes not owend by the current user.
ffStrbufAppendS(&procPath, "/loginuid");
ffGetFileContent(procPath.chars, &loginuid);
ffReadFileBuffer(procPath.chars, &loginuid);
if(ffStrbufComp(&userID, &loginuid) != 0)
{
ffStrbufSubstrBefore(&procPath, procPathLength);
@@ -332,7 +363,7 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re
//We check the cmdline for the process name, because it is not trimmed.
ffStrbufAppendS(&procPath, "/cmdline");
ffGetFileContent(procPath.chars, &processName);
ffReadFileBuffer(procPath.chars, &processName);
ffStrbufSubstrBeforeFirstC(&processName, '\0'); //Trim the arguments
ffStrbufSubstrAfterLastC(&processName, '/');
@@ -363,7 +394,7 @@ void ffdsDetectWMDE(const FFinstance* instance, FFDisplayServerResult* result)
getWMProtocolNameFromEnv(result);
//We don't want to detect anything in TTY
//This can't happen if a X11 connection succeeded, so we don't need to clear wmProcessName
//This can't happen if a connection succeeded, so we don't need to clear wmProcessName
if(ffStrbufIgnCaseCompS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_TTY) == 0)
return;
+4 -2
View File
@@ -1,8 +1,10 @@
#include "displayServer.h"
#ifdef FF_HAVE_XCB
#include <xcb/xcb.h>
#include "common/library.h"
#include <stdlib.h>
#include <string.h>
#include <xcb/xcb.h>
typedef struct XcbPropertyData
{
@@ -60,7 +62,7 @@ static void* xcbGetProperty(XcbPropertyData* data, xcb_connection_t* connection,
static void xcbDetectWMfromEWMH(XcbPropertyData* data, xcb_connection_t* connection, xcb_window_t rootWindow, FFDisplayServerResult* result)
{
if(result->wmProcessName.length > 0)
if(result->wmProcessName.length > 0 || ffStrbufCompS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND) == 0)
return;
xcb_window_t* wmWindow = (xcb_window_t*) xcbGetProperty(data, connection, rootWindow, "_NET_SUPPORTING_WM_CHECK");
+3 -1
View File
@@ -1,6 +1,8 @@
#include "displayServer.h"
#ifdef FF_HAVE_X11
#include "common/library.h"
#include "common/parsing.h"
#include <X11/Xlib.h>
typedef struct X11PropertyData
@@ -34,7 +36,7 @@ static unsigned char* x11GetProperty(X11PropertyData* data, Display* display, Wi
static void x11DetectWMFromEWMH(X11PropertyData* data, Display* display, FFDisplayServerResult* result)
{
if(result->wmProcessName.length > 0)
if(result->wmProcessName.length > 0 || ffStrbufCompS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND) == 0)
return;
Window* wmWindow = (Window*) x11GetProperty(data, display, DefaultRootWindow(display), "_NET_SUPPORTING_WM_CHECK");
+34 -29
View File
@@ -1,4 +1,8 @@
#include "fastfetch.h"
#include "detection/gtk.h"
#include "common/properties.h"
#include "common/settings.h"
#include "detection/displayserver.h"
#include <pthread.h>
@@ -10,7 +14,7 @@ static inline bool allPropertiesSet(FFGTKResult* result)
result->font.length > 0;
}
static inline void applyGTKDConfSettings(FFGTKResult* result, const char* themeName, const char* iconsName, const char* fontName, const char* cursorTheme, int cursorSize)
static inline void applyGTKSettings(FFGTKResult* result, const char* themeName, const char* iconsName, const char* fontName, const char* cursorTheme, int cursorSize)
{
if(result->theme.length == 0)
ffStrbufAppendS(&result->theme, themeName);
@@ -28,7 +32,7 @@ static inline void applyGTKDConfSettings(FFGTKResult* result, const char* themeN
ffStrbufAppendF(&result->cursorSize, "%i", cursorSize);
}
static void detectGTKFromDConf(FFinstance* instance, FFGTKResult* result)
static void detectGTKFromSettings(FFinstance* instance, FFGTKResult* result)
{
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -45,7 +49,7 @@ static void detectGTKFromDConf(FFinstance* instance, FFGTKResult* result)
if(init)
{
pthread_mutex_unlock(&mutex);
applyGTKDConfSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize);
applyGTKSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize);
return;
}
@@ -53,7 +57,15 @@ static void detectGTKFromDConf(FFinstance* instance, FFGTKResult* result)
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);
if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "Cinnamon") == 0)
if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "Xfce") == 0 || ffStrbufIgnCaseCompS(&wmde->dePrettyName, "Xfce4") == 0)
{
themeName = ffSettingsGetXFConf(instance, "xsettings", "/Net/ThemeName", FF_VARIANT_TYPE_STRING).strValue;
iconsName = ffSettingsGetXFConf(instance, "xsettings", "/Net/IconThemeName", FF_VARIANT_TYPE_STRING).strValue;
fontName = ffSettingsGetXFConf(instance, "xsettings", "/Gtk/FontName", FF_VARIANT_TYPE_STRING).strValue;
cursorTheme = ffSettingsGetXFConf(instance, "xsettings", "/Gtk/CursorThemeName", FF_VARIANT_TYPE_STRING).strValue;
cursorSize = ffSettingsGetXFConf(instance, "xsettings", "/Gtk/CursorThemeSize", FF_VARIANT_TYPE_INT).intValue;
}
else if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "Cinnamon") == 0)
{
themeName = ffSettingsGet(instance, "/org/cinnamon/desktop/interface/gtk-theme", "org.cinnamon.desktop.interface", NULL, "gtk-theme", FF_VARIANT_TYPE_STRING).strValue;
iconsName = ffSettingsGet(instance, "/org/cinnamon/desktop/interface/icon-theme", "org.cinnamon.desktop.interface", NULL, "icon-theme", FF_VARIANT_TYPE_STRING).strValue;
@@ -69,7 +81,7 @@ static void detectGTKFromDConf(FFinstance* instance, FFGTKResult* result)
cursorTheme = ffSettingsGet(instance, "/org/mate/peripherals-mouse/cursor-theme", "org.mate.peripherals-mouse", NULL, "cursor-theme", FF_VARIANT_TYPE_STRING).strValue;
cursorSize = ffSettingsGet(instance, "/org/mate/peripherals-mouse/cursor-size", "org.mate.peripherals-mouse", NULL, "cursor-size", FF_VARIANT_TYPE_INT).intValue;
}
else if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "Gnome") == 0)
else if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "Gnome") == 0 || ffStrbufIgnCaseCompS(&wmde->dePrettyName, "Unity") == 0 || ffStrbufIgnCaseCompS(&wmde->dePrettyName, "Budgie") == 0)
{
themeName = ffSettingsGet(instance, "/org/gnome/desktop/interface/gtk-theme", "org.gnome.desktop.interface", NULL, "gtk-theme", FF_VARIANT_TYPE_STRING).strValue;
iconsName = ffSettingsGet(instance, "/org/gnome/desktop/interface/icon-theme", "org.gnome.desktop.interface", NULL, "icon-theme", FF_VARIANT_TYPE_STRING).strValue;
@@ -79,7 +91,7 @@ static void detectGTKFromDConf(FFinstance* instance, FFGTKResult* result)
}
pthread_mutex_unlock(&mutex);
applyGTKDConfSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize);
applyGTKSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize);
}
static void detectGTKFromConfigFile(const char* filename, FFGTKResult* result)
@@ -95,15 +107,10 @@ static void detectGTKFromConfigFile(const char* filename, FFGTKResult* result)
static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFGTKResult* result)
{
//In case of an empty env variable
ffStrbufTrim(configDir, ' ');
if(configDir->length == 0)
return;
uint32_t configDirLength = configDir->length;
// <configdir>/gtk-<version>.0/settings.ini
ffStrbufAppendS(configDir, "/gtk-");
ffStrbufAppendS(configDir, "gtk-");
ffStrbufAppendS(configDir, version);
ffStrbufAppendS(configDir, ".0/settings.ini");
detectGTKFromConfigFile(configDir->chars, result);
@@ -112,7 +119,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG
return;
// <configdir>/gtk-<version>.0/gtkrc
ffStrbufAppendS(configDir, "/gtk-");
ffStrbufAppendS(configDir, "gtk-");
ffStrbufAppendS(configDir, version);
ffStrbufAppendS(configDir, ".0/gtkrc");
detectGTKFromConfigFile(configDir->chars, result);
@@ -121,7 +128,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG
return;
// <configdir>/gtkrc-<version>.0
ffStrbufAppendS(configDir, "/gtkrc-");
ffStrbufAppendS(configDir, "gtkrc-");
ffStrbufAppendS(configDir, version);
ffStrbufAppendS(configDir, ".0");
detectGTKFromConfigFile(configDir->chars, result);
@@ -130,7 +137,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG
return;
// <configdir>/.gtkrc-<version>.0
ffStrbufAppendS(configDir, "/.gtkrc-");
ffStrbufAppendS(configDir, ".gtkrc-");
ffStrbufAppendS(configDir, version);
ffStrbufAppendS(configDir, ".0");
detectGTKFromConfigFile(configDir->chars, result);
@@ -139,27 +146,25 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG
static void detectGTK(FFinstance* instance, const char* version, FFGTKResult* result)
{
//Mate, Cinnamon and Gnome use dconf to save theme config
//On other DEs, this will do nothing
detectGTKFromSettings(instance, result);
if(allPropertiesSet(result))
return;
//We need to do this because we use multiple threads on configDirs
FFstrbuf baseDirCopy;
ffStrbufInitA(&baseDirCopy, 64);
FFstrbuf baseDir;
ffStrbufInitA(&baseDir, 64);
for(uint32_t i = 0; i < instance->state.configDirs.length; i++)
{
FFstrbuf* baseDir = (FFstrbuf*) ffListGet(&instance->state.configDirs, i);
ffStrbufSet(&baseDirCopy, baseDir);
detectGTKFromConfigDir(&baseDirCopy, version, result);
ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i));
detectGTKFromConfigDir(&baseDir, version, result);
if(allPropertiesSet(result))
{
ffStrbufDestroy(&baseDirCopy);
return;
}
break;
}
ffStrbufDestroy(&baseDirCopy);
//Mate, Cinnamon and Gnome use dconf to save theme config
//On other DEs, this will do nothing
detectGTKFromDConf(instance, result);
ffStrbufDestroy(&baseDir);
}
#define FF_DETECT_GTK_IMPL(version) \
+21
View File
@@ -0,0 +1,21 @@
#pragma once
#ifndef FF_INCLUDED_detection_gtk
#define FF_INCLUDED_detection_gtk
#include "fastfetch.h"
typedef struct FFGTKResult
{
FFstrbuf theme;
FFstrbuf icons;
FFstrbuf font;
FFstrbuf cursor;
FFstrbuf cursorSize;
} FFGTKResult;
const FFGTKResult* ffDetectGTK2(FFinstance* instance);
const FFGTKResult* ffDetectGTK4(FFinstance* instance);
const FFGTKResult* ffDetectGTK3(FFinstance* instance);
#endif
+3
View File
@@ -1,4 +1,5 @@
#include "fastfetch.h"
#include "detection/media.h"
#include <string.h>
#include <pthread.h>
@@ -7,6 +8,8 @@
#define FF_DBUS_TIMEOUT_MILLISECONDS 35
#ifdef FF_HAVE_DBUS
#include "common/library.h"
#include "common/parsing.h"
#include <dbus/dbus.h>
#define FF_DBUS_ITER_CONTINUE(iterator) \
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#ifndef FF_INCLUDED_detection_media
#define FF_INCLUDED_detection_media
#include "fastfetch.h"
typedef struct FFMediaResult
{
FFstrbuf busNameShort; //e.g. plasma-browser-integration
FFstrbuf player; // e.g. Google Chrome
FFstrbuf song;
FFstrbuf artist;
FFstrbuf album;
FFstrbuf url;
} FFMediaResult;
const FFMediaResult* ffDetectMedia(FFinstance* instance);
#endif
+22 -5
View File
@@ -1,16 +1,22 @@
#include "fastfetch.h"
#include "detection/os.h"
#include "common/properties.h"
#include "common/parsing.h"
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#if !defined(__ANDROID__)
#if __ANDROID__
#include "common/settings.h"
#else
static void parseFile(const char* fileName, FFOSResult* result)
static bool parseFile(const char* fileName, FFOSResult* result)
{
if(result->name.length > 0 && result->prettyName.length > 0)
return;
if(result->id.length > 0 && result->name.length > 0 && result->prettyName.length > 0)
return true;
ffParsePropFileValues(fileName, 13, (FFpropquery[]) {
return ffParsePropFileValues(fileName, 13, (FFpropquery[]) {
{"NAME =", &result->name},
{"DISTRIB_DESCRIPTION =", &result->prettyName},
{"PRETTY_NAME =", &result->prettyName},
@@ -124,6 +130,17 @@ const FFOSResult* ffDetectOS(const FFinstance* instance)
{
parseFile(instance->config.osFile.chars, &result);
}
else if(instance->config.escapeBedrock && parseFile(FASTFETCH_TARGET_DIR_ROOT"/bedrock/etc/bedrock-release", &result))
{
if(result.id.length == 0)
ffStrbufAppendS(&result.id, "bedrock");
if(result.name.length == 0)
ffStrbufAppendS(&result.name, "Bedrock");
if(result.prettyName.length == 0)
ffStrbufAppendS(&result.prettyName, "Bedrock Linux");
}
else
{
parseFile(FASTFETCH_TARGET_DIR_ROOT"/etc/os-release", &result);
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#ifndef FF_INCLUDED_detection_os
#define FF_INCLUDED_detection_os
#include "fastfetch.h"
typedef struct FFOSResult
{
FFstrbuf systemName;
FFstrbuf name;
FFstrbuf prettyName;
FFstrbuf id;
FFstrbuf idLike;
FFstrbuf variant;
FFstrbuf variantID;
FFstrbuf version;
FFstrbuf versionID;
FFstrbuf codename;
FFstrbuf buildID;
FFstrbuf architecture;
} FFOSResult;
const FFOSResult* ffDetectOS(const FFinstance* instance);
#endif
+73 -54
View File
@@ -1,8 +1,21 @@
#include "fastfetch.h"
#include "detection/qt.h"
#include "common/properties.h"
#include "detection/displayserver.h"
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
static inline bool allValuesSet(const FFQtResult* result)
{
return
result->widgetStyle.length > 0 &&
result->colorScheme.length > 0 &&
result->icons.length > 0 &&
result->font.length > 0;
}
typedef enum PlasmaCategory
{
PLASMA_CATEGORY_GENERAL,
@@ -11,9 +24,9 @@ typedef enum PlasmaCategory
PLASMA_CATEGORY_OTHER
} PlasmaCategory;
static bool detectFromConfigFile(const FFstrbuf* filename, FFPlasmaResult* result)
static bool detectPlasmaFromFile(const char* filename, FFQtResult* result)
{
FILE* kdeglobals = fopen(filename->chars, "r");
FILE* kdeglobals = fopen(filename, "r");
if(kdeglobals == NULL)
return false;
@@ -67,10 +80,62 @@ static bool detectFromConfigFile(const FFstrbuf* filename, FFPlasmaResult* resul
return true;
}
const FFPlasmaResult* ffDetectPlasma(FFinstance* instance)
static void detectPlasma(const FFinstance* instance, FFQtResult* result)
{
bool foundAFile = false;
//We need to do this because we use multiple threads on configDirs
FFstrbuf baseDir;
ffStrbufInitA(&baseDir, 64);
for(uint32_t i = 0; i < instance->state.configDirs.length; i++)
{
ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i));
ffStrbufAppendS(&baseDir, "kdeglobals");
if(detectPlasmaFromFile(baseDir.chars, result))
foundAFile = true;
if(allValuesSet(result))
{
ffStrbufDestroy(&baseDir);
return;
}
}
ffStrbufDestroy(&baseDir);
if(!foundAFile)
return;
//In Plasma the default value is never set in the config file, but the whole key-value is discarded.
///We must set these values by our self if the file exists (it always does here)
if(result->widgetStyle.length == 0)
ffStrbufAppendS(&result->widgetStyle, "Breeze");
if(result->colorScheme.length == 0)
ffStrbufAppendS(&result->colorScheme, "BreezeLight");
if(result->icons.length == 0)
ffStrbufAppendS(&result->icons, "Breeze");
if(result->font.length == 0)
ffStrbufAppendS(&result->font, "Noto Sans, 10");
}
static void detectLXQt(const FFinstance* instance, FFQtResult* result)
{
ffParsePropFileConfigValues(instance, "lxqt/lxqt.conf", 3, (FFpropquery[]) {
{"style = ", &result->widgetStyle},
{"icon_theme = ", &result->icons},
{"font = ", &result->font}
});
}
const FFQtResult* ffDetectQt(FFinstance* instance)
{
static FFQtResult result;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static FFPlasmaResult result;
static bool init = false;
pthread_mutex_lock(&mutex);
if(init)
@@ -86,57 +151,11 @@ const FFPlasmaResult* ffDetectPlasma(FFinstance* instance)
ffStrbufInit(&result.font);
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);
if(ffStrbufIgnCaseCompS(&wmde->deProcessName, "plasmashell") != 0)
{
pthread_mutex_unlock(&mutex);
return &result;
}
bool foundAFile = false;
//We need to do this because we use multiple threads on configDirs
FFstrbuf baseDirCopy;
ffStrbufInitA(&baseDirCopy, 64);
for(uint32_t i = 0; i < instance->state.configDirs.length; i++)
{
FFstrbuf* baseDir = (FFstrbuf*) ffListGet(&instance->state.configDirs, i);
ffStrbufSet(&baseDirCopy, baseDir);
ffStrbufAppendS(&baseDirCopy, "/kdeglobals");
if(detectFromConfigFile(&baseDirCopy, &result))
foundAFile = true;
if(
result.widgetStyle.length > 0 &&
result.colorScheme.length > 0 &&
result.icons.length > 0 &&
result.font.length > 0
) break;
}
ffStrbufDestroy(&baseDirCopy);
if(!foundAFile)
{
pthread_mutex_unlock(&mutex);
return &result;
}
//In Plasma the default value is never set in the config file, but the whole key-value is discarded.
///We must set these values by our self if the file exists (it always does here)
if(result.widgetStyle.length == 0)
ffStrbufAppendS(&result.widgetStyle, "Breeze");
if(result.colorScheme.length == 0)
ffStrbufAppendS(&result.colorScheme, "BreezeLight");
if(result.icons.length == 0)
ffStrbufAppendS(&result.icons, "Breeze");
if(result.font.length == 0)
ffStrbufAppendS(&result.font, "Noto Sans, 10");
if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "KDE Plasma") == 0)
detectPlasma(instance, &result);
else if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "LXQt") == 0)
detectLXQt(instance, &result);
pthread_mutex_unlock(&mutex);
return &result;
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#ifndef FF_INCLUDED_detection_qt
#define FF_INCLUDED_detection_qt
#include "fastfetch.h"
typedef struct FFQtResult
{
FFstrbuf widgetStyle;
FFstrbuf colorScheme;
FFstrbuf icons;
FFstrbuf font;
} FFQtResult;
const FFQtResult* ffDetectQt(FFinstance* instance);
#endif
+26 -17
View File
@@ -1,16 +1,15 @@
#include "fastfetch.h"
#include "detection/temps.h"
#include "common/io.h"
#include <string.h>
#include <pthread.h>
#include <dirent.h>
#include <string.h>
static bool isTempFile(const char* name)
{
return
name[0] == 't' &&
name[1] == 'e' &&
name[2] == 'm' &&
name[3] == 'p' &&
strncmp(name, "temp", 4) == 0 &&
name[4] >= '0' &&
name[4] <= '9' &&
strncmp(name + 5, "_input", 6) == 0;
@@ -23,30 +22,42 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value)
return false;
uint32_t dirLength = dir->length;
value->value = 0.0 / 0.0; //use NaN as error value
FFstrbuf valueString;
ffStrbufInit(&valueString);
struct dirent* dirent;
while((dirent = readdir(dirp)) != NULL)
{
if(isTempFile(dirent->d_name))
{
ffStrbufAppendS(dir, dirent->d_name);
ffGetFileContent(dir->chars, &value->value);
ffStrbufSubstrBefore(dir, dirLength);
break;
}
if(!isTempFile(dirent->d_name))
continue;
ffStrbufAppendS(dir, dirent->d_name);
ffReadFileBuffer(dir->chars, &valueString);
ffStrbufSubstrBefore(dir, dirLength);
//ffStrbufToDouble() returns NaN if the string couldn't be parsed
value->value = ffStrbufToDouble(&valueString);
if(value->value != value->value)
continue;
value->value /= 1000.0; //millidegrees to degrees
break;
}
closedir(dirp);
ffStrbufDestroy(&valueString);
if(value->value.length == 0)
if(value->value != value->value)
return false;
ffStrbufAppendS(dir, "name");
ffGetFileContent(dir->chars, &value->name);
ffReadFileBuffer(dir->chars, &value->name);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufAppendS(dir, "device/class");
ffGetFileContent(dir->chars, &value->deviceClass);
ffReadFileBuffer(dir->chars, &value->deviceClass);
ffStrbufSubstrBefore(dir, dirLength);
return value->name.length > 0 || value->deviceClass.length > 0;
@@ -95,12 +106,10 @@ const FFTempsResult* ffDetectTemps(const FFinstance* instance)
FFTempValue* temp = ffListAdd(&result.values);
ffStrbufInit(&temp->name);
ffStrbufInit(&temp->deviceClass);
ffStrbufInit(&temp->value);
if(!parseHwmonDir(&baseDir, temp))
{
ffStrbufDestroy(&temp->name);
ffStrbufDestroy(&temp->deviceClass);
ffStrbufDestroy(&temp->value);
--result.values.length;
}
+22
View File
@@ -0,0 +1,22 @@
#pragma once
#ifndef FF_INCLUDED_detection_temps
#define FF_INCLUDED_detection_temps
#include "fastfetch.h"
typedef struct FFTempValue
{
FFstrbuf name;
FFstrbuf deviceClass;
double value;
} FFTempValue;
typedef struct FFTempsResult
{
FFlist values; //List of FFTempValue
} FFTempsResult;
const FFTempsResult* ffDetectTemps(const FFinstance* instance);
#endif
+24 -9
View File
@@ -1,7 +1,12 @@
#include "fastfetch.h"
#include "detection/terminalshell.h"
#include "common/io.h"
#include "common/parsing.h"
#include "common/processing.h"
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
@@ -20,7 +25,7 @@ static void getProcessInformation(const char* pid, FFstrbuf* processName, FFstrb
ffStrbufAppendS(&cmdlineFilePath, pid);
ffStrbufAppendS(&cmdlineFilePath, "/cmdline");
ffGetFileContent(cmdlineFilePath.chars, exe);
ffReadFileBuffer(cmdlineFilePath.chars, exe);
ffStrbufSubstrBeforeFirstC(exe, '\0'); //Trim the arguments
ffStrbufTrimLeft(exe, '-'); //Happens in TTY
@@ -68,12 +73,13 @@ static void getTerminalShell(FFTerminalShellResult* result, const char* pid)
//Common programs that are between terminal and own process, but are not the shell
if(
strcasecmp(name, "sudo") == 0 ||
strcasecmp(name, "su") == 0 ||
strcasecmp(name, "doas") == 0 ||
strcasecmp(name, "strace") == 0 ||
strcasecmp(name, "sshd") == 0 ||
strcasecmp(name, "gdb") == 0
strcasecmp(name, "sudo") == 0 ||
strcasecmp(name, "su") == 0 ||
strcasecmp(name, "doas") == 0 ||
strcasecmp(name, "strace") == 0 ||
strcasecmp(name, "sshd") == 0 ||
strcasecmp(name, "gdb") == 0 ||
strcasecmp(name, "guake-wrapped") == 0
) {
getTerminalShell(result, ppid);
return;
@@ -119,8 +125,17 @@ static void getTerminalFromEnv(FFTerminalShellResult* result)
term = getenv("SSH_TTY");
//Windows Terminal
if(!ffStrSet(term) && getenv("WT_SESSION") != NULL)
term = "Windows Terminal";
if(!ffStrSet(term) && (
getenv("WT_SESSION") != NULL ||
getenv("WT_PROFILE_ID") != NULL
)) term = "Windows Terminal";
//Termux
if(!ffStrSet(term) && (
getenv("TERMUX_VERSION") != NULL ||
getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL ||
getenv("TMUX_TMPDIR") != NULL
)) term = "Termux";
//Normal Terminal
if(!ffStrSet(term))
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#ifndef FF_INCLUDED_detection_terminalshell
#define FF_INCLUDED_detection_terminalshell
#include "fastfetch.h"
typedef struct FFTerminalShellResult
{
FFstrbuf shellProcessName;
FFstrbuf shellExe;
const char* shellExeName; //pointer to a char in shellExe
FFstrbuf shellVersion;
FFstrbuf terminalProcessName;
FFstrbuf terminalExe;
const char* terminalExeName; //pointer to a char in terminalExe
FFstrbuf userShellExe;
const char* userShellExeName; //pointer to a char in userShellExe
FFstrbuf userShellVersion;
} FFTerminalShellResult;
const FFTerminalShellResult* ffDetectTerminalShell(FFinstance* instance);
#endif
+54
View File
@@ -0,0 +1,54 @@
#include "fastfetch.h"
#include "detection/title.h"
#include <limits.h>
#include <unistd.h>
#include <pthread.h>
#include <netdb.h>
const FFTitleResult* ffDetectTitle(const FFinstance* instance)
{
static FFTitleResult result;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static bool init = false;
pthread_mutex_lock(&mutex);
if(init)
{
pthread_mutex_unlock(&mutex);
return &result;
}
init = true;
ffStrbufInit(&result.userName);
ffStrbufAppendS(&result.userName, instance->state.passwd->pw_name);
ffStrbufInitA(&result.hostname, HOST_NAME_MAX);
ffStrbufAppendS(&result.hostname, instance->state.utsname.nodename);
ffStrbufInitA(&result.fqdn, HOST_NAME_MAX);
struct addrinfo hints = {0};
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
struct addrinfo* info = NULL;
if(getaddrinfo(result.hostname.chars, "80", &hints, &info) == 0)
{
struct addrinfo* current = info;
while(result.fqdn.length == 0 && current != NULL)
{
ffStrbufAppendS(&result.fqdn, current->ai_canonname);
current = current->ai_next;
}
freeaddrinfo(info);
}
if(result.fqdn.length == 0)
ffStrbufAppend(&result.fqdn, &result.hostname);
pthread_mutex_unlock(&mutex);
return &result;
}
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#ifndef FF_INCLUDED_detection_title
#define FF_INCLUDED_detection_title
#include "fastfetch.h"
typedef struct FFTitleResult
{
FFstrbuf userName;
FFstrbuf hostname;
FFstrbuf fqdn; //Fully qualified domain name
} FFTitleResult;
const FFTitleResult* ffDetectTitle(const FFinstance* instance);
#endif
+231
View File
@@ -0,0 +1,231 @@
#include "fastfetch.h"
#include "detection/vulkan.h"
#include <pthread.h>
#ifdef FF_HAVE_VULKAN
#include "common/library.h"
#include "common/io.h"
#include "common/parsing.h"
#include <stdlib.h>
#include <vulkan/vulkan.h>
static inline void applyVulkanVersion(uint32_t vulkanVersion, FFVersion* ffVersion)
{
ffVersion->major = VK_VERSION_MAJOR(vulkanVersion);
ffVersion->minor = VK_VERSION_MINOR(vulkanVersion);
ffVersion->patch = VK_VERSION_PATCH(vulkanVersion);
}
static void applyDriverName(VkPhysicalDeviceDriverProperties* properties, FFstrbuf* result)
{
if(!ffStrSet(properties->driverName))
return;
ffStrbufAppendS(result, properties->driverName);
if(!ffStrSet(properties->driverInfo))
return;
ffStrbufAppendS(result, " [");
ffStrbufAppendS(result, properties->driverInfo);
ffStrbufAppendC(result, ']');
}
static void detectVulkan(const FFinstance* instance, FFVulkanResult* result)
{
FF_LIBRARY_LOAD(vulkan, instance->config.libVulkan, , "libvulkan.so", 2)
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkGetInstanceProcAddr,)
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkCreateInstance,)
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkDestroyInstance,)
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkEnumeratePhysicalDevices,)
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkGetPhysicalDeviceProperties,)
//Some drivers (nvdc) print messages to stdout
//and thats the best way i found to disable that
ffSuppressIO(true);
FFVersion instanceVersion = FF_VERSION_INIT;
//We need to get the function pointer this way, because it is only provided by vulkan 1.1 and higher.
//a dlsym would fail on 1.0 implementations
PFN_vkEnumerateInstanceVersion ffvkEnumerateInstanceVersion = (PFN_vkEnumerateInstanceVersion) ffvkGetInstanceProcAddr(NULL, "vkEnumerateInstanceVersion");
if(ffvkEnumerateInstanceVersion != NULL)
{
uint32_t version;
if(ffvkEnumerateInstanceVersion(&version) == VK_SUCCESS)
applyVulkanVersion(version, &instanceVersion);
}
const uint32_t projectVersion = VK_MAKE_VERSION(
FASTFETCH_PROJECT_VERSION_MAJOR,
FASTFETCH_PROJECT_VERSION_MINOR,
FASTFETCH_PROJECT_VERSION_PATCH
);
//We need to request 1.2 to get physicalDeviceDriverProperties
uint32_t requestedVkVersion = VK_API_VERSION_1_0;
if(instanceVersion.minor >= 2)
requestedVkVersion = VK_API_VERSION_1_2;
const VkApplicationInfo applicationInfo = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pNext = NULL,
.pApplicationName = FASTFETCH_PROJECT_NAME,
.applicationVersion = projectVersion,
.pEngineName = "vulkanPrintGPUs",
.engineVersion = projectVersion,
.apiVersion = requestedVkVersion
};
const VkInstanceCreateInfo instanceCreateInfo = {
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pNext = NULL,
.pApplicationInfo = &applicationInfo,
.enabledLayerCount = 0,
.ppEnabledLayerNames = NULL,
.enabledExtensionCount = 0,
.ppEnabledExtensionNames = NULL,
.flags = 0
};
VkInstance vkInstance;
if(ffvkCreateInstance(&instanceCreateInfo, NULL, &vkInstance) != VK_SUCCESS)
{
dlclose(vulkan);
ffSuppressIO(false);
return;
}
//if instance creation succeeded, but vkEnumerateInstanceVersion didn't, this means we are running against a vulkan 1.0 implementation
//explicitly set this version, if no device is found, so we still have at least this info
if(instanceVersion.major == 0 && instanceVersion.minor == 0 && instanceVersion.patch == 0)
instanceVersion.major = 1;
uint32_t physicalDeviceCount;
if(ffvkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, NULL) != VK_SUCCESS)
{
ffvkDestroyInstance(vkInstance, NULL);
dlclose(vulkan);
ffSuppressIO(false);
return;
}
VkPhysicalDevice* physicalDevices = malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount);
if(ffvkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, physicalDevices) != VK_SUCCESS)
{
free(physicalDevices);
ffvkDestroyInstance(vkInstance, NULL);
dlclose(vulkan);
ffSuppressIO(false);
return;
}
PFN_vkGetPhysicalDeviceProperties2 ffvkGetPhysicalDeviceProperties2 = (PFN_vkGetPhysicalDeviceProperties2) ffvkGetInstanceProcAddr(vkInstance, "vkGetPhysicalDeviceProperties2");
FFVersion maxDeviceApiVersion = FF_VERSION_INIT;
FFVersion maxDeviceConformanceVersion = FF_VERSION_INIT;
for(uint32_t i = 0; i < physicalDeviceCount; i++)
{
//Get device properties.
//On VK 1.2 and up, we use vkGetPhysicalDeviceProperties2, so we can put VkPhysicalDeviceDriverProperties in the pNext chain.
//This is required to get the driver name and conformance version.
VkPhysicalDeviceDriverProperties driverProperties;
driverProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
driverProperties.pNext = NULL;
driverProperties.driverName[0] = '\0';
driverProperties.conformanceVersion = (VkConformanceVersion) {0, 0, 0, 0};
VkPhysicalDeviceProperties2 physicalDeviceProperties;
physicalDeviceProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
physicalDeviceProperties.pNext = &driverProperties;
if(ffvkGetPhysicalDeviceProperties2 != NULL)
ffvkGetPhysicalDeviceProperties2(physicalDevices[i], &physicalDeviceProperties);
else
ffvkGetPhysicalDeviceProperties(physicalDevices[i], &physicalDeviceProperties.properties);
//If the device api version is higher than the current highest device api version, overwrite it
//In this case, also use the current device driver name as the shown driver name
FFVersion deviceAPIVersion = FF_VERSION_INIT;
applyVulkanVersion(physicalDeviceProperties.properties.apiVersion, &deviceAPIVersion);
if(ffVersionCompare(&deviceAPIVersion, &maxDeviceApiVersion) > 0)
{
maxDeviceApiVersion = deviceAPIVersion;
applyDriverName(&driverProperties, &result->driver);
}
//If the device conformance version is higher than the current highest device conformance version, overwrite it
FFVersion deviceConformanceVersion = FF_VERSION_INIT;
deviceConformanceVersion.major = driverProperties.conformanceVersion.major;
deviceConformanceVersion.minor = driverProperties.conformanceVersion.minor;
deviceConformanceVersion.patch = driverProperties.conformanceVersion.patch;
if(ffVersionCompare(&deviceConformanceVersion, &maxDeviceConformanceVersion) > 0)
maxDeviceConformanceVersion = deviceConformanceVersion;
//Add the device to the list of devices shown by the GPU module
//We don't want softare rasterizers to show up as physical gpu
if(physicalDeviceProperties.properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU)
continue;
FFGPUResult* gpu = ffListAdd(&result->devices);
ffStrbufInit(&gpu->vendor);
ffStrbufInit(&gpu->name);
ffStrbufInit(&gpu->driver);
gpu->temperature = 0.0 / 0.0; //NaN, no way to detect temperature using vulkan
ffStrbufAppendS(&gpu->name, physicalDeviceProperties.properties.deviceName);
}
//If the highest device version is lower than the instance version, use it as our vulkan version
//otherwise the instance version is the vulkan version
if(ffVersionCompare(&instanceVersion, &maxDeviceApiVersion) > 0)
ffVersionToPretty(&maxDeviceApiVersion, &result->apiVersion);
else
ffVersionToPretty(&instanceVersion, &result->apiVersion);
//Use the highest device conformace version as our conformance version
ffVersionToPretty(&maxDeviceConformanceVersion, &result->conformanceVersion);
free(physicalDevices);
ffvkDestroyInstance(vkInstance, NULL);
dlclose(vulkan);
ffSuppressIO(false);
}
#endif
const FFVulkanResult* ffDetectVulkan(const FFinstance* instance)
{
static FFVulkanResult result;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static bool init = false;
pthread_mutex_lock(&mutex);
if(init)
{
pthread_mutex_unlock(&mutex);
return &result;
}
init = true;
ffStrbufInit(&result.driver);
ffStrbufInit(&result.apiVersion);
ffStrbufInit(&result.conformanceVersion);
ffListInit(&result.devices, sizeof(FFGPUResult));
#ifdef FF_HAVE_VULKAN
detectVulkan(instance, &result);
#else
FF_UNUSED(instance);
#endif
pthread_mutex_unlock(&mutex);
return &result;
}
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#ifndef FF_INCLUDED_detection_vulkan
#define FF_INCLUDED_detection_vulkan
#include "fastfetch.h"
typedef struct FFGPUResult
{
FFstrbuf vendor;
FFstrbuf name;
FFstrbuf driver;
double temperature;
} FFGPUResult;
typedef struct FFVulkanResult
{
FFstrbuf driver;
FFstrbuf apiVersion;
FFstrbuf conformanceVersion;
FFlist devices; //List of FFGPUResult
} FFVulkanResult;
const FFVulkanResult* ffDetectVulkan(const FFinstance* instance);
#endif
+411 -199
View File
@@ -1,18 +1,26 @@
#include "fastfetch.h"
#include "util/FFvaluestore.h"
#include "common/printing.h"
#include "common/parsing.h"
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <malloc.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/stat.h>
typedef struct CustomValue
{
bool printKey;
FFstrbuf value;
} CustomValue;
// Things only needed by fastfetch
typedef struct FFdata
{
FFvaluestore valuestore;
FFvaluestore customValues;
FFstrbuf structure;
bool multithreading;
bool loadUserConfig;
} FFdata;
static void constructAndPrintCommandHelpFormat(const char* name, const char* def, uint32_t numArgs, ...)
@@ -28,7 +36,7 @@ static void constructAndPrintCommandHelpFormat(const char* name, const char* def
for(uint32_t i = 1; i <= numArgs; i++)
printf(" {%u}: %s\n", i, va_arg(argp, const char*));
printf("The default is something like \"%s\".\n", def);
printf("The default is something similar to \"%s\".\n", def);
va_end(argp);
}
@@ -62,10 +70,22 @@ static inline void printCommandHelp(const char* command)
}
else if(strcasecmp(command, "host-format") == 0)
{
constructAndPrintCommandHelpFormat("host", "{2} {3}", 3,
"Host family",
"Host name",
"Host version"
constructAndPrintCommandHelpFormat("host", "{2} {3}", 15,
"product family",
"product name",
"product version",
"product sku",
"bios date",
"bios release",
"bios vendor",
"bios version",
"board name",
"board vendor",
"board version",
"chassis type",
"chassis vendor",
"chassis version",
"sys vendor"
);
}
else if(strcasecmp(command, "kernel-format") == 0)
@@ -93,7 +113,7 @@ static inline void printCommandHelp(const char* command)
}
else if(strcasecmp(command, "packages-format") == 0)
{
constructAndPrintCommandHelpFormat("packages", "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (emerge), {7} (xps), {8}, (flatpak), {9} (snap)", 9,
constructAndPrintCommandHelpFormat("packages", "{2} (pacman){?3}[{3}]{?}, {4} (dpkg), {5} (rpm), {6} (emerge), {7} (xbps), {8} (nix-system), {9} (nix-user), {10} (nix-default), {11} (apk), {12} (flatpak), {13} (snap)", 13,
"Number of all packages",
"Number of pacman packages",
"Pacman branch on manjaro",
@@ -101,6 +121,10 @@ static inline void printCommandHelp(const char* command)
"Number of rpm packages",
"Number of emerge packages",
"Number of xbps packages",
"Number of nix-system packages",
"Number of nix-user packages",
"Number of nix-default packages",
"Number of apk packages",
"Number of flatpak packages",
"Number of snap packages"
);
@@ -222,7 +246,7 @@ static inline void printCommandHelp(const char* command)
}
else if(strcasecmp(command, "cpu-format") == 0)
{
constructAndPrintCommandHelpFormat("cpu", "{2} ({7}) @ {14}GHz", 14,
constructAndPrintCommandHelpFormat("cpu", "{2} ({7}) @ {15}GHz", 15,
"CPU name",
"Prettified CPU name",
"CPU Vendor name (Vendor ID)",
@@ -230,6 +254,7 @@ static inline void printCommandHelp(const char* command)
"CPU logical core count configured",
"CPU physical core count",
"Always set core count",
"CPU package temperature",
"frequency bios limit",
"frequency scaling max",
"frequency scaling min",
@@ -247,12 +272,13 @@ static inline void printCommandHelp(const char* command)
}
else if(strcasecmp(command, "gpu-format") == 0)
{
constructAndPrintCommandHelpFormat("gpu", "{2} {4}", 5,
constructAndPrintCommandHelpFormat("gpu", "{2} {4}", 6,
"GPU vendor",
"GPU vendor pretty",
"GPU name",
"GPU name pretty",
"GPU driver"
"GPU driver",
"GPU temperature"
);
}
else if(strcasecmp(command, "memory-format") == 0)
@@ -265,7 +291,7 @@ static inline void printCommandHelp(const char* command)
}
else if(strcasecmp(command, "disk-format") == 0)
{
constructAndPrintCommandHelpFormat("disk", "{}GB / {}GB ({4}%)", 4,
constructAndPrintCommandHelpFormat("disk", "{}GiB / {}GiB ({4}%)", 4,
"Used disk space",
"Total disk space",
"Number of files",
@@ -334,7 +360,7 @@ static inline void printCommandHelp(const char* command)
"day in month",
"day in Week",
"hour",
"hout with leading zero",
"hour with leading zero",
"hour 12h format",
"hour 12h format with leading zero",
"minute",
@@ -343,6 +369,31 @@ static inline void printCommandHelp(const char* command)
"second with leading zero"
);
}
else if(strcasecmp(command, "vulkan-format") == 0)
{
constructAndPrintCommandHelpFormat("vulkan", "{} (driver), {} (api version)", 3,
"Driver name",
"API version",
"Conformance version"
);
}
else if(strcasecmp(command, "opengl-format") == 0)
{
constructAndPrintCommandHelpFormat("opengl", "{}", 3,
"version",
"renderer",
"vendor",
"shading language version"
);
}
else if(strcasecmp(command, "opencl-format") == 0)
{
constructAndPrintCommandHelpFormat("opencl", "{}", 3,
"version",
"device",
"vendor"
);
}
else
fprintf(stderr, "No specific help for command %s provided\n", command);
}
@@ -403,58 +454,57 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
static void parseConfigFile(FFinstance* instance, FFdata* data, FILE* file)
{
char* lineStart = NULL;
char* line = NULL;
size_t len = 0;
ssize_t read;
FFstrbuf line;
ffStrbufInitA(&line, 256); //The default structure line needs this size
while ((read = getline(&lineStart, &len, file)) != -1)
while ((read = getline(&line, &len, file)) != -1)
{
ffStrbufSetS(&line, lineStart);
ffStrbufTrimRight(&line, '\n');
ffStrbufTrim(&line, ' ');
char* lineStart = line;
char* lineEnd = line + read - 1;
if(line.length == 0 || line.chars[0] == '#')
//Trim line left
while(isspace(*lineStart))
++lineStart;
//Continue if line is empty or a comment
if(*lineStart == '\0' || *lineStart == '#')
continue;
uint32_t firstSpace = ffStrbufFirstIndexC(&line, ' ');
//Trim line right
while(lineEnd > lineStart && isspace(*lineEnd))
--lineEnd;
*(lineEnd + 1) = '\0';
if(firstSpace >= line.length)
char* valueStart = strchr(lineStart, ' ');
//If the line has no white space, it is only a key
if(valueStart == NULL)
{
parseOption(instance, data, line.chars, NULL);
parseOption(instance, data, lineStart, NULL);
continue;
}
//Separate key and value by simply replacing the first space with a \0
char* valueStart = &line.chars[firstSpace];
//separate the key from the value
*valueStart = '\0';
++valueStart;
//Trim whitespace at beginning of value
while(*valueStart == ' ')
//Trim space of value left
while(isspace(*valueStart))
++valueStart;
//If we want whitespace in values, we need to quote it. This is done to keep consistency with shell.
if(*valueStart == '"')
if((*valueStart == '"' || *valueStart == '\'') && *valueStart == *lineEnd && lineEnd > valueStart)
{
char* last = line.chars + line.length - 1;
if(*last == '"')
{
++valueStart;
*last = '\0';
--line.length;
}
++valueStart;
--lineEnd;
}
parseOption(instance, data, line.chars, valueStart);
parseOption(instance, data, lineStart, valueStart);
}
ffStrbufDestroy(&line);
if(lineStart != NULL)
free(lineStart);
if(line != NULL)
free(line);
}
static void optionParseConfigFile(FFinstance* instance, FFdata* data, const char* key, const char* value)
@@ -625,6 +675,32 @@ static uint32_t optionParseUInt32(const char* key, const char* value)
return num;
}
static void optionParseCustomValue(FFdata* data, const char* key, const char* value, bool printKey)
{
if(value == NULL)
{
fprintf(stderr, "Error: usage: %s <key=value>\n", key);
exit(411);
}
char* separator = strchr(value, '=');
if(separator == NULL)
{
fprintf(stderr, "Error: usage: %s <key=value>, '=' missing\n", key);
exit(412);
}
*separator = '\0';
bool created;
CustomValue* customValue = ffValuestoreSet(&data->customValues, value, &created);
if(created)
ffStrbufInit(&customValue->value);
ffStrbufSetS(&customValue->value, separator + 1);
customValue->printKey = printKey;
}
static void parseOption(FFinstance* instance, FFdata* data, const char* key, const char* value)
{
///////////////////////
@@ -646,9 +722,14 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
puts(FASTFETCH_PROJECT_VERSION);
exit(0);
}
else if(strcasecmp(key, "--print-config") == 0)
else if(strcasecmp(key, "--print-config-system") == 0)
{
fputs(FASTFETCH_DATATEXT_CONFIG, stdout);
fputs(FASTFETCH_DATATEXT_CONFIG_SYSTEM, stdout);
exit(0);
}
else if(strcasecmp(key, "--print-config-user") == 0)
{
fputs(FASTFETCH_DATATEXT_CONFIG_USER, stdout);
exit(0);
}
else if(strcasecmp(key, "--print-structure") == 0)
@@ -673,17 +754,17 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
}
else if(strcasecmp(key, "--list-logos") == 0)
{
ffListBuiltinLogos();
ffLogoBuiltinList();
exit(0);
}
else if(strcasecmp(key, "--list-logos-autocompletion") == 0)
{
ffListBuiltinLogosAutocompletion();
ffLogoBuiltinListAutocompletion();
exit(0);
}
else if(strcasecmp(key, "--print-logos") == 0)
{
ffPrintBuiltinLogos(instance);
ffLogoBuiltinPrint(instance);
exit(0);
}
@@ -705,16 +786,31 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
else if(strcasecmp(key, "--load-config") == 0)
optionParseConfigFile(instance, data, key, value);
else if(strcasecmp(key, "--multithreading") == 0)
data->multithreading = optionParseBoolean(value);
instance->config.multithreading = optionParseBoolean(value);
else if(strcasecmp(key, "--allow-slow-operations") == 0)
instance->config.allowSlowOperations = optionParseBoolean(value);
else if(strcasecmp(key, "--escape-bedrock") == 0)
instance->config.escapeBedrock = optionParseBoolean(value);
else if(strcasecmp(key, "--pipe") == 0)
instance->config.pipe = optionParseBoolean(value);
else if(strcasecmp(key, "--load-user-config") == 0)
data->loadUserConfig = optionParseBoolean(value);
////////////////
//Logo options//
////////////////
else if(strcasecmp(key, "-l") == 0 || strcasecmp(key, "--logo") == 0)
optionParseString(key, value, &instance->config.logoSource);
{
optionParseString(key, value, &instance->config.logo.source);
//this is usally wanted when using the none logo
if(strcasecmp(value, "none") == 0)
{
instance->config.logo.paddingRight = 0;
instance->config.logo.paddingLeft = 0;
}
}
else if(strcasecmp(key, "--logo-type") == 0)
{
if(value == NULL)
@@ -724,19 +820,19 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
}
if(strcasecmp(value, "auto") == 0)
instance->config.logoType = FF_LOGO_TYPE_AUTO;
instance->config.logo.type = FF_LOGO_TYPE_AUTO;
else if(strcasecmp(value, "builtin") == 0)
instance->config.logoType = FF_LOGO_TYPE_BUILTIN;
instance->config.logo.type = FF_LOGO_TYPE_BUILTIN;
else if(strcasecmp(value, "file") == 0)
instance->config.logoType = FF_LOGO_TYPE_FILE;
instance->config.logo.type = FF_LOGO_TYPE_FILE;
else if(strcasecmp(value, "raw") == 0)
instance->config.logoType = FF_LOGO_TYPE_RAW;
instance->config.logo.type = FF_LOGO_TYPE_RAW;
else if(strcasecmp(value, "sixel") == 0)
instance->config.logoType = FF_LOGO_TYPE_SIXEL;
instance->config.logo.type = FF_LOGO_TYPE_SIXEL;
else if(strcasecmp(value, "kitty") == 0)
instance->config.logoType = FF_LOGO_TYPE_KITTY;
instance->config.logo.type = FF_LOGO_TYPE_KITTY;
else if(strcasecmp(value, "chafa") == 0)
instance->config.logoType = FF_LOGO_TYPE_CHAFA;
instance->config.logo.type = FF_LOGO_TYPE_CHAFA;
else
{
fprintf(stderr, "Error: unknown logo type: %s\n", value);
@@ -755,48 +851,48 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
exit(472);
}
optionParseColor(key, value, &instance->config.logoColors[index]);
optionParseColor(key, value, &instance->config.logo.colors[index]);
}
else if(strcasecmp(key, "--logo-width") == 0)
instance->config.logoWidth = optionParseUInt32(key, value);
instance->config.logo.width = optionParseUInt32(key, value);
else if(strcasecmp(key, "--logo-height") == 0)
instance->config.logoHeight = optionParseUInt32(key, value);
instance->config.logo.height = optionParseUInt32(key, value);
else if(strcasecmp(key, "--logo-padding") == 0)
{
uint32_t padding = optionParseUInt32(key, value);
instance->config.logoPaddingLeft = padding;
instance->config.logoPaddingRight = padding;
instance->config.logo.paddingLeft = padding;
instance->config.logo.paddingRight = padding;
}
else if(strcasecmp(key, "--logo-padding-left") == 0)
instance->config.logoPaddingLeft = optionParseUInt32(key, value);
instance->config.logo.paddingLeft = optionParseUInt32(key, value);
else if(strcasecmp(key, "--logo-padding-right") == 0)
instance->config.logoPaddingRight = optionParseUInt32(key, value);
instance->config.logo.paddingRight = optionParseUInt32(key, value);
else if(strcasecmp(key, "--logo-print-remaining") == 0)
instance->config.logoPrintRemaining = optionParseBoolean(value);
instance->config.logo.printRemaining = optionParseBoolean(value);
else if(strcasecmp(key, "--sixel") == 0)
{
optionParseString(key, value, &instance->config.logoSource);
instance->config.logoType = FF_LOGO_TYPE_SIXEL;
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_SIXEL;
}
else if(strcasecmp(key, "--kitty") == 0)
{
optionParseString(key, value, &instance->config.logoSource);
instance->config.logoType = FF_LOGO_TYPE_KITTY;
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_KITTY;
}
else if(strcasecmp(key, "--file") == 0)
{
optionCheckString(key, value, &instance->config.logoSource);
instance->config.logoType = FF_LOGO_TYPE_FILE;
optionCheckString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_FILE;
}
else if(strcasecmp(key, "--raw") == 0)
{
optionParseString(key, value, &instance->config.logoSource);
instance->config.logoType = FF_LOGO_TYPE_RAW;
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_RAW;
}
else if(strcasecmp(key, "--chafa") == 0)
{
optionParseString(key, value, &instance->config.logoSource);
instance->config.logoType = FF_LOGO_TYPE_CHAFA;
optionParseString(key, value, &instance->config.logo.source);
instance->config.logo.type = FF_LOGO_TYPE_CHAFA;
}
///////////////////
@@ -816,154 +912,218 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
else if(strcasecmp(key, "-c") == 0 || strcasecmp(key, "--color") == 0)
optionParseColor(key, value, &instance->config.mainColor);
else if(strcasecmp(key, "--set") == 0)
{
if(value == NULL)
{
fprintf(stderr, "Error: usage: %s <key=value>\n", key);
exit(411);
}
optionParseCustomValue(data, key, value, true);
else if(strcasecmp(key, "--set-keyless") == 0)
optionParseCustomValue(data, key, value, false);
char* separator = strchr(value, '=');
////////////////////////////////
//Format + Key + Error options//
////////////////////////////////
if(separator == NULL)
{
fprintf(stderr, "Error: usage: %s <key=value>, '=' missing\n", key);
exit(412);
}
*separator = '\0';
ffValuestoreSet(&data->valuestore, value, separator + 1);
}
////////////////////////
//Format + Key options//
////////////////////////
else if(strcasecmp(key, "--os-format") == 0)
optionParseString(key, value, &instance->config.osFormat);
else if(strcasecmp(key, "--os-key") == 0)
optionParseString(key, value, &instance->config.osKey);
else if(strcasecmp(key, "--host-format") == 0)
optionParseString(key, value, &instance->config.hostFormat);
optionParseString(key, value, &instance->config.os.key);
else if(strcasecmp(key, "--os-format") == 0)
optionParseString(key, value, &instance->config.os.outputFormat);
else if(strcasecmp(key, "--os-error") == 0)
optionParseString(key, value, &instance->config.os.errorFormat);
else if(strcasecmp(key, "--host-key") == 0)
optionParseString(key, value, &instance->config.hostKey);
else if(strcasecmp(key, "--kernel-format") == 0)
optionParseString(key, value, &instance->config.kernelFormat);
optionParseString(key, value, &instance->config.host.key);
else if(strcasecmp(key, "--host-format") == 0)
optionParseString(key, value, &instance->config.host.outputFormat);
else if(strcasecmp(key, "--host-error") == 0)
optionParseString(key, value, &instance->config.host.errorFormat);
else if(strcasecmp(key, "--kernel-key") == 0)
optionParseString(key, value, &instance->config.kernelKey);
else if(strcasecmp(key, "--uptime-format") == 0)
optionParseString(key, value, &instance->config.uptimeFormat);
optionParseString(key, value, &instance->config.kernel.key);
else if(strcasecmp(key, "--kernel-format") == 0)
optionParseString(key, value, &instance->config.kernel.outputFormat);
else if(strcasecmp(key, "--kernel-error") == 0)
optionParseString(key, value, &instance->config.kernel.errorFormat);
else if(strcasecmp(key, "--uptime-key") == 0)
optionParseString(key, value, &instance->config.uptimeKey);
else if(strcasecmp(key, "--processes-format") == 0)
optionParseString(key, value, &instance->config.processesFormat);
optionParseString(key, value, &instance->config.uptime.key);
else if(strcasecmp(key, "--uptime-format") == 0)
optionParseString(key, value, &instance->config.uptime.outputFormat);
else if(strcasecmp(key, "--uptime-error") == 0)
optionParseString(key, value, &instance->config.uptime.errorFormat);
else if(strcasecmp(key, "--processes-key") == 0)
optionParseString(key, value, &instance->config.processesKey);
else if(strcasecmp(key, "--packages-format") == 0)
optionParseString(key, value, &instance->config.packagesFormat);
optionParseString(key, value, &instance->config.processes.key);
else if(strcasecmp(key, "--processes-format") == 0)
optionParseString(key, value, &instance->config.processes.outputFormat);
else if(strcasecmp(key, "--processes-error") == 0)
optionParseString(key, value, &instance->config.processes.errorFormat);
else if(strcasecmp(key, "--packages-key") == 0)
optionParseString(key, value, &instance->config.packagesKey);
else if(strcasecmp(key, "--shell-format") == 0)
optionParseString(key, value, &instance->config.shellFormat);
optionParseString(key, value, &instance->config.packages.key);
else if(strcasecmp(key, "--packages-format") == 0)
optionParseString(key, value, &instance->config.packages.outputFormat);
else if(strcasecmp(key, "--packages-error") == 0)
optionParseString(key, value, &instance->config.packages.errorFormat);
else if(strcasecmp(key, "--shell-key") == 0)
optionParseString(key, value, &instance->config.shellKey);
else if(strcasecmp(key, "--resolution-format") == 0)
optionParseString(key, value, &instance->config.resolutionFormat);
optionParseString(key, value, &instance->config.shell.key);
else if(strcasecmp(key, "--shell-format") == 0)
optionParseString(key, value, &instance->config.shell.outputFormat);
else if(strcasecmp(key, "--shell-error") == 0)
optionParseString(key, value, &instance->config.shell.errorFormat);
else if(strcasecmp(key, "--resolution-key") == 0)
optionParseString(key, value, &instance->config.resolutionKey);
else if(strcasecmp(key, "--de-format") == 0)
optionParseString(key, value, &instance->config.deFormat);
optionParseString(key, value, &instance->config.resolution.key);
else if(strcasecmp(key, "--resolution-format") == 0)
optionParseString(key, value, &instance->config.resolution.outputFormat);
else if(strcasecmp(key, "--resolution-error") == 0)
optionParseString(key, value, &instance->config.resolution.errorFormat);
else if(strcasecmp(key, "--de-key") == 0)
optionParseString(key, value, &instance->config.deKey);
else if(strcasecmp(key, "--wm-format") == 0)
optionParseString(key, value, &instance->config.wmFormat);
optionParseString(key, value, &instance->config.de.key);
else if(strcasecmp(key, "--de-format") == 0)
optionParseString(key, value, &instance->config.de.outputFormat);
else if(strcasecmp(key, "--de-error") == 0)
optionParseString(key, value, &instance->config.de.errorFormat);
else if(strcasecmp(key, "--wm-key") == 0)
optionParseString(key, value, &instance->config.wmKey);
else if(strcasecmp(key, "--wm-theme-format") == 0)
optionParseString(key, value, &instance->config.wmThemeFormat);
optionParseString(key, value, &instance->config.wm.key);
else if(strcasecmp(key, "--wm-format") == 0)
optionParseString(key, value, &instance->config.wm.outputFormat);
else if(strcasecmp(key, "--wm-error") == 0)
optionParseString(key, value, &instance->config.wm.errorFormat);
else if(strcasecmp(key, "--wm-theme-key") == 0)
optionParseString(key, value, &instance->config.wmThemeKey);
else if(strcasecmp(key, "--theme-format") == 0)
optionParseString(key, value, &instance->config.themeFormat);
optionParseString(key, value, &instance->config.wmTheme.key);
else if(strcasecmp(key, "--wm-theme-format") == 0)
optionParseString(key, value, &instance->config.wmTheme.outputFormat);
else if(strcasecmp(key, "--wm-theme-error") == 0)
optionParseString(key, value, &instance->config.wmTheme.errorFormat);
else if(strcasecmp(key, "--theme-key") == 0)
optionParseString(key, value, &instance->config.themeKey);
else if(strcasecmp(key, "--icons-format") == 0)
optionParseString(key, value, &instance->config.iconsFormat);
optionParseString(key, value, &instance->config.theme.key);
else if(strcasecmp(key, "--theme-format") == 0)
optionParseString(key, value, &instance->config.theme.outputFormat);
else if(strcasecmp(key, "--theme-error") == 0)
optionParseString(key, value, &instance->config.theme.errorFormat);
else if(strcasecmp(key, "--icons-key") == 0)
optionParseString(key, value, &instance->config.iconsKey);
else if(strcasecmp(key, "--font-format") == 0)
optionParseString(key, value, &instance->config.fontFormat);
optionParseString(key, value, &instance->config.icons.key);
else if(strcasecmp(key, "--icons-format") == 0)
optionParseString(key, value, &instance->config.icons.outputFormat);
else if(strcasecmp(key, "--icons-error") == 0)
optionParseString(key, value, &instance->config.icons.errorFormat);
else if(strcasecmp(key, "--font-key") == 0)
optionParseString(key, value, &instance->config.fontKey);
optionParseString(key, value, &instance->config.font.key);
else if(strcasecmp(key, "--font-format") == 0)
optionParseString(key, value, &instance->config.font.outputFormat);
else if(strcasecmp(key, "--font-error") == 0)
optionParseString(key, value, &instance->config.font.errorFormat);
else if(strcasecmp(key, "--cursor-key") == 0)
optionParseString(key, value, &instance->config.cursorKey);
optionParseString(key, value, &instance->config.cursor.key);
else if(strcasecmp(key, "--cursor-format") == 0)
optionParseString(key, value, &instance->config.cursorFormat);
else if(strcasecmp(key, "--terminal-format") == 0)
optionParseString(key, value, &instance->config.terminalFormat);
optionParseString(key, value, &instance->config.cursor.outputFormat);
else if(strcasecmp(key, "--cursor-error") == 0)
optionParseString(key, value, &instance->config.cursor.errorFormat);
else if(strcasecmp(key, "--terminal-key") == 0)
optionParseString(key, value, &instance->config.terminalKey);
else if(strcasecmp(key, "--terminal-font-format") == 0)
optionParseString(key, value, &instance->config.termFontFormat);
optionParseString(key, value, &instance->config.terminal.key);
else if(strcasecmp(key, "--terminal-format") == 0)
optionParseString(key, value, &instance->config.terminal.outputFormat);
else if(strcasecmp(key, "--terminal-error") == 0)
optionParseString(key, value, &instance->config.terminal.errorFormat);
else if(strcasecmp(key, "--terminal-font-key") == 0)
optionParseString(key, value, &instance->config.termFontKey);
else if(strcasecmp(key, "--cpu-format") == 0)
optionParseString(key, value, &instance->config.cpuFormat);
else if(strcasecmp(key, "--cpu-usage-format") == 0)
optionParseString(key, value, &instance->config.cpuUsageFormat);
optionParseString(key, value, &instance->config.terminalFont.key);
else if(strcasecmp(key, "--terminal-font-format") == 0)
optionParseString(key, value, &instance->config.terminalFont.outputFormat);
else if(strcasecmp(key, "--terminal-font-error") == 0)
optionParseString(key, value, &instance->config.terminalFont.errorFormat);
else if(strcasecmp(key, "--cpu-key") == 0)
optionParseString(key, value, &instance->config.cpuKey);
optionParseString(key, value, &instance->config.cpu.key);
else if(strcasecmp(key, "--cpu-format") == 0)
optionParseString(key, value, &instance->config.cpu.outputFormat);
else if(strcasecmp(key, "--cpu-error") == 0)
optionParseString(key, value, &instance->config.cpu.errorFormat);
else if(strcasecmp(key, "--cpu-usage-key") == 0)
optionParseString(key, value, &instance->config.cpuUsageKey);
else if(strcasecmp(key, "--gpu-format") == 0)
optionParseString(key, value, &instance->config.gpuFormat);
optionParseString(key, value, &instance->config.cpuUsage.key);
else if(strcasecmp(key, "--cpu-usage-format") == 0)
optionParseString(key, value, &instance->config.cpuUsage.outputFormat);
else if(strcasecmp(key, "--cpu-usage-error") == 0)
optionParseString(key, value, &instance->config.cpuUsage.errorFormat);
else if(strcasecmp(key, "--gpu-key") == 0)
optionParseString(key, value, &instance->config.gpuKey);
else if(strcasecmp(key, "--memory-format") == 0)
optionParseString(key, value, &instance->config.memoryFormat);
optionParseString(key, value, &instance->config.gpu.key);
else if(strcasecmp(key, "--gpu-format") == 0)
optionParseString(key, value, &instance->config.gpu.outputFormat);
else if(strcasecmp(key, "--gpu-error") == 0)
optionParseString(key, value, &instance->config.gpu.errorFormat);
else if(strcasecmp(key, "--memory-key") == 0)
optionParseString(key, value, &instance->config.memoryKey);
else if(strcasecmp(key, "--disk-format") == 0)
optionParseString(key, value, &instance->config.diskFormat);
optionParseString(key, value, &instance->config.memory.key);
else if(strcasecmp(key, "--memory-format") == 0)
optionParseString(key, value, &instance->config.memory.outputFormat);
else if(strcasecmp(key, "--memory-error") == 0)
optionParseString(key, value, &instance->config.memory.errorFormat);
else if(strcasecmp(key, "--disk-key") == 0)
optionParseString(key, value, &instance->config.diskKey);
else if(strcasecmp(key, "--battery-format") == 0)
optionParseString(key, value, &instance->config.batteryFormat);
optionParseString(key, value, &instance->config.disk.key);
else if(strcasecmp(key, "--disk-format") == 0)
optionParseString(key, value, &instance->config.disk.outputFormat);
else if(strcasecmp(key, "--disk-error") == 0)
optionParseString(key, value, &instance->config.disk.errorFormat);
else if(strcasecmp(key, "--battery-key") == 0)
optionParseString(key, value, &instance->config.batteryKey);
else if(strcasecmp(key, "--locale-format") == 0)
optionParseString(key, value, &instance->config.localeFormat);
optionParseString(key, value, &instance->config.battery.key);
else if(strcasecmp(key, "--battery-format") == 0)
optionParseString(key, value, &instance->config.battery.outputFormat);
else if(strcasecmp(key, "--battery-error") == 0)
optionParseString(key, value, &instance->config.battery.errorFormat);
else if(strcasecmp(key, "--locale-key") == 0)
optionParseString(key, value, &instance->config.localeKey);
optionParseString(key, value, &instance->config.locale.key);
else if(strcasecmp(key, "--locale-format") == 0)
optionParseString(key, value, &instance->config.locale.outputFormat);
else if(strcasecmp(key, "--locale-error") == 0)
optionParseString(key, value, &instance->config.locale.errorFormat);
else if(strcasecmp(key, "--local-ip-key") == 0)
optionParseString(key, value, &instance->config.localIpKey);
optionParseString(key, value, &instance->config.localIP.key);
else if(strcasecmp(key, "--local-ip-format") == 0)
optionParseString(key, value, &instance->config.localIpFormat);
optionParseString(key, value, &instance->config.localIP.outputFormat);
else if(strcasecmp(key, "--local-ip-error") == 0)
optionParseString(key, value, &instance->config.localIP.errorFormat);
else if(strcasecmp(key, "--public-ip-key") == 0)
optionParseString(key, value, &instance->config.publicIpKey);
optionParseString(key, value, &instance->config.publicIP.key);
else if(strcasecmp(key, "--public-ip-format") == 0)
optionParseString(key, value, &instance->config.publicIpFormat);
optionParseString(key, value, &instance->config.publicIP.outputFormat);
else if(strcasecmp(key, "--public-ip-error") == 0)
optionParseString(key, value, &instance->config.publicIP.errorFormat);
else if(strcasecmp(key, "--player-key") == 0)
optionParseString(key, value, &instance->config.playerKey);
optionParseString(key, value, &instance->config.player.key);
else if(strcasecmp(key, "--player-format") == 0)
optionParseString(key, value, &instance->config.playerFormat);
optionParseString(key, value, &instance->config.player.outputFormat);
else if(strcasecmp(key, "--player-error") == 0)
optionParseString(key, value, &instance->config.player.errorFormat);
else if(strcasecmp(key, "--song-key") == 0)
optionParseString(key, value, &instance->config.songKey);
optionParseString(key, value, &instance->config.song.key);
else if(strcasecmp(key, "--song-format") == 0)
optionParseString(key, value, &instance->config.songFormat);
optionParseString(key, value, &instance->config.song.outputFormat);
else if(strcasecmp(key, "--song-error") == 0)
optionParseString(key, value, &instance->config.song.errorFormat);
else if(strcasecmp(key, "--datetime-key") == 0)
optionParseString(key, value, &instance->config.dateTimeKey);
optionParseString(key, value, &instance->config.dateTime.key);
else if(strcasecmp(key, "--datetime-format") == 0)
optionParseString(key, value, &instance->config.dateTimeFormat);
optionParseString(key, value, &instance->config.dateTime.outputFormat);
else if(strcasecmp(key, "--datetime-error") == 0)
optionParseString(key, value, &instance->config.dateTime.errorFormat);
else if(strcasecmp(key, "--date-key") == 0)
optionParseString(key, value, &instance->config.dateKey);
optionParseString(key, value, &instance->config.date.key);
else if(strcasecmp(key, "--date-format") == 0)
optionParseString(key, value, &instance->config.dateFormat);
optionParseString(key, value, &instance->config.date.outputFormat);
else if(strcasecmp(key, "--date-error") == 0)
optionParseString(key, value, &instance->config.date.errorFormat);
else if(strcasecmp(key, "--time-key") == 0)
optionParseString(key, value, &instance->config.timeKey);
optionParseString(key, value, &instance->config.time.key);
else if(strcasecmp(key, "--time-format") == 0)
optionParseString(key, value, &instance->config.timeFormat);
optionParseString(key, value, &instance->config.time.outputFormat);
else if(strcasecmp(key, "--time-error") == 0)
optionParseString(key, value, &instance->config.time.errorFormat);
else if(strcasecmp(key, "--vulkan-key") == 0)
optionParseString(key, value, &instance->config.vulkan.key);
else if(strcasecmp(key, "--vulkan-format") == 0)
optionParseString(key, value, &instance->config.vulkan.outputFormat);
else if(strcasecmp(key, "--vulkan-error") == 0)
optionParseString(key, value, &instance->config.vulkan.errorFormat);
else if(strcasecmp(key, "--opengl-key") == 0)
optionParseString(key, value, &instance->config.openGL.key);
else if(strcasecmp(key, "--opengl-format") == 0)
optionParseString(key, value, &instance->config.openGL.outputFormat);
else if(strcasecmp(key, "--opengl-error") == 0)
optionParseString(key, value, &instance->config.openGL.errorFormat);
else if(strcasecmp(key, "--opencl-key") == 0)
optionParseString(key, value, &instance->config.openCL.key);
else if(strcasecmp(key, "--opencl-format") == 0)
optionParseString(key, value, &instance->config.openCL.outputFormat);
else if(strcasecmp(key, "--opencl-error") == 0)
optionParseString(key, value, &instance->config.openCL.errorFormat);
///////////////////
//Library options//
@@ -993,17 +1153,29 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
optionParseString(key, value, &instance->config.libXFConf);
else if(strcasecmp(key, "--lib-sqlite") == 0 || strcasecmp(key, "--lib-sqlite3") == 0)
optionParseString(key, value, &instance->config.libSQLite3);
else if(strcasecmp(key, "--lib-rpm") == 0)
optionParseString(key, value, &instance->config.librpm);
else if(strcasecmp(key, "--lib-imagemagick") == 0)
optionParseString(key, value, &instance->config.libImageMagick);
else if(strcasecmp(key, "--lib-z") == 0)
optionParseString(key, value, &instance->config.libZ);
else if(strcasecmp(key, "--lib-chafa") == 0)
optionParseString(key, value, &instance->config.libChafa);
else if(strcasecmp(key, "--lib-egl") == 0)
optionParseString(key, value, &instance->config.libEGL);
else if(strcasecmp(key, "--lib-glx") == 0)
optionParseString(key, value, &instance->config.libGLX);
else if(strcasecmp(key, "--lib-osmesa") == 0)
optionParseString(key, value, &instance->config.libOSMesa);
else if(strcasecmp(key, "--lib-opencl") == 0)
optionParseString(key, value, &instance->config.libOpenCL);
//////////////////
//Module options//
//////////////////
else if(strcasecmp(key, "--title-fqdn") == 0)
instance->config.titleFQDN = optionParseBoolean(value);
else if(strcasecmp(key, "--disk-folders") == 0)
optionParseString(key, value, &instance->config.diskFolders);
else if(strcasecmp(key, "--battery-dir") == 0)
@@ -1022,6 +1194,28 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
optionParseString(key, value, &instance->config.playerName);
else if(strcasecmp(key, "--public-ip-timeout") == 0)
instance->config.publicIpTimeout = optionParseUInt32(key, value);
else if(strcasecmp(key, "--gl") == 0)
{
if(value == NULL)
{
fprintf(stderr, "Error: usage: %s <type>\n", key);
exit(491);
}
if(strcasecmp(value, "auto") == 0)
instance->config.glType = FF_GL_TYPE_AUTO;
else if(strcasecmp(value, "egl") == 0)
instance->config.glType = FF_GL_TYPE_EGL;
else if(strcasecmp(value, "glx") == 0)
instance->config.glType = FF_GL_TYPE_GLX;
else if(strcasecmp(value, "osmesa") == 0)
instance->config.glType = FF_GL_TYPE_OSMESA;
else
{
fprintf(stderr, "Error: unknown gl type: %s\n", value);
exit(492);
}
}
//////////////////
//Unknown option//
@@ -1034,8 +1228,21 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
}
}
static void parseDefaultConfigFile(FFinstance* instance, FFdata* data)
static void parseConfigFileSystem(FFinstance* instance, FFdata* data)
{
FILE* file = fopen(FASTFETCH_TARGET_DIR_ROOT"/etc/fastfetch/config.conf", "r");
if(file == NULL)
return;
parseConfigFile(instance, data, file);
fclose(file);
}
static void parseConfigFileUser(FFinstance* instance, FFdata* data)
{
if(!data->loadUserConfig)
return;
FFstrbuf* filename = ffListGet(&instance->state.configDirs, 0);
uint32_t filenameLength = filename->length;
@@ -1058,7 +1265,7 @@ static void parseDefaultConfigFile(FFinstance* instance, FFdata* data)
file = fopen(filename->chars, "w");
if(file != NULL)
{
fputs(FASTFETCH_DATATEXT_CONFIG, file);
fputs(FASTFETCH_DATATEXT_CONFIG_USER, file);
fclose(file);
}
@@ -1067,11 +1274,13 @@ static void parseDefaultConfigFile(FFinstance* instance, FFdata* data)
static void parseArguments(FFinstance* instance, FFdata* data, int argc, const char** argv)
{
if(!data->loadUserConfig)
return;
for(int i = 1; i < argc; i++)
{
if(i == argc - 1 || (
*argv[i + 1] == '-' &&
strcasecmp(argv[i], "--offsetx") != 0 && // --offsetx allows negative values
strcasecmp(argv[i], "--separator-string") != 0 // Separator string can start with a -
)) {
parseOption(instance, data, argv[i], NULL);
@@ -1086,10 +1295,10 @@ static void parseArguments(FFinstance* instance, FFdata* data, int argc, const c
static void parseStructureCommand(FFinstance* instance, FFdata* data, const char* line)
{
const char* setValue = ffValuestoreGet(&data->valuestore, line);
if(setValue != NULL)
CustomValue* customValue = ffValuestoreGet(&data->customValues, line);
if(customValue != NULL)
{
ffPrintCustom(instance, line, setValue);
ffPrintCustom(instance, customValue->printKey ? line : NULL, customValue->value.chars);
return;
}
@@ -1163,8 +1372,14 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char
ffPrintTime(instance);
else if(strcasecmp(line, "colors") == 0)
ffPrintColors(instance);
else if(strcasecmp(line, "vulkan") == 0)
ffPrintVulkan(instance);
else if(strcasecmp(line, "opengl") == 0)
ffPrintOpenGL(instance);
else if(strcasecmp(line, "opencl") == 0)
ffPrintOpenCL(instance);
else
ffPrintError(instance, line, 0, NULL, NULL, 0, "<no implementation provided>");
ffPrintErrorString(instance, line, 0, NULL, NULL, "<no implementation provided>");
}
int main(int argc, const char** argv)
@@ -1174,17 +1389,14 @@ int main(int argc, const char** argv)
//Data stores things only needed for the configuration of fastfetch
FFdata data;
ffValuestoreInit(&data.valuestore);
ffValuestoreInit(&data.customValues, sizeof(CustomValue));
ffStrbufInitA(&data.structure, 256);
data.multithreading = true;
data.loadUserConfig = true;
parseDefaultConfigFile(&instance, &data);
parseConfigFileSystem(&instance, &data);
parseConfigFileUser(&instance, &data);
parseArguments(&instance, &data, argc, argv);
//Start detection threads
if(data.multithreading)
ffStartDetectionThreads(&instance);
//If we don't have a custom structure, use the default one
if(data.structure.length == 0)
ffStrbufSetS(&data.structure, FASTFETCH_DATATEXT_STRUCTURE);
+86 -404
View File
@@ -3,24 +3,17 @@
#ifndef FASTFETCH_INCLUDED
#define FASTFETCH_INCLUDED
#include <stddef.h>
#include "fastfetch_config.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/sysinfo.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include "fastfetch_config.h"
#include "util/FFstrbuf.h"
#include "util/FFlist.h"
#include "util/FFvaluestore.h"
static inline void ffUnused(int dummy, ...) { (void) dummy; }
#define FF_UNUSED(...) ffUnused(0, __VA_ARGS__);
@@ -42,18 +35,36 @@ typedef enum FFLogoType
FF_LOGO_TYPE_CHAFA //Image file, printed as ascii art using libchafa
} FFLogoType;
typedef enum FFGLType
{
FF_GL_TYPE_AUTO,
FF_GL_TYPE_EGL,
FF_GL_TYPE_GLX,
FF_GL_TYPE_OSMESA
} FFGLType;
typedef struct FFModuleArgs
{
FFstrbuf key;
FFstrbuf outputFormat;
FFstrbuf errorFormat;
} FFModuleArgs;
typedef struct FFconfig
{
FFstrbuf logoSource;
FFLogoType logoType;
FFstrbuf logoColors[FASTFETCH_LOGO_MAX_COLORS];
uint32_t logoWidth;
uint32_t logoHeight;
uint32_t logoPaddingLeft;
uint32_t logoPaddingRight;
bool logoPrintRemaining;
struct
{
FFstrbuf source;
FFLogoType type;
FFstrbuf colors[FASTFETCH_LOGO_MAX_COLORS];
uint32_t width;
uint32_t height;
uint32_t paddingLeft;
uint32_t paddingRight;
bool printRemaining;
} logo;
FFstrbuf mainColor; //If this is empty, ffPrintLogo will set it to the main color of the logo
FFstrbuf mainColor; //If this is empty, ffLogoPrint will set it to the main color of the logo
FFstrbuf separator;
bool showErrors;
@@ -62,69 +73,45 @@ typedef struct FFconfig
bool allowSlowOperations;
bool disableLinewrap;
bool hideCursor;
bool escapeBedrock;
FFGLType glType;
bool pipe; //disables logo and all escape sequences
bool multithreading;
FFstrbuf osFormat;
FFstrbuf osKey;
FFstrbuf hostFormat;
FFstrbuf hostKey;
FFstrbuf kernelFormat;
FFstrbuf kernelKey;
FFstrbuf uptimeFormat;
FFstrbuf uptimeKey;
FFstrbuf processesFormat;
FFstrbuf processesKey;
FFstrbuf packagesFormat;
FFstrbuf packagesKey;
FFstrbuf shellFormat;
FFstrbuf shellKey;
FFstrbuf resolutionFormat;
FFstrbuf resolutionKey;
FFstrbuf deFormat;
FFstrbuf deKey;
FFstrbuf wmFormat;
FFstrbuf wmKey;
FFstrbuf wmThemeFormat;
FFstrbuf wmThemeKey;
FFstrbuf themeFormat;
FFstrbuf themeKey;
FFstrbuf iconsFormat;
FFstrbuf iconsKey;
FFstrbuf fontFormat;
FFstrbuf fontKey;
FFstrbuf cursorFormat;
FFstrbuf cursorKey;
FFstrbuf terminalFormat;
FFstrbuf terminalKey;
FFstrbuf termFontFormat;
FFstrbuf termFontKey;
FFstrbuf cpuFormat;
FFstrbuf cpuKey;
FFstrbuf cpuUsageFormat;
FFstrbuf cpuUsageKey;
FFstrbuf gpuFormat;
FFstrbuf gpuKey;
FFstrbuf memoryFormat;
FFstrbuf memoryKey;
FFstrbuf diskFormat;
FFstrbuf diskKey;
FFstrbuf batteryFormat;
FFstrbuf batteryKey;
FFstrbuf localeFormat;
FFstrbuf localeKey;
FFstrbuf localIpKey;
FFstrbuf localIpFormat;
FFstrbuf publicIpKey;
FFstrbuf publicIpFormat;
FFstrbuf playerKey;
FFstrbuf playerFormat;
FFstrbuf songKey;
FFstrbuf songFormat;
FFstrbuf dateTimeKey;
FFstrbuf dateTimeFormat;
FFstrbuf dateKey;
FFstrbuf dateFormat;
FFstrbuf timeKey;
FFstrbuf timeFormat;
FFModuleArgs os;
FFModuleArgs host;
FFModuleArgs kernel;
FFModuleArgs uptime;
FFModuleArgs processes;
FFModuleArgs packages;
FFModuleArgs shell;
FFModuleArgs resolution;
FFModuleArgs de;
FFModuleArgs wm;
FFModuleArgs wmTheme;
FFModuleArgs theme;
FFModuleArgs icons;
FFModuleArgs font;
FFModuleArgs cursor;
FFModuleArgs terminal;
FFModuleArgs terminalFont;
FFModuleArgs cpu;
FFModuleArgs cpuUsage;
FFModuleArgs gpu;
FFModuleArgs memory;
FFModuleArgs disk;
FFModuleArgs battery;
FFModuleArgs locale;
FFModuleArgs localIP;
FFModuleArgs publicIP;
FFModuleArgs player;
FFModuleArgs song;
FFModuleArgs dateTime;
FFModuleArgs date;
FFModuleArgs time;
FFModuleArgs vulkan;
FFModuleArgs openGL;
FFModuleArgs openCL;
FFstrbuf libPCI;
FFstrbuf libVulkan;
@@ -138,9 +125,16 @@ typedef struct FFconfig
FFstrbuf libDBus;
FFstrbuf libXFConf;
FFstrbuf libSQLite3;
FFstrbuf librpm;
FFstrbuf libImageMagick;
FFstrbuf libZ;
FFstrbuf libChafa;
FFstrbuf libEGL;
FFstrbuf libGLX;
FFstrbuf libOSMesa;
FFstrbuf libOpenCL;
bool titleFQDN;
FFstrbuf diskFolders;
@@ -179,213 +173,8 @@ typedef struct FFinstance
FFstate state;
} FFinstance;
typedef struct FFTitleResult
{
FFstrbuf userName;
FFstrbuf hostname;
} FFTitleResult;
typedef struct FFOSResult
{
FFstrbuf systemName;
FFstrbuf name;
FFstrbuf prettyName;
FFstrbuf id;
FFstrbuf idLike;
FFstrbuf variant;
FFstrbuf variantID;
FFstrbuf version;
FFstrbuf versionID;
FFstrbuf codename;
FFstrbuf buildID;
FFstrbuf architecture;
} FFOSResult;
typedef struct FFPlasmaResult
{
FFstrbuf widgetStyle;
FFstrbuf colorScheme;
FFstrbuf icons;
FFstrbuf font;
} FFPlasmaResult;
typedef struct FFGTKResult
{
FFstrbuf theme;
FFstrbuf icons;
FFstrbuf font;
FFstrbuf cursor;
FFstrbuf cursorSize;
} FFGTKResult;
typedef struct FFTerminalShellResult
{
FFstrbuf shellProcessName;
FFstrbuf shellExe;
const char* shellExeName; //pointer to a char in shellExe
FFstrbuf shellVersion;
FFstrbuf terminalProcessName;
FFstrbuf terminalExe;
const char* terminalExeName; //pointer to a char in terminalExe
FFstrbuf userShellExe;
const char* userShellExeName; //pointer to a char in userShellExe
FFstrbuf userShellVersion;
} FFTerminalShellResult;
typedef struct FFResolutionResult
{
uint32_t width;
uint32_t height;
uint32_t refreshRate;
} FFResolutionResult;
typedef struct FFDisplayServerResult
{
FFstrbuf wmProcessName;
FFstrbuf wmPrettyName;
FFstrbuf wmProtocolName;
FFstrbuf deProcessName;
FFstrbuf dePrettyName;
FFstrbuf deVersion;
FFlist resolutions; //List of FFResolutionResult
} FFDisplayServerResult;
typedef struct FFTempValue
{
FFstrbuf name;
FFstrbuf value;
FFstrbuf deviceClass;
} FFTempValue;
typedef struct FFTempsResult
{
FFlist values; //List of FFTempValue
} FFTempsResult;
typedef struct FFMediaResult
{
FFstrbuf busNameShort; //e.g. plasma-browser-integration
FFstrbuf player; // e.g. Google Chrome
FFstrbuf song;
FFstrbuf artist;
FFstrbuf album;
FFstrbuf url;
} FFMediaResult;
typedef struct FFDateTimeResult
{
//Examples for 21.02.2022 - 15:18:37
uint16_t year; //2022
uint8_t yearShort; //22
uint8_t month; //2
FFstrbuf monthPretty; //02
FFstrbuf monthName; //February
FFstrbuf monthNameShort; //Feb
uint8_t week; //8
FFstrbuf weekday; //Monday
FFstrbuf weekdayShort; //Mon
uint16_t dayInYear; //52
uint8_t dayInMonth; //21
uint8_t dayInWeek; //1
uint8_t hour; //15
FFstrbuf hourPretty; //15
uint8_t hour12; //3
FFstrbuf hour12Pretty; //03
uint8_t minute; //18
FFstrbuf minutePretty; //18
uint8_t second; //37
FFstrbuf secondPretty; //37
} FFDateTimeResult;
typedef enum FFformatargtype
{
FF_FORMAT_ARG_TYPE_NULL = 0,
FF_FORMAT_ARG_TYPE_UINT,
FF_FORMAT_ARG_TYPE_UINT16,
FF_FORMAT_ARG_TYPE_UINT8,
FF_FORMAT_ARG_TYPE_INT,
FF_FORMAT_ARG_TYPE_STRING,
FF_FORMAT_ARG_TYPE_STRBUF,
FF_FORMAT_ARG_TYPE_DOUBLE,
FF_FORMAT_ARG_TYPE_LIST
} FFformatargtype;
typedef struct FFformatarg
{
FFformatargtype type;
const void* value;
} FFformatarg;
typedef struct FFcache
{
FILE* value;
FILE* split;
} FFcache;
typedef enum FFvarianttype
{
FF_VARIANT_TYPE_STRING,
FF_VARIANT_TYPE_BOOL,
FF_VARIANT_TYPE_INT
} FFvarianttype;
typedef union FFvariant
{
const char* strValue;
int32_t intValue;
struct
{
bool boolValueSet;
bool boolValue;
};
} FFvariant;
#define FF_VARIANT_NULL ((FFvariant){.strValue = NULL})
typedef struct FFfont
{
FFstrbuf pretty;
FFstrbuf name;
FFstrbuf size;
FFlist styles;
} FFfont;
typedef struct FFpropquery
{
const char* start;
FFstrbuf* buffer;
} FFpropquery;
typedef enum FFInitState
{
FF_INITSTATE_UNINITIALIZED = 0,
FF_INITSTATE_SUCCESSFUL = 1,
FF_INITSTATE_FAILED = 2
} FFInitState;
#define FF_LIBRARY_SYMBOL(symbolName) \
__typeof__(&symbolName) ff ## symbolName;
#define FF_LIBRARY_LOAD(libraryObjectName, userLibraryName, returnValue, ...) \
void* libraryObjectName = ffLibraryLoad(&userLibraryName, __VA_ARGS__, NULL);\
if(libraryObjectName == NULL) \
return returnValue;
#define FF_LIBRARY_LOAD_SYMBOL_ADRESS(library, symbolMapping, symbolName, returnValue) \
symbolMapping = dlsym(library, #symbolName); \
if(symbolMapping == NULL) \
{ \
dlclose(library); \
return returnValue; \
}
#define FF_LIBRARY_LOAD_SYMBOL(library, symbolName, returnValue) \
__typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADRESS(library, ff ## symbolName, symbolName, returnValue);
//////////////////////
// Common functions //
// Init functions //
//////////////////////
//common/init.c
@@ -395,135 +184,25 @@ void ffFinish(FFinstance* instance);
void ffListFeatures();
//common/threading.c
void ffStartDetectionThreads(FFinstance* instance);
//common/io.c
void ffAppendFDContent(int fd, FFstrbuf* buffer);
bool ffAppendFileContent(const char* fileName, FFstrbuf* buffer); //returns true if open() succeeds. This is used to differentiate between <file not found> and <empty file>
bool ffGetFileContent(const char* fileName, FFstrbuf* buffer);
bool ffWriteFDContent(int fd, const FFstrbuf* content);
bool ffWriteFileContent(const char* fileName, const FFstrbuf* buffer);
bool ffFileExists(const char* fileName, mode_t mode);
void ffSuppressIO(bool suppress); // Not thread safe!
void ffGetTerminalResponse(const char* request, const char* format, ...);
//common/printing.c
void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numFormatArgs, const char* message, ...);
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments);
void ffPrintColor(const FFstrbuf* colorValue);
void ffPrintCharTimes(char c, uint32_t times);
//common/caching.c
void ffCacheValidate(FFinstance* instance);
void ffCacheOpenWrite(FFinstance* instance, const char* moduleName, FFcache* cache);
void ffCacheClose(FFcache* cache);
bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numArgs);
void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, FFcache* cache, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments);
void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments);
//common/properties.c
bool ffParsePropLine(const char* line, const char* start, FFstrbuf* buffer);
bool ffParsePropLines(const char* lines, const char* start, FFstrbuf* buffer);
bool ffParsePropFileValues(const char* filename, uint32_t numQueries, FFpropquery* queries);
bool ffParsePropFile(const char* filename, const char* start, FFstrbuf* buffer);
bool ffParsePropFileHomeValues(const FFinstance* instance, const char* relativeFile, uint32_t numQueries, FFpropquery* queries);
bool ffParsePropFileHome(const FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer);
bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativeFile, uint32_t numQueries, FFpropquery* queries);
bool ffParsePropFileConfig(const FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer);
//common/font.c
void ffFontInitQt(FFfont* font, const char* data);
void ffFontInitPango(FFfont* font, const char* data);
void ffFontInitCopy(FFfont* font, const char* name);
void ffFontDestroy(FFfont* font);
//common/format.c
void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg);
void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments);
//common/parsing.c
bool ffStrSet(const char* str);
void ffParseSemver(FFstrbuf* buffer, const FFstrbuf* major, const FFstrbuf* minor, const FFstrbuf* patch);
void ffParseGTK(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3, const FFstrbuf* gtk4);
//common/processing.c
void ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[]);
//common/libraries.c
void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...);
//common/networking.c
void ffNetworkingGetHttp(const char* host, const char* path, uint32_t timeout, FFstrbuf* buffer);
//common/settings.c
FFvariant ffSettingsGetDConf(FFinstance* instance, const char* key, FFvarianttype type);
FFvariant ffSettingsGetGSettings(FFinstance* instance, const char* schemaName, const char* path, const char* key, FFvarianttype type);
FFvariant ffSettingsGet(FFinstance* instance, const char* dconfKey, const char* gsettingsSchemaName, const char* gsettingsPath, const char* gsettingsKey, FFvarianttype type);
FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, const char* propertyName, FFvarianttype type);
int ffSettingsGetSQLite3Int(FFinstance* instance, const char* dbPath, const char* query);
#ifdef __ANDROID__
bool ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result);
#endif
////////////////////
// Logo functions //
////////////////////
void ffPrintLogo(FFinstance* instance);
void ffPrintRemainingLogo(FFinstance* instance);
void ffLogoPrint(FFinstance* instance);
void ffLogoPrintRemaining(FFinstance* instance);
void ffLogoPrintLine(FFinstance* instance);
void ffPrintLogoLine(FFinstance* instance);
void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat);
void ffPrintBuiltinLogos(FFinstance* instance);
void ffListBuiltinLogos();
void ffListBuiltinLogosAutocompletion();
/////////////////////////
// Detection functions //
/////////////////////////
//detection/os.c
const FFOSResult* ffDetectOS(const FFinstance* instance);
//detection/plasma.c
const FFPlasmaResult* ffDetectPlasma(FFinstance* instance);
//detection/gtk.c
const FFGTKResult* ffDetectGTK2(FFinstance* instance);
const FFGTKResult* ffDetectGTK4(FFinstance* instance);
const FFGTKResult* ffDetectGTK3(FFinstance* instance);
//detection/displayServer.c
const FFDisplayServerResult* ffConnectDisplayServer(const FFinstance* instance);
//detection/terminalShell.c
const FFTerminalShellResult* ffDetectTerminalShell(FFinstance* instance);
//detection/temps.c (currently unused)
const FFTempsResult* ffDetectTemps(const FFinstance* instance);
//detection/media.c
const FFMediaResult* ffDetectMedia(FFinstance* instance);
//detection/dateTime.c
const FFDateTimeResult* ffDetectDateTime(const FFinstance* instance);
void ffLogoBuiltinPrint(FFinstance* instance);
void ffLogoBuiltinList();
void ffLogoBuiltinListAutocompletion();
//////////////////////
// Module functions //
//////////////////////
//Common
const FFTitleResult* ffDetectTitle(FFinstance* instance);
void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFstrbuf* key, const FFstrbuf* format);
void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs);
//Printing
@@ -563,5 +242,8 @@ void ffPrintTime(FFinstance* instance);
void ffPrintLocalIp(FFinstance* instance);
void ffPrintPublicIp(FFinstance* instance);
void ffPrintColors(FFinstance* instance);
void ffPrintVulkan(FFinstance* instance);
void ffPrintOpenGL(FFinstance* instance);
void ffPrintOpenCL(FFinstance* instance);
#endif
+4 -1
View File
@@ -4,6 +4,8 @@
#define FASTFETCH_PROJECT_NAME "@PROJECT_NAME@"
#define FASTFETCH_PROJECT_VERSION "@PROJECT_VERSION@"
#define FASTFETCH_PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define FASTFETCH_PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@
#define FASTFETCH_PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@
#define FASTFETCH_PROJECT_VERSION_TWEAK "@PROJECT_VERSION_TWEAK@"
#define FASTFETCH_TARGET_DIR_ROOT "@TARGET_DIR_ROOT@"
@@ -11,7 +13,8 @@
#define FASTFETCH_TARGET_DIR_HOME "@TARGET_DIR_HOME@"
#define FASTFETCH_DATATEXT_STRUCTURE "@DATATEXT_STRUCTURE@"
#define FASTFETCH_DATATEXT_CONFIG "@DATATEXT_CONFIG@" //Requires FASTFETCH_PROJECT_VERSION and FASTFETCH_DATATEXT_STRUCTURE to be set
#define FASTFETCH_DATATEXT_CONFIG_SYSTEM "@DATATEXT_CONFIG_SYSTEM@" //Requires FASTFETCH_PROJECT_VERSION to be set
#define FASTFETCH_DATATEXT_CONFIG_USER "@DATATEXT_CONFIG_USER@" //Requires FASTFETCH_PROJECT_VERSION and FASTFETCH_DATATEXT_STRUCTURE to be set
#define FASTFETCH_DATATEXT_MODULES "@DATATEXT_MODULES@"
#define FASTFETCH_DATATEXT_HELP "@DATATEXT_HELP@"
#define FASTFETCH_DATATEXT_HELP_COLOR "@DATATEXT_HELP_COLOR@"
+3 -4
View File
@@ -10,10 +10,7 @@ int main(int argc, char** argv)
//Modify instance.config here
//Multithreading --> better performance
ffStartDetectionThreads(&instance);
//Does things like disabling line wrap
//Does things like starting detection threads, disabling line wrap, etc
ffStart(&instance);
//Printing
@@ -50,6 +47,8 @@ int main(int argc, char** argv)
//ffPrintDateTime(&instance);
//ffPrintDate(&instance);
//ffPrintTime(&instance);
//ffPrintVulkan(&instance);
//ffPrintOpenGL(&instance);
ffPrintBreak(&instance);
ffPrintColors(&instance);
+244 -232
View File
@@ -1,25 +1,12 @@
#include "logo.h"
#include <limits.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
typedef struct FFlogo
{
const char* data;
const char** names; //Null terminated
const char** builtinColors; //Null terminated
bool performColorReplacement;
} FFlogo;
#define FF_LOGO_INIT static FFlogo logo; static bool init = false; if(init) return &logo; init = true;
#define FF_LOGO_NAMES(...) static const char* names[] = (const char*[]) { __VA_ARGS__, NULL }; logo.names = names;
#define FF_LOGO_LINES(x) logo.data = x;
#define FF_LOGO_COLORS(...) static const char* colors[] = (const char*[]) { __VA_ARGS__, NULL }; logo.builtinColors = colors;
#define FF_LOGO_RETURN return &logo;
static const FFlogo* getLogoUnknown()
const FFlogo* ffLogoBuiltinGetUnknown()
{
FF_LOGO_INIT
FF_LOGO_NAMES("unknown", "question mark", "?")
@@ -56,6 +43,92 @@ static const FFlogo* getLogoNone()
FF_LOGO_RETURN
}
static const FFlogo* getLogoAlmaLinux()
{
FF_LOGO_INIT
FF_LOGO_NAMES("almalinux")
FF_LOGO_LINES(
"$1 'c:.\n"
"$1 lkkkx, .. $2.. ,cc,\n"
"$1 okkkk:ckkx' $2.lxkkx.okkkkd\n"
"$1 .:llcokkx' $2:kkkxkko:xkkd,\n"
"$1 .xkkkkdood: $2;kx, .lkxlll;\n"
"$1 xkkx. $2xk' xkkkkk:\n"
"$1 'xkx. $2xd .....,.\n"
"$3 .. $1:xkl' $2:c ..''..\n"
"$3 .dkx' $1.:ldl:'. $2' $4':lollldkkxo;\n"
"$3 .''lkkko' $4ckkkx.\n"
"$3'xkkkd:kkd. .. $5;' $4:kkxo.\n"
"$3,xkkkd;kk' ,d; $5ld. $4':dkd::cc,\n"
"$3 .,,.;xkko'.';lxo. $5dx, $4:kkk'xkkkkc\n"
"$3 'dkkkkkxo:. $5;kx $4.kkk:;xkkd.\n"
"$3 ..... $5.;dk:. $5lkk. $4:;,\n"
" $5:kkkkkkkdoxkkx\n"
" ,c,,;;;:xkkd.\n"
" ;kkkkl...\n"
" ;kkkkl\n"
" ,od;";
)
FF_LOGO_COLORS(
"31", // red
"1;33", // yellow
"34", // blue
"1;32", // light green
"36" // cyan
)
FF_LOGO_RETURN
}
static const FFlogo* getLogoAlpine()
{
FF_LOGO_INIT
FF_LOGO_NAMES("alpine", "alpinelinux", "alpine-linux")
FF_LOGO_LINES(
" .hddddddddddddddddddddddh.\n"
" :dddddddddddddddddddddddddd:\n"
" /dddddddddddddddddddddddddddd/\n"
" +dddddddddddddddddddddddddddddd+\n"
" `sdddddddddddddddddddddddddddddddds`\n"
" `ydddddddddddd++hdddddddddddddddddddy`\n"
".hddddddddddd+` `+ddddh:-sdddddddddddh. \n"
"hdddddddddd+` `+y: .sddddddddddh\n"
"ddddddddh+` `//` `.` -sddddddddd\n"
"ddddddh+` `/hddh/` `:s- -sddddddd\n"
"ddddh+` `/+/dddddh/` `+s- -sddddd\n"
"ddd+` `/o` :dddddddh/` `oy- .yddd\n"
"hdddyo+ohddyosdddddddddho+oydddy++ohdddh\n"
".hddddddddddddddddddddddddddddddddddddh.\n"
" `yddddddddddddddddddddddddddddddddddy`\n"
" `sdddddddddddddddddddddddddddddddds`\n"
" +dddddddddddddddddddddddddddddd+\n"
" /dddddddddddddddddddddddddddd/\n"
" :dddddddddddddddddddddddddd:\n"
" .hddddddddddddddddddddddh.";
)
FF_LOGO_COLORS(
"34" //blue
)
FF_LOGO_RETURN
}
static const FFlogo* getLogoAlpineSmall()
{
FF_LOGO_INIT
FF_LOGO_NAMES("alpine_small", "alpine-linux-small")
FF_LOGO_LINES(
" /\\ /\\\n"
" // \\ \\\n"
" // \\ \\\n"
"/// \\ \\\n"
"// \\ \\\n"
" \\"
)
FF_LOGO_COLORS(
"34" //blue
)
FF_LOGO_RETURN
}
static const FFlogo* getLogoAndroid()
{
FF_LOGO_INIT
@@ -168,18 +241,18 @@ static const FFlogo* getLogoArtix()
" 'oookkxxoo'\n"
" 'oiioxkkxxoo'\n"
" ':;:iiiioxxxoo'\n"
" `'.;::ioxxoo''\n"
" `'.;::ioxxoo'\n"
" '-. `':;jiooo'\n"
" 'oooio-.. `'i:io'\n"
" 'ooooxxxxoio:,. `'-;'\n"
" 'ooooxxxxxkkxoooIi:-. `'\n"
" 'ooooxxxxxkkkkxoiiiiiji'\n"
" 'ooooxxxxxkxxoiiii:'` .i'\n"
" 'ooooxxxxxoi:::'` .;ioxo'\n"
" 'ooooxooi::'` .:iiixkxxo'\n"
" 'ooooi:'` `'';ioxxo'\n"
"'i:'` '':io'\n"
"'` `'";
" 'oooio-.. `'i:io'\n"
" 'ooooxxxxoio:,. `'-;'\n"
" 'ooooxxxxxkkxoooIi:-. `'\n"
" 'ooooxxxxxkkkkxoiiiiiji'\n"
" 'ooooxxxxxkxxoiiii:'` .i'\n"
" 'ooooxxxxxoi:::'` .;ioxo'\n"
" 'ooooxooi::'` .:iiixkxxo'\n"
" 'ooooi:'` `'';ioxxo'\n"
" 'i:'` '':io'\n"
"'` `'";
)
FF_LOGO_COLORS(
"36" //cyan
@@ -239,6 +312,36 @@ static const FFlogo* getLogoArcoLinux()
FF_LOGO_RETURN
}
static const FFlogo* getLogoBedrock()
{
FF_LOGO_INIT
FF_LOGO_NAMES("bedrock", "bedrocklinux", "bedrock-linux")
FF_LOGO_LINES(
"--------------------------------------\n"
"--------------------------------------\n"
"--------------------------------------\n"
"---$2\\\\\\\\\\\\\\\\\\\\\\\\$1-----------------------\n"
"----$2\\\\\\ \\\\\\$1----------------------\n"
"-----$2\\\\\\ \\\\\\$1---------------------\n"
"------$2\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\$1------\n"
"-------$2\\\\\\ \\\\\\$1-----\n"
"--------$2\\\\\\ \\\\\\$1----\n"
"---------$2\\\\\\ ______ \\\\\\$1---\n"
"----------$2\\\\\\ ///$1---\n"
"-----------$2\\\\\\ ///$1----\n"
"------------$2\\\\\\ ///$1-----\n"
"-------------$2\\\\\\////////////////$1------\n"
"--------------------------------------\n"
"--------------------------------------\n"
"--------------------------------------"
)
FF_LOGO_COLORS(
"90", //grey
"37" //white
)
FF_LOGO_RETURN
}
static const FFlogo* getLogoCachyOS()
{
FF_LOGO_INIT
@@ -708,6 +811,27 @@ static const FFlogo* getLogoKDENeon()
FF_LOGO_RETURN
}
static const FFlogo* getLogoKISSLinux()
{
FF_LOGO_INIT
FF_LOGO_NAMES("kiss", "kiss-linux", "kisslinux")
FF_LOGO_LINES(
" $3 ___ \n"
" ($2.· $3| \n"
" ($1<> $3| \n"
" / $2__$3 \\ \n"
" ( $1/ \\ $3/| \n"
"$1_$3/\\ $2__)$3/$1_$3) \n"
"$1\\/$3-____$1\\/$2 \n"
)
FF_LOGO_COLORS(
"35", //magenta
"37", //white
"34" //blue
)
FF_LOGO_RETURN
}
static const FFlogo* getLogoKubuntu()
{
FF_LOGO_INIT
@@ -741,6 +865,32 @@ static const FFlogo* getLogoKubuntu()
FF_LOGO_RETURN
}
static const FFlogo* getLogoLangitKetujuh()
{
FF_LOGO_INIT
FF_LOGO_NAMES("l7", "langitketujuh", "LangitKetujuh")
FF_LOGO_LINES(
"\n"
"\n"
" $2. '7L7L7L7L7L7L7L7L7L7L7L7L7L7L7L7L7L7\n"
" $2L7. '7L7L7L7L7L7L7L7L7L7L7L7L7L7L7L7\n"
" $2L7L7L 7L7L7L7L7L7L7L7L7L7L7L7L7L7\n"
" $2L7L7L7 L7L7L7\n"
" $2L7L7L7 'L7L7L7L7L7L7L7L7L7L7\n"
" $2L7L7L7 'L7L7L7L7L7L7L7L7\n"
" $2L7L7L7 'L7L7L7L7L7L7\n"
" $2L7L7L7 L7L7L7\n"
" $2L7L7L7L7L7L7L7L7L7L7LL7L7L7. '7L7L7\n"
" $2L7L7L7L7L7L7L7L7L7L7L7L7L7L7L7L. 'L7\n"
" $2L7L7L7L7L7L7L7L7L7L7L7L7L7L7L7L7L7. '\n"
)
FF_LOGO_COLORS(
"34", //blue
"37" //white
)
FF_LOGO_RETURN
}
static const FFlogo* getLogoLinux()
{
FF_LOGO_INIT
@@ -931,25 +1081,34 @@ static const FFlogo* getLogoNixOsOld()
FF_LOGO_INIT
FF_LOGO_NAMES("nixos_old", "nix-old", "nixos-old", "nix_old", "nix-os-old", "nix_os_old")
FF_LOGO_LINES(
"$1 ::::. $2'::::: ::::'\n"
"$1 '::::: $2':::::. ::::'\n"
"$1 ::::: $2'::::.:::::\n"
"$1 .......:::::..... $2::::::::\n"
"$1 ::::::::::::::::::. $2:::::: $1::::.\n"
" ::::::::::::::::::::: $2:::::. $1.::::'\n"
"$2 ..... ::::' $1:::::'\n"
"$2 ::::: '::' $1:::::'\n"
"$2 ........::::: ' $1:::::::::::.\n"
"$2::::::::::::: $1:::::::::::::\n"
"$2 ::::::::::: $1.. $1:::::\n"
"$2 .::::: $1.::: $1:::::\n"
"$2 .::::: $1::::: $1''''' $2.....\n"
" ::::: $1':::::. $2......:::::::::::::'\n"
" ::: $1::::::. $2':::::::::::::::::'\n"
"$1 .:::::::: $2'::::::::::\n"
"$1 .::::''::::. $2'::::.\n"
"$1 .::::' ::::. $2'::::.\n"
"$1 .:::: :::: $2'::::."
"$1 ____ $2_______ ____\n"
"$1 /####\\ $2\\######\\ /####\\\n"
"$1 ######\\ $2\\######\\ /#####/\n"
"$1 \\######\\ $2\\######\\ /#####/\n"
"$1 \\######\\ $2\\######\\/#####/ $1/\\\n"
"$1 \\######\\ $2\\###########/ $1/##\\\n"
"$1 ________\\######\\______$2\\#########/ $1/####\\\n"
"$1 /#######################$2\\#######/ $1/######\n"
"$1 /#########################$2\\######\\ $1/######/\n"
"$1 /###########################$2\\######\\ $1/######/\n"
"$1 ¯¯¯¯¯¯¯¯¯¯¯¯$2/######/$1¯¯¯¯¯¯¯¯¯$2\\######$1/######/\n"
"$2 /######/ $2\\####$1/######/________\n"
"$2 _____________/######/ $2\\##$1/################\\\n"
"$2 /###################/ $2\\$1/##################\\\n"
"$2 \\##################/$1\\ /###################/\n"
"$2 \\################/$1##\\ /######/¯¯¯¯¯¯¯¯¯¯¯¯¯\n"
"$2 ¯¯¯¯¯¯¯¯/######/$1####\\ /######/\n"
"$2 /######/$1######\\$2_________$1/######/$2____________\n"
"$2 /######/ $1\\######\\$2###########################/\n"
"$2 /######/ $1\\######\\$2#########################/\n"
"$2 ######/ $1/#######\\$2#######################/\n"
"$2 \\####/ $1/#########\\$2¯¯¯¯¯¯\\######\\¯¯¯¯¯¯¯¯\n"
"$2 \\##/ $1/###########\\$2 \\######\\\n"
"$2 \\/ $1/#####/\\######\\$2 \\######\\\n"
"$1 $1/#####/ \\######\\$2 \\######\\\n"
"$1 $1/#####/ \\######\\$2 \\######\n"
"$1 $1\\####/ \\######\\$2 \\####/\n"
"$1 $1¯¯¯¯ ¯¯¯¯¯¯¯$2 ¯¯¯¯"
)
FF_LOGO_COLORS(
"34", //blue
@@ -1282,6 +1441,38 @@ static const FFlogo* getLogoRockyLinux()
FF_LOGO_RETURN
}
static const FFlogo* getLogoRosaLinux()
{
FF_LOGO_INIT
FF_LOGO_NAMES("rosa", "rosa-linux", "rosalinux")
FF_LOGO_LINES(
" ROSAROSAROSAROSAR\n"
" ROSA AROS\n"
" ROS SAROSAROSAROSAR AROS\n"
" RO ROSAROSAROSAROSAROSAR RO\n"
" ARO AROSAROSAROSARO AROS ROS\n"
" ARO ROSAROS OSAR ROSA ROS\n"
" RO AROSA ROSAROSAROSA ROSAR RO\n"
"RO ROSAR ROSAROSAROSAR R ROSARO RO\n"
"RO ROSA AROSAROSAROSA AR ROSARO AR\n"
"RO AROS ROSAROSAROSA ROS AROSARO AR\n"
"RO AROS ROSAROSARO ROSARO ROSARO AR\n"
"RO ROS AROSAROS ROSAROSA AROSAR AR\n"
"RO ROSA ROS ROSAROSAR ROSARO RO\n"
" RO ROS AROSAROSAROSA ROSARO AR\n"
" ARO ROSA ROSAROSAROS AROSAR ARO\n"
" ARO OROSA R ROSAROS ROS\n"
" RO AROSAROS AROSAROSAR RO\n"
" AROS AROSAROSAROSARO AROS\n"
" ROSA SARO\n"
" ROSAROSAROSAROSAR"
)
FF_LOGO_COLORS(
"34" //blue
)
FF_LOGO_RETURN
}
static const FFlogo* getLogoUbuntu()
{
FF_LOGO_INIT
@@ -1412,13 +1603,14 @@ static const FFlogo* getLogoZorin()
FF_LOGO_RETURN
}
typedef const FFlogo*(*GetLogoMethod)();
static GetLogoMethod* getLogos()
GetLogoMethod* ffLogoBuiltinGetAll()
{
static GetLogoMethod logoMethods[] = {
ffLogoBuiltinGetUnknown,
getLogoNone,
getLogoUnknown,
getLogoAlmaLinux,
getLogoAlpine,
getLogoAlpineSmall,
getLogoAndroid,
getLogoAndroidSmall,
getLogoArch,
@@ -1426,6 +1618,7 @@ static GetLogoMethod* getLogos()
getLogoArcoLinux,
getLogoArtix,
getLogoArtixSmall,
getLogoBedrock,
getLogoCachyOS,
getLogoCelOS,
getLogoCentOS,
@@ -1443,7 +1636,9 @@ static GetLogoMethod* getLogos()
getLogoGentoo,
getLogoGentooSmall,
getLogoKDENeon,
getLogoKISSLinux,
getLogoKubuntu,
getLogoLangitKetujuh,
getLogoLinux,
getLogoManjaro,
getLogoManjaroSmall,
@@ -1464,6 +1659,7 @@ static GetLogoMethod* getLogos()
getLogoRedHatEnterpriseLinux,
getLogoRedstarOS,
getLogoRockyLinux,
getLogoRosaLinux,
getLogoUbuntu,
getLogoUbuntuSmall,
getLogoVoid,
@@ -1474,187 +1670,3 @@ static GetLogoMethod* getLogos()
return logoMethods;
}
static bool logoHasName(const FFlogo* logo, const char* name)
{
const char** logoName = logo->names;
while(*logoName != NULL)
{
if(strcasecmp(*logoName, name) == 0)
return true;
++logoName;
}
return false;
}
static const FFlogo* getBuiltinLogo(const char* name)
{
GetLogoMethod* methods = getLogos();
while(*methods != NULL)
{
const FFlogo* logo = (*methods)();
if(logoHasName(logo, name))
return logo;
++methods;
}
return NULL;
}
static const FFlogo* detectBuiltinLogoWithVersion(const FFstrbuf* versionString, const FFstrbuf* name)
{
if(versionString->length == 0)
return getBuiltinLogo(name->chars);
#define FF_PRINT_LOGO_VERSIONED_IF_EXISTS(newLogo, oldLogo, ver) \
if(logoHasName(newLogo, name->chars)) \
{ \
long version = strtol(versionString->chars, NULL, 10); \
return (version == 0 || version == LONG_MAX || version == LONG_MIN || version >= ver) ? newLogo : oldLogo; \
}
FF_PRINT_LOGO_VERSIONED_IF_EXISTS(getLogoFedora(), getLogoFedoraOld(), 34)
FF_PRINT_LOGO_VERSIONED_IF_EXISTS(getLogoMint(), getLogoMintOld(), 19)
return getBuiltinLogo(name->chars);
}
static const FFlogo* detectBuiltinLogo(const FFinstance* instance)
{
static const FFlogo* logo;
static bool detected = false;
if(detected)
return logo;
detected = true;
const FFOSResult* os = ffDetectOS(instance);
logo = detectBuiltinLogoWithVersion(&os->version, &os->name);
if(logo != NULL)
return logo;
logo = detectBuiltinLogoWithVersion(&os->version, &os->id);
if(logo != NULL)
return logo;
logo = detectBuiltinLogoWithVersion(&os->version, &os->idLike);
if(logo != NULL)
return logo;
logo = detectBuiltinLogoWithVersion(&os->version, &os->systemName);
if(logo != NULL)
return logo;
return getLogoUnknown();
}
void ffLogoSetMainColor(FFinstance* instance)
{
const FFlogo* logo = NULL;
if(instance->config.logoSource.length > 0)
logo = getBuiltinLogo(instance->config.logoSource.chars);
if(logo == NULL)
logo = detectBuiltinLogo(instance);
ffStrbufAppendS(&instance->config.mainColor, logo->builtinColors[0]);
}
static void printLogoStruct(FFinstance* instance, const FFlogo* logo, bool doColorReplacement)
{
if(!doColorReplacement)
{
ffLogoPrint(instance, logo->data, false);
return;
}
const char** colors = logo->builtinColors;
for(int i = 0; *colors != NULL && i < FASTFETCH_LOGO_MAX_COLORS; i++, colors++)
{
if(instance->config.logoColors[i].length == 0)
ffStrbufAppendS(&instance->config.logoColors[i], *colors);
}
ffLogoPrint(instance, logo->data, true);
}
void ffLogoPrintUnknown(FFinstance* instance)
{
printLogoStruct(instance, getLogoUnknown(), false);
}
bool ffLogoPrintBuiltinIfExists(FFinstance* instance)
{
const FFlogo* logo = getBuiltinLogo(instance->config.logoSource.chars);
if(logo == NULL)
return false;
printLogoStruct(instance, logo, true);
return true;
}
void ffLogoPrintBuiltinDetected(FFinstance* instance)
{
printLogoStruct(instance, detectBuiltinLogo(instance), true);
}
void ffPrintBuiltinLogos(FFinstance* instance)
{
GetLogoMethod* methods = getLogos();
while(*methods != NULL)
{
const FFlogo* logo = (*methods)();
printf("\033[%sm%s:\033[0m\n", logo->builtinColors[0], logo->names[0]);
printLogoStruct(instance, logo, true);
ffPrintRemainingLogo(instance);
instance->state.logoHeight = 0;
for(uint8_t i = 0; i < FASTFETCH_LOGO_MAX_COLORS; i++)
ffStrbufClear(&instance->config.logoColors[i]);
puts("\n");
++methods;
}
}
void ffListBuiltinLogos()
{
GetLogoMethod* methods = getLogos();
uint32_t counter = 0;
while(*methods != NULL)
{
const FFlogo* logo = (*methods)();
const char** names = logo->names;
printf("%u)%s ", counter, counter < 10 ? " " : "");
++counter;
while(*names != NULL)
{
printf("\"%s\" ", *names);
++names;
}
putchar('\n');
++methods;
}
}
void ffListBuiltinLogosAutocompletion()
{
GetLogoMethod* methods = getLogos();
while(*methods != NULL)
{
printf("%s\n", (*methods)()->names[0]);
++methods;
}
}
+2
View File
@@ -1,6 +1,8 @@
#ifdef FF_HAVE_IMAGEMAGICK6
#include "image.h"
#include "common/library.h"
#include <magick/MagickCore.h>
static FF_LIBRARY_SYMBOL(ResizeImage);
+2
View File
@@ -1,6 +1,8 @@
#ifdef FF_HAVE_IMAGEMAGICK7
#include "image.h"
#include "common/library.h"
#include <MagickCore/MagickCore.h>
static FF_LIBRARY_SYMBOL(ResizeImage);
+31 -28
View File
@@ -1,4 +1,6 @@
#include "image.h"
#include "common/io.h"
#include "common/printing.h"
#if defined(FF_HAVE_IMAGEMAGICK7) || defined(FF_HAVE_IMAGEMAGICK6)
@@ -17,6 +19,8 @@
#include <sys/ioctl.h>
#ifdef FF_HAVE_ZLIB
#include "common/library.h"
#include <stdlib.h>
#include <zlib.h>
static bool compressBlob(const FFinstance* instance, void** blob, size_t* length)
@@ -92,7 +96,7 @@ static void writeCacheStrbuf(FFLogoRequestData* requestData, const FFstrbuf* val
{
uint32_t cacheDirLength = requestData->cacheDir.length;
ffStrbufAppendS(&requestData->cacheDir, cacheFileName);
ffWriteFileContent(requestData->cacheDir.chars, value);
ffWriteFileBuffer(requestData->cacheDir.chars, value);
ffStrbufSubstrBefore(&requestData->cacheDir, cacheDirLength);
}
@@ -107,7 +111,7 @@ static void writeCacheUint32(FFLogoRequestData* requestData, uint32_t value, con
static void printImagePixels(FFinstance* instance, FFLogoRequestData* requestData, const FFstrbuf* result, const char* cacheFileName)
{
//Calculate character dimensions
instance->state.logoWidth = requestData->logoCharacterWidth + instance->config.logoPaddingLeft + instance->config.logoPaddingRight;
instance->state.logoWidth = requestData->logoCharacterWidth + instance->config.logo.paddingLeft + instance->config.logo.paddingRight;
instance->state.logoHeight = requestData->logoCharacterHeight;
if(requestData->type == FF_LOGO_TYPE_KITTY)
@@ -116,16 +120,16 @@ static void printImagePixels(FFinstance* instance, FFLogoRequestData* requestDat
//Write cache files
writeCacheStrbuf(requestData, result, cacheFileName);
if(instance->config.logoWidth == 0)
if(instance->config.logo.width == 0)
writeCacheUint32(requestData, instance->state.logoWidth, FF_CACHE_FILE_WIDTH);
if(instance->config.logoHeight == 0)
if(instance->config.logo.height == 0)
writeCacheUint32(requestData, instance->state.logoHeight, FF_CACHE_FILE_HEIGHT);
//Write result to stdout
ffPrintCharTimes(' ', instance->config.logoPaddingLeft);
ffPrintCharTimes(' ', instance->config.logo.paddingLeft);
fflush(stdout);
ffWriteFDContent(STDOUT_FILENO, result);
ffWriteFDBuffer(STDOUT_FILENO, result);
//Go to upper left corner
fputs("\033[9999999D", stdout);
@@ -255,7 +259,7 @@ static bool printImageChafa(FFinstance* instance, FFLogoRequestData* requestData
result.length = (uint32_t) str->len;
result.chars = str->str;
ffLogoPrint(instance, result.chars, false);
ffLogoPrintChars(instance, result.chars, false);
writeCacheStrbuf(requestData, &result, FF_CACHE_FILE_CHAFA);
ffg_string_free(str, TRUE);
@@ -294,7 +298,7 @@ FFLogoImageResult ffLogoPrintImageImpl(FFinstance* instance, FFLogoRequestData*
}
//+1, because we need to copy the null byte too
imageData.ffCopyMagickString(imageInfoIn->filename, instance->config.logoSource.chars, instance->config.logoSource.length + 1);
imageData.ffCopyMagickString(imageInfoIn->filename, instance->config.logo.source.chars, instance->config.logo.source.length + 1);
imageData.image = ffReadImage(imageInfoIn, imageData.exceptionInfo);
ffDestroyImageInfo(imageInfoIn);
@@ -373,7 +377,7 @@ static void readCachedStrbuf(FFLogoRequestData* requestData, FFstrbuf* result, c
{
uint32_t cacheDirLength = requestData->cacheDir.length;
ffStrbufAppendS(&requestData->cacheDir, cacheFileName);
ffAppendFileContent(requestData->cacheDir.chars, result);
ffAppendFileBuffer(requestData->cacheDir.chars, result);
ffStrbufSubstrBefore(&requestData->cacheDir, cacheDirLength);
}
@@ -412,14 +416,14 @@ static bool printCachedChars(FFinstance* instance, FFLogoRequestData* requestDat
return false;
}
ffLogoPrint(instance, content.chars, false);
ffLogoPrintChars(instance, content.chars, false);
ffStrbufDestroy(&content);
return true;
}
static bool printCachedPixel(FFinstance* instance, FFLogoRequestData* requestData)
{
requestData->logoCharacterWidth = instance->config.logoWidth;
requestData->logoCharacterWidth = instance->config.logo.width;
if(requestData->logoCharacterWidth == 0)
{
requestData->logoCharacterWidth = readCachedUint32(requestData, FF_CACHE_FILE_WIDTH);
@@ -427,7 +431,7 @@ static bool printCachedPixel(FFinstance* instance, FFLogoRequestData* requestDat
return false;
}
requestData->logoCharacterHeight = instance->config.logoHeight;
requestData->logoCharacterHeight = instance->config.logo.height;
if(requestData->logoCharacterHeight == 0)
{
requestData->logoCharacterHeight = readCachedUint32(requestData, FF_CACHE_FILE_HEIGHT);
@@ -448,7 +452,7 @@ static bool printCachedPixel(FFinstance* instance, FFLogoRequestData* requestDat
if(fd == -1)
return false;
ffPrintCharTimes(' ', instance->config.logoPaddingLeft);
ffPrintCharTimes(' ', instance->config.logo.paddingLeft);
fflush(stdout);
char buffer[32768];
@@ -458,7 +462,7 @@ static bool printCachedPixel(FFinstance* instance, FFLogoRequestData* requestDat
close(fd);
instance->state.logoWidth = requestData->logoCharacterWidth + instance->config.logoPaddingLeft + instance->config.logoPaddingRight;
instance->state.logoWidth = requestData->logoCharacterWidth + instance->config.logo.paddingLeft + instance->config.logo.paddingRight;
instance->state.logoHeight = requestData->logoCharacterHeight;
//Go to upper left corner
@@ -499,12 +503,12 @@ static bool getCharacterPixelDimensions(FFLogoRequestData* requestData)
return requestData->characterPixelWidth > 1.0 && requestData->characterPixelHeight > 1.0;
}
FFLogoImageResult ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type)
bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type)
{
//Performance optimisation
#ifndef FF_HAVE_CHAFA
if(type == FF_LOGO_TYPE_CHAFA)
return FF_LOGO_IMAGE_RESULT_INIT_ERROR;
return false;
#endif
FFLogoRequestData requestData;
@@ -513,28 +517,27 @@ FFLogoImageResult ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type
requestData.characterPixelHeight = 1;
if(
(type != FF_LOGO_TYPE_CHAFA || instance->config.logoWidth == 0 || instance->config.logoHeight == 0) &&
(type != FF_LOGO_TYPE_CHAFA || instance->config.logo.width == 0 || instance->config.logo.height == 0) &&
!getCharacterPixelDimensions(&requestData)
)
return FF_LOGO_IMAGE_RESULT_RUN_ERROR;
return false;
requestData.logoPixelWidth = simpleCeil((double) instance->config.logoWidth * requestData.characterPixelWidth);
requestData.logoPixelHeight = simpleCeil((double) instance->config.logoHeight * requestData.characterPixelHeight);
requestData.logoPixelWidth = simpleCeil((double) instance->config.logo.width * requestData.characterPixelWidth);
requestData.logoPixelHeight = simpleCeil((double) instance->config.logo.height * requestData.characterPixelHeight);
ffStrbufInitA(&requestData.cacheDir, PATH_MAX * 2);
ffStrbufAppend(&requestData.cacheDir, &instance->state.cacheDir);
ffStrbufAppendS(&requestData.cacheDir, "images");
ffStrbufEnsureFree(&requestData.cacheDir, PATH_MAX);
if(realpath(instance->config.logoSource.chars, requestData.cacheDir.chars + requestData.cacheDir.length) == NULL)
if(realpath(instance->config.logo.source.chars, requestData.cacheDir.chars + requestData.cacheDir.length) == NULL)
{
//We can safely return here, because if realpath failed, we surely won't be able to read the file
ffStrbufDestroy(&requestData.cacheDir);
return FF_LOGO_IMAGE_RESULT_RUN_ERROR;
return false;
}
ffStrbufRecalculateLength(&requestData.cacheDir);
if(!ffStrbufEndsWithC(&requestData.cacheDir, '/'))
ffStrbufAppendC(&requestData.cacheDir, '/');
ffStrbufEnsureEndsWithC(&requestData.cacheDir, '/');
ffStrbufAppendF(&requestData.cacheDir, "%u", requestData.logoPixelWidth);
ffStrbufAppendC(&requestData.cacheDir, '*');
@@ -544,7 +547,7 @@ FFLogoImageResult ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type
if(!instance->config.recache && printCached(instance, &requestData))
{
ffStrbufDestroy(&requestData.cacheDir);
return FF_LOGO_IMAGE_RESULT_SUCCESS;
return true;
}
FFLogoImageResult result = FF_LOGO_IMAGE_RESULT_INIT_ERROR;
@@ -559,13 +562,13 @@ FFLogoImageResult ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type
#endif
ffStrbufDestroy(&requestData.cacheDir);
return result;
return result == FF_LOGO_IMAGE_RESULT_SUCCESS;
}
#else //FF_HAVE_IMAGEMAGICK{6, 7}
FFLogoImageResult ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type)
bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type)
{
FF_UNUSED(instance, type);
return FF_LOGO_IMAGE_RESULT_RUN_ERROR;
return false;
}
#endif //FF_HAVE_IMAGEMAGICK{6, 7}
+7 -1
View File
@@ -10,6 +10,13 @@
#define MAGICKCORE_HDRI_ENABLE 1
#define MAGICKCORE_QUANTUM_DEPTH 16
typedef enum FFLogoImageResult
{
FF_LOGO_IMAGE_RESULT_SUCCESS, //Logo printed
FF_LOGO_IMAGE_RESULT_INIT_ERROR, //Failed to load library, try again with next IM version
FF_LOGO_IMAGE_RESULT_RUN_ERROR //Failed to load / convert image, cancle whole sixel code
} FFLogoImageResult;
typedef struct FFLogoRequestData
{
FFLogoType type;
@@ -44,5 +51,4 @@ FFLogoImageResult ffLogoPrintImageIM7(FFinstance* instance, FFLogoRequestData* r
FFLogoImageResult ffLogoPrintImageIM6(FFinstance* instance, FFLogoRequestData* requestData);
#endif
#endif
+235 -99
View File
@@ -1,24 +1,29 @@
#include "logo.h"
#include "common/io.h"
#include "common/printing.h"
#include "detection/os.h"
#include "detection/terminalshell.h"
#include <ctype.h>
#include <string.h>
void ffLogoPrint(FFinstance* instance, const char* data, bool doColorReplacement)
void ffLogoPrintChars(FFinstance* instance, const char* data, bool doColorReplacement)
{
uint32_t currentlineLength = 0;
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
ffPrintCharTimes(' ', instance->config.logoPaddingLeft);
ffPrintCharTimes(' ', instance->config.logo.paddingLeft);
//Use logoColor[0] as the default color
if(doColorReplacement)
ffPrintColor(&instance->config.logoColors[0]);
ffPrintColor(&instance->config.logo.colors[0]);
while(*data != '\0')
{
//We are at the end of a line. Print paddings and update max line length
if(*data == '\n' || (*data == '\r' && *(data + 1) == '\n'))
{
ffPrintCharTimes(' ', instance->config.logoPaddingRight);
ffPrintCharTimes(' ', instance->config.logo.paddingRight);
//We have \r\n, skip the \r
if(*data == '\r')
@@ -27,7 +32,7 @@ void ffLogoPrint(FFinstance* instance, const char* data, bool doColorReplacement
putchar('\n');
++data;
ffPrintCharTimes(' ', instance->config.logoPaddingLeft);
ffPrintCharTimes(' ', instance->config.logo.paddingLeft);
if(currentlineLength > instance->state.logoWidth)
instance->state.logoWidth = currentlineLength;
@@ -95,7 +100,7 @@ void ffLogoPrint(FFinstance* instance, const char* data, bool doColorReplacement
}
else
{
ffPrintColor(&instance->config.logoColors[index]);
ffPrintColor(&instance->config.logo.colors[index]);
++data;
continue;
}
@@ -128,14 +133,14 @@ void ffLogoPrint(FFinstance* instance, const char* data, bool doColorReplacement
}
}
ffPrintCharTimes(' ', instance->config.logoPaddingRight);
ffPrintCharTimes(' ', instance->config.logo.paddingRight);
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
//Happens if the last line is the longest
if(currentlineLength > instance->state.logoWidth)
instance->state.logoWidth = currentlineLength;
instance->state.logoWidth += instance->config.logoPaddingLeft + instance->config.logoPaddingRight;
instance->state.logoWidth += instance->config.logo.paddingLeft + instance->config.logo.paddingRight;
//Go to the leftmost position
fputs("\033[9999999D", stdout);
@@ -145,137 +150,268 @@ void ffLogoPrint(FFinstance* instance, const char* data, bool doColorReplacement
printf("\033[%uA", instance->state.logoHeight);
}
static void logoPrintFile(FFinstance* instance, bool doColorReplacement)
static void logoApplyMainColor(FFinstance* instance, const FFlogo* logo)
{
if(instance->config.mainColor.length == 0)
ffStrbufAppendS(&instance->config.mainColor, logo->builtinColors[0]);
}
static bool logoHasName(const FFlogo* logo, const char* name)
{
const char** logoName = logo->names;
while(*logoName != NULL)
{
if(strcasecmp(*logoName, name) == 0)
return true;
++logoName;
}
return false;
}
static const FFlogo* logoGetBuiltin(const char* name)
{
GetLogoMethod* methods = ffLogoBuiltinGetAll();
while(*methods != NULL)
{
const FFlogo* logo = (*methods)();
if(logoHasName(logo, name))
return logo;
++methods;
}
return NULL;
}
static const FFlogo* logoGetBuiltinDetected(FFinstance* instance)
{
const FFOSResult* os = ffDetectOS(instance);
const FFlogo* logo = logoGetBuiltin(os->id.chars);
if(logo != NULL)
return logo;
logo = logoGetBuiltin(os->name.chars);
if(logo != NULL)
return logo;
logo = logoGetBuiltin(os->prettyName.chars);
if(logo != NULL)
return logo;
logo = logoGetBuiltin(os->idLike.chars);
if(logo != NULL)
return logo;
logo = logoGetBuiltin(os->systemName.chars);
if(logo != NULL)
return logo;
return ffLogoBuiltinGetUnknown();
}
static inline void logoApplyMainColorDetected(FFinstance* instance)
{
logoApplyMainColor(instance, logoGetBuiltinDetected(instance));
}
static void logoPrintStruct(FFinstance* instance, const FFlogo* logo)
{
logoApplyMainColor(instance, logo);
const char** colors = logo->builtinColors;
for(int i = 0; *colors != NULL && i < FASTFETCH_LOGO_MAX_COLORS; i++, colors++)
{
if(instance->config.logo.colors[i].length == 0)
ffStrbufAppendS(&instance->config.logo.colors[i], *colors);
}
ffLogoPrintChars(instance, logo->data, true);
}
static bool logoPrintBuiltinIfExists(FFinstance* instance, const char* name)
{
const FFlogo* logo = logoGetBuiltin(name);
if(logo == NULL)
return false;
logoPrintStruct(instance, logo);
return true;
}
static inline void logoPrintDetected(FFinstance* instance)
{
logoPrintStruct(instance, logoGetBuiltinDetected(instance));
}
static bool logoPrintFileIfExists(FFinstance* instance, bool doColorReplacement)
{
FFstrbuf content;
ffStrbufInitA(&content, 2047);
if(ffAppendFileContent(instance->config.logoSource.chars, &content))
ffLogoPrint(instance, content.chars, doColorReplacement);
else
ffLogoPrintUnknown(instance);
if(!ffAppendFileBuffer(instance->config.logo.source.chars, &content))
{
ffStrbufDestroy(&content);
return false;
}
logoApplyMainColorDetected(instance);
ffLogoPrintChars(instance, content.chars, doColorReplacement);
ffStrbufDestroy(&content);
return true;
}
static void logoPrintDetected(FFinstance* instance)
static bool logoPrintImageIfExists(FFinstance* instance, FFLogoType logo)
{
//If no logo source is given, detect the logo from OS and print the right builtin one
if(instance->config.logoSource.length == 0)
if(!ffLogoPrintImageIfExists(instance, logo))
return false;
logoApplyMainColorDetected(instance);
return true;
}
static void logoPrintKnownType(FFinstance* instance)
{
bool successfull;
if(instance->config.logo.type == FF_LOGO_TYPE_BUILTIN)
successfull = logoPrintBuiltinIfExists(instance, instance->config.logo.source.chars);
else if(instance->config.logo.type == FF_LOGO_TYPE_FILE)
successfull = logoPrintFileIfExists(instance, true);
else if(instance->config.logo.type == FF_LOGO_TYPE_RAW)
successfull = logoPrintFileIfExists(instance, false);
else //image
successfull = logoPrintImageIfExists(instance, instance->config.logo.type);
if(!successfull)
logoPrintDetected(instance);
}
void ffLogoPrint(FFinstance* instance)
{
//In pipe mode, we don't have a logo or padding.
//We also don't need to set main color, because it won't be printed anyway.
//So we can return quickly here.
if(instance->config.pipe)
{
ffLogoPrintBuiltinDetected(instance);
instance->state.logoHeight = 0;
instance->state.logoWidth = 0;
return;
}
//If a logo source is given, first look if it is the name of a builtin logo
if(ffLogoPrintBuiltinIfExists(instance))
//If the source is not set, we can directly print the detected logo.
if(instance->config.logo.source.length == 0)
{
logoPrintDetected(instance);
return;
}
//If the source and source type is set to something else than auto, always print with the set type.
if(instance->config.logo.source.length > 0 && instance->config.logo.type != FF_LOGO_TYPE_AUTO)
{
logoPrintKnownType(instance);
return;
}
//If source matches the name of a builtin logo, print it and return.
if(logoPrintBuiltinIfExists(instance, instance->config.logo.source.chars))
return;
const FFTerminalShellResult* terminalShell = ffDetectTerminalShell(instance);
FFLogoImageResult imageResult = FF_LOGO_IMAGE_RESULT_INIT_ERROR;
//Terminals that are known to support kitty graphics protocol
//Try to load the logo as image.
if(
//Terminal emulators that support kitty graphics protocol.
bool supportsKitty =
ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "kitty") == 0 ||
ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "konsole") == 0 ||
ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "wezterm") == 0 ||
ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "wayst") == 0
) {
imageResult = ffLogoPrintImageIfExists(instance, FF_LOGO_TYPE_KITTY);
if(imageResult == FF_LOGO_IMAGE_RESULT_SUCCESS)
return;
}
ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "wayst") == 0;
//If the logo can be loaded as an image, convert it to ascii art.
//This happens in all terminals, that don't support kitty graphics protocol
if(
imageResult != FF_LOGO_IMAGE_RESULT_RUN_ERROR &&
ffLogoPrintImageIfExists(instance, FF_LOGO_TYPE_CHAFA) == FF_LOGO_IMAGE_RESULT_SUCCESS
) return;
//Try to load the logo as an image. If it succeeds, print it and return.
if(logoPrintImageIfExists(instance, supportsKitty ? FF_LOGO_TYPE_KITTY : FF_LOGO_TYPE_CHAFA))
return;
//Print the content of the file as logo
logoPrintFile(instance, true);
//Try to load the logo as a file. If it succeeds, print it and return.
if(logoPrintFileIfExists(instance, true))
return;
logoPrintDetected(instance);
}
void ffPrintLogo(FFinstance* instance)
{
if(instance->config.mainColor.length == 0)
ffLogoSetMainColor(instance);
if( //Logo type needs set logo name, but nothing was given. Print question mark
instance->config.logoType != FF_LOGO_TYPE_AUTO &&
instance->config.logoSource.length == 0
)
ffLogoPrintUnknown(instance);
else if(instance->config.logoType == FF_LOGO_TYPE_BUILTIN)
{
if(!ffLogoPrintBuiltinIfExists(instance))
ffLogoPrintUnknown(instance);
}
else if(instance->config.logoType == FF_LOGO_TYPE_FILE)
logoPrintFile(instance, true);
else if(instance->config.logoType == FF_LOGO_TYPE_RAW)
logoPrintFile(instance, false);
else if(instance->config.logoType == FF_LOGO_TYPE_SIXEL || instance->config.logoType == FF_LOGO_TYPE_KITTY || instance->config.logoType == FF_LOGO_TYPE_CHAFA)
{
if(ffLogoPrintImageIfExists(instance, instance->config.logoType) != FF_LOGO_IMAGE_RESULT_SUCCESS)
ffLogoPrintBuiltinDetected(instance);
}
else
logoPrintDetected(instance);
}
static inline void printLogoWidth(const FFinstance* instance)
void ffLogoPrintLine(FFinstance* instance)
{
if(instance->state.logoWidth > 0)
printf("\033[%uC", instance->state.logoWidth);
++instance->state.keysHeight;
}
void ffPrintRemainingLogo(FFinstance* instance)
void ffLogoPrintRemaining(FFinstance* instance)
{
if(!instance->config.logoPrintRemaining)
return;
for(uint32_t i = instance->state.keysHeight; i <= instance->state.logoHeight; i++)
while(instance->state.keysHeight <= instance->state.logoHeight)
{
printLogoWidth(instance);
ffLogoPrintLine(instance);
putchar('\n');
}
}
void ffPrintLogoLine(FFinstance* instance)
void ffLogoBuiltinPrint(FFinstance* instance)
{
printLogoWidth(instance);
++instance->state.keysHeight;
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
GetLogoMethod* methods = ffLogoBuiltinGetAll();
while(*methods != NULL)
{
const FFlogo* logo = (*methods)();
printf("\033[%sm%s:\033[0m\n", logo->builtinColors[0], logo->names[0]);
logoPrintStruct(instance, logo);
ffLogoPrintRemaining(instance);
//reset everything
instance->state.logoHeight = 0;
instance->state.keysHeight = 0;
for(uint8_t i = 0; i < FASTFETCH_LOGO_MAX_COLORS; i++)
ffStrbufClear(&instance->config.logo.colors[i]);
puts("\n");
++methods;
}
}
void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat)
void ffLogoBuiltinList()
{
ffPrintLogoLine(instance);
GetLogoMethod* methods = ffLogoBuiltinGetAll();
fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout);
ffPrintColor(&instance->config.mainColor);
uint32_t counter = 0;
if(customKeyFormat == NULL || customKeyFormat->length == 0)
while(*methods != NULL)
{
fputs(moduleName, stdout);
const FFlogo* logo = (*methods)();
const char** names = logo->names;
if(moduleIndex > 0)
printf(" %hhu", moduleIndex);
}
else
{
FFstrbuf key;
ffStrbufInit(&key);
ffParseFormatString(&key, customKeyFormat, NULL, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex}
});
ffStrbufWriteTo(&key, stdout);
ffStrbufDestroy(&key);
}
printf("%u)%s ", counter, counter < 10 ? " " : "");
++counter;
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
ffStrbufWriteTo(&instance->config.separator, stdout);
fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout);
while(*names != NULL)
{
printf("\"%s\" ", *names);
++names;
}
putchar('\n');
++methods;
}
}
void ffLogoBuiltinListAutocompletion()
{
GetLogoMethod* methods = ffLogoBuiltinGetAll();
while(*methods != NULL)
{
printf("%s\n", (*methods)()->names[0]);
++methods;
}
}
+13 -14
View File
@@ -5,24 +5,23 @@
#include "fastfetch.h"
typedef struct FFlogo
{
const char* data;
const char** names; //Null terminated
const char** builtinColors; //Null terminated
} FFlogo;
typedef const FFlogo*(*GetLogoMethod)();
//logo.c
void ffLogoPrint(FFinstance* instance, const char* data, bool doColorReplacement);
void ffLogoPrintChars(FFinstance* instance, const char* data, bool doColorReplacement);
//builtin.c
void ffLogoSetMainColor(FFinstance* instance);
void ffLogoPrintUnknown(FFinstance* instance);
bool ffLogoPrintBuiltinIfExists(FFinstance* instance);
void ffLogoPrintBuiltinDetected(FFinstance* instance);
typedef enum FFLogoImageResult
{
FF_LOGO_IMAGE_RESULT_SUCCESS, //Logo printed
FF_LOGO_IMAGE_RESULT_INIT_ERROR, //Failed to load library, try again with next IM version
FF_LOGO_IMAGE_RESULT_RUN_ERROR //Failed to load / convert image, cancle whole sixel code
} FFLogoImageResult;
const FFlogo* ffLogoBuiltinGetUnknown();
GetLogoMethod* ffLogoBuiltinGetAll();
//image/image.c
FFLogoImageResult ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type);
bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type);
#endif
+15 -15
View File
@@ -1,6 +1,7 @@
#include "fastfetch.h"
#include "common/io.h"
#include "common/printing.h"
#include <unistd.h>
#include <dirent.h>
#define FF_BATTERY_MODULE_NAME "Battery"
@@ -24,7 +25,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//type must exist and be "Battery"
ffStrbufAppendS(dir, "/type");
ffGetFileContent(dir->chars, &testBatteryBuffer);
ffReadFileBuffer(dir->chars, &testBatteryBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Battery") != 0)
@@ -35,7 +36,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//scope may not exist or must not be "Device"
ffStrbufAppendS(dir, "/scope");
ffGetFileContent(dir->chars, &testBatteryBuffer);
ffReadFileBuffer(dir->chars, &testBatteryBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Device") == 0)
@@ -50,7 +51,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//capacity must exist and be not empty
ffStrbufInit(&result->capacity);
ffStrbufAppendS(dir, "/capacity");
ffGetFileContent(dir->chars, &result->capacity);
ffReadFileBuffer(dir->chars, &result->capacity);
ffStrbufSubstrBefore(dir, dirLength);
if(result->capacity.length == 0)
@@ -64,30 +65,30 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
ffStrbufInit(&result->manufacturer);
ffStrbufAppendS(dir, "/manufacturer");
ffGetFileContent(dir->chars, &result->manufacturer);
ffReadFileBuffer(dir->chars, &result->manufacturer);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->modelName);
ffStrbufAppendS(dir, "/model_name");
ffGetFileContent(dir->chars, &result->modelName);
ffReadFileBuffer(dir->chars, &result->modelName);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->technology);
ffStrbufAppendS(dir, "/technology");
ffGetFileContent(dir->chars, &result->technology);
ffReadFileBuffer(dir->chars, &result->technology);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->status);
ffStrbufAppendS(dir, "/status");
ffGetFileContent(dir->chars, &result->status);
ffReadFileBuffer(dir->chars, &result->status);
ffStrbufSubstrBefore(dir, dirLength);
}
static void printBattery(FFinstance* instance, const BatteryResult* result, uint8_t index)
{
if(instance->config.batteryFormat.length == 0)
if(instance->config.battery.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.batteryKey);
ffPrintLogoAndKey(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.battery.key);
bool showStatus =
result->status.length > 0 &&
@@ -114,7 +115,7 @@ static void printBattery(FFinstance* instance, const BatteryResult* result, uint
}
else
{
ffPrintFormatString(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.batteryKey, &instance->config.batteryFormat, NULL, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.battery, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->technology},
@@ -131,8 +132,7 @@ void ffPrintBattery(FFinstance* instance)
if(instance->config.batteryDir.length > 0)
{
ffStrbufAppend(&baseDir, &instance->config.batteryDir);
if(!ffStrbufEndsWithC(&baseDir, '/'))
ffStrbufAppendC(&baseDir, '/');
ffStrbufEndsWithC(&baseDir, '/');
}
else
{
@@ -144,7 +144,7 @@ void ffPrintBattery(FFinstance* instance)
DIR* dirp = opendir(baseDir.chars);
if(dirp == NULL)
{
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.batteryKey, &instance->config.batteryFormat, FF_BATTERY_NUM_FORMAT_ARGS, "opendir(\"%s\") == NULL", baseDir.chars);
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.battery, "opendir(\"%s\") == NULL", baseDir.chars);
ffStrbufDestroy(&baseDir);
return;
}
@@ -175,7 +175,7 @@ void ffPrintBattery(FFinstance* instance)
}
if(results.length == 0)
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.batteryKey, &instance->config.batteryFormat, FF_BATTERY_NUM_FORMAT_ARGS, "%s doesn't contain any battery folder", baseDir.chars);
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.battery, "%s doesn't contain any battery folder", baseDir.chars);
ffListDestroy(&results);
ffStrbufDestroy(&baseDir);
+2 -1
View File
@@ -1,7 +1,8 @@
#include "fastfetch.h"
#include "common/printing.h"
void ffPrintBreak(FFinstance* instance)
{
ffPrintLogoLine(instance);
ffLogoPrintLine(instance);
putchar('\n');
}
+12 -2
View File
@@ -1,8 +1,18 @@
#include "fastfetch.h"
#include "common/printing.h"
void ffPrintColors(FFinstance* instance)
{
ffPrintLogoLine(instance);
if(instance->config.pipe)
{
ffLogoPrintLine(instance);
puts("████████████████████████");
ffLogoPrintLine(instance);
puts("████████████████████████");
return;
}
ffLogoPrintLine(instance);
// 4%d: Set the background color
// 3%d: Set the foreground color
@@ -11,7 +21,7 @@ void ffPrintColors(FFinstance* instance)
puts(FASTFETCH_TEXT_MODIFIER_RESET);
ffPrintLogoLine(instance);
ffLogoPrintLine(instance);
// 1: Set everything to bolt. This causes normal colors on some systems to be bright.
// 4%d: Set the backgound to the not bright color
+47 -22
View File
@@ -1,48 +1,63 @@
#include "fastfetch.h"
#include "common/io.h"
#include "common/properties.h"
#include "common/printing.h"
#include "common/caching.h"
#include "detection/temps.h"
#include <string.h>
#include <stdlib.h>
#define FF_CPU_MODULE_NAME "CPU"
#define FF_CPU_NUM_FORMAT_ARGS 14
static double parseHz(FFstrbuf* content)
{
if(content->length == 0)
return 0;
double herz;
if(sscanf(content->chars, "%lf", &herz) != 1)
return 0;
return herz;
}
#define FF_CPU_NUM_FORMAT_ARGS 15
static double getGhz(const char* policyFile, const char* cpuFile)
{
FFstrbuf content;
ffStrbufInit(&content);
ffGetFileContent(policyFile, &content);
ffReadFileBuffer(policyFile, &content);
if(content.length == 0)
ffGetFileContent(cpuFile, &content);
ffReadFileBuffer(cpuFile, &content);
double herz = parseHz(&content);
double herz = ffStrbufToDouble(&content);
ffStrbufDestroy(&content);
//ffStrbufToDouble failed
if(herz != herz)
return 0;
herz /= 1000.0; //to MHz
return herz / 1000.0; //to GHz
}
static double detectCPUTemp(const FFinstance* instance)
{
const FFTempsResult *temps = ffDetectTemps(instance);
for(uint32_t i = 0; i < temps->values.length; i++)
{
FFTempValue* value = ffListGet(&temps->values, i);
if(
ffStrbufFirstIndexS(&value->name, "cpu") < value->name.length ||
ffStrbufCompS(&value->name, "k10temp") == 0 ||
ffStrbufCompS(&value->name, "coretemp") == 0
) return value->value;
}
return 0.0 / 0.0; //NaN
}
void ffPrintCPU(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS))
if(ffPrintFromCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpu, FF_CPU_NUM_FORMAT_ARGS))
return;
FILE* cpuinfo = fopen("/proc/cpuinfo", "r");
if(cpuinfo == NULL)
{
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, "fopen(\"""/proc/cpuinfo\", \"r\") == NULL");
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpu, "fopen(\"""/proc/cpuinfo\", \"r\") == NULL");
return;
}
@@ -81,7 +96,12 @@ void ffPrintCPU(FFinstance* instance)
fclose(cpuinfo);
double procGhz = parseHz(&procGhzString) / 1000.0; //to GHz
double procGhz = ffStrbufToDouble(&procGhzString);
if(procGhz != procGhz)
procGhz = 0; //NaN
else
procGhz /= 1000.0; //To GHz
ffStrbufDestroy(&procGhzString);
double biosLimit = getGhz("/sys/devices/system/cpu/cpufreq/policy0/bios_limit", "/sys/devices/system/cpu/cpu0/cpufreq/bios_limit");
@@ -124,7 +144,7 @@ void ffPrintCPU(FFinstance* instance)
) {
ffStrbufDestroy(&name);
ffStrbufDestroy(&vendor);
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, "No CPU info found in /proc/cpuinfo");
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpu, "No CPU info found in /proc/cpuinfo");
return;
}
@@ -143,6 +163,10 @@ void ffPrintCPU(FFinstance* instance)
ffStrbufSubstrBeforeFirstC(&namePretty, '@'); //Cut the speed output in the name as we append our own
ffStrbufTrimRight(&namePretty, ' '); //If we removed the @ in previous step there was most likely a space before it
double cpuTemp;
if(instance->config.cpu.outputFormat.length > 0)
cpuTemp = detectCPUTemp(instance);
FFstrbuf cpu;
ffStrbufInitA(&cpu, 128);
@@ -164,7 +188,7 @@ void ffPrintCPU(FFinstance* instance)
if(ghz > 0)
ffStrbufAppendF(&cpu, " @ %.9gGHz", ghz);
ffPrintAndWriteToCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpuKey, &cpu, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintAndWriteToCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpu, &cpu, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &name},
{FF_FORMAT_ARG_TYPE_STRBUF, &namePretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &vendor},
@@ -172,6 +196,7 @@ void ffPrintCPU(FFinstance* instance)
{FF_FORMAT_ARG_TYPE_INT, &numProcsAvailable},
{FF_FORMAT_ARG_TYPE_INT, &physicalCores},
{FF_FORMAT_ARG_TYPE_INT, &numProcs},
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpuTemp},
{FF_FORMAT_ARG_TYPE_DOUBLE, &biosLimit},
{FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMaxFreq},
{FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMinFreq},
+5 -5
View File
@@ -1,6 +1,6 @@
#include "fastfetch.h"
#include "common/printing.h"
#include <stdio.h>
#include <unistd.h>
#define FF_CPU_USAGE_MODULE_NAME "CPU Usage"
@@ -12,7 +12,7 @@ void ffPrintCPUUsage(FFinstance* instance)
FILE* procStat = fopen("/proc/stat", "r");
if(procStat == NULL)
{
ffPrintError(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsageKey, &instance->config.cpuUsageFormat, FF_CPU_USAGE_NUM_FORMAT_ARGS, "fopen(\"""/proc/stat\", \"r\") == NULL");
ffPrintError(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpu, "fopen(\"""/proc/stat\", \"r\") == NULL");
return;
}
if (fscanf(procStat, "cpu%ld%ld%ld%ld%ld%ld%ld", &user, &nice, &system, &idle, &iowait, &irq, &softirq) < 0) goto exit;
@@ -31,15 +31,15 @@ void ffPrintCPUUsage(FFinstance* instance)
long totalOverPeriod = totalJiffies2 - totalJiffies1;
double cpuPercent = (double)workOverPeriod / (double)totalOverPeriod * 100;
if(instance->config.cpuUsageFormat.length == 0)
if(instance->config.cpuUsage.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsageKey);
ffPrintLogoAndKey(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsage.key);
printf("%.2lf%%\n", cpuPercent);
}
else
{
ffPrintFormatString(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsageKey, &instance->config.cpuUsageFormat, NULL, FF_CPU_USAGE_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsage, FF_CPU_USAGE_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpuPercent}
});
}
+22 -8
View File
@@ -1,4 +1,12 @@
#include "fastfetch.h"
#include "common/properties.h"
#include "common/printing.h"
#include "common/parsing.h"
#include "common/settings.h"
#include "detection/gtk.h"
#include "detection/displayserver.h"
#include <stdlib.h>
#define FF_CURSOR_MODULE_NAME "Cursor"
#define FF_CURSOR_NUM_FORMAT_ARGS 2
@@ -12,9 +20,9 @@ static void printCursor(FFinstance* instance, FFstrbuf* cursorTheme, const FFstr
if(cursorTheme->length == 0)
ffStrbufAppendS(cursorTheme, "default");
if(instance->config.cursorFormat.length == 0)
if(instance->config.cursor.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey);
ffPrintLogoAndKey(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor.key);
ffStrbufWriteTo(cursorTheme, stdout);
if(cursorSize != NULL && cursorSize->length > 0)
@@ -28,7 +36,7 @@ static void printCursor(FFinstance* instance, FFstrbuf* cursorTheme, const FFstr
}
else
{
ffPrintFormatString(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, NULL, FF_CURSOR_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, FF_CURSOR_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, cursorTheme},
{FF_FORMAT_ARG_TYPE_STRBUF, cursorSize}
});
@@ -47,7 +55,7 @@ static void printCursorGTK(FFinstance* instance)
if(gtk->cursor.length == 0)
{
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Couldn't detect GTK Cursor");
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't detect GTK Cursor");
return;
}
@@ -69,7 +77,7 @@ static void printCursorXFCE(FFinstance* instance)
if(cursorTheme.length == 0)
{
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Couldn't find xfce cursor in xfconf (xsettings::/Gtk/CursorThemeName)");
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't find xfce cursor in xfconf (xsettings::/Gtk/CursorThemeName)");
return;
}
@@ -105,7 +113,7 @@ static void printCursorFromConfigFile(FFinstance* instance, const char* relative
}
if(cursorTheme.length == 0)
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Couldn't find cursor in %s", relativeFilePath);
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't find cursor in %s", relativeFilePath);
else
printCursor(instance, &cursorTheme, &cursorSize);
@@ -185,15 +193,21 @@ static bool printCursorFromEnv(FFinstance* instance)
void ffPrintCursor(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Cursor detection is not supported on Android");
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Cursor detection is not supported on Android");
return;
#endif
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);
if(ffStrbufCompS(&wmde->wmPrettyName, "WSLg") == 0)
{
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "WSLg uses native windows cursor");
return;
}
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0)
{
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Cursor isn't supported in TTY");
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Cursor isn't supported in TTY");
return;
}
+3 -1
View File
@@ -1,7 +1,9 @@
#include "fastfetch.h"
#include "common/printing.h"
void ffPrintCustom(FFinstance* instance, const char* key, const char* value)
{
ffPrintLogoAndKey(instance, key, 0, NULL);
puts(value);
ffPrintUserString(value);
puts(FASTFETCH_TEXT_MODIFIER_RESET);
}
+5 -3
View File
@@ -1,17 +1,19 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "detection/datetime.h"
#define FF_DATE_MODULE_NAME "Date"
void ffPrintDate(FFinstance* instance)
{
if(instance->config.dateFormat.length > 0)
if(instance->config.date.outputFormat.length > 0)
{
ffPrintDateTimeFormat(instance, FF_DATE_MODULE_NAME, &instance->config.dateKey, &instance->config.dateFormat);
ffPrintDateTimeFormat(instance, FF_DATE_MODULE_NAME, &instance->config.date);
return;
}
const FFDateTimeResult* datetime = ffDetectDateTime(instance);
ffPrintLogoAndKey(instance, FF_DATE_MODULE_NAME, 0, &instance->config.dateKey);
ffPrintLogoAndKey(instance, FF_DATE_MODULE_NAME, 0, &instance->config.date.key);
//yyyy-mm-dd
printf("%u-%s-%u\n", datetime->year, datetime->monthPretty.chars, datetime->dayInMonth);
+7 -5
View File
@@ -1,12 +1,14 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "detection/datetime.h"
#define FF_DATETIME_MODULE_NAME "Date & Time"
#define FF_DATETIME_NUM_FORMAT_ARGS 20
void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFstrbuf* key, const FFstrbuf* format)
void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs)
{
const FFDateTimeResult* result = ffDetectDateTime(instance);
ffPrintFormatString(instance, moduleName, 0, key, format, NULL, FF_DATETIME_NUM_FORMAT_ARGS, (FFformatarg[]) {
ffPrintFormat(instance, moduleName, 0, moduleArgs, FF_DATETIME_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_UINT16, &result->year},
{FF_FORMAT_ARG_TYPE_UINT8, &result->yearShort},
{FF_FORMAT_ARG_TYPE_UINT8, &result->month},
@@ -32,14 +34,14 @@ void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const F
void ffPrintDateTime(FFinstance* instance)
{
if(instance->config.dateTimeFormat.length > 0)
if(instance->config.dateTime.outputFormat.length > 0)
{
ffPrintDateTimeFormat(instance, FF_DATETIME_MODULE_NAME, &instance->config.dateTimeKey, &instance->config.dateTimeFormat);
ffPrintDateTimeFormat(instance, FF_DATETIME_MODULE_NAME, &instance->config.dateTime);
return;
}
const FFDateTimeResult* datetime = ffDetectDateTime(instance);
ffPrintLogoAndKey(instance, FF_DATETIME_MODULE_NAME, 0, &instance->config.dateTimeKey);
ffPrintLogoAndKey(instance, FF_DATETIME_MODULE_NAME, 0, &instance->config.dateTime.key);
//yyyy-mm-dd hh:mm:ss
printf("%u-%s-%u %s:%s:%s\n", datetime->year, datetime->monthPretty.chars, datetime->dayInMonth, datetime->hourPretty.chars, datetime->minutePretty.chars, datetime->secondPretty.chars);
+7 -7
View File
@@ -1,6 +1,6 @@
#include "fastfetch.h"
#include <string.h>
#include "common/printing.h"
#include "detection/displayserver.h"
#define FF_DE_MODULE_NAME "DE"
#define FF_DE_NUM_FORMAT_ARGS 3
@@ -8,7 +8,7 @@
void ffPrintDesktopEnvironment(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey, &instance->config.deFormat, FF_DE_NUM_FORMAT_ARGS, "DE detection is not supported on Android");
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, "DE detection is not supported on Android");
return;
#endif
@@ -16,13 +16,13 @@ void ffPrintDesktopEnvironment(FFinstance* instance)
if(result->dePrettyName.length == 0)
{
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey, &instance->config.deFormat, FF_DE_NUM_FORMAT_ARGS, "No DE found");
ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, "No DE found");
return;
}
if(instance->config.deFormat.length == 0)
if(instance->config.de.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey);
ffPrintLogoAndKey(instance, FF_DE_MODULE_NAME, 0, &instance->config.de.key);
ffStrbufWriteTo(&result->dePrettyName, stdout);
@@ -36,7 +36,7 @@ void ffPrintDesktopEnvironment(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey, &instance->config.deFormat, NULL, FF_DE_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, FF_DE_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &result->deProcessName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->dePrettyName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->deVersion}
+31 -17
View File
@@ -1,4 +1,5 @@
#include "fastfetch.h"
#include "common/printing.h"
#include <sys/statvfs.h>
@@ -7,7 +8,7 @@
static void getKey(FFinstance* instance, FFstrbuf* key, const char* folderPath, bool showFolderPath)
{
if(instance->config.diskKey.length == 0)
if(instance->config.disk.key.length == 0)
{
if(showFolderPath)
ffStrbufAppendF(key, FF_DISK_MODULE_NAME" (%s)", folderPath);
@@ -16,7 +17,7 @@ static void getKey(FFinstance* instance, FFstrbuf* key, const char* folderPath,
}
else
{
ffParseFormatString(key, &instance->config.diskKey, NULL, 1, (FFformatarg[]){
ffParseFormatString(key, &instance->config.disk.key, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, folderPath}
});
}
@@ -24,26 +25,39 @@ static void getKey(FFinstance* instance, FFstrbuf* key, const char* folderPath,
static void printStatvfs(FFinstance* instance, FFstrbuf* key, struct statvfs* fs)
{
const uint32_t GB = 1024 * 1024 * 1024;
const double GB = 1024 * 1024 * 1024;
uint32_t total = (uint32_t) ((fs->f_blocks * fs->f_frsize) / GB);
uint32_t available = (uint32_t) ((fs->f_bfree * fs->f_frsize) / GB);
uint32_t used = total - available;
uint8_t percentage = (uint8_t) ((used / (double) total) * 100.0);
double total = ((double) (fs->f_blocks * fs->f_frsize)) / GB;
double available = ((double) (fs->f_bfree * fs->f_frsize)) / GB;
double used = total - available;
uint8_t percentage = (uint8_t) ((used / total) * 100.0);
uint32_t files = (uint32_t) (fs->f_files - fs->f_ffree);
if(instance->config.diskFormat.length == 0)
if(instance->config.disk.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, key->chars, 0, NULL);
printf("%uGB / %uGB (%u%%)\n", used, total, percentage);
if(used >= 100.0)
printf("%.0f", used);
else
printf("%.1f", used);
fputs(" GB / ", stdout);
if(total >= 100.0)
printf("%.0f", total);
else
printf("%.1f", total);
printf("GiB (%u%%)\n", percentage);
}
else
{
ffPrintFormatString(instance, key->chars, 0, NULL, &instance->config.diskFormat, NULL, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT, &used},
{FF_FORMAT_ARG_TYPE_UINT, &total},
{FF_FORMAT_ARG_TYPE_UINT, &files},
ffPrintFormatString(instance, key->chars, 0, NULL, &instance->config.disk.outputFormat, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_DOUBLE, &used},
{FF_FORMAT_ARG_TYPE_DOUBLE, &total},
{FF_FORMAT_ARG_TYPE_DOUBLE, &files},
{FF_FORMAT_ARG_TYPE_UINT8, &percentage}
});
}
@@ -64,9 +78,9 @@ static void printFolder(FFinstance* instance, const char* folderPath)
struct statvfs fs;
int ret = statvfs(folderPath, &fs);
if(ret != 0 && instance->config.diskFormat.length == 0)
if(ret != 0 && instance->config.disk.outputFormat.length == 0)
{
ffPrintError(instance, key.chars, 0, NULL, &instance->config.diskFormat, FF_DISK_NUM_FORMAT_ARGS, "statvfs(\"%s\", &fs) != 0 (%i)", folderPath, ret);
ffPrintErrorString(instance, key.chars, 0, NULL, &instance->config.disk.errorFormat, "statvfs(\"%s\", &fs) != 0 (%i)", folderPath, ret);
ffStrbufDestroy(&key);
return;
}
@@ -89,7 +103,7 @@ void ffPrintDisk(FFinstance* instance)
{
FF_STRBUF_CREATE(key);
getKey(instance, &key, "", false);
ffPrintError(instance, key.chars, 0, NULL, &instance->config.diskFormat, FF_DISK_NUM_FORMAT_ARGS, "statvfs failed for both / and " FASTFETCH_TARGET_DIR_HOME);
ffPrintErrorString(instance, key.chars, 0, NULL, &instance->config.disk.errorFormat, "statvfs failed for both / and " FASTFETCH_TARGET_DIR_HOME);
ffStrbufDestroy(&key);
return;
}
@@ -108,7 +122,7 @@ void ffPrintDisk(FFinstance* instance)
{
FF_STRBUF_CREATE(key);
getKey(instance, &key, "", false);
ffPrintError(instance, key.chars, 0, NULL, &instance->config.diskFormat, FF_DISK_NUM_FORMAT_ARGS, "Custom disk folders string doesn't contain any folders");
ffPrintErrorString(instance, key.chars, 0, NULL, &instance->config.disk.errorFormat, "Custom disk folders string doesn't contain any folders");
ffStrbufDestroy(&key);
return;
}
+14 -8
View File
@@ -1,4 +1,10 @@
#include "fastfetch.h"
#include "common/font.h"
#include "common/printing.h"
#include "common/parsing.h"
#include "detection/qt.h"
#include "detection/gtk.h"
#include "detection/displayserver.h"
#define FF_FONT_MODULE_NAME "Font"
#define FF_FONT_NUM_FORMAT_ARGS 21
@@ -6,7 +12,7 @@
void ffPrintFont(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_FONT_NUM_FORMAT_ARGS, "Font detection is not supported on Android");
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "Font detection is not supported on Android");
return;
#endif
@@ -14,18 +20,18 @@ void ffPrintFont(FFinstance* instance)
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0)
{
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_FONT_NUM_FORMAT_ARGS, "Font isn't supported in TTY");
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "Font isn't supported in TTY");
return;
}
const FFstrbuf* plasmaRaw = &ffDetectPlasma(instance)->font;
const FFstrbuf* plasmaRaw = &ffDetectQt(instance)->font;
const FFstrbuf* gtk2Raw = &ffDetectGTK2(instance)->font;
const FFstrbuf* gtk3Raw = &ffDetectGTK3(instance)->font;
const FFstrbuf* gtk4Raw = &ffDetectGTK4(instance)->font;
if(plasmaRaw->length == 0 && gtk2Raw->length == 0 && gtk3Raw->length == 0 && gtk4Raw->length == 0)
{
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_FONT_NUM_FORMAT_ARGS, "No fonts found");
ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "No fonts found");
return;
}
@@ -45,13 +51,13 @@ void ffPrintFont(FFinstance* instance)
ffStrbufInitA(&gtk, 64);
ffParseGTK(&gtk, &gtk2.pretty, &gtk3.pretty, &gtk4.pretty);
if(instance->config.fontFormat.length == 0)
if(instance->config.font.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey);
ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font.key);
if(plasma.pretty.length > 0)
{
ffStrbufWriteTo(&plasma.pretty, stdout);
fputs(" [Plasma]", stdout);
fputs(" [QT]", stdout);
if(gtk.length > 0)
fputs(", ", stdout);
@@ -60,7 +66,7 @@ void ffPrintFont(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, NULL, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, plasmaRaw},
{FF_FORMAT_ARG_TYPE_STRBUF, &plasma.name},
{FF_FORMAT_ARG_TYPE_STRBUF, &plasma.size},
+168 -200
View File
@@ -1,185 +1,16 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "common/caching.h"
#include "common/parsing.h"
#include "detection/temps.h"
#include "detection/vulkan.h"
#include <string.h>
#include <stdlib.h>
#define FF_GPU_MODULE_NAME "GPU"
#define FF_GPU_NUM_FORMAT_ARGS 5
#define FF_GPU_NUM_FORMAT_ARGS 6
typedef struct GPUResult
{
FFstrbuf vendor;
FFstrbuf name;
FFstrbuf driver;
} GPUResult;
#ifdef FF_HAVE_VULKAN
#include <vulkan/vulkan.h>
static void vulkanFillGPUs(FFinstance* instance, FFlist* results)
{
FF_LIBRARY_LOAD(vulkan, instance->config.libVulkan, , "libvulkan.so", 2)
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkCreateInstance,)
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkDestroyInstance,)
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkEnumeratePhysicalDevices,)
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkGetPhysicalDeviceProperties,)
//Some drivers (nvdc) print messages to stdout
//and thats the best way i found to disable that
ffSuppressIO(true);
const VkApplicationInfo applicationInfo = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pNext = NULL,
.pApplicationName = FASTFETCH_PROJECT_NAME,
.applicationVersion = VK_MAKE_VERSION(FASTFETCH_PROJECT_VERSION_MAJOR, 0, 0),
.pEngineName = "vulkanPrintGPUs",
.engineVersion = VK_MAKE_VERSION(FASTFETCH_PROJECT_VERSION_MAJOR, 0, 0),
.apiVersion = VK_API_VERSION_1_0,
};
const VkInstanceCreateInfo instanceCreateInfo = {
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pNext = NULL,
.pApplicationInfo = &applicationInfo,
.enabledLayerCount = 0,
.ppEnabledLayerNames = NULL,
.enabledExtensionCount = 0,
.ppEnabledExtensionNames = NULL,
.flags = 0
};
VkInstance vkInstance;
if(ffvkCreateInstance(&instanceCreateInfo, NULL, &vkInstance) != VK_SUCCESS)
{
dlclose(vulkan);
ffSuppressIO(false);
return;
}
uint32_t physicalDeviceCount;
if(ffvkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, NULL) != VK_SUCCESS)
{
ffvkDestroyInstance(vkInstance, NULL);
dlclose(vulkan);
ffSuppressIO(false);
return;
}
VkPhysicalDevice* physicalDevices = malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount);
if(ffvkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, physicalDevices) != VK_SUCCESS)
{
free(physicalDevices);
ffvkDestroyInstance(vkInstance, NULL);
dlclose(vulkan);
ffSuppressIO(false);
return;
}
for(uint32_t i = 0; i < physicalDeviceCount; i++)
{
VkPhysicalDeviceProperties physicalDeviceProperties;
ffvkGetPhysicalDeviceProperties(physicalDevices[i], &physicalDeviceProperties);
//We don't want softare rasterizers
if(physicalDeviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU)
continue;
GPUResult* result = ffListAdd(results);
ffStrbufInit(&result->vendor);
ffStrbufInit(&result->name);
ffStrbufInit(&result->driver);
ffStrbufAppendS(&result->name, physicalDeviceProperties.deviceName);
}
free(physicalDevices);
ffvkDestroyInstance(vkInstance, NULL);
dlclose(vulkan);
ffSuppressIO(false);
return;
}
#endif
#ifdef FF_HAVE_LIBPCI
#include <pci/pci.h>
#include <unistd.h>
//see https://github.com/pciutils/pciutils/blob/5bdf63b6b1bc35b59c4b3f47f7ca83ca1868155b/ls-kernel.c#L220
static void pciGetDriver(struct pci_dev* dev, FFstrbuf* driver, char*(*ffpci_get_param)(struct pci_access*, char*))
{
if(dev->access->method != PCI_ACCESS_SYS_BUS_PCI)
return;
const char* base = ffpci_get_param(dev->access, "sysfs.path");
if(!ffStrSet(base))
return;
FFstrbuf path;
ffStrbufInitA(&path, 64);
ffStrbufAppendF(&path, "%s/devices/%04x:%02x:%02x.%d/driver", base, dev->domain, dev->bus, dev->dev, dev->func);
ffStrbufEnsureFree(driver, 1023);
ssize_t resultLength = readlink(path.chars, driver->chars, driver->allocated - 1); //-1 for null terminator
if(resultLength > 0)
{
driver->length = (uint32_t) resultLength;
driver->chars[resultLength] = '\0';
ffStrbufSubstrAfterLastC(driver, '/');
}
ffStrbufDestroy(&path);
}
static void pciFillGPUs(FFinstance* instance, FFlist* results)
{
FF_LIBRARY_LOAD(pci, instance->config.libPCI, , "libpci.so", 4)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_alloc,)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_init,)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_scan_bus,)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_fill_info,)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_lookup_name,)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_get_param,)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_cleanup,)
struct pci_access *pacc = ffpci_alloc();
ffpci_init(pacc);
ffpci_scan_bus(pacc);
struct pci_dev* dev;
for (dev=pacc->devices; dev; dev=dev->next)
{
ffpci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_CLASS);
char class[1024];
ffpci_lookup_name(pacc, class, sizeof(class), PCI_LOOKUP_CLASS, dev->device_class);
if(
strcasecmp("VGA compatible controller", class) == 0 ||
strcasecmp("3D controller", class) == 0 ||
strcasecmp("Display controller", class) == 0
) {
GPUResult* result = ffListAdd(results);
ffStrbufInitA(&result->vendor, 256);
ffpci_lookup_name(pacc, result->vendor.chars, (int) result->vendor.allocated -1, PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id);
ffStrbufRecalculateLength(&result->vendor);
ffStrbufInitA(&result->name, 256);
ffpci_lookup_name(pacc, result->name.chars, (int) result->name.allocated - 1, PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
ffStrbufRecalculateLength(&result->name);
ffStrbufInit(&result->driver);
if(instance->config.gpuFormat.length > 0) //We only need it for the format string, so don't detect it if it isn't needed
pciGetDriver(dev, &result->driver, ffpci_get_param);
};
}
ffpci_cleanup(pacc);
dlclose(pci);
}
#endif
static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, GPUResult* result)
static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, FFGPUResult* result)
{
const char* vendorPretty;
if(ffStrbufIgnCaseCompS(&result->vendor, "Advanced Micro Devices, Inc. [AMD/ATI]") == 0)
@@ -207,12 +38,13 @@ static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache,
ffStrbufAppend(&gpu, &namePretty);
ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpuKey, cache, &gpu, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, cache, &gpu, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &result->vendor},
{FF_FORMAT_ARG_TYPE_STRING, vendorPretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &namePretty},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->driver},
{FF_FORMAT_ARG_TYPE_DOUBLE, &result->temperature}
});
ffStrbufDestroy(&result->vendor);
@@ -222,32 +54,168 @@ static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache,
ffStrbufDestroy(&namePretty);
}
void ffPrintGPU(FFinstance* instance)
static void printGPUList(FFinstance* instance, const FFlist* list)
{
if(ffPrintFromCache(instance, FF_GPU_MODULE_NAME, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS))
return;
FFlist gpus;
ffListInitA(&gpus, sizeof(GPUResult), 4);
FFcache cache;
ffCacheOpenWrite(instance, FF_GPU_MODULE_NAME, &cache);
#ifdef FF_HAVE_LIBPCI
pciFillGPUs(instance, &gpus);
#endif
#ifdef FF_HAVE_VULKAN
if(gpus.length == 0)
vulkanFillGPUs(instance, &gpus);
#endif
for(uint8_t i = 0; i < (uint8_t) gpus.length; i++)
printGPUResult(instance, gpus.length == 1 ? 0 : (uint8_t) (i + 1), &cache, ffListGet(&gpus, i));
if(gpus.length == 0)
ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, "No GPUs found.");
for(uint8_t i = 0; i < (uint8_t) list->length; i++)
printGPUResult(instance, list->length == 1 ? 0 : (uint8_t) (i + 1), &cache, ffListGet(list, i));
ffCacheClose(&cache);
ffListDestroy(&gpus);
}
#ifdef FF_HAVE_LIBPCI
#include "common/library.h"
#include <string.h>
#include <unistd.h>
#include <pci/pci.h>
//see https://github.com/pciutils/pciutils/blob/5bdf63b6b1bc35b59c4b3f47f7ca83ca1868155b/ls-kernel.c#L220
static void pciGetDriver(struct pci_dev* dev, FFstrbuf* driver, char*(*ffpci_get_param)(struct pci_access*, char*))
{
if(dev->access->method != PCI_ACCESS_SYS_BUS_PCI)
return;
const char* base = ffpci_get_param(dev->access, "sysfs.path");
if(!ffStrSet(base))
return;
FFstrbuf path;
ffStrbufInitA(&path, 64);
ffStrbufAppendF(&path, "%s/devices/%04x:%02x:%02x.%d/driver", base, dev->domain, dev->bus, dev->dev, dev->func);
ffStrbufEnsureFree(driver, 1023);
ssize_t resultLength = readlink(path.chars, driver->chars, driver->allocated - 1); //-1 for null terminator
if(resultLength > 0)
{
driver->length = (uint32_t) resultLength;
driver->chars[resultLength] = '\0';
ffStrbufSubstrAfterLastC(driver, '/');
}
ffStrbufDestroy(&path);
}
static double pciGetTemperatur(const FFinstance* instance, uint16_t deviceClass)
{
const FFTempsResult* tempsResult = ffDetectTemps(instance);
for(uint32_t i = 0; i < tempsResult->values.length; i++)
{
FFTempValue* tempValue = ffListGet(&tempsResult->values, i);
uint32_t tempClass;
if(sscanf(tempValue->deviceClass.chars, "%x", &tempClass) != 1)
continue;
//The kernel exposes the device class multiplied by 256 for some reason
if(tempClass == deviceClass * 256)
return tempValue->value;
}
return 0.0 / 0.0; //NaN
}
static bool pciPrintGPUs(FFinstance* instance)
{
FF_LIBRARY_LOAD(pci, instance->config.libPCI, false, "libpci.so", 4)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_alloc, false)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_init, false)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_scan_bus, false)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_fill_info, false)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_lookup_name, false)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_get_param, false)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_cleanup, false)
FFlist results;
ffListInit(&results, sizeof(FFGPUResult));
struct pci_access *pacc = ffpci_alloc();
ffpci_init(pacc);
ffpci_scan_bus(pacc);
struct pci_dev* dev;
for (dev=pacc->devices; dev; dev=dev->next)
{
ffpci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_CLASS);
char class[1024];
ffpci_lookup_name(pacc, class, sizeof(class), PCI_LOOKUP_CLASS, dev->device_class);
if(
strcasecmp("VGA compatible controller", class) == 0 ||
strcasecmp("3D controller", class) == 0 ||
strcasecmp("Display controller", class) == 0
) {
FFGPUResult* result = ffListAdd(&results);
ffStrbufInitA(&result->vendor, 256);
ffpci_lookup_name(pacc, result->vendor.chars, (int) ffStrbufGetFree(&result->vendor), PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id);
ffStrbufRecalculateLength(&result->vendor);
ffStrbufInitA(&result->name, 256);
ffpci_lookup_name(pacc, result->name.chars, (int) ffStrbufGetFree(&result->name), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id);
ffStrbufRecalculateLength(&result->name);
ffStrbufInit(&result->driver);
result->temperature = 0;
//We only need it for the format string, so don't detect it if it isn't needed
if(instance->config.gpu.outputFormat.length > 0)
{
pciGetDriver(dev, &result->driver, ffpci_get_param);
result->temperature = pciGetTemperatur(instance, dev->device_class);
}
};
}
ffpci_cleanup(pacc);
dlclose(pci);
if(results.length == 0)
{
ffListDestroy(&results);
return false;
}
printGPUList(instance, &results);
ffListDestroy(&results);
return true;
}
#endif
static bool vulkanPrintGPUs(FFinstance* instance)
{
const FFVulkanResult* result = ffDetectVulkan(instance);
if(result->devices.length == 0)
return false;
printGPUList(instance, &result->devices);
return true;
}
void ffPrintGPU(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_GPU_MODULE_NAME, &instance->config.gpu, FF_GPU_NUM_FORMAT_ARGS))
return;
if(
getenv("WSLENV") != NULL ||
getenv("WSL_DISTRO") != NULL ||
getenv("WSL_INTEROP") != NULL
) {
ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpu, "WSL doesn't expose senseful GPU names");
return;
}
#ifdef FF_HAVE_LIBPCI
if(pciPrintGPUs(instance))
return;
#endif
if(vulkanPrintGPUs(instance))
return;
ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpu, "No GPUs found.");
}
+119 -54
View File
@@ -1,10 +1,19 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "common/caching.h"
#include <ctype.h>
#include <stdlib.h>
#define FF_HOST_MODULE_NAME "Host"
#define FF_HOST_NUM_FORMAT_ARGS 3
#define FF_HOST_NUM_FORMAT_ARGS 15
#ifndef __ANDROID__
#include "common/io.h"
#else
#include <ctype.h>
#endif
#ifndef __ANDROID__
static bool hostValueSet(FFstrbuf* value)
{
ffStrbufTrimRight(value, '\n');
@@ -32,100 +41,156 @@ static bool hostValueSet(FFstrbuf* value)
;
}
#ifndef __ANDROID__
static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
{
ffGetFileContent(devicesPath, buffer);
ffReadFileBuffer(devicesPath, buffer);
if(buffer->length == 0)
ffGetFileContent(classPath, buffer);
ffReadFileBuffer(classPath, buffer);
}
#endif
void ffPrintHost(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_HOST_MODULE_NAME, &instance->config.hostKey, &instance->config.hostFormat, FF_HOST_NUM_FORMAT_ARGS))
if(ffPrintFromCache(instance, FF_HOST_MODULE_NAME, &instance->config.host, FF_HOST_NUM_FORMAT_ARGS))
return;
FFstrbuf family;
ffStrbufInit(&family);
FFstrbuf product_family;
ffStrbufInit(&product_family);
#ifndef __ANDROID__
getHostValue("/sys/devices/virtual/dmi/id/product_family", "/sys/class/dmi/id/product_family", &family);
getHostValue("/sys/devices/virtual/dmi/id/product_family", "/sys/class/dmi/id/product_family", &product_family);
if(!hostValueSet(&product_family))
ffStrbufClear(&product_family);
#else
ffSettingsGetAndroidProperty("ro.product.device", &family);
ffSettingsGetAndroidProperty("ro.product.device", &product_family);
#endif
bool familySet = hostValueSet(&family);
FFstrbuf name;
ffStrbufInit(&name);
FFstrbuf product_name;
ffStrbufInit(&product_name);
#ifndef __ANDROID__
getHostValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", &name);
getHostValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", &product_name);
if(name.length == 0)
ffGetFileContent("/sys/firmware/devicetree/base/model", &name);
if(product_name.length == 0)
ffReadFileBuffer("/sys/firmware/devicetree/base/model", &product_name);
if(name.length == 0)
ffGetFileContent("/tmp/sysinfo/model", &name);
if(product_name.length == 0)
ffReadFileBuffer("/tmp/sysinfo/model", &product_name);
if(ffStrbufStartsWithS(&name, "Standard PC"))
if(ffStrbufStartsWithS(&product_name, "Standard PC"))
{
FFstrbuf copy;
ffStrbufInitCopy(&copy, &name);
ffStrbufSetS(&name, "KVM/QEMU ");
ffStrbufAppend(&name, &copy);
ffStrbufInitCopy(&copy, &product_name);
ffStrbufSetS(&product_name, "KVM/QEMU ");
ffStrbufAppend(&product_name, &copy);
ffStrbufDestroy(&copy);
}
if(!hostValueSet(&product_name))
ffStrbufClear(&product_name);
//On WSL, the real host can't be detected. Instead use WSL as host.
if(product_name.length == 0 && product_family.length == 0 && (
getenv("WSLENV") != NULL ||
getenv("WSL_DISTRO") != NULL ||
getenv("WSL_INTEROP") != NULL
)) ffStrbufAppendS(&product_name, "Windows Subsystem for Linux");
#else
ffSettingsGetAndroidProperty("ro.product.brand", &name);
if(name.length > 0){
name.chars[0] = (char) toupper(name.chars[0]);
ffStrbufAppendC(&name, ' ');
ffSettingsGetAndroidProperty("ro.product.brand", &product_name);
if(product_name.length > 0){
product_name.chars[0] = (char) toupper(product_name.chars[0]);
ffStrbufAppendC(&product_name, ' ');
}
if(!ffSettingsGetAndroidProperty("ro.product.model", &name))
ffSettingsGetAndroidProperty("ro.product.name", &name);
if(!ffSettingsGetAndroidProperty("ro.product.model", &product_name))
ffSettingsGetAndroidProperty("ro.product.name", &product_name);
ffStrbufTrimRight(&name, ' ');
ffStrbufTrimRight(&product_name, ' ');
#endif
bool nameSet = hostValueSet(&name);
FFstrbuf version;
ffStrbufInit(&version);
#ifndef __ANDROID__
getHostValue("/sys/devices/virtual/dmi/id/product_version", "/sys/class/dmi/id/product_version", &version);
#endif
bool versionSet = hostValueSet(&version);
if(!familySet && !nameSet)
if(product_family.length == 0 && product_name.length == 0)
{
ffStrbufDestroy(&family);
ffStrbufDestroy(&name);
ffStrbufDestroy(&version);
ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &instance->config.hostKey, &instance->config.hostFormat, FF_HOST_NUM_FORMAT_ARGS, "neither family nor name is set by O.E.M.");
ffStrbufDestroy(&product_family);
ffStrbufDestroy(&product_name);
ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &instance->config.host, "neither product_family nor product_name is set by O.E.M.");
return;
}
#ifdef __ANDROID__
#define FF_HOST_DATA(name) \
FFstrbuf name; \
ffStrbufInitA(&name, 0);
#else
#define FF_HOST_DATA(name) \
FFstrbuf name; \
ffStrbufInit(&name); \
getHostValue("/sys/devices/virtual/dmi/id/"#name, "/sys/class/dmi/id/"#name, &name); \
if(!hostValueSet(&name)) \
ffStrbufClear(&name);
#endif
FF_HOST_DATA(product_version)
FF_HOST_DATA(product_sku)
FF_HOST_DATA(bios_date)
FF_HOST_DATA(bios_release)
FF_HOST_DATA(bios_vendor)
FF_HOST_DATA(bios_version)
FF_HOST_DATA(board_name)
FF_HOST_DATA(board_vendor)
FF_HOST_DATA(board_version)
FF_HOST_DATA(chassis_type)
FF_HOST_DATA(chassis_vendor)
FF_HOST_DATA(chassis_version)
FF_HOST_DATA(sys_vendor)
FFstrbuf host;
ffStrbufInit(&host);
if(nameSet)
ffStrbufAppend(&host, &name);
if(product_name.length > 0)
ffStrbufAppend(&host, &product_name);
else
ffStrbufAppend(&host, &family);
ffStrbufAppend(&host, &product_family);
if(versionSet)
if(product_version.length > 0)
{
ffStrbufAppendC(&host, ' ');
ffStrbufAppend(&host, &version);
ffStrbufAppend(&host, &product_version);
}
ffPrintAndWriteToCache(instance, FF_HOST_MODULE_NAME, &instance->config.hostKey, &host, &instance->config.hostFormat, FF_HOST_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &family},
{FF_FORMAT_ARG_TYPE_STRBUF, &name},
{FF_FORMAT_ARG_TYPE_STRBUF, &version}
ffPrintAndWriteToCache(instance, FF_HOST_MODULE_NAME, &instance->config.host, &host, FF_HOST_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &product_family},
{FF_FORMAT_ARG_TYPE_STRBUF, &product_name},
{FF_FORMAT_ARG_TYPE_STRBUF, &product_version},
{FF_FORMAT_ARG_TYPE_STRBUF, &product_sku},
{FF_FORMAT_ARG_TYPE_STRBUF, &bios_date},
{FF_FORMAT_ARG_TYPE_STRBUF, &bios_release},
{FF_FORMAT_ARG_TYPE_STRBUF, &bios_vendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &bios_version},
{FF_FORMAT_ARG_TYPE_STRBUF, &board_name},
{FF_FORMAT_ARG_TYPE_STRBUF, &board_vendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &board_version},
{FF_FORMAT_ARG_TYPE_STRBUF, &chassis_type},
{FF_FORMAT_ARG_TYPE_STRBUF, &chassis_vendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &chassis_version},
{FF_FORMAT_ARG_TYPE_STRBUF, &sys_vendor}
});
ffStrbufDestroy(&family);
ffStrbufDestroy(&name);
ffStrbufDestroy(&version);
ffStrbufDestroy(&product_family);
ffStrbufDestroy(&product_name);
//On Android, all of them get initialized without heap, so no need to destroy them.
#ifndef __ANDROID__
ffStrbufDestroy(&product_version);
ffStrbufDestroy(&product_sku);
ffStrbufDestroy(&bios_date);
ffStrbufDestroy(&bios_release);
ffStrbufDestroy(&bios_vendor);
ffStrbufDestroy(&bios_version);
ffStrbufDestroy(&board_name);
ffStrbufDestroy(&board_vendor);
ffStrbufDestroy(&board_version);
ffStrbufDestroy(&chassis_type);
ffStrbufDestroy(&chassis_vendor);
ffStrbufDestroy(&chassis_version);
ffStrbufDestroy(&sys_vendor);
#endif
}
+13 -8
View File
@@ -1,4 +1,9 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "common/parsing.h"
#include "detection/qt.h"
#include "detection/gtk.h"
#include "detection/displayserver.h"
#define FF_ICONS_MODULE_NAME "Icons"
#define FF_ICONS_NUM_FORMAT_ARGS 5
@@ -6,7 +11,7 @@
void ffPrintIcons(FFinstance* instance)
{
#ifdef __ANDROID__
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey, &instance->config.iconsFormat, FF_ICONS_NUM_FORMAT_ARGS, "Icons detection is not supported on Android");
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, "Icons detection is not supported on Android");
return;
#endif
@@ -14,32 +19,32 @@ void ffPrintIcons(FFinstance* instance)
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0)
{
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_ICONS_NUM_FORMAT_ARGS, "Icons aren't supported in TTY");
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, "Icons aren't supported in TTY");
return;
}
const FFstrbuf* plasma = &ffDetectPlasma(instance)->icons;
const FFstrbuf* plasma = &ffDetectQt(instance)->icons;
const FFstrbuf* gtk2 = &ffDetectGTK2(instance)->icons;
const FFstrbuf* gtk3 = &ffDetectGTK3(instance)->icons;
const FFstrbuf* gtk4 = &ffDetectGTK4(instance)->icons;
if(plasma->length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
{
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey, &instance->config.iconsFormat, FF_ICONS_NUM_FORMAT_ARGS, "No icons could be found");
ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, "No icons could be found");
return;
}
FF_STRBUF_CREATE(gtkPretty);
ffParseGTK(&gtkPretty, gtk2, gtk3, gtk4);
if(instance->config.iconsFormat.length == 0)
if(instance->config.icons.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey);
ffPrintLogoAndKey(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons.key);
if(plasma->length > 0)
{
ffStrbufWriteTo(plasma, stdout);
fputs(" [Plasma]", stdout);
fputs(" [QT]", stdout);
if(gtkPretty.length > 0)
fputs(", ", stdout);
@@ -49,7 +54,7 @@ void ffPrintIcons(FFinstance* instance)
}
else
{
ffPrintFormatString(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey, &instance->config.iconsFormat, NULL, FF_ICONS_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, FF_ICONS_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, plasma},
{FF_FORMAT_ARG_TYPE_STRBUF, gtk2},
{FF_FORMAT_ARG_TYPE_STRBUF, gtk3},
+4 -3
View File
@@ -1,18 +1,19 @@
#include "fastfetch.h"
#include "common/printing.h"
#define FF_KERNEL_MODULE_NAME "Kernel"
#define FF_KERNEL_NUM_FORMAT_ARGS 3
void ffPrintKernel(FFinstance* instance)
{
if(instance->config.kernelFormat.length == 0)
if(instance->config.kernel.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernelKey);
ffPrintLogoAndKey(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernel.key);
puts(instance->state.utsname.release);
}
else
{
ffPrintFormatString(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernelKey, &instance->config.kernelFormat, NULL, FF_KERNEL_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernel, FF_KERNEL_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.sysname},
{FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.release},
{FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.version}
+22 -7
View File
@@ -1,4 +1,9 @@
#include "fastfetch.h"
#include "common/properties.h"
#include "common/printing.h"
#include "common/caching.h"
#include <stdlib.h>
#define FF_LOCALE_MODULE_NAME "Locale"
#define FF_LOCALE_NUM_FORMAT_ARGS 1
@@ -22,24 +27,34 @@ static void getLocaleFromEnv(FFstrbuf* locale)
void ffPrintLocale(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.localeKey, &instance->config.localeFormat, FF_LOCALE_NUM_FORMAT_ARGS))
if(ffPrintFromCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.locale, FF_LOCALE_NUM_FORMAT_ARGS))
return;
FFstrbuf locale;
ffStrbufInit(&locale);
ffParsePropFile(FASTFETCH_TARGET_DIR_ROOT"/etc/locale.conf", "LANG =", &locale);
if (locale.length == 0)
getLocaleFromEnv(&locale);
//Ubuntu (and deriviates) use a non standard locale file.
//Parse it first, because on distributions where it exists, it takes precedence.
//Otherwise use the standard /etc/locale.conf file.
ffParsePropFile(FASTFETCH_TARGET_DIR_ROOT"/etc/default/locale", "LANG =", &locale);
if(locale.length == 0)
{
ffPrintError(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.localeKey, &instance->config.localeFormat, FF_LOCALE_NUM_FORMAT_ARGS, "No locale found");
ffParsePropFile(FASTFETCH_TARGET_DIR_ROOT"/etc/locale.conf", "LANG =", &locale);
}
if(locale.length == 0)
{
getLocaleFromEnv(&locale);
}
if(locale.length == 0)
{
ffPrintError(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.locale, "No locale found");
return;
}
ffPrintAndWriteToCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.localeKey, &locale, &instance->config.localeFormat, FF_LOCALE_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintAndWriteToCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.locale, &locale, FF_LOCALE_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &locale}
});
+18 -11
View File
@@ -1,31 +1,38 @@
#include "fastfetch.h"
#include "common/printing.h"
#define FF_LOCALIP_MODULE_NAME "Local IP"
#define FF_LOCALIP_NUM_FORMAT_ARGS 1
#include <sys/types.h>
#include <string.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
static void printValue(FFinstance* instance, const char* ifaName, const char* addressBuffer)
{
FF_STRBUF_CREATE(key);
FFstrbuf key;
ffStrbufInit(&key);
if (instance->config.localIpKey.length == 0) {
if (instance->config.localIP.key.length == 0)
{
ffStrbufAppendF(&key, FF_LOCALIP_MODULE_NAME " (%s)", ifaName);
} else {
ffParseFormatString(&key, &instance->config.localIpKey, NULL, 1, (FFformatarg[]){
}
else
{
ffParseFormatString(&key, &instance->config.localIP.key, 1, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, ifaName}
});
}
if (instance->config.localIpFormat.length == 0) {
ffPrintLogoAndKey(instance, FF_LOCALIP_MODULE_NAME, 0, &key);
if (instance->config.localIP.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, key.chars, 0, NULL);
puts(addressBuffer);
} else {
ffPrintFormatString(instance, FF_LOCALIP_MODULE_NAME, 0, &key, &instance->config.localIpFormat, NULL, FF_LOCALIP_NUM_FORMAT_ARGS, (FFformatarg[]){
}
else
{
ffPrintFormatString(instance, key.chars, 0, NULL, &instance->config.localIP.outputFormat, FF_LOCALIP_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, addressBuffer}
});
}
@@ -38,7 +45,7 @@ void ffPrintLocalIp(FFinstance* instance)
struct ifaddrs* ifAddrStruct = NULL;
int ret = getifaddrs(&ifAddrStruct);
if (ret < 0) {
ffPrintError(instance, FF_LOCALIP_MODULE_NAME, 0, &instance->config.localIpKey, &instance->config.localIpFormat, FF_LOCALIP_NUM_FORMAT_ARGS, "getifaddrs(&ifAddrStruct) < 0 (%i)", ret);
ffPrintError(instance, FF_LOCALIP_MODULE_NAME, 0, &instance->config.localIP, "getifaddrs(&ifAddrStruct) < 0 (%i)", ret);
return;
}
+8 -5
View File
@@ -1,4 +1,7 @@
#include "fastfetch.h"
#include "common/printing.h"
#include <stdlib.h>
#define FF_MEMORY_MODULE_NAME "Memory"
#define FF_MEMORY_NUM_FORMAT_ARGS 3
@@ -8,7 +11,7 @@ void ffPrintMemory(FFinstance* instance)
{
FILE* meminfo = fopen("/proc/meminfo", "r");
if(meminfo == NULL) {
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, FF_MEMORY_NUM_FORMAT_ARGS, "fopen(\"""/proc/meminfo\", \"r\") == NULL");
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, "fopen(\"""/proc/meminfo\", \"r\") == NULL");
return;
}
@@ -42,18 +45,18 @@ void ffPrintMemory(FFinstance* instance)
if(used_mem == 0 && total_mem == 0 && percentage == 0)
{
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, FF_MEMORY_NUM_FORMAT_ARGS, "/proc/meminfo could't be parsed");
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, "/proc/meminfo could't be parsed");
return;
}
if(instance->config.memoryFormat.length == 0)
if(instance->config.memory.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey);
ffPrintLogoAndKey(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory.key);
printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage);
}
else
{
ffPrintFormatString(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, NULL, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormat(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_UINT, &used_mem},
{FF_FORMAT_ARG_TYPE_UINT, &total_mem},
{FF_FORMAT_ARG_TYPE_UINT8, &percentage}
+95
View File
@@ -0,0 +1,95 @@
#include "fastfetch.h"
#include "common/printing.h"
#define FF_OPENCL_MODULE_NAME "OpenCL"
#define FF_OPENCL_NUM_FORMAT_ARGS 3
#ifdef FF_HAVE_OPENCL
#include "common/library.h"
#include "common/parsing.h"
#define CL_TARGET_OPENCL_VERSION 100
#include <CL/cl.h>
typedef struct OpenCLData
{
FF_LIBRARY_SYMBOL(clGetPlatformIDs);
FF_LIBRARY_SYMBOL(clGetDeviceIDs);
FF_LIBRARY_SYMBOL(clGetDeviceInfo);
} OpenCLData;
static const char* openCLHandelData(FFinstance* instance, OpenCLData* data)
{
cl_platform_id platformID;
cl_uint numPlatforms;
data->ffclGetPlatformIDs(1, &platformID, &numPlatforms);
if(numPlatforms == 0)
return "clGetPlatformIDs returned 0 platforms";
cl_device_id deviceID;
cl_uint numDevices;
data->ffclGetDeviceIDs(platformID, CL_DEVICE_TYPE_GPU, 1, &deviceID, &numDevices);
if(numDevices == 0)
data->ffclGetDeviceIDs(platformID, CL_DEVICE_TYPE_ALL, 1, &deviceID, &numDevices);
if(numDevices == 0)
return "clGetDeviceIDs returned 0 devices";
char version[64];
data->ffclGetDeviceInfo(deviceID, CL_DEVICE_VERSION, sizeof(version), version, NULL);
if(!ffStrSet(version))
return "clGetDeviceInfo returned NULL or empty string";
char device[128];
data->ffclGetDeviceInfo(deviceID, CL_DEVICE_NAME, sizeof(device), device, NULL);
char vendor[32];
data->ffclGetDeviceInfo(deviceID, CL_DEVICE_VENDOR, sizeof(vendor), vendor, NULL);
if(instance->config.openCL.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL.key);
puts(version);
}
else
{
ffPrintFormat(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL, FF_OPENCL_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRING, version},
{FF_FORMAT_ARG_TYPE_STRING, device},
{FF_FORMAT_ARG_TYPE_STRING, vendor}
});
}
return NULL;
}
static const char* printOpenCL(FFinstance* instance)
{
OpenCLData data;
FF_LIBRARY_LOAD(opencl, instance->config.libOpenCL, "dlopen libOpenCL.so failed", "libOpenCL.so", 1);
FF_LIBRARY_LOAD_SYMBOL_ADRESS(opencl, data.ffclGetPlatformIDs, clGetPlatformIDs, "dlsym clGetPlatformIDs failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(opencl, data.ffclGetDeviceIDs, clGetDeviceIDs, "dlsym clGetDeviceIDs failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(opencl, data.ffclGetDeviceInfo, clGetDeviceInfo, "dlsym clGetDeviceInfo failed");
const char* error = openCLHandelData(instance, &data);
dlclose(opencl);
return error;
}
#endif
void ffPrintOpenCL(FFinstance* instance)
{
const char* error;
#ifdef FF_HAVE_OPENCL
error = printOpenCL(instance);
#else
error = "Fastfetch was build without OpenCL support";
#endif
if(error != NULL)
ffPrintError(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL, error);
}
+395
View File
@@ -0,0 +1,395 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "common/parsing.h"
#include <string.h>
#define FF_OPENGL_MODULE_NAME "OpenGL"
#define FF_OPENGL_NUM_FORMAT_ARGS 4
#if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA)
#define FF_HAVE_GL 1
#include "common/library.h"
#include <GL/gl.h>
#define FF_OPENGL_BUFFER_WIDTH 1
#define FF_OPENGL_BUFFER_HEIGHT 1
typedef struct GLData
{
FF_LIBRARY_SYMBOL(glGetString);
} GLData;
static const char* glHandlePrint(FFinstance* instance, const GLData* data)
{
const char* version = (const char*) data->ffglGetString(GL_VERSION);
if(!ffStrSet(version))
return "glGetString(GL_VERSION) returned NULL";
const char* renderer = (const char*) data->ffglGetString(GL_RENDERER);
const char* vendor = (const char*) data->ffglGetString(GL_VENDOR);
const char* slv = (const char*) data->ffglGetString(GL_SHADING_LANGUAGE_VERSION);
if(instance->config.openGL.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGL.key);
puts(version);
}
else
{
ffPrintFormat(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGL, FF_OPENGL_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRING, version},
{FF_FORMAT_ARG_TYPE_STRING, renderer},
{FF_FORMAT_ARG_TYPE_STRING, vendor},
{FF_FORMAT_ARG_TYPE_STRING, slv}
});
}
return NULL;
}
#ifdef FF_HAVE_EGL
#include <EGL/egl.h>
typedef struct EGLData
{
GLData glData;
FF_LIBRARY_SYMBOL(eglGetProcAddress);
FF_LIBRARY_SYMBOL(eglGetDisplay);
FF_LIBRARY_SYMBOL(eglInitialize);
FF_LIBRARY_SYMBOL(eglBindAPI);
FF_LIBRARY_SYMBOL(eglGetConfigs);
FF_LIBRARY_SYMBOL(eglCreatePbufferSurface);
FF_LIBRARY_SYMBOL(eglCreateContext);
FF_LIBRARY_SYMBOL(eglMakeCurrent);
FF_LIBRARY_SYMBOL(eglDestroyContext);
FF_LIBRARY_SYMBOL(eglDestroySurface);
FF_LIBRARY_SYMBOL(eglTerminate);
EGLDisplay display;
EGLConfig config;
EGLSurface surface;
EGLContext context;
} EGLData;
static const char* eglHandleContext(FFinstance* instance, EGLData* data)
{
if(data->ffeglMakeCurrent(data->display, data->surface, data->surface, data->context) != EGL_TRUE)
return "eglMakeCurrent returned EGL_FALSE";
return glHandlePrint(instance, &data->glData);
}
static const char* eglHandleSurface(FFinstance* instance, EGLData* data)
{
data->context = data->ffeglCreateContext(data->display, data->config, EGL_NO_CONTEXT, (EGLint[]){EGL_NONE});
if(data->context == EGL_NO_CONTEXT)
return "eglCreateContext returned EGL_NO_CONTEXT";
const char* error = eglHandleContext(instance, data);
data->ffeglDestroyContext(data->display, data->context);
return error;
}
static const char* eglHandleDisplay(FFinstance* instance, EGLData* data)
{
if(data->ffeglBindAPI(EGL_OPENGL_API) != EGL_TRUE)
return "eglBindAPI returned EGL_FALSE";
EGLint eglConfigCount;
data->ffeglGetConfigs(data->display, &data->config, 1, &eglConfigCount);
if(eglConfigCount == 0)
return "eglGetConfigs returned 0 configs";
data->surface = data->ffeglCreatePbufferSurface(data->display, data->config, (EGLint[]){
EGL_WIDTH, FF_OPENGL_BUFFER_WIDTH,
EGL_HEIGHT, FF_OPENGL_BUFFER_HEIGHT,
EGL_NONE
});
if(data->surface == EGL_NO_SURFACE)
return "eglCreatePbufferSurface returned EGL_NO_SURFACE";
const char* error = eglHandleSurface(instance, data);
data->ffeglDestroySurface(data->display, data->surface);
return error;
}
static const char* eglHandleData(FFinstance* instance, EGLData* data)
{
data->glData.ffglGetString = (__typeof__(data->glData.ffglGetString)) data->ffeglGetProcAddress("glGetString");
if(!data->glData.ffglGetString)
return "eglGetProcAddress(glGetString) returned NULL";
data->display = data->ffeglGetDisplay(EGL_DEFAULT_DISPLAY);
if(data->display == EGL_NO_DISPLAY)
return "eglGetDisplay returned EGL_NO_DISPLAY";
EGLint major, minor;
if(data->ffeglInitialize(data->display, &major, &minor) == EGL_FALSE)
return "eglInitialize returned EGL_FALSE";
const char* error = eglHandleDisplay(instance, data);
data->ffeglTerminate(data->display);
return error;
}
static const char* eglPrint(FFinstance* instance)
{
EGLData eglData;
FF_LIBRARY_LOAD(egl, instance->config.libEGL, "dlopen egl failed", "libEGL.so", 1);
FF_LIBRARY_LOAD_SYMBOL_ADRESS(egl, eglData.ffeglGetProcAddress, eglGetProcAddress, "dlsym eglGetProcAddress failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(egl, eglData.ffeglGetDisplay, eglGetDisplay, "dlsym eglGetDisplay failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(egl, eglData.ffeglInitialize, eglInitialize, "dlsym eglInitialize failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(egl, eglData.ffeglBindAPI, eglBindAPI, "dlsym eglBindAPI failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(egl, eglData.ffeglGetConfigs, eglGetConfigs, "dlsym eglGetConfigs failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(egl, eglData.ffeglCreatePbufferSurface, eglCreatePbufferSurface, "dlsym eglCreatePbufferSurface failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(egl, eglData.ffeglCreateContext, eglCreateContext, "dlsym eglCreateContext failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(egl, eglData.ffeglMakeCurrent, eglMakeCurrent, "dlsym eglMakeCurrent failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(egl, eglData.ffeglDestroyContext, eglDestroyContext, "dlsym eglDestroyContext failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(egl, eglData.ffeglDestroySurface, eglDestroySurface, "dlsym eglDestroySurface failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(egl, eglData.ffeglTerminate, eglTerminate, "dlsym eglTerminate failed");
const char* error = eglHandleData(instance, &eglData);
dlclose(egl);
return error;
}
#endif //FF_HAVE_EGL
#ifdef FF_HAVE_GLX
#include <GL/glx.h>
typedef struct GLXData
{
GLData glData;
FF_LIBRARY_SYMBOL(glXGetProcAddress);
FF_LIBRARY_SYMBOL(XOpenDisplay);
FF_LIBRARY_SYMBOL(glXChooseVisual);
FF_LIBRARY_SYMBOL(XCreatePixmap);
FF_LIBRARY_SYMBOL(glXCreateGLXPixmap);
FF_LIBRARY_SYMBOL(glXCreateContext);
FF_LIBRARY_SYMBOL(glXMakeCurrent);
FF_LIBRARY_SYMBOL(glXDestroyContext);
FF_LIBRARY_SYMBOL(glXDestroyGLXPixmap);
FF_LIBRARY_SYMBOL(XFreePixmap);
FF_LIBRARY_SYMBOL(XCloseDisplay);
Display* display;
XVisualInfo* visualInfo;
Pixmap pixmap;
GLXPixmap glxPixmap;
GLXContext context;
} GLXData;
static const char* glxHandleContext(FFinstance* instance, GLXData* data)
{
if(data->ffglXMakeCurrent(data->display, data->glxPixmap, data->context) != True)
return "glXMakeCurrent returned False";
return glHandlePrint(instance, &data->glData);
}
static const char* glxHandleGLXPixmap(FFinstance* instance, GLXData* data)
{
data->context = data->ffglXCreateContext(data->display, data->visualInfo, NULL, True);
if(data->context == NULL)
return "glXCreateContext returned NULL";
const char* error = glxHandleContext(instance, data);
data->ffglXDestroyContext(data->display, data->context);
return error;
}
static const char* glxHandlePixmap(FFinstance* instance, GLXData* data)
{
data->glxPixmap = data->ffglXCreateGLXPixmap(data->display, data->visualInfo, data->pixmap);
if(data->glxPixmap == None)
return "glXCreateGLXPixmap returned None";
const char* error = glxHandleGLXPixmap(instance, data);
data->ffglXDestroyGLXPixmap(data->display, data->glxPixmap);
return error;
}
static const char* glxHandleVisualInfo(FFinstance* instance, GLXData* data)
{
data->pixmap = data->ffXCreatePixmap(data->display, DefaultRootWindow(data->display), FF_OPENGL_BUFFER_WIDTH, FF_OPENGL_BUFFER_HEIGHT, (unsigned int) data->visualInfo->depth);
if(data->pixmap == None)
return "XCreatePixmap returned None";
const char* error = glxHandlePixmap(instance, data);
data->ffXFreePixmap(data->display, data->pixmap);
return error;
}
static const char* glxHandleDisplay(FFinstance* instance, GLXData* data)
{
data->visualInfo = data->ffglXChooseVisual(data->display, DefaultScreen(data->display), (int[]){None});
if(data->visualInfo == NULL)
return "glXChooseVisual returned NULL";
return glxHandleVisualInfo(instance, data);
}
static const char* glxHandleData(FFinstance* instance, GLXData* data)
{
data->glData.ffglGetString = (__typeof__(data->glData.ffglGetString)) data->ffglXGetProcAddress((const GLubyte*) "glGetString");
if(data->glData.ffglGetString == NULL)
return "glXGetProcAddress(glGetString) returned NULL";
data->display = data->ffXOpenDisplay(NULL);
if(data->display == NULL)
return "XOpenDisplay returned NULL";
const char* error = glxHandleDisplay(instance, data);
data->ffXCloseDisplay(data->display);
return error;
}
static const char* glxPrint(FFinstance* instance)
{
GLXData data;
FF_LIBRARY_LOAD(glx, instance->config.libGLX, "dlopen glx failed", "libGLX.so", 1);
FF_LIBRARY_LOAD_SYMBOL_ADRESS(glx, data.ffglXGetProcAddress, glXGetProcAddress, "dlsym glXGetProcAddress failed");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(glx, data.ffXOpenDisplay, XOpenDisplay, "dlsym XOpenDisplay returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(glx, data.ffglXChooseVisual, glXChooseVisual, "dlsym glXChooseVisual returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(glx, data.ffXCreatePixmap, XCreatePixmap, "dlsym XCreatePixmap returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(glx, data.ffglXCreateGLXPixmap, glXCreateGLXPixmap, "dlsym glXCreateGLXPixmap returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(glx, data.ffglXCreateContext, glXCreateContext, "dlsym glXCreateContext returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(glx, data.ffglXMakeCurrent, glXMakeCurrent, "dlsym glXMakeCurrent returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(glx, data.ffglXDestroyContext, glXDestroyContext, "dlsym glXDestroyContext returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(glx, data.ffglXDestroyGLXPixmap, glXDestroyGLXPixmap, "dlsym glXDestroyGLXPixmap returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(glx, data.ffXFreePixmap, XFreePixmap, "dlsym XFreePixmap returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(glx, data.ffXCloseDisplay, XCloseDisplay, "dlsym XCloseDisplay returned NULL");
const char* error = glxHandleData(instance, &data);
dlclose(glx);
return error;
}
#endif //FF_HAVE_GLX
#ifdef FF_HAVE_OSMESA
#include <GL/osmesa.h>
typedef struct OSMesaData
{
GLData glData;
FF_LIBRARY_SYMBOL(OSMesaGetProcAddress);
FF_LIBRARY_SYMBOL(OSMesaCreateContext);
FF_LIBRARY_SYMBOL(OSMesaMakeCurrent);
FF_LIBRARY_SYMBOL(OSMesaDestroyContext);
OSMesaContext context;
} OSMesaData;
static const char* osMesaHandleContext(FFinstance* instance, OSMesaData* data)
{
unsigned char buffer[FF_OPENGL_BUFFER_WIDTH * FF_OPENGL_BUFFER_HEIGHT * sizeof(uint32_t)]; // 4 bytes per pixel (RGBA)
if(data->ffOSMesaMakeCurrent(data->context, buffer, GL_UNSIGNED_BYTE, FF_OPENGL_BUFFER_WIDTH, FF_OPENGL_BUFFER_HEIGHT) != GL_TRUE)
return "OSMesaMakeCurrent returned GL_FALSE";
return glHandlePrint(instance, &data->glData);
}
static const char* osMesaHandleData(FFinstance* instance, OSMesaData* data)
{
//The case to void* is required here, because OSMESAproc can't be cast to (__typeof__(data->glData.ffglGetString)) without a warning, even though it is the actual type.
data->glData.ffglGetString = (__typeof__(data->glData.ffglGetString)) (void*) data->ffOSMesaGetProcAddress("glGetString");
if(data->glData.ffglGetString == NULL)
return "OSMesaGetProcAddress(glGetString) returned NULL";
data->context = data->ffOSMesaCreateContext(OSMESA_RGBA, NULL);
if(data->context == NULL)
return "OSMesaCreateContext returned NULL";
const char* error = osMesaHandleContext(instance, data);
data->ffOSMesaDestroyContext(data->context);
return error;
}
static const char* osMesaPrint(FFinstance* instance)
{
OSMesaData data;
FF_LIBRARY_LOAD(osmesa, instance->config.libOSMesa, "dlopen osmesa failed", "libOSMesa.so", 8);
FF_LIBRARY_LOAD_SYMBOL_ADRESS(osmesa, data.ffOSMesaGetProcAddress, OSMesaGetProcAddress, "dlsym OSMesaGetProcAddress returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(osmesa, data.ffOSMesaCreateContext, OSMesaCreateContext, "dlsym OSMesaCreateContext returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(osmesa, data.ffOSMesaMakeCurrent, OSMesaMakeCurrent, "dlsym OSMesaMakeCurrent returned NULL");
FF_LIBRARY_LOAD_SYMBOL_ADRESS(osmesa, data.ffOSMesaDestroyContext, OSMesaDestroyContext, "dlsym OSMesaDestroyContext returned NULL");
const char* error = osMesaHandleData(instance, &data);
dlclose(osmesa);
return error;
}
#endif //FF_HAVE_OSMESA
static const char* glPrint(FFinstance* instance)
{
if(instance->config.glType == FF_GL_TYPE_GLX)
{
#ifdef FF_HAVE_GLX
return glxPrint(instance);
#else
return "fastfetch was compiled without glx support";
#endif
}
if(instance->config.glType == FF_GL_TYPE_EGL)
{
#ifdef FF_HAVE_EGL
return eglPrint(instance);
#else
return "fastfetch was compiled without egl support";
#endif
}
if(instance->config.glType == FF_GL_TYPE_OSMESA)
{
#ifdef FF_HAVE_OSMESA
return osMesaPrint(instance);
#else
return "fastfetch was compiled without osmesa support";
#endif
}
const char* error = ""; // not NULL dummy value
#ifdef FF_HAVE_EGL
error = eglPrint(instance);
#endif
#ifdef FF_HAVE_GLX
if(error != NULL)
error = glxPrint(instance);
#endif
//We don't use osmesa in auto mode here, because it is a software implementation,
//that doesn't reflect the opengl supported by the hardware
return error;
}
#endif // FF_HAVE_GL
void ffPrintOpenGL(FFinstance* instance)
{
const char* error;
#ifndef FF_HAVE_GL
error = "Fastfetch was built without gl support.";
#else
error = glPrint(instance);
#endif
if(error != NULL)
ffPrintError(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGL, error);
}
+97 -61
View File
@@ -1,88 +1,124 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "detection/os.h"
#include <ctype.h>
#define FF_OS_MODULE_NAME "OS"
#define FF_OS_NUM_FORMAT_ARGS 12
void ffPrintOS(FFinstance* instance)
static void buildOutputDefault(const FFOSResult* os, FFstrbuf* result)
{
if(ffPrintFromCache(instance, FF_OS_MODULE_NAME, &instance->config.osKey, &instance->config.osFormat, FF_OS_NUM_FORMAT_ARGS))
return;
const FFOSResult* result = ffDetectOS(instance);
if(result->name.length == 0 && result->prettyName.length == 0)
{
ffPrintError(instance, FF_OS_MODULE_NAME, 0, &instance->config.osKey, &instance->config.osFormat, FF_OS_NUM_FORMAT_ARGS, "Could not detect OS");
return;
}
FFstrbuf os;
ffStrbufInit(&os);
//Create the basic output
if(result->name.length > 0)
ffStrbufAppend(&os, &result->name);
else if(result->prettyName.length > 0)
ffStrbufAppend(&os, &result->name);
else if(result->id.length > 0)
ffStrbufAppend(&os, &result->id);
else if(result->systemName.length > 0)
ffStrbufAppend(&os, &result->systemName);
if(os->name.length > 0)
ffStrbufAppend(result, &os->name);
else if(os->prettyName.length > 0)
ffStrbufAppend(result, &os->name);
else if(os->id.length > 0)
ffStrbufAppend(result, &os->id);
else if(os->systemName.length > 0)
ffStrbufAppend(result, &os->systemName);
else
ffStrbufAppendS(&os, "Linux");
ffStrbufAppendS(result, "Linux");
//Append version if it is missing
if(result->versionID.length > 0 && ffStrbufFirstIndex(&os, &result->versionID) == os.length)
if(os->versionID.length > 0 && ffStrbufFirstIndex(result, &os->versionID) == result->length)
{
ffStrbufAppendC(&os, ' ');
ffStrbufAppend(&os, &result->versionID);
ffStrbufAppendC(result, ' ');
ffStrbufAppend(result, &os->versionID);
}
else if(result->versionID.length == 0 && result->version.length > 0 && ffStrbufFirstIndex(&os, &result->version) == os.length)
else if(os->versionID.length == 0 && os->version.length > 0 && ffStrbufFirstIndex(result, &os->version) == result->length)
{
ffStrbufAppendC(&os, ' ');
ffStrbufAppend(&os, &result->version);
ffStrbufAppendC(result, ' ');
ffStrbufAppend(result, &os->version);
}
//Append variant if it is missing
if(result->variant.length > 0 && ffStrbufFirstIndex(&os, &result->variant) == os.length)
if(os->variant.length > 0 && ffStrbufFirstIndex(result, &os->variant) == result->length)
{
ffStrbufAppendS(&os, " (");
ffStrbufAppend(&os, &result->variant);
ffStrbufAppendC(&os, ')');
ffStrbufAppendS(result, " (");
ffStrbufAppend(result, &os->variant);
ffStrbufAppendC(result, ')');
}
else if(result->variant.length == 0 && result->variantID.length > 0 && ffStrbufFirstIndex(&os, &result->variantID) == os.length)
else if(os->variant.length == 0 && os->variantID.length > 0 && ffStrbufFirstIndex(result, &os->variantID) == result->length)
{
ffStrbufAppendS(&os, " (");
ffStrbufAppend(&os, &result->variantID);
ffStrbufAppendC(&os, ')');
ffStrbufAppendS(result, " (");
ffStrbufAppend(result, &os->variantID);
ffStrbufAppendC(result, ')');
}
//Append architecture if it is missing
if(ffStrbufFirstIndex(&os, &result->architecture) == os.length)
if(ffStrbufFirstIndex(result, &os->architecture) == result->length)
{
ffStrbufAppendS(&os, " [");
ffStrbufAppend(&os, &result->architecture);
ffStrbufAppendC(&os, ']');
ffStrbufAppendC(result, ' ');
ffStrbufAppend(result, &os->architecture);
}
}
static void buildOutputNixOS(const FFOSResult* os, FFstrbuf* result)
{
ffStrbufAppendS(result, "NixOS");
if(os->buildID.length > 0)
{
ffStrbufAppendC(result, ' ');
ffStrbufAppend(result, &os->buildID);
}
ffPrintAndWriteToCache(instance, FF_OS_MODULE_NAME, &instance->config.osKey, &os, &instance->config.osFormat, FF_OS_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &result->systemName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->prettyName},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->id},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->idLike},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->variant},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->variantID},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->version},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->versionID},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->codename},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->buildID},
{FF_FORMAT_ARG_TYPE_STRBUF, &result->architecture}
});
if(os->codename.length > 0)
{
ffStrbufAppendS(result, " (");
ffStrbufAppendC(result, (char) toupper(os->codename.chars[0]));
ffStrbufAppendS(result, os->codename.chars + 1);
ffStrbufAppendC(result, ')');
}
ffStrbufDestroy(&os);
if(os->architecture.length > 0)
{
ffStrbufAppendC(result, ' ');
ffStrbufAppend(result, &os->architecture);
}
}
void ffPrintOS(FFinstance* instance)
{
const FFOSResult* os = ffDetectOS(instance);
if(os->name.length == 0 && os->prettyName.length == 0)
{
ffPrintError(instance, FF_OS_MODULE_NAME, 0, &instance->config.os, "Could not detect OS");
return;
}
if(instance->config.os.outputFormat.length == 0)
{
FFstrbuf result;
ffStrbufInit(&result);
if(ffStrbufIgnCaseCompS(&os->id, "nixos") == 0)
buildOutputNixOS(os, &result);
else
buildOutputDefault(os, &result);
ffPrintLogoAndKey(instance, FF_OS_MODULE_NAME, 0, &instance->config.os.key);
ffStrbufPutTo(&result, stdout);
ffStrbufDestroy(&result);
}
else
{
ffPrintFormat(instance, FF_OS_MODULE_NAME, 0, &instance->config.os, FF_OS_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &os->systemName},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->prettyName},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->id},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->idLike},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->variant},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->variantID},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->version},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->versionID},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->codename},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->buildID},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->architecture}
});
}
}

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