From 9de922203391a6b45fcf91b4c96cef471945d2d6 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 9 Nov 2024 20:51:52 +0300 Subject: [PATCH] refactor printing logic; separate distro logo --- src/main.rs | 66 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5cb9904..790734d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,15 +4,13 @@ mod release; mod system; mod uptime; -use std::io::Write; - use crate::colors::{print_dots, BLUE, CYAN, RESET}; 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 color_eyre::Report; +use std::io::{self, Write}; fn main() -> Result<(), Report> { color_eyre::install()?; @@ -33,16 +31,13 @@ fn main() -> Result<(), Report> { storage: get_root_disk_usage()?, colors: print_dots(), }; - print_system_info(&fields); + print_system_info(&fields)?; } Ok(()) } // Struct to hold all the fields we need to print -// helps avoid clippy warnings about argument count -// and makes it easier to pass around, though its -// not like we need to struct Fields { user_info: String, os_name: String, @@ -55,7 +50,19 @@ struct Fields { colors: String, } -fn print_system_info(fields: &Fields) { +const LOGO: [&str; 9] = [ + " ▟█▖ ▝█▙ ▗█▛", + " ▗▄▄▟██▄▄▄▄▄▝█▙█▛ ▖", + " ▀▀▀▀▀▀▀▀▀▀▀▘▝██ ▟█▖", + " ▟█▛ ▝█▘▟█▛", + "▟█████▛ ▟█████▛", + " ▟█▛▗█▖ ▟█▛", + " ▝█▛ ██▖▗▄▄▄▄▄▄▄▄▄▄▄", + " ▝ ▟█▜█▖▀▀▀▀▀██▛▀▀▘", + " ▟█▘ ▜█▖ ▝█▛ ", +]; + +fn print_system_info(fields: &Fields) -> io::Result<()> { let Fields { user_info, os_name, @@ -68,16 +75,35 @@ fn print_system_info(fields: &Fields) { colors, } = fields; - let _ = std::io::stdout().write_all(format!( - " - {CYAN} ▟█▖ {BLUE}▝█▙ ▗█▛ {user_info} ~{RESET} - {CYAN} ▗▄▄▟██▄▄▄▄▄{BLUE}▝█▙█▛ {CYAN}▖ {CYAN} {BLUE}System{RESET}  {os_name} - {CYAN} ▀▀▀▀▀▀▀▀▀▀▀▘{BLUE}▝██ {CYAN}▟█▖ {CYAN} {BLUE}Kernel{RESET}  {kernel_version} - {BLUE} ▟█▛ {BLUE}▝█▘{CYAN}▟█▛ {CYAN} {BLUE}Shell{RESET}  {shell} - {BLUE}▟█████▛ {CYAN}▟█████▛ {CYAN} {BLUE}Uptime{RESET}  {uptime} - {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} -").as_bytes()); + // Labels and values to be printed + let system_info = [ + ("", "System", os_name), + ("", "Kernel", kernel_version), + ("", "Shell", shell), + ("", "Uptime", uptime), + ("", "Desktop", desktop), + ("󰍛", "Memory", memory_usage), + ("󱥎", "Storage (/)", storage), + ("", "Colors", colors), + ]; + + let label_width = system_info + .iter() + .map(|(_, label, _)| label.len()) + .max() + .unwrap_or(0); + + writeln!(io::stdout(), "{:<27} {} ~{RESET}", LOGO[0], user_info)?; + for (logo_line, (icon, label, value)) in LOGO[1..].iter().zip(system_info.iter()) { + writeln!( + io::stdout(), + "{:<27} {CYAN}{:<2} {BLUE}{: