mirror of
https://github.com/NotAShelf/microfetch.git
synced 2025-02-06 04:03:17 +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
104
Cargo.lock
generated
104
Cargo.lock
generated
|
@ -2,21 +2,6 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "addr2line"
|
|
||||||
version = "0.21.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
|
|
||||||
dependencies = [
|
|
||||||
"gimli",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "adler"
|
|
||||||
version = "1.0.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aho-corasick"
|
name = "aho-corasick"
|
||||||
version = "1.1.3"
|
version = "1.1.3"
|
||||||
|
@ -44,21 +29,6 @@ version = "1.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "backtrace"
|
|
||||||
version = "0.3.71"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d"
|
|
||||||
dependencies = [
|
|
||||||
"addr2line",
|
|
||||||
"cc",
|
|
||||||
"cfg-if",
|
|
||||||
"libc",
|
|
||||||
"miniz_oxide",
|
|
||||||
"object",
|
|
||||||
"rustc-demangle",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.6.0"
|
version = "2.6.0"
|
||||||
|
@ -77,12 +47,6 @@ version = "0.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
|
checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cc"
|
|
||||||
version = "1.1.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
@ -147,19 +111,6 @@ version = "0.7.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
|
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "color-eyre"
|
|
||||||
version = "0.6.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5"
|
|
||||||
dependencies = [
|
|
||||||
"backtrace",
|
|
||||||
"eyre",
|
|
||||||
"indenter",
|
|
||||||
"once_cell",
|
|
||||||
"owo-colors",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "criterion"
|
name = "criterion"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
|
@ -233,22 +184,6 @@ version = "1.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "eyre"
|
|
||||||
version = "0.6.12"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec"
|
|
||||||
dependencies = [
|
|
||||||
"indenter",
|
|
||||||
"once_cell",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gimli"
|
|
||||||
version = "0.28.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "half"
|
name = "half"
|
||||||
version = "2.4.1"
|
version = "2.4.1"
|
||||||
|
@ -265,12 +200,6 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
|
checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "indenter"
|
|
||||||
version = "0.3.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "is-terminal"
|
name = "is-terminal"
|
||||||
version = "0.4.13"
|
version = "0.4.13"
|
||||||
|
@ -332,23 +261,13 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "microfetch"
|
name = "microfetch"
|
||||||
version = "0.4.4"
|
version = "0.4.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"color-eyre",
|
|
||||||
"criterion",
|
"criterion",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"nix",
|
"nix",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "miniz_oxide"
|
|
||||||
version = "0.7.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
|
|
||||||
dependencies = [
|
|
||||||
"adler",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nix"
|
name = "nix"
|
||||||
version = "0.29.0"
|
version = "0.29.0"
|
||||||
|
@ -370,15 +289,6 @@ dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "object"
|
|
||||||
version = "0.32.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.19.0"
|
version = "1.19.0"
|
||||||
|
@ -391,12 +301,6 @@ version = "11.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9"
|
checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "owo-colors"
|
|
||||||
version = "3.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "plotters"
|
name = "plotters"
|
||||||
version = "0.3.6"
|
version = "0.3.6"
|
||||||
|
@ -492,12 +396,6 @@ version = "0.8.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustc-demangle"
|
|
||||||
version = "0.1.24"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.18"
|
version = "1.0.18"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "microfetch"
|
name = "microfetch"
|
||||||
version = "0.4.4"
|
version = "0.4.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
@ -13,7 +13,6 @@ path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nix = { version = "0.29", features = ["fs", "hostname", "feature"] }
|
nix = { version = "0.29", features = ["fs", "hostname", "feature"] }
|
||||||
color-eyre = { version = "0.6", default-features = false }
|
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
@ -28,7 +27,7 @@ opt-level = 3
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = true
|
strip = true
|
||||||
opt-level = "z"
|
opt-level = "s"
|
||||||
lto = true
|
lto = true
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
|
|
@ -9,12 +9,9 @@ use crate::desktop::get_desktop_info;
|
||||||
use crate::release::{get_os_pretty_name, get_system_info};
|
use crate::release::{get_os_pretty_name, get_system_info};
|
||||||
use crate::system::{get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname};
|
use crate::system::{get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname};
|
||||||
use crate::uptime::get_current;
|
use crate::uptime::get_current;
|
||||||
use color_eyre::Report;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
fn main() -> Result<(), Report> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
color_eyre::install()?;
|
|
||||||
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
if args.len() > 1 && args[1] == "--version" {
|
if args.len() > 1 && args[1] == "--version" {
|
||||||
println!("Microfetch {}", env!("CARGO_PKG_VERSION"));
|
println!("Microfetch {}", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use color_eyre::Result;
|
|
||||||
use nix::sys::utsname::UtsName;
|
use nix::sys::utsname::UtsName;
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
|
@ -30,6 +29,5 @@ pub fn get_os_pretty_name() -> Result<String, io::Error> {
|
||||||
return Ok(pretty_name.to_string());
|
return Ok(pretty_name.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok("Unknown".to_string())
|
Ok("Unknown".to_string())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::colors::COLORS;
|
use crate::colors::COLORS;
|
||||||
use color_eyre::Result;
|
|
||||||
use nix::sys::{statvfs::statvfs, utsname::UtsName};
|
use nix::sys::{statvfs::statvfs, utsname::UtsName};
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
|
@ -8,7 +7,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn get_username_and_hostname(utsname: &UtsName) -> String {
|
pub fn get_username_and_hostname(utsname: &UtsName) -> String {
|
||||||
let username = env::var("USER").unwrap_or("unknown_user".to_string());
|
let username = env::var("USER").unwrap_or_else(|_| "unknown_user".to_string());
|
||||||
let hostname = utsname
|
let hostname = utsname
|
||||||
.nodename()
|
.nodename()
|
||||||
.to_str()
|
.to_str()
|
||||||
|
@ -24,7 +23,7 @@ pub fn get_username_and_hostname(utsname: &UtsName) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_shell() -> String {
|
pub fn get_shell() -> String {
|
||||||
let shell_path = env::var("SHELL").unwrap_or("unknown_shell".to_string());
|
let shell_path = env::var("SHELL").unwrap_or_else(|_| "unknown_shell".to_string());
|
||||||
let shell_name = shell_path.rsplit('/').next().unwrap_or("unknown_shell");
|
let shell_name = shell_path.rsplit('/').next().unwrap_or("unknown_shell");
|
||||||
shell_name.to_string()
|
shell_name.to_string()
|
||||||
}
|
}
|
||||||
|
@ -34,11 +33,14 @@ pub fn get_root_disk_usage() -> Result<String, io::Error> {
|
||||||
let block_size = vfs.block_size() as u64;
|
let block_size = vfs.block_size() as u64;
|
||||||
let total_blocks = vfs.blocks();
|
let total_blocks = vfs.blocks();
|
||||||
let available_blocks = vfs.blocks_available();
|
let available_blocks = vfs.blocks_available();
|
||||||
|
|
||||||
let total_size = block_size * total_blocks;
|
let total_size = block_size * total_blocks;
|
||||||
let used_size = total_size - (block_size * available_blocks);
|
let used_size = total_size - (block_size * available_blocks);
|
||||||
|
|
||||||
let total_size = total_size as f64 / (1024.0 * 1024.0 * 1024.0);
|
let total_size = total_size as f64 / (1024.0 * 1024.0 * 1024.0);
|
||||||
let used_size = used_size as f64 / (1024.0 * 1024.0 * 1024.0);
|
let used_size = used_size as f64 / (1024.0 * 1024.0 * 1024.0);
|
||||||
let usage = (used_size / total_size) * 100.0;
|
let usage = (used_size / total_size) * 100.0;
|
||||||
|
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
"{used_size:.2} GiB / {total_size:.2} GiB ({cyan}{usage:.0}%{reset})",
|
"{used_size:.2} GiB / {total_size:.2} GiB ({cyan}{usage:.0}%{reset})",
|
||||||
cyan = COLORS.cyan,
|
cyan = COLORS.cyan,
|
||||||
|
@ -52,7 +54,9 @@ pub fn get_memory_usage() -> Result<String, io::Error> {
|
||||||
let mut total_memory_kb = 0.0;
|
let mut total_memory_kb = 0.0;
|
||||||
let mut available_memory_kb = 0.0;
|
let mut available_memory_kb = 0.0;
|
||||||
let mut meminfo = String::with_capacity(2048);
|
let mut meminfo = String::with_capacity(2048);
|
||||||
|
|
||||||
File::open("/proc/meminfo")?.read_to_string(&mut meminfo)?;
|
File::open("/proc/meminfo")?.read_to_string(&mut meminfo)?;
|
||||||
|
|
||||||
for line in meminfo.lines() {
|
for line in meminfo.lines() {
|
||||||
let mut split = line.split_whitespace();
|
let mut split = line.split_whitespace();
|
||||||
match split.next().unwrap_or_default() {
|
match split.next().unwrap_or_default() {
|
||||||
|
@ -65,14 +69,17 @@ pub fn get_memory_usage() -> Result<String, io::Error> {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let total_memory_gb = total_memory_kb / 1024.0 / 1024.0;
|
let total_memory_gb = total_memory_kb / 1024.0 / 1024.0;
|
||||||
let available_memory_gb = available_memory_kb / 1024.0 / 1024.0;
|
let available_memory_gb = available_memory_kb / 1024.0 / 1024.0;
|
||||||
let used_memory_gb = total_memory_gb - available_memory_gb;
|
let used_memory_gb = total_memory_gb - available_memory_gb;
|
||||||
|
|
||||||
Ok((used_memory_gb, total_memory_gb))
|
Ok((used_memory_gb, total_memory_gb))
|
||||||
}
|
}
|
||||||
|
|
||||||
let (used_memory, total_memory) = parse_memory_info()?;
|
let (used_memory, total_memory) = parse_memory_info()?;
|
||||||
let percentage_used = (used_memory / total_memory * 100.0).round() as u64;
|
let percentage_used = (used_memory / total_memory * 100.0).round() as u64;
|
||||||
|
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
"{used_memory:.2} GiB / {total_memory:.2} GiB ({cyan}{percentage_used}%{reset})",
|
"{used_memory:.2} GiB / {total_memory:.2} GiB ({cyan}{percentage_used}%{reset})",
|
||||||
cyan = COLORS.cyan,
|
cyan = COLORS.cyan,
|
||||||
|
|
|
@ -1,26 +1,20 @@
|
||||||
use color_eyre::Result;
|
|
||||||
use nix::sys::sysinfo::sysinfo;
|
use nix::sys::sysinfo::sysinfo;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
pub fn get_current() -> Result<String, io::Error> {
|
pub fn get_current() -> Result<String, io::Error> {
|
||||||
let info = sysinfo().map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
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 days = total_minutes / (60 * 24);
|
||||||
let hours = (total_minutes % (60 * 24)) / 60;
|
let hours = (total_minutes % (60 * 24)) / 60;
|
||||||
let minutes = total_minutes % 60;
|
let minutes = total_minutes % 60;
|
||||||
|
|
||||||
let mut parts = Vec::with_capacity(3);
|
let parts = [(days, "day"), (hours, "hour"), (minutes, "minute")]
|
||||||
if days > 0 {
|
.iter()
|
||||||
parts.push(format!("{days} days"));
|
.filter(|&&(value, _)| value > 0)
|
||||||
}
|
.map(|&(value, label)| format!("{value} {label}{}", if value > 1 { "s" } else { "" }))
|
||||||
if hours > 0 || days > 0 {
|
.collect::<Vec<_>>();
|
||||||
parts.push(format!("{hours} hours"));
|
|
||||||
}
|
|
||||||
if minutes > 0 || hours > 0 || days > 0 {
|
|
||||||
parts.push(format!("{minutes} minutes"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(parts.join(", "))
|
Ok(parts.join(", "))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue