mirror of
				https://github.com/NotAShelf/microfetch.git
				synced 2025-11-04 07:32:20 +00:00 
			
		
		
		
	refactor: clean up a few things
I've decided to keep lazy_static for now as std::sync::LazyLock seems to have a slightly bigger impact on binary size.
This commit is contained in:
		
					parent
					
						
							
								671ce6b8e5
							
						
					
				
			
			
				commit
				
					
						c139026704
					
				
			
		
					 5 changed files with 16 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -12,8 +12,8 @@ pub struct Colors {
 | 
			
		|||
 | 
			
		||||
impl Colors {
 | 
			
		||||
    const fn new(is_no_color: bool) -> Self {
 | 
			
		||||
        match is_no_color {
 | 
			
		||||
            true => Self {
 | 
			
		||||
        if is_no_color {
 | 
			
		||||
            Self {
 | 
			
		||||
                reset: "",
 | 
			
		||||
                blue: "",
 | 
			
		||||
                cyan: "",
 | 
			
		||||
| 
						 | 
				
			
			@ -21,8 +21,9 @@ impl Colors {
 | 
			
		|||
                yellow: "",
 | 
			
		||||
                red: "",
 | 
			
		||||
                magenta: "",
 | 
			
		||||
            },
 | 
			
		||||
            false => Self {
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            Self {
 | 
			
		||||
                reset: "\x1b[0m",
 | 
			
		||||
                blue: "\x1b[34m",
 | 
			
		||||
                cyan: "\x1b[36m",
 | 
			
		||||
| 
						 | 
				
			
			@ -30,7 +31,7 @@ impl Colors {
 | 
			
		|||
                yellow: "\x1b[33m",
 | 
			
		||||
                red: "\x1b[31m",
 | 
			
		||||
                magenta: "\x1b[35m",
 | 
			
		||||
            },
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										11
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								src/main.rs
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -9,7 +9,7 @@ use crate::desktop::get_desktop_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::uptime::get_current;
 | 
			
		||||
use std::io::Write;
 | 
			
		||||
use std::io::{Write, stdout};
 | 
			
		||||
 | 
			
		||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
 | 
			
		||||
    let args: Vec<String> = std::env::args().collect();
 | 
			
		||||
| 
						 | 
				
			
			@ -20,7 +20,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
 | 
			
		|||
        let fields = Fields {
 | 
			
		||||
            user_info: get_username_and_hostname(&utsname),
 | 
			
		||||
            os_name: get_os_pretty_name()?,
 | 
			
		||||
            kernel_version: get_system_info(&utsname)?,
 | 
			
		||||
            kernel_version: get_system_info(&utsname),
 | 
			
		||||
            shell: get_shell(),
 | 
			
		||||
            desktop: get_desktop_info(),
 | 
			
		||||
            uptime: get_current()?,
 | 
			
		||||
| 
						 | 
				
			
			@ -77,10 +77,9 @@ fn print_system_info(fields: &Fields) {
 | 
			
		|||
    {blue}   ▟█▛{cyan}▗█▖       {cyan}▟█▛          {cyan}  {blue}Desktop{reset}       {desktop}
 | 
			
		||||
    {blue}  ▝█▛  {cyan}██▖{blue}▗▄▄▄▄▄▄▄▄▄▄▄       {cyan}  {blue}Memory{reset}        {memory_usage}
 | 
			
		||||
    {blue}   ▝  {cyan}▟█▜█▖{blue}▀▀▀▀▀██▛▀▀▘       {cyan}  {blue}Storage (/){reset}   {storage}
 | 
			
		||||
    {cyan}     ▟█▘ ▜█▖    {blue}▝█▛          {cyan}  {blue}Colors{reset}        {colors}");
 | 
			
		||||
    {cyan}     ▟█▘ ▜█▖    {blue}▝█▛          {cyan}  {blue}Colors{reset}        {colors}\n");
 | 
			
		||||
 | 
			
		||||
    std::io::stdout()
 | 
			
		||||
        .lock()
 | 
			
		||||
        .write_all(format!("{}\n", system_info).as_bytes())
 | 
			
		||||
    stdout()
 | 
			
		||||
        .write_all(system_info.as_bytes())
 | 
			
		||||
        .expect("Failed to write to stdout");
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,13 +4,13 @@ use std::{
 | 
			
		|||
    io::{self, BufRead, BufReader},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
pub fn get_system_info(utsname: &UtsName) -> nix::Result<String> {
 | 
			
		||||
    Ok(format!(
 | 
			
		||||
pub fn get_system_info(utsname: &UtsName) -> String {
 | 
			
		||||
    format!(
 | 
			
		||||
        "{} {} ({})",
 | 
			
		||||
        utsname.sysname().to_str().unwrap_or("Unknown"),
 | 
			
		||||
        utsname.release().to_str().unwrap_or("Unknown"),
 | 
			
		||||
        utsname.machine().to_str().unwrap_or("Unknown")
 | 
			
		||||
    ))
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn get_os_pretty_name() -> Result<String, io::Error> {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,7 +49,6 @@ pub fn get_root_disk_usage() -> Result<String, io::Error> {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
pub fn get_memory_usage() -> Result<String, io::Error> {
 | 
			
		||||
    #[inline(always)]
 | 
			
		||||
    fn parse_memory_info() -> Result<(f64, f64), io::Error> {
 | 
			
		||||
        let mut total_memory_kb = 0.0;
 | 
			
		||||
        let mut available_memory_kb = 0.0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue