From c941d2bdff9195a303b21302c529aa008fd7c186 Mon Sep 17 00:00:00 2001 From: Snehit Sah Date: Wed, 1 May 2024 19:17:41 +0530 Subject: [PATCH 1/3] crab in different function Signed-off-by: Snehit Sah --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index aa0ec53..c68e35e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,11 @@ use ansi_term::Color::Red; use sysinfo::{ComponentExt, ProcessorExt, System, SystemExt}; use termion::{cursor::DetectCursorPos, raw::IntoRawMode}; + +fn print_crab() { + println!("{}",Red.paint(" /\\\r\n ( / @ @ ()\r\n \\ __| |__ /\r\n -/ \" \\-\r\n /-| |-\\\r\n / /-\\ /-\\ \\\r\n / /-`---\'-\\ \\\r\n / \\\r\n") ); +} + fn main() { println!(" "); let left_pad = 25; @@ -8,7 +13,7 @@ fn main() { let mut sys = System::new_all(); sys.refresh_all(); - println!("{}",Red.paint(" /\\\r\n ( / @ @ ()\r\n \\ __| |__ /\r\n -/ \" \\-\r\n /-| |-\\\r\n / /-\\ /-\\ \\\r\n / /-`---\'-\\ \\\r\n / \\\r\n") ); + print_crab(); let mut cursor_row = stdout.cursor_pos().unwrap().1; cursor_row = cursor_row - 9; From 9e7c6ff9b302b15ed7f440bd4b4139d3002980f3 Mon Sep 17 00:00:00 2001 From: Snehit Sah Date: Thu, 2 May 2024 18:48:34 +0530 Subject: [PATCH 2/3] labels are customizable (can use emojis now) Signed-off-by: Snehit Sah --- Cargo.lock | 385 +++++++++++++++++++++++++++++++++++++++++----------- Cargo.toml | 2 + src/main.rs | 153 ++++++++++++++++++--- 3 files changed, 442 insertions(+), 98 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e44d562..04b4933 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,16 +12,16 @@ dependencies = [ ] [[package]] -name = "autocfg" -version = "1.0.1" +name = "bitflags" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "1.2.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "cfg-if" @@ -29,118 +29,149 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "confy" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45b1f4c00870f07dc34adcac82bb6a72cc5aabca8536ba1797e01df51d2ce9a0" +dependencies = [ + "directories", + "serde", + "thiserror", + "toml", +] + [[package]] name = "core-foundation-sys" -version = "0.8.2" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "crabfetch" version = "0.1.0" dependencies = [ "ansi_term", + "confy", + "serde", "sysinfo", "termion", ] [[package]] -name = "crossbeam-channel" -version = "0.5.1" +name = "crossbeam-deque" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", + "crossbeam-epoch", "crossbeam-utils", ] [[package]] -name = "crossbeam-deque" -version = "0.8.1" +name = "crossbeam-epoch" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "cfg-if", - "crossbeam-epoch", "crossbeam-utils", ] [[package]] -name = "crossbeam-epoch" -version = "0.9.5" +name = "crossbeam-utils" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + +[[package]] +name = "directories" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35" dependencies = [ - "cfg-if", - "crossbeam-utils", - "lazy_static", - "memoffset", - "scopeguard", + "dirs-sys", ] [[package]] -name = "crossbeam-utils" -version = "0.8.5" +name = "dirs-sys" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" dependencies = [ - "cfg-if", - "lazy_static", + "libc", + "option-ext", + "redox_users", + "windows-sys", ] [[package]] name = "either" -version = "1.6.1" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" + +[[package]] +name = "equivalent" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] -name = "hermit-abi" -version = "0.1.19" +name = "getrandom" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" dependencies = [ + "cfg-if", "libc", + "wasi", ] [[package]] -name = "lazy_static" -version = "1.4.0" +name = "hashbrown" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", +] [[package]] name = "libc" -version = "0.2.99" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] -name = "memoffset" -version = "0.6.4" +name = "libredox" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "autocfg", + "bitflags 2.5.0", + "libc", ] [[package]] -name = "ntapi" -version = "0.3.6" +name = "memchr" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" -dependencies = [ - "winapi", -] +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] -name = "num_cpus" -version = "1.13.0" +name = "ntapi" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" dependencies = [ - "hermit-abi", - "libc", + "winapi", ] [[package]] @@ -151,64 +182,125 @@ checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" [[package]] name = "once_cell" -version = "1.8.0" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] +name = "proc-macro2" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] [[package]] name = "rayon" -version = "1.5.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ - "autocfg", - "crossbeam-deque", "either", "rayon-core", ] [[package]] name = "rayon-core" -version = "1.9.1" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "lazy_static", - "num_cpus", ] [[package]] name = "redox_syscall" -version = "0.2.10" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] name = "redox_termios" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" +checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb" + +[[package]] +name = "redox_users" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" dependencies = [ - "redox_syscall", + "getrandom", + "libredox", + "thiserror", +] + +[[package]] +name = "serde" +version = "1.0.200" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.200" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", ] [[package]] -name = "scopeguard" -version = "1.1.0" +name = "syn" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] name = "sysinfo" -version = "0.20.0" +version = "0.20.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0af066e6272f2175c1783cfc2ebf3e2d8dfe2c182b00677fdeccbf8291af83fb" +checksum = "e223c65cd36b485a34c2ce6e38efa40777d31c4166d9076030c74cdcf971679f" dependencies = [ "cfg-if", "core-foundation-sys", @@ -231,6 +323,72 @@ dependencies = [ "redox_termios", ] +[[package]] +name = "thiserror" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "toml" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "winapi" version = "0.3.9" @@ -252,3 +410,78 @@ 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-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "winnow" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml index 65413b5..33b0a64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,5 @@ exclude = ["/.github"] sysinfo = "0.20.0" ansi_term = "0.12.1" termion = "1.5.6" +confy = "0.6.1" +serde = { version = "1.0.152", features = ["derive"] } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index c68e35e..ef097d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,103 @@ use ansi_term::Color::Red; +use confy; +use serde::{Deserialize, Serialize}; use sysinfo::{ComponentExt, ProcessorExt, System, SystemExt}; use termion::{cursor::DetectCursorPos, raw::IntoRawMode}; +#[derive(Serialize, Deserialize)] +enum Module { + OS, + Kernel, + Host, + CPU, + Cores, + Usage, + Temp, + Mem, + Swap, +} + +#[derive(Serialize, Deserialize)] +struct CustomParameters { + os: Option, + kernel: Option, + host: Option, + cpu: Option, + cores: Option, + usage: Option, + temp: Option, + mem: Option, + swap: Option, +} + +#[derive(Serialize, Deserialize)] +struct CustomLabels { + os: String, + kernel: String, + host: String, + cpu: String, + cores: String, + usage: String, + temp: String, + mem: String, + swap: String, +} + +#[derive(Serialize, Deserialize)] + +struct Config { + modules: Vec, + custom_parameters: CustomParameters, + custom_labels: CustomLabels, +} + +impl ::std::default::Default for Config { + fn default() -> Self { + Self { + modules: vec![ + Module::OS, + Module::Kernel, + Module::Host, + Module::CPU, + Module::Cores, + Module::Usage, + Module::Temp, + Module::Mem, + Module::Swap, + ], + custom_labels: CustomLabels { + os: String::from("OS"), + kernel: String::from("Kernel"), + host: String::from("Host"), + cpu: String::from("CPU"), + cores: String::from("Cores"), + usage: String::from("Usage"), + temp: String::from("Temp"), + mem: String::from("Memory"), + swap: String::from("Swap"), + }, + custom_parameters: CustomParameters { + os: Option::None, + kernel: Option::None, + host: Option::None, + cpu: Option::None, + cores: Option::None, + usage: Option::None, + temp: Option::None, + mem: Option::None, + swap: Option::None, + }, + } + } +} + fn print_crab() { println!("{}",Red.paint(" /\\\r\n ( / @ @ ()\r\n \\ __| |__ /\r\n -/ \" \\-\r\n /-| |-\\\r\n / /-\\ /-\\ \\\r\n / /-`---\'-\\ \\\r\n / \\\r\n") ); } fn main() { + let cfg: Config = confy::load("crabfetch", None).unwrap(); + println!(" "); let left_pad = 25; let mut stdout = std::io::stdout().into_raw_mode().unwrap(); @@ -20,39 +111,47 @@ fn main() { println!( "{}{} : {}\r", termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint("OS"), - sys.name().unwrap() + Red.bold().paint(cfg.custom_labels.os), + cfg.custom_parameters.os.unwrap_or(sys.name().unwrap()) ); cursor_row = cursor_row + 1; println!( "{}{} : {}\r", termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint("Kernel"), - sys.kernel_version().unwrap() + Red.bold().paint(cfg.custom_labels.kernel), + cfg.custom_parameters + .kernel + .unwrap_or(sys.kernel_version().unwrap()) ); cursor_row = cursor_row + 1; println!( "{}{} : {}\r", termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint("Host"), - sys.host_name().unwrap() + Red.bold().paint(cfg.custom_labels.host), + cfg.custom_parameters + .host + .unwrap_or(sys.host_name().unwrap()) ); cursor_row = cursor_row + 1; println!( "{}{} : {}\r", termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint("CPU"), - sys.processors()[0].brand() + Red.bold().paint(cfg.custom_labels.cpu), + cfg.custom_parameters + .cpu + .unwrap_or(sys.processors()[0].brand().to_string()) ); cursor_row = cursor_row + 1; println!( "{}{} : {}\r", termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint("Cores"), - sys.processors().len() + Red.bold().paint(cfg.custom_labels.cores), + cfg.custom_parameters + .cores + .unwrap_or(sys.processors().len().to_string()) ); cursor_row = cursor_row + 1; @@ -64,8 +163,10 @@ fn main() { println!( "{}{} : {}%\r", termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint("Usage"), - usage / sys.processors().len() + Red.bold().paint(cfg.custom_labels.usage), + cfg.custom_parameters + .usage + .unwrap_or((usage / sys.processors().len()).to_string()) ); cursor_row = cursor_row + 1; @@ -74,8 +175,10 @@ fn main() { println!( "{}{} : {}C\r", termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint("Temp"), - component.temperature() + Red.bold().paint(cfg.custom_labels.temp), + cfg.custom_parameters + .temp + .unwrap_or(component.temperature().to_string()) ); cursor_row = cursor_row + 1; break; @@ -83,19 +186,25 @@ fn main() { } println!( - "{}{} : {}MB/{}MB\r", + "{}{} : {}\r", termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint("Mem"), - sys.used_memory() / 1024, - sys.total_memory() / 1024 + Red.bold().paint(cfg.custom_labels.mem), + cfg.custom_parameters.mem.unwrap_or(format!( + "{}MB/{}MB", + sys.used_memory() / 1024, + sys.total_memory() / 1024 + )) ); cursor_row = cursor_row + 1; println!( - "{}{} : {}MB/{}MB\r", + "{}{} : {}\r", termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint("Swap"), - sys.used_swap() / 1024, - sys.total_swap() / 1024 + Red.bold().paint(cfg.custom_labels.swap), + cfg.custom_parameters.swap.unwrap_or(format!( + "{}MB/{}MB", + sys.used_swap() / 1024, + sys.total_swap() / 1024 + )) ); } From eb4ceb0280715c871219ce7f628ca693f3283047 Mon Sep 17 00:00:00 2001 From: Snehit Sah Date: Thu, 2 May 2024 19:17:37 +0530 Subject: [PATCH 3/3] can reorder or omit modules Signed-off-by: Snehit Sah --- src/main.rs | 211 ++++++++++++++++++++++++++++------------------------ 1 file changed, 115 insertions(+), 96 deletions(-) diff --git a/src/main.rs b/src/main.rs index ef097d5..e6a7a43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -108,103 +108,122 @@ fn main() { let mut cursor_row = stdout.cursor_pos().unwrap().1; cursor_row = cursor_row - 9; - println!( - "{}{} : {}\r", - termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint(cfg.custom_labels.os), - cfg.custom_parameters.os.unwrap_or(sys.name().unwrap()) - ); - cursor_row = cursor_row + 1; - println!( - "{}{} : {}\r", - termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint(cfg.custom_labels.kernel), - cfg.custom_parameters - .kernel - .unwrap_or(sys.kernel_version().unwrap()) - ); - cursor_row = cursor_row + 1; - println!( - "{}{} : {}\r", - termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint(cfg.custom_labels.host), - cfg.custom_parameters - .host - .unwrap_or(sys.host_name().unwrap()) - ); - cursor_row = cursor_row + 1; - - println!( - "{}{} : {}\r", - termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint(cfg.custom_labels.cpu), - cfg.custom_parameters - .cpu - .unwrap_or(sys.processors()[0].brand().to_string()) - ); - cursor_row = cursor_row + 1; - - println!( - "{}{} : {}\r", - termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint(cfg.custom_labels.cores), - cfg.custom_parameters - .cores - .unwrap_or(sys.processors().len().to_string()) - ); - cursor_row = cursor_row + 1; - - let mut usage = 0; - - for processor in sys.processors() { - usage = usage + processor.cpu_usage() as usize; - } - println!( - "{}{} : {}%\r", - termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint(cfg.custom_labels.usage), - cfg.custom_parameters - .usage - .unwrap_or((usage / sys.processors().len()).to_string()) - ); - cursor_row = cursor_row + 1; - - for component in sys.components() { - if component.label().contains("Package id") { - println!( - "{}{} : {}C\r", - termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint(cfg.custom_labels.temp), - cfg.custom_parameters - .temp - .unwrap_or(component.temperature().to_string()) - ); - cursor_row = cursor_row + 1; - break; + for module in &cfg.modules { + match module { + Module::OS => { + println!( + "{}{} : {}\r", + termion::cursor::Goto(left_pad, cursor_row), + Red.bold().paint(&cfg.custom_labels.os), + cfg.custom_parameters + .os + .clone() + .unwrap_or(sys.name().unwrap()) + ); + } + Module::Kernel => { + println!( + "{}{} : {}\r", + termion::cursor::Goto(left_pad, cursor_row), + Red.bold().paint(&cfg.custom_labels.kernel), + cfg.custom_parameters + .kernel + .clone() + .unwrap_or(sys.kernel_version().unwrap()) + ); + } + Module::Host => { + println!( + "{}{} : {}\r", + termion::cursor::Goto(left_pad, cursor_row), + Red.bold().paint(&cfg.custom_labels.host), + cfg.custom_parameters + .host + .clone() + .unwrap_or(sys.host_name().unwrap()) + ); + } + Module::CPU => { + println!( + "{}{} : {}\r", + termion::cursor::Goto(left_pad, cursor_row), + Red.bold().paint(&cfg.custom_labels.cpu), + cfg.custom_parameters + .cpu + .clone() + .unwrap_or(sys.processors()[0].brand().to_string()) + ); + } + Module::Cores => { + println!( + "{}{} : {}\r", + termion::cursor::Goto(left_pad, cursor_row), + Red.bold().paint(&cfg.custom_labels.cores), + cfg.custom_parameters + .cores + .clone() + .unwrap_or(sys.processors().len().to_string()) + ); + } + Module::Usage => { + let mut usage = 0; + + for processor in sys.processors() { + usage = usage + processor.cpu_usage() as usize; + } + println!( + "{}{} : {}%\r", + termion::cursor::Goto(left_pad, cursor_row), + Red.bold().paint(&cfg.custom_labels.usage), + cfg.custom_parameters + .usage + .clone() + .unwrap_or((usage / sys.processors().len()).to_string()) + ); + } + Module::Temp => { + for component in sys.components() { + if component.label().contains("Package id") { + println!( + "{}{} : {}\r", + termion::cursor::Goto(left_pad, cursor_row), + Red.bold().paint(&cfg.custom_labels.temp), + cfg.custom_parameters + .temp + .clone() + .unwrap_or(format!("{}C",component.temperature().to_string())) + ); + break; + } + } + } + Module::Mem => { + println!( + "{}{} : {}\r", + termion::cursor::Goto(left_pad, cursor_row), + Red.bold().paint(&cfg.custom_labels.mem), + cfg.custom_parameters.mem.clone().unwrap_or(format!( + "{}MB/{}MB", + sys.used_memory() / 1024, + sys.total_memory() / 1024 + )) + ); + } + Module::Swap => { + println!( + "{}{} : {}\r", + termion::cursor::Goto(left_pad, cursor_row), + Red.bold().paint(&cfg.custom_labels.swap), + cfg.custom_parameters.swap.clone().unwrap_or(format!( + "{}MB/{}MB", + sys.used_swap() / 1024, + sys.total_swap() / 1024 + )) + ); + } } - } - println!( - "{}{} : {}\r", - termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint(cfg.custom_labels.mem), - cfg.custom_parameters.mem.unwrap_or(format!( - "{}MB/{}MB", - sys.used_memory() / 1024, - sys.total_memory() / 1024 - )) - ); - cursor_row = cursor_row + 1; - - println!( - "{}{} : {}\r", - termion::cursor::Goto(left_pad, cursor_row), - Red.bold().paint(cfg.custom_labels.swap), - cfg.custom_parameters.swap.unwrap_or(format!( - "{}MB/{}MB", - sys.used_swap() / 1024, - sys.total_swap() / 1024 - )) - ); + cursor_row = cursor_row + 1; + } }