treewide: format with nightly rustfmt rules

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ib8502372dafe2e970024f606b44825af6a6a6964
This commit is contained in:
raf 2025-11-17 16:10:31 +03:00
commit 9bd4c9a70a
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
6 changed files with 220 additions and 203 deletions

View file

@ -1,11 +1,16 @@
use criterion::{Criterion, criterion_group, criterion_main}; use criterion::{Criterion, criterion_group, criterion_main};
use microfetch_lib::colors::print_dots; use microfetch_lib::{
use microfetch_lib::desktop::get_desktop_info; colors::print_dots,
use microfetch_lib::release::{get_os_pretty_name, get_system_info}; desktop::get_desktop_info,
use microfetch_lib::system::{ release::{get_os_pretty_name, get_system_info},
get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname, 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) { fn main_benchmark(c: &mut Criterion) {
let utsname = nix::sys::utsname::uname().expect("lol"); let utsname = nix::sys::utsname::uname().expect("lol");

View file

@ -1,5 +1,4 @@
use std::env; use std::{env, sync::LazyLock};
use std::sync::LazyLock;
pub struct Colors { pub struct Colors {
pub reset: &'static str, pub reset: &'static str,
@ -43,6 +42,7 @@ pub static COLORS: LazyLock<Colors> = LazyLock::new(|| {
Colors::new(is_no_color) Colors::new(is_no_color)
}); });
#[must_use]
pub fn print_dots() -> String { pub fn print_dots() -> String {
format!( format!(
"{} {} {} {} {} {} {}", "{} {} {} {} {} {} {}",

View file

@ -1,3 +1,4 @@
#[must_use]
pub fn get_desktop_info() -> String { pub fn get_desktop_info() -> String {
// Retrieve the environment variables and handle Result types // Retrieve the environment variables and handle Result types
let desktop_env = std::env::var("XDG_CURRENT_DESKTOP"); 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 // Trim "none+" from the start of desktop_env if present
// Use "Unknown" if desktop_env is empty or has an error // Use "Unknown" if desktop_env is empty or has an error
let desktop_env = match desktop_env { let desktop_env = match desktop_env {
Err(_) => "Unknown".to_string(), Err(_) => "Unknown".to_owned(),
Ok(s) => s.trim_start_matches("none+").to_string(), Ok(s) => s.trim_start_matches("none+").to_owned(),
}; };
// Handle the case where display_backend might be empty after capitalization // Handle the case where display_backend might be empty after capitalization
@ -22,7 +23,7 @@ pub fn get_desktop_info() -> String {
} else { } else {
&display_backend &display_backend
} }
.to_string(); .to_owned();
format!("{desktop_env} ({display_backend})") format!("{desktop_env} ({display_backend})")
} }

View file

@ -1,9 +1,11 @@
use nix::sys::utsname::UtsName;
use std::{ use std::{
fs::File, fs::File,
io::{self, BufRead, BufReader}, io::{self, BufRead, BufReader},
}; };
use nix::sys::utsname::UtsName;
#[must_use]
pub fn get_system_info(utsname: &UtsName) -> String { pub fn get_system_info(utsname: &UtsName) -> String {
format!( format!(
"{} {} ({})", "{} {} ({})",
@ -24,10 +26,10 @@ pub fn get_os_pretty_name() -> Result<String, io::Error> {
.strip_prefix('"') .strip_prefix('"')
.and_then(|s| s.strip_suffix('"')) .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())
} }

View file

@ -1,18 +1,21 @@
use crate::colors::COLORS;
use nix::sys::{statvfs::statvfs, utsname::UtsName};
use std::{ use std::{
env, env,
fs::File, fs::File,
io::{self, Read}, 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 { 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 let hostname = utsname
.nodename() .nodename()
.to_str() .to_str()
.unwrap_or("unknown_host") .unwrap_or("unknown_host")
.to_string(); .to_owned();
format!( format!(
"{yellow}{username}{red}@{green}{hostname}{reset}", "{yellow}{username}{red}@{green}{hostname}{reset}",
yellow = COLORS.yellow, yellow = COLORS.yellow,
@ -22,10 +25,12 @@ pub fn get_username_and_hostname(utsname: &UtsName) -> String {
) )
} }
#[must_use]
pub fn get_shell() -> String { 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"); 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> { 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() { 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() {
"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:" => { "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 // MemTotal comes before MemAvailable, stop parsing
break; 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; 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,
reset = COLORS.reset, reset = COLORS.reset,
)) ))