mirror of
https://github.com/NotAShelf/microfetch.git
synced 2025-11-25 16:52:50 +00:00
treewide: format with nightly rustfmt rules
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ib8502372dafe2e970024f606b44825af6a6a6964
This commit is contained in:
parent
af8031f9ec
commit
9bd4c9a70a
6 changed files with 220 additions and 203 deletions
|
|
@ -1,11 +1,16 @@
|
|||
use criterion::{Criterion, criterion_group, criterion_main};
|
||||
use microfetch_lib::colors::print_dots;
|
||||
use microfetch_lib::desktop::get_desktop_info;
|
||||
use microfetch_lib::release::{get_os_pretty_name, get_system_info};
|
||||
use microfetch_lib::system::{
|
||||
get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname,
|
||||
use microfetch_lib::{
|
||||
colors::print_dots,
|
||||
desktop::get_desktop_info,
|
||||
release::{get_os_pretty_name, get_system_info},
|
||||
system::{
|
||||
get_memory_usage,
|
||||
get_root_disk_usage,
|
||||
get_shell,
|
||||
get_username_and_hostname,
|
||||
},
|
||||
uptime::get_current,
|
||||
};
|
||||
use microfetch_lib::uptime::get_current;
|
||||
|
||||
fn main_benchmark(c: &mut Criterion) {
|
||||
let utsname = nix::sys::utsname::uname().expect("lol");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use std::env;
|
||||
use std::sync::LazyLock;
|
||||
use std::{env, sync::LazyLock};
|
||||
|
||||
pub struct Colors {
|
||||
pub reset: &'static str,
|
||||
|
|
@ -43,6 +42,7 @@ pub static COLORS: LazyLock<Colors> = LazyLock::new(|| {
|
|||
Colors::new(is_no_color)
|
||||
});
|
||||
|
||||
#[must_use]
|
||||
pub fn print_dots() -> String {
|
||||
format!(
|
||||
"{} {} {} {} {} {} {}",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#[must_use]
|
||||
pub fn get_desktop_info() -> String {
|
||||
// Retrieve the environment variables and handle Result types
|
||||
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP");
|
||||
|
|
@ -12,8 +13,8 @@ pub fn get_desktop_info() -> String {
|
|||
// Trim "none+" from the start of desktop_env if present
|
||||
// Use "Unknown" if desktop_env is empty or has an error
|
||||
let desktop_env = match desktop_env {
|
||||
Err(_) => "Unknown".to_string(),
|
||||
Ok(s) => s.trim_start_matches("none+").to_string(),
|
||||
Err(_) => "Unknown".to_owned(),
|
||||
Ok(s) => s.trim_start_matches("none+").to_owned(),
|
||||
};
|
||||
|
||||
// Handle the case where display_backend might be empty after capitalization
|
||||
|
|
@ -22,7 +23,7 @@ pub fn get_desktop_info() -> String {
|
|||
} else {
|
||||
&display_backend
|
||||
}
|
||||
.to_string();
|
||||
.to_owned();
|
||||
|
||||
format!("{desktop_env} ({display_backend})")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
use nix::sys::utsname::UtsName;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{self, BufRead, BufReader},
|
||||
};
|
||||
|
||||
use nix::sys::utsname::UtsName;
|
||||
|
||||
#[must_use]
|
||||
pub fn get_system_info(utsname: &UtsName) -> String {
|
||||
format!(
|
||||
"{} {} ({})",
|
||||
|
|
@ -24,10 +26,10 @@ pub fn get_os_pretty_name() -> Result<String, io::Error> {
|
|||
.strip_prefix('"')
|
||||
.and_then(|s| s.strip_suffix('"'))
|
||||
{
|
||||
return Ok(trimmed.to_string());
|
||||
return Ok(trimmed.to_owned());
|
||||
}
|
||||
return Ok(pretty_name.to_string());
|
||||
return Ok(pretty_name.to_owned());
|
||||
}
|
||||
}
|
||||
Ok("Unknown".to_string())
|
||||
Ok("Unknown".to_owned())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
use crate::colors::COLORS;
|
||||
use nix::sys::{statvfs::statvfs, utsname::UtsName};
|
||||
use std::{
|
||||
env,
|
||||
fs::File,
|
||||
io::{self, Read},
|
||||
};
|
||||
|
||||
use nix::sys::{statvfs::statvfs, utsname::UtsName};
|
||||
|
||||
use crate::colors::COLORS;
|
||||
|
||||
#[must_use]
|
||||
pub fn get_username_and_hostname(utsname: &UtsName) -> String {
|
||||
let username = env::var("USER").unwrap_or_else(|_| "unknown_user".to_string());
|
||||
let username = env::var("USER").unwrap_or_else(|_| "unknown_user".to_owned());
|
||||
let hostname = utsname
|
||||
.nodename()
|
||||
.to_str()
|
||||
.unwrap_or("unknown_host")
|
||||
.to_string();
|
||||
.to_owned();
|
||||
format!(
|
||||
"{yellow}{username}{red}@{green}{hostname}{reset}",
|
||||
yellow = COLORS.yellow,
|
||||
|
|
@ -22,10 +25,12 @@ pub fn get_username_and_hostname(utsname: &UtsName) -> String {
|
|||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_shell() -> String {
|
||||
let shell_path = env::var("SHELL").unwrap_or_else(|_| "unknown_shell".to_string());
|
||||
let shell_path =
|
||||
env::var("SHELL").unwrap_or_else(|_| "unknown_shell".to_owned());
|
||||
let shell_name = shell_path.rsplit('/').next().unwrap_or("unknown_shell");
|
||||
shell_name.to_string()
|
||||
shell_name.to_owned()
|
||||
}
|
||||
|
||||
pub fn get_root_disk_usage() -> Result<String, io::Error> {
|
||||
|
|
@ -59,12 +64,15 @@ pub fn get_memory_usage() -> Result<String, io::Error> {
|
|||
for line in meminfo.lines() {
|
||||
let mut split = line.split_whitespace();
|
||||
match split.next().unwrap_or_default() {
|
||||
"MemTotal:" => total_memory_kb = split.next().unwrap_or("0").parse().unwrap_or(0.0),
|
||||
"MemTotal:" => {
|
||||
total_memory_kb = split.next().unwrap_or("0").parse().unwrap_or(0.0)
|
||||
},
|
||||
"MemAvailable:" => {
|
||||
available_memory_kb = split.next().unwrap_or("0").parse().unwrap_or(0.0);
|
||||
available_memory_kb =
|
||||
split.next().unwrap_or("0").parse().unwrap_or(0.0);
|
||||
// MemTotal comes before MemAvailable, stop parsing
|
||||
break;
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
@ -80,7 +88,8 @@ pub fn get_memory_usage() -> Result<String, io::Error> {
|
|||
let percentage_used = (used_memory / total_memory * 100.0).round() as u64;
|
||||
|
||||
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,
|
||||
reset = COLORS.reset,
|
||||
))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue