From 0c9c35b971b209c6fbb451cb683b60239fac8d7a Mon Sep 17 00:00:00 2001 From: Adrian Groh Date: Thu, 16 Feb 2023 16:16:19 +0100 Subject: [PATCH] Initial commit --- .gitignore | 10 + Cargo.lock | 1251 +++++++++++++++++++++++++++++++++++ Cargo.toml | 26 + LICENSE | 19 + README.md | 149 +++++ pfetch-extractor/Cargo.toml | 15 + pfetch-extractor/logos.sh | 709 ++++++++++++++++++++ pfetch-extractor/src/lib.rs | 105 +++ print_all.sh | 66 ++ src/lib.rs | 440 ++++++++++++ src/main.rs | 284 ++++++++ 11 files changed, 3074 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 pfetch-extractor/Cargo.toml create mode 100644 pfetch-extractor/logos.sh create mode 100644 pfetch-extractor/src/lib.rs create mode 100755 print_all.sh create mode 100644 src/lib.rs create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73fab07 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..42da146 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1251 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +dependencies = [ + "memchr", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + +[[package]] +name = "bstr" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f0778972c64420fdedc63f09919c8a88bda7b25135357fd25a5d9f3257e832" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +dependencies = [ + "iana-time-zone", + "num-integer", + "num-traits", + "serde", + "winapi", +] + +[[package]] +name = "cocoa" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c49e86fc36d5704151f5996b7b3795385f50ce09e3be0f47a0cfde869681cf8" +dependencies = [ + "bitflags", + "block", + "core-foundation 0.7.0", + "core-graphics 0.19.2", + "foreign-types", + "libc", + "objc", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "com" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e17887fd17353b65b1b2ef1c526c83e26cd72e74f598a8dc1bee13a48f3d9f6" +dependencies = [ + "com_macros", +] + +[[package]] +name = "com_macros" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d375883580a668c7481ea6631fc1a8863e33cc335bf56bfad8d7e6d4b04b13a5" +dependencies = [ + "com_macros_support", + "proc-macro2", + "syn", +] + +[[package]] +name = "com_macros_support" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad899a1087a9296d5644792d7cb72b8e34c1bec8e7d4fbc002230169a6e8710c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "core-foundation" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +dependencies = [ + "core-foundation-sys 0.7.0", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys 0.8.3", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "core-graphics" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923" +dependencies = [ + "bitflags", + "core-foundation 0.7.0", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" +dependencies = [ + "bitflags", + "core-foundation 0.9.3", + "core-graphics-types", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" +dependencies = [ + "bitflags", + "core-foundation 0.9.3", + "foreign-types", + "libc", +] + +[[package]] +name = "core-video-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ecad23610ad9757664d644e369246edde1803fcb43ed72876565098a5d3828" +dependencies = [ + "cfg-if 0.1.10", + "core-foundation-sys 0.7.0", + "core-graphics 0.19.2", + "libc", + "metal", + "objc", +] + +[[package]] +name = "cxx" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "futures" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" + +[[package]] +name = "futures-executor" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" + +[[package]] +name = "futures-macro" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" + +[[package]] +name = "futures-task" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" + +[[package]] +name = "futures-util" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gethostname" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "globset" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", +] + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "home" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408" +dependencies = [ + "winapi", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +dependencies = [ + "android_system_properties", + "core-foundation-sys 0.8.3", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + +[[package]] +name = "if-addrs" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2273e421f7c4f0fc99e1934fe4776f59d8df2972f4199d703fc0da9f2a9f73de" +dependencies = [ + "if-addrs-sys", + "libc", + "winapi", +] + +[[package]] +name = "if-addrs-sys" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de74b9dd780476e837e5eb5ab7c88b49ed304126e412030a0adba99c8efe79ea" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "js-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "libmacchina" +version = "6.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2009e687ca8eb9897596373801cda8c5e745477a54b89d3251221cd41b0d23" +dependencies = [ + "cfg-if 1.0.0", + "core-foundation 0.9.3", + "core-graphics 0.22.3", + "core-video-sys", + "dirs", + "home", + "if-addrs", + "itertools", + "libc", + "local-ip-address", + "mach", + "nix", + "num_cpus", + "os-release", + "regex", + "sqlite", + "sysctl", + "walkdir", + "windows", + "winreg", + "wmi", + "x11rb", +] + +[[package]] +name = "link-cplusplus" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" +dependencies = [ + "cc", +] + +[[package]] +name = "local-ip-address" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eab7f092fb08006040e656c2adce6670e6a516bea831a8b2b3d0fb24d4488f5" +dependencies = [ + "libc", + "neli", + "thiserror", + "windows-sys", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "metal" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e198a0ee42bdbe9ef2c09d0b9426f3b2b47d90d93a4a9b0395c4cea605e92dc0" +dependencies = [ + "bitflags", + "block", + "cocoa", + "core-graphics 0.19.2", + "foreign-types", + "log", + "objc", +] + +[[package]] +name = "neli" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9053554eb5dcb7e10d9cdab1206965bde870eed5d0d341532ca035e3ba221508" +dependencies = [ + "byteorder", + "libc", +] + +[[package]] +name = "nix" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "libc", + "memoffset", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", + "objc_exception", +] + +[[package]] +name = "objc_exception" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4" +dependencies = [ + "cc", +] + +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "os-release" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82f29ae2f71b53ec19cc23385f8e4f3d90975195aa3d09171ba3bef7159bec27" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "pfetch" +version = "0.1.0" +dependencies = [ + "dotenv", + "glob", + "globset", + "libmacchina", + "pfetch-extractor", + "which", +] + +[[package]] +name = "pfetch-extractor" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "regex", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + +[[package]] +name = "proc-macro2" +version = "1.0.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scratch" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" + +[[package]] +name = "serde" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + +[[package]] +name = "sqlite" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e66cb949f931ece6201d72bffad3f3601b94998a345793713dd13af70a77c185" +dependencies = [ + "libc", + "sqlite3-sys", +] + +[[package]] +name = "sqlite3-src" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1815a7a02c996eb8e5c64f61fcb6fd9b12e593ce265c512c5853b2513635691" +dependencies = [ + "cc", + "pkg-config", +] + +[[package]] +name = "sqlite3-sys" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d47c99824fc55360ba00caf28de0b8a0458369b832e016a64c13af0ad9fbb9ee" +dependencies = [ + "libc", + "sqlite3-src", +] + +[[package]] +name = "syn" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sysctl" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225e483f02d0ad107168dc57381a8a40c3aeea6abe47f37506931f861643cfa8" +dependencies = [ + "bitflags", + "byteorder", + "libc", + "thiserror", + "walkdir", +] + +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" + +[[package]] +name = "which" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +dependencies = [ + "either", + "libc", + "once_cell", +] + +[[package]] +name = "widestring" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-wsapoll" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1c4bd0a50ac6020f65184721f758dba47bb9fbc2133df715ec74a237b26794a" +dependencies = [ + "windows_aarch64_msvc 0.39.0", + "windows_i686_gnu 0.39.0", + "windows_i686_msvc 0.39.0", + "windows_x86_64_gnu 0.39.0", + "windows_x86_64_msvc 0.39.0", +] + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec7711666096bd4096ffa835238905bb33fb87267910e154b18b44eaabb340f2" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" + +[[package]] +name = "windows_i686_gnu" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "763fc57100a5f7042e3057e7e8d9bdd7860d330070251a73d003563a3bb49e1b" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" + +[[package]] +name = "windows_i686_msvc" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bc7cbfe58828921e10a9f446fcaaf649204dcfe6c1ddd712c5eebae6bda1106" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6868c165637d653ae1e8dc4d82c25d4f97dd6605eaa8d784b5c6e0ab2a252b65" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e4d40883ae9cae962787ca76ba76390ffa29214667a111db9e0a1ad8377e809" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" + +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + +[[package]] +name = "wmi" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8c8d5af750290e68a5bfc45cc4ca326de7dcf1c8d801d3a6dfa838cedc02194" +dependencies = [ + "chrono", + "com", + "futures", + "log", + "serde", + "thiserror", + "widestring", + "winapi", +] + +[[package]] +name = "x11rb" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" +dependencies = [ + "gethostname", + "nix", + "winapi", + "winapi-wsapoll", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" +dependencies = [ + "nix", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..771785f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,26 @@ +[workspace] +members = ["pfetch-extractor"] + +[package] +name = "pfetch" +version = "0.1.0" +edition = "2021" +authors = ["Gobidev"] +description = "A rewrite of the pfetch system information tool" +repository = "https://github.com/Gobidev/pfetch-rs" +license = "MIT" +keywords = ["fetch", "pfetch", "cli", "system"] +categories = ["command-line-utilities"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +pfetch-extractor = { path = "./pfetch-extractor" } +globset = "0.4.10" +dotenv = "0.15.0" +glob = "0.3.1" +which = "4.4.0" +libmacchina = "6" + +[profile.release] +strip = true diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..eb05d23 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2023 Adrian Groh + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fa97371 --- /dev/null +++ b/README.md @@ -0,0 +1,149 @@ +

pfetch-rs

+

A rewrite of the pfetch system information tool by dylanaraps in Rust


+

+ +## About + +If you are familiar with the [pfetch](https://github.com/dylanaraps/pfetch) +system information tool by [dylanaraps](https://github.com/dylanaraps), this +does the exact same thing, but with an about _10x faster_ runtime. _pfetch_ is +simple by design with some (but not many) configuration options and a +minimalistic look. + +**Supported Platforms:** Linux, Android, DragonflyBSD, FreeBSD, NetBSD, OpenBSD, +WSL, Haiku, MacOS, Minix, Solaris, IRIX, SerenityOS + +_Disclaimer: Aside from Linux, all of these platforms are untested. If you run +into problems, please open an issue._ + +**Included Logos:** Alpine Linux, Android, Arch Linux, ArcoLinux, Artix Linux, +Bedrock Linux, Buildroot, CelOS, CentOS, Crystal Linux, dahliaOS, Debian, +Devuan, DragonflyBSD, Elementary OS, EndeavourOS, Fedora, FreeBSD, Garuda Linux, +Gentoo Linux, Gnu, Guix, Haiku, HydroOS, Hyperbola, instantOS, IRIX, KDE neon, +Linux Lite, Linux, Mint, macOS, Mageia, Manjaro, Minix, MX Linux, NetBSD, NixOS, +OpenBSD, openSUSE Tumbleweed, openSUSE Leap, OpenWrt, Parabola, Pop!\_OS +(updated), PureOS, Raspbian, SerenityOS, Slackware, Solus, Solaris, Ubuntu, Void +Linux, Xeonix Linux, Fiwix (new), MorphOS (new), AmogOS (new), Aperio (new) + +For all other distributions, a penguin will be displayed. + +_Credit to [the original pfetch](https://github.com/dylanaraps/pfetch) and +[its contributors](https://github.com/dylanaraps/pfetch/graphs/contributors)._ + +If you want to add a logo, feel free to make a Pull Request. + +## Status + +This project is still in early development, expect things to not work properly. +Please open issues for bugs you are encountering. + +## Installation + +### Cargo + +```sh +cargo install pfetch +``` + +## Performance + +Benchmarks performed on an AMD Ryzen 5 3600. Execution time is measured using +[hyperfine](https://github.com/sharkdp/hyperfine) with `-w 4 -m 500 -N` flags + +| Implementation | Mean [ms] | Min [ms] | Max [ms] | +| :---------------: | :--------: | :------: | :------: | +| POSIX `sh` (bash) | 27.3 ± 0.9 | 25.3 | 23.2 | +| POSIX `sh` (dash) | 19.3 ± 0.6 | 18.3 | 24.0 | +| Rust | 2.1 ± 0.2 | 1.8 | 3.6 | + +_Note: This is with `pacman` being the only installed package manager. +Especially having `nix` installed will have a big impact on performance, as +querying installed `nix` packages is very costly._ + +## Configuration + +Like the original `pfetch`, `pfetch-rs` is configured through environment +variables. Your existing config will probably still work, the only difference is +how padding is configured. + +If you want to display a custom logo, you will have to download the source code, +make your changes to `./pfetch-extractor/logos.sh` and build the binary with +`cargo b --release`. + +```sh +# Which information to display. +# Default: first example below +# Valid: space separated string +# +# OFF by default: shell editor wm de palette +PF_INFO="ascii title os host kernel uptime pkgs memory" + +# Example: Only ASCII. +PF_INFO="ascii" + +# Example: Only Information. +PF_INFO="title os host kernel uptime pkgs memory" + +# A file containing environment variables to source before running pfetch. +# Default: unset +# Valid: A shell script +PF_SOURCE="" + +# Separator between info name and info data. +# Default: unset +# Valid: string +PF_SEP=":" + +# Enable/Disable colors in output: +# Default: 1 +# Valid: 1 (enabled), 0 (disabled) +PF_COLOR=1 + +# Color of info names: +# Default: unset (auto) +# Valid: 0-9 +PF_COL1=4 + +# Color of info data: +# Default: unset (auto) +# Valid: 0-9 +PF_COL2=9 + +# Color of title data: +# Default: unset (auto) +# Valid: 0-9 +PF_COL3=1 + +# Alignment paddings (this is different to the original version). +# Default: unset (auto) +# Valid: int +PF_PAD1="" +PF_PAD2="" +PF_PAD3="" + +# Which ascii art to use. +# Default: unset (auto) +# Valid: string +PF_ASCII="openbsd" + +# The below environment variables control more +# than just 'pfetch' and can be passed using +# 'HOSTNAME=cool_pc pfetch' to restrict their +# usage solely to 'pfetch'. + +# Which user to display. +USER="" + +# Which hostname to display. +HOSTNAME="" + +# Which editor to display. +EDITOR="" + +# Which shell to display. +SHELL="" + +# Which desktop environment to display. +XDG_CURRENT_DESKTOP="" + +``` diff --git a/pfetch-extractor/Cargo.toml b/pfetch-extractor/Cargo.toml new file mode 100644 index 0000000..15a460c --- /dev/null +++ b/pfetch-extractor/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "pfetch-extractor" +version = "0.1.0" +edition = "2021" +authors = ["Gobidev"] + +[lib] +proc-macro = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +proc-macro2 = "1.0.50" +quote = "1.0.23" +regex = "1.7.1" diff --git a/pfetch-extractor/logos.sh b/pfetch-extractor/logos.sh new file mode 100644 index 0000000..f0022ba --- /dev/null +++ b/pfetch-extractor/logos.sh @@ -0,0 +1,709 @@ +#!/bin/bash + +# Most of the below logos are from pfetch by Dylan Araps licensed under the MIT License +# The MIT License (MIT) + +# Copyright (c) 2016-2019 Dylan Araps +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +case ${1:-${PF_ASCII:-${distro:-$os}}} in + [Aa]lpine*) + read_ascii 4 <<- EOF + ${c4} /\\ /\\ + /${c7}/ ${c4}\\ \\ + /${c7}/ ${c4}\\ \\ + /${c7}// ${c4}\\ \\ + ${c7}// ${c4}\\ \\ + ${c4}\\ + EOF + ;; + + [Aa]ndroid*) + read_ascii 2 <<- EOF + ${c2} ;, ,; + ${c2} ';,.-----.,;' + ${c2} ,' ', + ${c2} / O O \\ + ${c2}| | + ${c2}'-----------------' + EOF + ;; + + [Aa]rch*) + read_ascii 4 <<- EOF + ${c6} /\\ + ${c6} / \\ + ${c6} /\\ \\ + ${c4} / \\ + ${c4} / ,, \\ + ${c4} / | | -\\ + ${c4} /_-'' ''-_\\ + EOF + ;; + + [Aa]rco*) + read_ascii 4 <<- EOF + ${c4} /\\ + ${c4} / \\ + ${c4} / /\\ \\ + ${c4} / / \\ \\ + ${c4} / / \\ \\ + ${c4} / / _____\\ \\ + ${c4}/_/ \`----.\\_\\ + EOF + ;; + + [Aa]rtix*) + read_ascii 6 <<- EOF + ${c4} /\\ + ${c4} / \\ + ${c4} /\`'.,\\ + ${c4} / ', + ${c4} / ,\`\\ + ${c4} / ,.'\`. \\ + ${c4}/.,'\` \`'.\\ + EOF + ;; + + [Bb]edrock*) + read_ascii 4 <<- EOF + ${c7}__ + ${c7}\\ \\___ + ${c7} \\ _ \\ + ${c7} \\___/ + EOF + ;; + + [Bb]uildroot*) + read_ascii 3 <<- EOF + ${c3} ___ + ${c3} / \` \\ + ${c3}| : :| + ${c3}-. _:__.- + ${c3} \` ---- \` + EOF + ;; + + [Cc]el[Oo][Ss]*) + read_ascii 5 <<- EOF + ${c5} .////\\\\\//\\. + ${c5} //_ \\\\ + ${c5} /_ ${c7}############## + ${c5} // *\\ + ${c7}############### ${c5}|# + ${c5} \/ */ + ${c5} \* ${c7}############## + ${c5} */, .// + ${c5} '_///\\\\\//_' + EOF + ;; + + [Cc]ent[Oo][Ss]*) + read_ascii 5 <<- EOF + ${c2} ____${c3}^${c5}____ + ${c2} |\\ ${c3}|${c5} /| + ${c2} | \\ ${c3}|${c5} / | + ${c5}<---- ${c4}----> + ${c4} | / ${c2}|${c3} \\ | + ${c4} |/__${c2}|${c3}__\\| + ${c2} v + EOF + ;; + + [Cc]rystal*[Ll]inux) + read_ascii 5 <<- EOF + ${c5} -//. + ${c5} -//. + ${c5} -//. . + ${c5} -//. '//- + ${c5} /+: :+/ + ${c5} .//' .//. + ${c5} . .//. + ${c5} .//. + ${c5} .//. + EOF + ;; + + [Dd]ahlia*) + read_ascii 1 <<- EOF + ${c1} _ + ${c1} ___/ \\___ + ${c1} | _-_ | + ${c1} | / \ | + ${c1}/ | | \\ + ${c1}\\ | | / + ${c1} | \ _ _ / | + ${c1} |___ - ___| + ${c1} \\_/ + EOF + ;; + + [Dd]ebian*) + read_ascii 1 <<- EOF + ${c1} _____ + ${c1} / __ \\ + ${c1}| / | + ${c1}| \\___- + ${c1}-_ + ${c1} --_ + EOF + ;; + + [Dd]evuan*) + read_ascii 6 <<- EOF + ${c4} ..:::. + ${c4} ..-==- + ${c4} .+#: + ${c4} =@@ + ${c4} :+%@#: + ${c4}.:=+#@@%*: + ${c4}#@@@#=: + EOF + ;; + + [Dd]ragon[Ff]ly*) + read_ascii 1 <<- EOF + ,${c1}_${c7}, + ('-_${c1}|${c7}_-') + >--${c1}|${c7}--< + (_-'${c1}|${c7}'-_) + ${c1}| + ${c1}| + ${c1}| + EOF + ;; + + [Ee]lementary*) + read_ascii <<- EOF + ${c7} _______ + ${c7} / ____ \\ + ${c7}/ | / /\\ + ${c7}|__\\ / / | + ${c7}\\ /__/ / + ${c7}\\_______/ + EOF + ;; + + [Ee]ndeavour*) + read_ascii 4 <<- EOF + ${c1}/${c4}\\ + ${c1}/${c4}/ \\${c6}\\ + ${c1}/${c4}/ \\ ${c6}\\ + ${c1}/ ${c4}/ _) ${c6}) + ${c1}/_${c4}/___-- ${c6}__- + ${c6}/____-- + EOF + ;; + + [Ff]edora* | [Nn]obara*) + read_ascii 4 <<- EOF + ${c4},'''''. + ${c4}| ,. | + ${c4}| | '_' + ${c4} ,....| |.. + ${c4}.' ,_;| ..' + ${c4}| | | | + ${c4}| ',_,' | + ${c4} '. ,' + ${c4}''''' + EOF + ;; + + [Ff]ree[Bb][Ss][Dd]*) + read_ascii 1 <<- EOF + ${c1}/\\,-'''''-,/\\ + ${c1}\\_) (_/ + ${c1}| | + ${c1}| | + ${c1}; ; + ${c1}'-_____-' + EOF + ;; + + [Gg]aruda*) + read_ascii 4 <<- EOF + ${c3} _______ + ${c3} __/ \\_ + ${c3} _/ / \\_ + ${c7} _/ /_________\\ + ${c7}_/ | + ${c2}\\ ____________ + ${c2} \\_ __/ + ${c2} \\__________/ + EOF + ;; + + [Gg]entoo*) + read_ascii 5 <<- EOF + ${c5} _-----_ + ${c5}( \\ + ${c5}\\ 0 \\ + ${c7} \\ ) + ${c7} / _/ + ${c7}( _- + ${c7}\\____- + EOF + ;; + + [Gg][Nn][Uu]*) + read_ascii 3 <<- EOF + ${c2} _-\`\`-, ,-\`\`-_ + ${c2} .' _-_| |_-_ '. + ${c2}./ /_._ _._\\ \\. + ${c2}: _/_._\`:'_._\\_ : + ${c2}\\:._/ ,\` \\ \\ \\_.:/ + ${c2} ,-';'.@) \\ @) \\ + ${c2} ,'/' ..- .\\,-.| + ${c2} /'/' \\(( \\\` ./ ) + ${c2} '/'' \\_,----' + ${c2} '/'' ,;/'' + ${c2} \`\`;' + EOF + ;; + + [Gg]uix[Ss][Dd]* | [Gg]uix*) + read_ascii 3 <<- EOF + ${c3}|.__ __.| + ${c3}|__ \\ / __| + ${c3}\\ \\ / / + ${c3}\\ \\ / / + ${c3}\\ \\ / / + ${c3}\\ \\/ / + ${c3}\\__/ + EOF + ;; + + [Hh]aiku*) + read_ascii 3 <<- EOF + ${c3} ,^, + ${c3} / \\ + ${c3}*--_ ; ; _--* + ${c3}\\ '" "' / + ${c3}'. .' + ${c3}.-'" "'-. + ${c3}'-.__. .__.-' + ${c3}|_| + EOF + ;; + + [Hh]ydroOS*) + read_ascii 4 <<- EOF + ${c1}╔╗╔╗──╔╗───╔═╦══╗ + ${c1}║╚╝╠╦╦╝╠╦╦═╣║║══╣ + ${c1}║╔╗║║║╬║╔╣╬║║╠══║ + ${c1}╚╝╚╬╗╠═╩╝╚═╩═╩══╝ + ${c1}───╚═╝ + EOF + ;; + + [Hh]yperbola*) + read_ascii <<- EOF + ${c7} |\`__.\`/ + ${c7} \____/ + ${c7} .--. + ${c7} / \\ + ${c7} / ___ \\ + ${c7}/ .\` \`.\\ + ${c7}/.\` \`.\\ + EOF + ;; + + [Ii]glunix*) + read_ascii <<- EOF + ${c7} | + ${c7} | | + ${c7} | + ${c7} | ________ + ${c7} | /\\ | \\ + ${c7} / \\ | \\ | + ${c7} / \\ \\ | + ${c7} / \\________\\ + ${c7} \\ / / + ${c7} \\ / / + ${c7} \\ / / + ${c7} \\/________/ + EOF + ;; + + [Ii]nstant[Oo][Ss]*) + read_ascii <<- EOF + ${c7} ,-''-, + ${c7}: .''. : + ${c7}: ',,' : + ${c7} '-____:__ + ${c7} : \`. + ${c7} \`._.' + EOF + ;; + + [Ii][Rr][Ii][Xx]*) + read_ascii 1 <<- EOF + ${c1} __ + ${c1} \\ \\ __ + ${c1} \\ \\ / / + ${c1} \\ v / + ${c1} / . \\ + ${c1} /_/ \\ \\ + ${c1} \\_\\ + EOF + ;; + + [Kk][Dd][Ee]*[Nn]eon*) + read_ascii 6 <<- EOF + ${c7} .${c6}__${c7}.${c6}__${c7}. + ${c6} / _${c7}.${c6}_ \\ + ${c6} / / \\ \\ + ${c7} . ${c6}| ${c7}O${c6} | ${c7}. + ${c6} \\ \\_${c7}.${c6}_/ / + ${c6} \\${c7}.${c6}__${c7}.${c6}__${c7}.${c6}/ + EOF + ;; + + [Ll]inux*[Ll]ite* | [Ll]ite*) + read_ascii 3 <<- EOF + ${c3} /\\ + ${c3} / \\ + ${c3} / ${c7}/ ${c3}/ + ${c3}> ${c7}/ ${c3}/ + ${c3}\\ ${c7}\\ ${c3}\\ + ${c3}\\_${c7}\\${c3}_\\ + ${c7} \\ + EOF + ;; + + [Ll]inux*[Mm]int* | [Mm]int) + read_ascii 2 <<- EOF + ${c2} ___________ + ${c2}|_ \\ + ${c2}| ${c7}| _____ ${c2}| + ${c2}| ${c7}| | | | ${c2}| + ${c2}| ${c7}| | | | ${c2}| + ${c2}| ${c7}\\__${c7}___/ ${c2}| + ${c2}\\_________/ + EOF + ;; + + [Ll]inux*) + read_ascii 4 <<- EOF + ${c4} ___ + ${c4}(${c7}.. ${c4}| + ${c4}(${c5}<> ${c4}| + ${c4}/ ${c7}__ ${c4}\\ + ${c4}( ${c7}/ \\ ${c4}/| + ${c5}_${c4}/\\ ${c7}__)${c4}/${c5}_${c4}) + ${c5}\/${c4}-____${c5}\/ + EOF + ;; + + [Mm]ac[Oo][Ss]* | [Dd]arwin*) + read_ascii 1 <<- EOF + ${c2} .:' + ${c2} _ :'_ + ${c3} .'\`_\`-'_\`\`. + ${c1}:________.-' + ${c1}:_______: + ${c4} :_______\`-; + ${c5} \`._.-._.' + EOF + ;; + + [Mm]ageia*) + read_ascii 2 <<- EOF + ${c6} * + ${c6} * + ${c6} ** + ${c7} /\\__/\\ + ${c7}/ \\ + ${c7}\\ / + ${c7} \\____/ + EOF + ;; + + [Mm]anjaro*) + read_ascii 2 <<- EOF + ${c2}||||||||| |||| + ${c2}||||||||| |||| + ${c2}|||| |||| + ${c2}|||| |||| |||| + ${c2}|||| |||| |||| + ${c2}|||| |||| |||| + ${c2}|||| |||| |||| + EOF + ;; + + [Mm]inix*) + read_ascii 4 <<- EOF + ${c4} ,, ,, + ${c4};${c7},${c4} ', ,' ${c7},${c4}; + ${c4}; ${c7}',${c4} ',,' ${c7},'${c4} ; + ${c4}; ${c7}',${c4} ${c7},'${c4} ; + ${c4}; ${c7};, '' ,;${c4} ; + ${c4}; ${c7};${c4};${c7}',,'${c4};${c7};${c4} ; + ${c4}', ${c7};${c4};; ;;${c7};${c4} ,' + ${c4} '${c7};${c4}' '${c7};${c4}' + EOF + ;; + + [Mm][Xx]*) + read_ascii <<- EOF + ${c7} \\\\ / + ${c7} \\\\/ + ${c7} \\\\ + ${c7} /\\/ \\\\ + ${c7} / \\ /\\ + ${c7} / \\/ \\ + ${c7}/__________\\ + EOF + ;; + + [Nn]et[Bb][Ss][Dd]*) + read_ascii 3 <<- EOF + ${c7}\\\\${c3}\`-______,----__ + ${c7} \\\\ ${c3}__,---\`_ + ${c7} \\\\ ${c3}\`.____ + ${c7} \\\\${c3}-______,----\`- + ${c7} \\\\ + ${c7} \\\\ + ${c7} \\\\ + EOF + ;; + + [Nn]ix[Oo][Ss]*) + read_ascii 4 <<- EOF + ${c4} \\\\ \\\\ // + ${c4} ==\\\\__\\\\/ // + ${c4} // \\\\// + ${c4}==// //== + ${c4} //\\\\___// + ${c4}// /\\\\ \\\\== + ${c4} // \\\\ \\\\ + EOF + ;; + + [Oo]pen[Bb][Ss][Dd]*) + read_ascii 3 <<- EOF + ${c3} _____ + ${c3} \\- -/ + ${c3} \\_/ \\ + ${c3} | ${c7}O O${c3} | + ${c3} |_ < ) 3 ) + ${c3} / \\ / + ${c3} /-_____-\\ + EOF + ;; + + [Oo]pen[Ss][Uu][Ss][Ee]*[Tt]umbleweed*) + read_ascii 2 <<- EOF + ${c2} _____ ______ + ${c2} / ____\\ / ____ \\ + ${c2}/ / \`/ / \\ \\ + ${c2}\\ \\____/ /,____/ / + ${c2} \\______/ \\_____/ + EOF + ;; + + [Oo]pen[Ss][Uu][Ss][Ee]* | [Oo]pen*SUSE* | SUSE* | suse*) + read_ascii 2 <<- EOF + ${c2} _______ + ${c2}__| __ \\ + ${c2} / .\\ \\ + ${c2} \\__/ | + ${c2} _______| + ${c2} \\_______ + ${c2}__________/ + EOF + ;; + + [Oo]pen[Ww]rt*) + read_ascii 1 <<- EOF + ${c1} _______ + ${c1}| |.-----.-----.-----. + ${c1}| - || _ | -__| | + ${c1}|_______|| __|_____|__|__| + ${c1} ________|__| __ + ${c1}| | | |.----.| |_ + ${c1}| | | || _|| _| + ${c1}|________||__| |____| + EOF + ;; + + [Pp]arabola*) + read_ascii 5 <<- EOF + ${c5} __ __ __ _ + ${c5}.\`_//_//_/ / \`. + ${c5} / .\` + ${c5} / .\` + ${c5} /.\` + ${c5} /\` + EOF + ;; + + [Pp]op!_[Oo][Ss]*) + read_ascii 6 <<- EOF + ${c6} .///////, + ${c6} //${c7}76767${c6}////// + ${c6} //${c7}76${c6}//${c7}76${c6}//${c7}767${c6}// + ${c6} ////${c7}7676'${c6}//${c7}76${c6}//// + ${c6} /////${c7}76${c6}////${c7}7${c6}///// + ${c6} /////${c7}76${c6}//${c7}76${c6}//// + ${c6} ///${c7}76767676${c6}// + ${c6} \`///////' + EOF + ;; + + [Pp]ure[Oo][Ss]*) + read_ascii <<- EOF + ${c7} _____________ + ${c7}| _________ | + ${c7}| | | | + ${c7}| | | | + ${c7}| |_________| | + ${c7}|_____________| + EOF + ;; + + [Rr]aspbian*) + read_ascii 1 <<- EOF + ${c2} __ __ + ${c2} (_\\)(/_) + ${c1} (_(__)_) + ${c1}(_(_)(_)_) + ${c1} (_(__)_) + ${c1} (__) + EOF + ;; + + [Ss]erenity[Oo][Ss]*) + read_ascii 4 <<- EOF + ${c7} _____ + ${c1} ,-${c7} -, + ${c1} ;${c7} ( ; + ${c1}| ${c7}. \_${c1}.,${c7} | + ${c1}| ${c7}o _${c1} ',${c7} | + ${c1} ; ${c7}(_)${c1} )${c7} ; + ${c1} '-_____-${c7}' + EOF + ;; + + [Ss]lackware*) + read_ascii 4 <<- EOF + ${c4} ________ + ${c4} / ______| + ${c4} | |______ + ${c4} \\______ \\ + ${c4} ______| | + ${c4}| |________/ + ${c4}|____________ + EOF + ;; + + [Ss]olus*) + read_ascii 4 <<- EOF + ${c6} + ${c6} /| + ${c6} / |\\ + ${c6} / | \\ _ + ${c6} /___|__\\_\\ + ${c6} \\ / + ${c6} \`-------´ + EOF + ;; + + [Ss]un[Oo][Ss] | [Ss]olaris*) + read_ascii 3 <<- EOF + ${c3} . .; . + ${c3} . :; :: ;: . + ${c3} .;. .. .. .;. + ${c3}.. .. .. .. + ${c3} .;, ,;. + EOF + ;; + + [Uu]buntu*) + read_ascii 3 <<- EOF + ${c3} _ + ${c3} ---(_) + ${c3} _/ --- \\ + ${c3}(_) | | + ${c3} \\ --- _/ + ${c3} ---(_) + EOF + ;; + + [Vv]oid*) + read_ascii 2 <<- EOF + ${c2} _______ + ${c2} _ \\______ - + ${c2}| \\ ___ \\ | + ${c2}| | / \ | | + ${c2}| | \___/ | | + ${c2}| \\______ \\_| + ${c2} -_______\\ + EOF + ;; + + [Xx]eonix*) + read_ascii 2 <<- EOF + ${c2} ___ ___ + ${c2}___ \ \/ / ___ + ${c2}\ \ \ / / / + ${c2} \ \/ \/ / + ${c2} \ /\ / + ${c2} \__/ \__/ + EOF + ;; + [Ff]iwix*) + read_ascii 12 <<- EOF + ${c6}_____ ${c4}_____ + ${c6}\\ \\ ${c4}\\ \\ + ${c6}\\ \\ ${c4}\\ \\ + ${c6}/ \\ \\ ${c4}\\ \\ + ${c6}( \\ \\ ${c4}\\ \\ + ${c6}( / / ${c4}/ / + ${c6}\\ / / ${c4}/ / + ${c6}/ / ${c4}/ / + ${c6}/____/ ${c4}/____/ + EOF + ;; + [Mm]orphOS*) + read_ascii 1 <<- EOF + ${c4} __ \/ __ + ${c4} /o \{}/ o\\ + ${c4} \ () / + ${c4} \`> /\ <\` + ${c4} (o/\/\o) + ${c4} ) ( + EOF + ;; + [Aa]mog[Oo][Ss]*) + read_ascii 4 <<- EOF + ${c7} -///:. + ${c7} smhhhhmh\` + ${c7} :NA${c4}mogO${c7}SNs + ${c7} hNNmmmmNNN + ${c7} NNNNNNNNNN + ${c7} :NNNNNNNNNN + ${c7} mNNssussNNN + ${c7} sNn: sNNo + ${c7}+ooo+ sNNo + ${c7} +oooo\` + EOF + ;; +esac diff --git a/pfetch-extractor/src/lib.rs b/pfetch-extractor/src/lib.rs new file mode 100644 index 0000000..219323d --- /dev/null +++ b/pfetch-extractor/src/lib.rs @@ -0,0 +1,105 @@ +use proc_macro::TokenStream; +use quote::quote; +use regex::Regex; + +#[proc_macro] +pub fn parse_logos(_input: TokenStream) -> TokenStream { + let raw_logos = include_str!("../logos.sh"); + let raw_logos = raw_logos + .split_once("in\n") + .expect("Invalid logos.sh file") + .1; + let raw_logos = raw_logos + .split_once("\nesac") + .expect("Invalid logos.sh file") + .0; + + let mut tux = None; + let logos = raw_logos + .split(";;\n") + .filter_map(|raw_logo| { + let (is_tux, logo) = parse_logo(raw_logo)?; + if is_tux { + tux = Some(logo.clone()); + } + Some(logo) + }) + .collect::>(); + + let tux = tux.unwrap(); + + quote! { (#tux, [#(#logos),*]) }.into() +} + +fn parse_logo(input: &str) -> Option<(bool, proc_macro2::TokenStream)> { + let input = input.trim().replace('\t', ""); + if input.is_empty() { + return None; + } + let regex = Regex::new(r"^\(?(.*)\)[\s\S]*read_ascii *(\d)? *(\d)?").unwrap(); + + let groups = regex + .captures(&input) + .expect("Error while parsing logos.sh"); + + let pattern = &groups[1]; + let primary_color = match groups.get(2) { + Some(color) => color.as_str().parse::().unwrap(), + None => 7, + }; + let secondary_color = match groups.get(3) { + Some(color) => color.as_str().parse::().unwrap(), + None => (primary_color + 1) % 8, + }; + + let logo = input + .split_once("EOF\n") + .expect("Could not find start of logo") + .1 + .split_once("\nEOF") + .expect("Could not find end of logo") + .0; + + let mut logo_parts = vec![]; + for logo_part in logo.split("${") { + if let Some((new_color, rest)) = logo_part.split_once('}') { + let new_color: u8 = match new_color { + "c0" => 0, + "c1" => 1, + "c2" => 2, + "c3" => 3, + "c4" => 4, + "c5" => 5, + "c6" => 6, + "c7" => 7, + _ => panic!("Unknown color: {new_color}"), + }; + let rest = rest.replace("\\\\", "\\"); + let rest = rest.replace("\\`", "`"); + let lines = rest.split('\n').collect::>(); + let last_index = lines.len() - 1; + for (index, line) in lines.into_iter().enumerate() { + let mut line = line.to_owned(); + if index != last_index { + line += "\n"; + } + logo_parts.push(quote! { (Color(#new_color), #line) }); + } + } else if !logo_part.is_empty() { + let logo_part = logo_part.replace("\\\\", "\\"); + logo_parts.push(quote! { (Color(9), #logo_part) }); + } + } + + Some(( + pattern == "[Ll]inux*", + quote! { + Logo { + primary_color: Color(#primary_color), + secondary_color: Color(#secondary_color), + pattern: #pattern, + logo_parts: &[#(#logo_parts),*], + } + }, + )) +} diff --git a/print_all.sh b/print_all.sh new file mode 100755 index 0000000..30e68e5 --- /dev/null +++ b/print_all.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# A small script to run pfetch (command specified with arguments) with all available logos + +while read -r logo; do + PF_ASCII=$logo "$@" +done << EOF +alpine +android +arch +arco +artix +bedrock +buildroot +celos +centos +crystallinux +dahlia +debian +devuan +dragonfly +elementary +endeavour +fedora +freebsd +garuda +gentoo +gnu +guix +haiku +hydroOS +hyperbola +iglunix +instantos +irix +kdeneon +linuxlite +linuxmint +linux +macos +mageia +manjaro +minix +mx +netbsd +nixos +openbsd +opensusetumbleweed +opensuse +openwrt +parabola +pop!_os +pureos +raspbian +serenityos +slackware +solus +solaris +ubuntu +void +xeonix +fiwix +morphos +amogos +aperio +EOF diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..e0212a0 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,440 @@ +use std::{env, fmt::Display, fs, io::Result, process::Command, str::FromStr}; + +use glob::glob; +use globset::Glob; +use libmacchina::{ + traits::GeneralReadout as _, traits::KernelReadout as _, traits::MemoryReadout as _, + traits::PackageReadout as _, GeneralReadout, KernelReadout, MemoryReadout, PackageReadout, +}; +use pfetch_extractor::parse_logos; + +#[derive(Clone, Copy)] +pub struct Color(pub u8); + +impl Display for Color { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "\x1b[3{}m", self.0) + } +} + +impl FromStr for Color { + type Err = String; + + fn from_str(s: &str) -> std::result::Result { + match s.parse::() { + Ok(color) => { + if color >= 9 { + Err(format!("Invalid color: {color}")) + } else { + Ok(Color(color)) + } + } + Err(_) => Err(format!("Not a valid color: {s}")), + } + } +} + +pub struct Logo { + pub primary_color: Color, + pub secondary_color: Color, + pub pattern: &'static str, + pub logo_parts: &'static [(Color, &'static str)], +} + +impl Display for Logo { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + self.logo_parts + .iter() + .map(|(color, part)| format!("{color}{part}")) + .collect::() + ) + } +} + +#[derive(Debug)] +pub enum PackageManager { + Pacman, + Dpkg, + Xbps, + Apk, + Rpm, + Flatpak, + Crux, + Guix, + Opkg, + Kiss, + Portage, + Pkgtool, + Nix, +} + +/// Obtain the amount of installed packages on the system by checking all installed supported package +/// managers and adding the amounts +pub fn total_packages(package_readout: &PackageReadout) -> usize { + match env::consts::OS { + "linux" => { + let macchina_package_count: Vec<(String, usize)> = package_readout + .count_pkgs() + .iter() + .map(|(macchina_manager, count)| (macchina_manager.to_string(), *count)) + .collect(); + [ + PackageManager::Pacman, + PackageManager::Dpkg, + PackageManager::Xbps, + PackageManager::Apk, + PackageManager::Rpm, + PackageManager::Flatpak, + PackageManager::Crux, + PackageManager::Guix, + PackageManager::Opkg, + PackageManager::Kiss, + PackageManager::Portage, + PackageManager::Pkgtool, + PackageManager::Nix, + ] + .iter() + .map(|mngr| packages(mngr, &macchina_package_count)) + .sum() + } + "macos" => { + // pkgin + run_and_count_lines("pkgin", &["list"]) + // dpkg + + run_and_count_lines("dpkg-query", &["-f", "'.\n'", "-W"]) + // brew + + if check_if_command_exists("brew") { + match glob("/usr/local/Cellar/*") { + Ok(files) => files.count(), + Err(_) => 0, + } + } else { + 0 + } + // port + + match run_system_command("port", &["installed"]) { + Ok(output) => { + // port prints a single line to stdout when no packages are installed + if output == "No ports are installed." { + 0 + } else { + output.lines().count() + } + }, + Err(_) => 0, + } + } + "freebsd" | "dragonfly" => run_and_count_lines("pkg", &["info"]), + "openbsd" => match glob("/var/db/pkg/*/") { + Ok(files) => files.count(), + Err(_) => 0, + }, + "netbsd" => run_and_count_lines("pkg_info", &[]), + "solaris" => { + run_and_count_lines("pkginfo", &["-i"]) + run_and_count_lines("pkg", &["list"]) + } + _ => 0, + } +} + +fn get_macchina_package_count( + macchina_result: &[(String, usize)], + package_manager_name: &str, +) -> Option { + macchina_result + .iter() + .find(|entry| entry.0 == package_manager_name) + .map(|entry| entry.1) +} + +/// return the amount of packages installed with a given linux package manager +/// Return `0` if the package manager is not installed +fn packages(pkg_manager: &PackageManager, macchina_package_count: &[(String, usize)]) -> usize { + match pkg_manager { + // libmacchina has very fast implementations for most package managers, so we use them + // where we can, otherwise we fall back to method used by dylans version of pfetch + PackageManager::Pacman + | PackageManager::Flatpak + | PackageManager::Dpkg + | PackageManager::Xbps + | PackageManager::Apk + | PackageManager::Rpm + | PackageManager::Portage + | PackageManager::Opkg => get_macchina_package_count( + macchina_package_count, + &format!("{pkg_manager:?}").to_lowercase(), + ) + .unwrap_or(0), + PackageManager::Guix => run_and_count_lines("guix", &["package", "--list-installed"]), + PackageManager::Crux => { + if check_if_command_exists("crux") { + run_and_count_lines("pkginfo", &["-i"]) + } else { + 0 + } + } + PackageManager::Kiss => { + if check_if_command_exists("kiss") { + match glob("/var/db/kiss/installed/*/") { + Ok(files) => files.count(), + Err(_) => 0, + } + } else { + 0 + } + } + PackageManager::Pkgtool => { + if check_if_command_exists("pkgtool") { + match glob("/var/log/packages/*") { + Ok(files) => files.count(), + Err(_) => 0, + } + } else { + 0 + } + } + // TODO: nix -q is very slow + PackageManager::Nix => { + if check_if_command_exists("nix-store") { + run_and_count_lines( + "nix-store", + &["-q", "--requisites", "/run/current-system/sw"], + ) + run_and_count_lines( + "nix-store", + &[ + "-q", + "--requisites", + &format!("{}/.nix-profile", env::var("HOME").unwrap_or_default()), + ], + ) + } else { + 0 + } + } + } +} + +pub fn user_at_hostname( + general_readout: &GeneralReadout, + username_override: &Option, + hostname_override: &Option, +) -> Option { + let username = match username_override { + Some(username) => Ok(username.to_string()), + None => general_readout.username(), + }; + let hostname = match hostname_override { + Some(hostname) => Ok(hostname.to_string()), + None => general_readout.hostname(), + }; + if username.is_err() || hostname.is_err() { + None + } else { + Some(format!( + "{}@{}", + username.unwrap_or_default(), + hostname.unwrap_or_default() + )) + } +} + +pub fn memory(memory_readout: &MemoryReadout) -> Option { + let total_memory = memory_readout.total(); + let used_memory = memory_readout.used(); + if total_memory.is_err() || used_memory.is_err() { + None + } else { + Some(format!( + "{}M / {}M", + used_memory.unwrap() / 1024, + total_memory.unwrap() / 1024 + )) + } +} + +pub fn os(general_readout: &GeneralReadout) -> Option { + match general_readout.distribution() { + Ok(distribution) => Some(distribution), + Err(_) => None, + } +} + +pub fn kernel(kernel_readout: &KernelReadout) -> Option { + match kernel_readout.os_release() { + Ok(kernel_version) => Some(kernel_version), + Err(_) => None, + } +} + +fn seconds_to_string(time: usize) -> String { + let days = if time > 86400 { + let days_pre = time / 60 / 60 / 24; + days_pre.to_string() + "d" + } else { + "".to_string() + }; + let hours = if time > 3600 { + let hours_pre = (time / 60 / 60) % 24; + hours_pre.to_string() + "h" + } else { + "".to_string() + }; + let minutes = if time > 60 { + let minutes_pre = (time / 60) % 60; + minutes_pre.to_string() + "m" + } else { + "0m".to_string() + }; + format!("{days} {hours} {minutes}").trim_start().to_owned() +} + +pub fn uptime(general_readout: &GeneralReadout) -> Option { + match general_readout.uptime() { + Ok(uptime) => Some(seconds_to_string(uptime)), + Err(_) => None, + } +} + +pub fn host() -> Option { + const BLACKLIST: &[&str] = &[ + "To", + "Be", + "be", + "Filled", + "filled", + "By", + "by", + "O.E.M.", + "OEM", + "Not", + "Applicable", + "Specified", + "System", + "Product", + "Name", + "Version", + "Undefined", + "Default", + "string", + "INVALID", + "�", + "os", + "Type1ProductConfigId", + "", + ]; + + // get device from system files + let product_name = + fs::read_to_string("/sys/devices/virtual/dmi/id/product_name").unwrap_or_default(); + let product_name = product_name.trim(); + let product_version = + fs::read_to_string("/sys/devices/virtual/dmi/id/product_version").unwrap_or_default(); + let product_version = product_version.trim(); + let product_model = + fs::read_to_string("/sys/firmware/devicetree/base/model").unwrap_or_default(); + let product_model = product_model.trim(); + + let final_str = format!("{product_name} {product_version} {product_model}") + .split(' ') + .filter(|word| !BLACKLIST.contains(word)) + .collect::>() + .join(" "); + + // if string is empty, display system architecture instead + let final_str = if final_str.is_empty() { + run_system_command("uname", &["-m"]).unwrap_or("Unknown".to_owned()) + } else { + final_str + }; + if final_str.is_empty() { + None + } else { + Some(final_str) + } +} + +pub fn logo(logo_name: &str) -> Logo { + let (tux, logos) = parse_logos!(); + logos + .into_iter() + .find(|logo| { + logo.pattern.split('|').any(|glob| { + Glob::new(glob.trim()) + .expect("Invalid logo pattern") + .compile_matcher() + .is_match(logo_name) + }) + }) + .unwrap_or(tux) +} + +pub fn shell(general_readout: &GeneralReadout) -> Option { + match general_readout.shell( + libmacchina::traits::ShellFormat::Relative, + libmacchina::traits::ShellKind::Default, + ) { + Ok(shell) => Some(shell), + Err(_) => None, + } +} + +pub fn editor() -> Option { + match env::var("VISUAL") { + Ok(editor) => Some(editor.trim().to_owned()), + Err(_) => match env::var("EDITOR") { + Ok(editor) => Some(editor.trim().to_owned()), + Err(_) => None, + }, + } +} + +pub fn wm(general_readout: &GeneralReadout) -> Option { + match general_readout.window_manager() { + Ok(wm) => Some(wm), + Err(_) => None, + } +} + +pub fn de(general_readout: &GeneralReadout) -> Option { + match general_readout.desktop_environment() { + Ok(de) => Some(de), + Err(_) => None, + } +} + +pub fn palette() -> String { + (1..7) + .map(|num| format!("\x1b[4{num}m ")) + .collect::() + + "\x1b[0m" +} + +fn run_system_command(command: &str, args: &[&str]) -> Result { + let mut output = + String::from_utf8_lossy(&Command::new(command).args(args).output()?.stdout).into_owned(); + output.truncate(output.trim_end().len()); + Ok(output) +} + +fn check_if_command_exists(command: &str) -> bool { + which::which(command).is_ok() +} + +fn _system_command_error(command: &str, args: &[&str]) -> Result { + let mut output = + String::from_utf8_lossy(&Command::new(command).args(args).output()?.stderr).into_owned(); + output.truncate(output.trim_end().len()); + Ok(output) +} + +/// Return the amount of line the output of a system command produces +/// Returns `0` if command fails +fn run_and_count_lines(command: &str, args: &[&str]) -> usize { + run_system_command(command, args) + .unwrap_or_default() + .lines() + .count() +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..741449e --- /dev/null +++ b/src/main.rs @@ -0,0 +1,284 @@ +use libmacchina::{ + traits::GeneralReadout as _, traits::KernelReadout as _, traits::MemoryReadout as _, + traits::PackageReadout as _, GeneralReadout, KernelReadout, MemoryReadout, PackageReadout, +}; +use std::{env, fmt::Display, str::FromStr}; + +#[derive(Debug, PartialEq)] +enum PfetchInfo { + Ascii, + Title, + Os, + Host, + Kernel, + Uptime, + Pkgs, + Memory, + Shell, + Editor, + Wm, + De, + Palette, + BlankLine, +} + +impl Display for PfetchInfo { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", format!("{self:?}").to_lowercase()) + } +} + +impl FromStr for PfetchInfo { + type Err = String; + + fn from_str(info: &str) -> Result { + match info { + "ascii" => Ok(PfetchInfo::Ascii), + "title" => Ok(PfetchInfo::Title), + "os" => Ok(PfetchInfo::Os), + "host" => Ok(PfetchInfo::Host), + "kernel" => Ok(PfetchInfo::Kernel), + "uptime" => Ok(PfetchInfo::Uptime), + "pkgs" => Ok(PfetchInfo::Pkgs), + "memory" => Ok(PfetchInfo::Memory), + "shell" => Ok(PfetchInfo::Shell), + "editor" => Ok(PfetchInfo::Editor), + "wm" => Ok(PfetchInfo::Wm), + "de" => Ok(PfetchInfo::De), + "palette" => Ok(PfetchInfo::Palette), + unknown_info => Err(format!("Unknown pfetch info: {unknown_info}")), + } + } +} + +fn pfetch(info: Vec<(pfetch::Color, String, String)>, logo: pfetch::Logo, logo_enabled: bool) { + let raw_logo = if logo_enabled { + logo.logo_parts + .iter() + .map(|(_, part)| *part) + .collect::() + } else { + "".to_string() + }; + let logo = logo.to_string(); + let mut logo_lines = logo.lines(); + let raw_logo_lines: Vec<_> = raw_logo.lines().collect(); + let logo_width = raw_logo_lines + .iter() + .map(|line| line.chars().count()) + .max() + .unwrap_or(0); + let line_amount = usize::max(raw_logo_lines.len(), info.len()); + + let info1_width = info + .iter() + .skip(1) + .map(|(_, line, _)| { + if line.starts_with("\x1b[4") { + 0 + } else { + line.len() + } + }) + .max() + .unwrap_or(0); + + let padding1 = match dotenv::var("PF_PAD1") { + Ok(padding0) => padding0.parse::().unwrap_or(0), + Err(_) => 0, + }; + let padding2 = match dotenv::var("PF_PAD2") { + Ok(padding1) => padding1.parse::().unwrap_or(0), + Err(_) => 3, + }; + let padding3 = match dotenv::var("PF_PAD3") { + Ok(padding2) => padding2.parse::().unwrap_or(0), + Err(_) => 1, + }; + + let mut pfetch_str = String::new(); + + for l in 0..line_amount { + pfetch_str += &format!( + "{padding1}\x1b[1m{logo}{padding2}{color}{info1}\x1b[0m{separator}{padding3}{color2}{info2}\n", + padding1 = " ".repeat(padding1), + logo = if logo_enabled { + logo_lines.next().unwrap_or("") + } else { + "" + }, + padding2 = " ".repeat( + logo_width - raw_logo_lines.get(l).map_or(0, |line| line.chars().count()) + + if logo_enabled { padding2 } else { 0 } + ), + color = info.get(l).map_or("".to_owned(), |line| line.0.to_string()), + info1 = info.get(l).map_or("", |line| &line.1), + separator = info.get(l).map_or("".to_string(), |line| + if ! &line.2.is_empty() { + dotenv::var("PF_SEP").unwrap_or_default() + } else { "".to_string() } + ), + padding3 = " ".repeat( + info1_width.saturating_sub(info.get(l).map_or(0, |(_, line, _)| line.len())) + + padding3 + ), + color2 = match dotenv::var("PF_COL2") { + Ok(newcolor) => { + match pfetch::Color::from_str(&newcolor) { + Ok(newcolor) => format!("{newcolor}"), + Err(_) => "".to_string(), + } + }, + Err(_) => "".to_string() + }, + info2 = info.get(l).map_or("", |line| &line.2) + ) + } + + // if colors are disabled, remove them from string + if dotenv::var("PF_COLOR").unwrap_or_default() == "0" { + pfetch_str = pfetch_str + .split("\x1b[") + .map(|chunk| chunk.chars().skip(3).collect::()) + .collect(); + } + println!("{pfetch_str}"); +} + +struct Readouts { + general_readout: GeneralReadout, + package_readout: PackageReadout, + memory_readout: MemoryReadout, + kernel_readout: KernelReadout, +} + +fn get_info(info: &PfetchInfo, readouts: &Readouts) -> Option { + match info { + PfetchInfo::Ascii => None, + PfetchInfo::Title => { + let hostname_override = match dotenv::var("HOSTNAME") { + Ok(hostname) => Some(hostname), + Err(_) => None, + }; + let username_override = match dotenv::var("USER") { + Ok(username) => Some(username), + Err(_) => None, + }; + pfetch::user_at_hostname( + &readouts.general_readout, + &username_override, + &hostname_override, + ) + } + PfetchInfo::Os => pfetch::os(&readouts.general_readout), + PfetchInfo::Host => pfetch::host(), + PfetchInfo::Kernel => pfetch::kernel(&readouts.kernel_readout), + PfetchInfo::Uptime => pfetch::uptime(&readouts.general_readout), + PfetchInfo::Pkgs => Some(pfetch::total_packages(&readouts.package_readout).to_string()), + PfetchInfo::Memory => pfetch::memory(&readouts.memory_readout), + PfetchInfo::Shell => match dotenv::var("SHELL") { + Ok(shell) => Some(shell), + Err(_) => pfetch::shell(&readouts.general_readout), + }, + PfetchInfo::Editor => match dotenv::var("EDITOR") { + Ok(editor) => Some(editor), + Err(_) => pfetch::editor(), + }, + PfetchInfo::Wm => pfetch::wm(&readouts.general_readout), + PfetchInfo::De => match dotenv::var("XDG_CURRENT_DESKTOP") { + Ok(de) => Some(de), + Err(_) => pfetch::de(&readouts.general_readout), + }, + PfetchInfo::Palette => Some(pfetch::palette()), + PfetchInfo::BlankLine => Some("".to_string()), + } +} + +fn main() { + // source file specified by env: PF_SOURCE + if let Ok(filepath) = dotenv::var("PF_SOURCE") { + dotenv::from_path(filepath).unwrap(); + } + + let enabled_pf_info_base: Vec = match dotenv::var("PF_INFO") { + Ok(pfetch_infos) => pfetch_infos + .trim() + .split(' ') + .map(|info| PfetchInfo::from_str(info).unwrap()) + .collect(), + Err(_) => vec![ + PfetchInfo::Ascii, + PfetchInfo::Title, + PfetchInfo::Os, + PfetchInfo::Host, + PfetchInfo::Kernel, + PfetchInfo::Uptime, + PfetchInfo::Pkgs, + PfetchInfo::Memory, + ], + }; + + // insert blank lines before and after palettes + let mut enabled_pf_info: Vec = vec![]; + let mut ascii_enabled: bool = false; + for info in enabled_pf_info_base { + match info { + PfetchInfo::Palette => { + enabled_pf_info.push(PfetchInfo::BlankLine); + enabled_pf_info.push(PfetchInfo::Palette); + enabled_pf_info.push(PfetchInfo::BlankLine); + } + PfetchInfo::Ascii => { + ascii_enabled = true; + } + i => enabled_pf_info.push(i), + } + } + + let readouts = Readouts { + general_readout: GeneralReadout::new(), + package_readout: PackageReadout::new(), + memory_readout: MemoryReadout::new(), + kernel_readout: KernelReadout::new(), + }; + + let os = get_info(&PfetchInfo::Os, &readouts).unwrap_or_default(); + + let logo_override = env::var("PF_ASCII"); + let logo_name = logo_override.as_ref().unwrap_or(&os); + let mut logo = pfetch::logo(logo_name); + + // color overrides + if let Ok(newcolor) = dotenv::var("PF_COL1") { + if let Ok(newcolor) = pfetch::Color::from_str(&newcolor) { + logo.primary_color = newcolor; + } + } + + if let Ok(newcolor) = dotenv::var("PF_COL3") { + if let Ok(newcolor) = pfetch::Color::from_str(&newcolor) { + logo.secondary_color = newcolor; + } + } + + let gathered_pfetch_info: Vec<(pfetch::Color, String, String)> = enabled_pf_info + .iter() + .filter_map(|info| { + let info_result = get_info(info, &readouts); + match info_result { + Some(info_str) => match info { + PfetchInfo::Title => Some((logo.secondary_color, info_str, "".to_string())), + PfetchInfo::Os => Some((logo.primary_color, info.to_string(), os.to_owned())), + PfetchInfo::BlankLine => { + Some((logo.primary_color, "".to_string(), "".to_string())) + } + PfetchInfo::Palette => Some((logo.primary_color, info_str, "".to_string())), + _ => Some((logo.primary_color, info.to_string(), info_str)), + }, + None => None, + } + }) + .collect(); + + pfetch(gathered_pfetch_info, logo, ascii_enabled); +}