Skip to content

Commit b553324

Browse files
committed
get rid of color_eyre
Should never have added it. Annoyingly long compile times for no reason...
1 parent 4fff13a commit b553324

File tree

6 files changed

+19
-126
lines changed

6 files changed

+19
-126
lines changed

Cargo.lock

Lines changed: 0 additions & 102 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "microfetch"
3-
version = "0.4.4"
3+
version = "0.4.5"
44
edition = "2021"
55

66
[lib]
@@ -13,7 +13,6 @@ path = "src/main.rs"
1313

1414
[dependencies]
1515
nix = { version = "0.29", features = ["fs", "hostname", "feature"] }
16-
color-eyre = { version = "0.6", default-features = false }
1716
lazy_static = "1.5.0"
1817

1918
[dev-dependencies]

src/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ use crate::desktop::get_desktop_info;
99
use crate::release::{get_os_pretty_name, get_system_info};
1010
use crate::system::{get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname};
1111
use crate::uptime::get_current;
12-
use color_eyre::Report;
1312
use std::io::Write;
1413

15-
fn main() -> Result<(), Report> {
16-
color_eyre::install()?;
17-
14+
fn main() -> Result<(), Box<dyn std::error::Error>> {
1815
let args: Vec<String> = std::env::args().collect();
1916
if args.len() > 1 && args[1] == "--version" {
2017
println!("Microfetch {}", env!("CARGO_PKG_VERSION"));

src/release.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use color_eyre::Result;
21
use nix::sys::utsname::UtsName;
32
use std::{
43
fs::File,
@@ -30,6 +29,5 @@ pub fn get_os_pretty_name() -> Result<String, io::Error> {
3029
return Ok(pretty_name.to_string());
3130
}
3231
}
33-
3432
Ok("Unknown".to_string())
3533
}

src/system.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::colors::COLORS;
2-
use color_eyre::Result;
32
use nix::sys::{statvfs::statvfs, utsname::UtsName};
43
use std::{
54
env,
@@ -8,7 +7,7 @@ use std::{
87
};
98

109
pub fn get_username_and_hostname(utsname: &UtsName) -> String {
11-
let username = env::var("USER").unwrap_or("unknown_user".to_string());
10+
let username = env::var("USER").unwrap_or_else(|_| "unknown_user".to_string());
1211
let hostname = utsname
1312
.nodename()
1413
.to_str()
@@ -24,7 +23,7 @@ pub fn get_username_and_hostname(utsname: &UtsName) -> String {
2423
}
2524

2625
pub fn get_shell() -> String {
27-
let shell_path = env::var("SHELL").unwrap_or("unknown_shell".to_string());
26+
let shell_path = env::var("SHELL").unwrap_or_else(|_| "unknown_shell".to_string());
2827
let shell_name = shell_path.rsplit('/').next().unwrap_or("unknown_shell");
2928
shell_name.to_string()
3029
}
@@ -34,11 +33,14 @@ pub fn get_root_disk_usage() -> Result<String, io::Error> {
3433
let block_size = vfs.block_size() as u64;
3534
let total_blocks = vfs.blocks();
3635
let available_blocks = vfs.blocks_available();
36+
3737
let total_size = block_size * total_blocks;
3838
let used_size = total_size - (block_size * available_blocks);
39+
3940
let total_size = total_size as f64 / (1024.0 * 1024.0 * 1024.0);
4041
let used_size = used_size as f64 / (1024.0 * 1024.0 * 1024.0);
4142
let usage = (used_size / total_size) * 100.0;
43+
4244
Ok(format!(
4345
"{used_size:.2} GiB / {total_size:.2} GiB ({cyan}{usage:.0}%{reset})",
4446
cyan = COLORS.cyan,
@@ -52,7 +54,9 @@ pub fn get_memory_usage() -> Result<String, io::Error> {
5254
let mut total_memory_kb = 0.0;
5355
let mut available_memory_kb = 0.0;
5456
let mut meminfo = String::with_capacity(2048);
57+
5558
File::open("/proc/meminfo")?.read_to_string(&mut meminfo)?;
59+
5660
for line in meminfo.lines() {
5761
let mut split = line.split_whitespace();
5862
match split.next().unwrap_or_default() {
@@ -65,14 +69,17 @@ pub fn get_memory_usage() -> Result<String, io::Error> {
6569
_ => (),
6670
}
6771
}
72+
6873
let total_memory_gb = total_memory_kb / 1024.0 / 1024.0;
6974
let available_memory_gb = available_memory_kb / 1024.0 / 1024.0;
7075
let used_memory_gb = total_memory_gb - available_memory_gb;
76+
7177
Ok((used_memory_gb, total_memory_gb))
7278
}
7379

7480
let (used_memory, total_memory) = parse_memory_info()?;
7581
let percentage_used = (used_memory / total_memory * 100.0).round() as u64;
82+
7683
Ok(format!(
7784
"{used_memory:.2} GiB / {total_memory:.2} GiB ({cyan}{percentage_used}%{reset})",
7885
cyan = COLORS.cyan,

src/uptime.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
1-
use color_eyre::Result;
21
use nix::sys::sysinfo::sysinfo;
32
use std::io;
43

54
pub fn get_current() -> Result<String, io::Error> {
65
let info = sysinfo().map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
7-
let uptime_seconds = info.uptime().as_secs_f64();
6+
let uptime_seconds = info.uptime().as_secs();
87

9-
let total_minutes = (uptime_seconds / 60.0).round() as u64;
8+
let total_minutes = uptime_seconds / 60;
109
let days = total_minutes / (60 * 24);
1110
let hours = (total_minutes % (60 * 24)) / 60;
1211
let minutes = total_minutes % 60;
1312

14-
let mut parts = Vec::with_capacity(3);
15-
if days > 0 {
16-
parts.push(format!("{days} days"));
17-
}
18-
if hours > 0 || days > 0 {
19-
parts.push(format!("{hours} hours"));
20-
}
21-
if minutes > 0 || hours > 0 || days > 0 {
22-
parts.push(format!("{minutes} minutes"));
23-
}
13+
let parts = [(days, "day"), (hours, "hour"), (minutes, "minute")]
14+
.iter()
15+
.filter(|&&(value, _)| value > 0)
16+
.map(|&(value, label)| format!("{value} {label}{}", if value > 1 { "s" } else { "" }))
17+
.collect::<Vec<_>>();
2418

2519
Ok(parts.join(", "))
2620
}

0 commit comments

Comments
 (0)