From 869e676b19630edb379bada64bf3e733e5ead2eb Mon Sep 17 00:00:00 2001 From: Jan Willems Date: Sat, 25 May 2024 13:31:26 +0200 Subject: [PATCH 1/5] refactor: Updated the dependencies and adapted the code accordingly. --- Cargo.toml | 6 +++--- src/main.rs | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3812721..7f1af95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,6 @@ publish = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -colored = "2.0.0" -whoami = "1.1.1" -sysinfo = { version = "0.23.2", default-features = false } +colored = "2.1.0" +whoami = "1.5.1" +sysinfo = { version = "0.30.12", default-features = false } diff --git a/src/main.rs b/src/main.rs index 93ab3d9..011f43b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use colored::*; use std::string::ToString; -use sysinfo::{System, SystemExt, RefreshKind, ProcessorExt}; +use sysinfo::{System, RefreshKind, CpuRefreshKind}; +use whoami::fallible; const FERRIS_ART: &[&str] = &[ " ", @@ -66,25 +67,28 @@ fn main() { art = false; } - let mut sys = System::new_with_specifics(RefreshKind::new().with_cpu()); + let mut sys = System::new_with_specifics(RefreshKind::new().with_cpu(CpuRefreshKind::everything())); sys.refresh_all(); - let kernel = sys.kernel_version().unwrap_or_else(|| "Unknown".into()); + let kernel = System::kernel_version().unwrap_or_else(|| "Unknown".into()); let total_ram = sys.total_memory(); let used_ram = sys.used_memory(); - let cpu = sys.processors()[0].brand(); + let cpu = sys.cpus()[0].brand(); let rustc_ver = get_ver("rustc -V"); let cargo_ver = get_ver("cargo -V"); let rustup_ver = get_ver("rustup -V"); let cargo_crates = get_cargo_crates(); + let username = fallible::username().unwrap_or("unknown".to_string()); + let hostname = fallible::hostname().unwrap_or("unknown".to_string()); + let userinfo = format!( "{}{}{}", - whoami::username().bright_red().bold(), + username.bright_red().bold(), "@".bold(), - whoami::hostname().bright_red().bold() + hostname.bright_red().bold() ); - let splitline = "═".repeat(whoami::username().len() + whoami::hostname().len() + 1); + let splitline = "═".repeat(username.len() + hostname.len() + 1); let rustc_ver = format!("{}{}", "rustc ver: ".bright_red(), rustc_ver); let rustup_ver = format!("{}{}", "rustup ver: ".bright_red(), rustup_ver); let cargo_ver = format!("{}{}", "cargo ver: ".bright_red(), cargo_ver); From fcb2aec8989159d542966920924941b3a566d982 Mon Sep 17 00:00:00 2001 From: Jan Willems Date: Tue, 28 May 2024 08:24:16 +0200 Subject: [PATCH 2/5] feat: Updated the layout; looks much cleaner now. --- src/main.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 011f43b..08adb1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,7 +51,7 @@ fn get_cargo_crates() -> usize { fn render(art: bool, info: &[String]) { if art { for (ferris_line, info_line) in FERRIS_ART.iter().zip(info) { - println!("{} {}", ferris_line.red(), info_line); + println!("{} {}", ferris_line.bright_red(), info_line); } } else { for line in info { @@ -89,16 +89,16 @@ fn main() { hostname.bright_red().bold() ); let splitline = "═".repeat(username.len() + hostname.len() + 1); - let rustc_ver = format!("{}{}", "rustc ver: ".bright_red(), rustc_ver); - let rustup_ver = format!("{}{}", "rustup ver: ".bright_red(), rustup_ver); - let cargo_ver = format!("{}{}", "cargo ver: ".bright_red(), cargo_ver); - let cargo_crates = format!("{}{}", "cargo crates: ".bright_red(), cargo_crates); - let os = format!("{}{}", "os: ".bright_red(), whoami::distro()); - let kernel = format!("{}{}", "kernel: ".bright_red(), kernel); - let cpu = format!("{}{}", "cpu: ".bright_red(), cpu); + let rustc_ver = format!("{}{}", " rustc: ".bright_red(), rustc_ver); + let rustup_ver = format!("{}{}", " rustup: ".bright_red(), rustup_ver); + let cargo_ver = format!("{}{}", " cargo: ".bright_red(), cargo_ver); + let cargo_crates = format!("{}{}", " crates: ".bright_red(), cargo_crates); + let os = format!("{}{}", " os: ".bright_red(), whoami::distro()); + let kernel = format!("{}{}", " kernel: ".bright_red(), kernel); + let cpu = format!("{}{}", " cpu: ".bright_red(), cpu); let ram = format!( "{}{} » {}{}", - "ram: ".bright_red(), + " ram: ".bright_red(), used_ram, total_ram, " MB" @@ -130,7 +130,6 @@ fn main() { render( art, &[ - "".to_string(), "".to_string(), userinfo, splitline, From 4a3da43a5bc23bf5b4c2e10094e4ae43d676c212 Mon Sep 17 00:00:00 2001 From: Jan Willems Date: Tue, 28 May 2024 08:24:56 +0200 Subject: [PATCH 3/5] chore: Ignored .idea directory. --- .idea/.gitignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..463742f --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,6 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +.idea From 3ba7693ab6097d8ae7f35b0791a4782cb48af948 Mon Sep 17 00:00:00 2001 From: Jan Willems Date: Tue, 28 May 2024 08:25:34 +0200 Subject: [PATCH 4/5] chore: Ignored .idea directory. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 22d3516..11c9c89 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ Cargo.lock # Added by cargo /target +/.idea \ No newline at end of file From 1f8928a436c6fb06d85d43bbd2cb47e24255c832 Mon Sep 17 00:00:00 2001 From: Jan Willems Date: Tue, 28 May 2024 08:32:40 +0200 Subject: [PATCH 5/5] fix: The RAM conversion is done properly. --- Cargo.toml | 1 + src/main.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7f1af95..d52f277 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,4 @@ publish = true colored = "2.1.0" whoami = "1.5.1" sysinfo = { version = "0.30.12", default-features = false } +humansize = "2.1.3" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 08adb1e..3098c67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use colored::*; use std::string::ToString; use sysinfo::{System, RefreshKind, CpuRefreshKind}; use whoami::fallible; +use humansize::{make_format, DECIMAL}; const FERRIS_ART: &[&str] = &[ " ", @@ -96,12 +97,14 @@ fn main() { let os = format!("{}{}", " os: ".bright_red(), whoami::distro()); let kernel = format!("{}{}", " kernel: ".bright_red(), kernel); let cpu = format!("{}{}", " cpu: ".bright_red(), cpu); + + let formatter = make_format(DECIMAL); + let ram = format!( - "{}{} » {}{}", + "{}{} » {}", " ram: ".bright_red(), - used_ram, - total_ram, - " MB" + formatter(used_ram), + formatter(total_ram) ); let bright_colors = format!(