Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Updated the dependencies and adapted the code accordingly. #13

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Cargo.lock
# Added by cargo

/target
/.idea
6 changes: 6 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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 }
humansize = "2.1.3"
48 changes: 27 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use colored::*;
use std::string::ToString;
use sysinfo::{System, SystemExt, RefreshKind, ProcessorExt};
use sysinfo::{System, RefreshKind, CpuRefreshKind};
use whoami::fallible;
use humansize::{make_format, DECIMAL};

const FERRIS_ART: &[&str] = &[
" ",
Expand Down Expand Up @@ -50,7 +52,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 {
Expand All @@ -66,38 +68,43 @@ 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 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 splitline = "═".repeat(username.len() + hostname.len() + 1);
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 formatter = make_format(DECIMAL);

let ram = format!(
"{}{} » {}{}",
"ram: ".bright_red(),
used_ram,
total_ram,
" MB"
"{}{} » {}",
" ram: ".bright_red(),
formatter(used_ram),
formatter(total_ram)
);

let bright_colors = format!(
Expand Down Expand Up @@ -126,7 +133,6 @@ fn main() {
render(
art,
&[
"".to_string(),
"".to_string(),
userinfo,
splitline,
Expand Down