mirror of
https://github.com/NotAShelf/microfetch.git
synced 2025-12-08 14:03:51 +00:00
get rid of color_eyre
Should never have added it. Annoyingly long compile times for no reason...
This commit is contained in:
parent
4fff13a51f
commit
592fb58474
6 changed files with 21 additions and 128 deletions
|
|
@ -1,26 +1,20 @@
|
|||
use color_eyre::Result;
|
||||
use nix::sys::sysinfo::sysinfo;
|
||||
use std::io;
|
||||
|
||||
pub fn get_current() -> Result<String, io::Error> {
|
||||
let info = sysinfo().map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
||||
let uptime_seconds = info.uptime().as_secs_f64();
|
||||
let uptime_seconds = info.uptime().as_secs();
|
||||
|
||||
let total_minutes = (uptime_seconds / 60.0).round() as u64;
|
||||
let total_minutes = uptime_seconds / 60;
|
||||
let days = total_minutes / (60 * 24);
|
||||
let hours = (total_minutes % (60 * 24)) / 60;
|
||||
let minutes = total_minutes % 60;
|
||||
|
||||
let mut parts = Vec::with_capacity(3);
|
||||
if days > 0 {
|
||||
parts.push(format!("{days} days"));
|
||||
}
|
||||
if hours > 0 || days > 0 {
|
||||
parts.push(format!("{hours} hours"));
|
||||
}
|
||||
if minutes > 0 || hours > 0 || days > 0 {
|
||||
parts.push(format!("{minutes} minutes"));
|
||||
}
|
||||
let parts = [(days, "day"), (hours, "hour"), (minutes, "minute")]
|
||||
.iter()
|
||||
.filter(|&&(value, _)| value > 0)
|
||||
.map(|&(value, label)| format!("{value} {label}{}", if value > 1 { "s" } else { "" }))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok(parts.join(", "))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue