Merge pull request #1 from hllhnd/clippy-fixes

Fix clippy warnings, minor code quality improvements
This commit is contained in:
iVacon 2023-06-16 18:07:05 +03:00 committed by GitHub
commit 8afde3292b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,7 +14,7 @@ fn main() {
let user = String::from_utf8_lossy(&user.stdout); let user = String::from_utf8_lossy(&user.stdout);
let hostname = Command::new("uname") let hostname = Command::new("uname")
.args(&["-n"]) .args(["-n"])
.output() .output()
.expect("Failed to get hostname"); .expect("Failed to get hostname");
@ -38,18 +38,17 @@ fn main() {
} }
// Release file processing, huge credit to ChatGPT for this one! // Release file processing, huge credit to ChatGPT for this one!
let mut distro_name: String = (&release_distro[5..release_distro.len() - 1]).to_string(); let mut distro_name: String = release_distro[5..release_distro.len() - 1].to_string();
distro_name = distro_name.replace("\"", ""); distro_name = distro_name.replace('\"', "");
// println!("OS: {}", Red.paint(distro_name.clone())); // println!("OS: {}", Red.paint(distro_name.clone()));
let figlet = Command::new("figlet") let figlet = Command::new("figlet")
.args(["-f", "smslant", &distro_name.clone()]) .args(["-f", "smslant", &distro_name])
.output(); .output();
if figlet.is_err() == false { if let Ok(output) = figlet {
let figlet = figlet.unwrap(); let output = String::from_utf8_lossy(&output.stdout);
let figlet = String::from_utf8_lossy(&figlet.stdout); print!("{}", output);
print!("{}", figlet);
} }
// Print all the things we've been saving. // Print all the things we've been saving.
println!("{}@{}", user.clone().trim(), hostname.clone().trim()); println!("{}@{}", user.clone().trim(), hostname.clone().trim());
@ -79,7 +78,6 @@ fn main() {
// Vars // Vars
let mut ramtotal: u32 = 0; let mut ramtotal: u32 = 0;
let mut ramavail: u32 = 0; let mut ramavail: u32 = 0;
let mut ramused: u32 = 0;
// Read 1st & 2nd line // Read 1st & 2nd line
if let Some(Ok(line)) = lines.next() { if let Some(Ok(line)) = lines.next() {
@ -89,7 +87,7 @@ fn main() {
line_processed = &line_processed[0..line_processed.len() - 3]; line_processed = &line_processed[0..line_processed.len() - 3];
// mafs // mafs
let mut ram_gb: u32 = line_processed.parse().unwrap(); let mut ram_gb: u32 = line_processed.parse().unwrap();
ram_gb = ram_gb / 1048576; ram_gb /= 1048576;
ramtotal = ram_gb; ramtotal = ram_gb;
} }
} }
@ -103,12 +101,12 @@ fn main() {
line_processed = &line_processed[0..line_processed.len() - 3]; line_processed = &line_processed[0..line_processed.len() - 3];
// mafs // mafs
let mut ram_gb: u32 = line_processed.parse().unwrap(); let mut ram_gb: u32 = line_processed.parse().unwrap();
ram_gb = ram_gb / 1048576; ram_gb /= 1048576;
ramavail = ram_gb; ramavail = ram_gb;
} }
} }
ramused = ramtotal - ramavail; let ramused = ramtotal - ramavail;
println!("│ Mem: {}/{} GB ({} GB Available)", Green.paint(ramused.to_string()), Green.paint(ramtotal.to_string()), Green.paint(ramavail.to_string())); println!("│ Mem: {}/{} GB ({} GB Available)", Green.paint(ramused.to_string()), Green.paint(ramtotal.to_string()), Green.paint(ramavail.to_string()));
@ -140,15 +138,14 @@ fn main() {
let mut i = 1; let mut i = 1;
while i < 5 { while i < 5 {
lines.next(); lines.next();
i = i + 1; i += 1;
} }
drop(i);
let mut model: String = String::new(); let mut model: String = String::new();
if let Some(Ok(line)) = lines.next() { if let Some(Ok(line)) = lines.next() {
model = line.split(":").nth(1).expect("Failed to parse CPU Info").trim().to_string(); model = line.split(':').nth(1).expect("Failed to parse CPU Info").trim().to_string();
} }
println!("┘ CPU: {}", Purple.paint(model)); println!("┘ CPU: {}", Purple.paint(model));
@ -156,6 +153,5 @@ fn main() {
} }
// Colours // Colours
println!(""); println!("\n{} {} {} {} {} {}", Red.paint(""), Green.paint(""), Yellow.paint(""), Blue.paint(""), Purple.paint(""), Cyan.paint(""));
println!("{} {} {} {} {} {}", Red.paint(""), Green.paint(""), Yellow.paint(""), Blue.paint(""), Purple.paint(""), Cyan.paint(""));
} }