mirror of
https://github.com/NotAShelf/microfetch.git
synced 2024-11-22 15:40:41 +00:00
refactor printing logic; separate distro logo
This commit is contained in:
parent
8f5bfcbd05
commit
9de9222033
1 changed files with 46 additions and 20 deletions
66
src/main.rs
66
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}{:<width$}{RESET} {value}{RESET}",
|
||||
logo_line,
|
||||
icon,
|
||||
label,
|
||||
width = label_width
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue