mirror of
https://github.com/NotAShelf/microfetch.git
synced 2024-11-22 23:40:42 +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 system;
|
||||||
mod uptime;
|
mod uptime;
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
use crate::colors::{print_dots, BLUE, CYAN, RESET};
|
use crate::colors::{print_dots, BLUE, CYAN, RESET};
|
||||||
use crate::desktop::get_desktop_info;
|
use crate::desktop::get_desktop_info;
|
||||||
use crate::release::{get_os_pretty_name, get_system_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::system::{get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname};
|
||||||
use crate::uptime::get_current;
|
use crate::uptime::get_current;
|
||||||
|
|
||||||
use color_eyre::Report;
|
use color_eyre::Report;
|
||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
fn main() -> Result<(), Report> {
|
fn main() -> Result<(), Report> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
|
@ -33,16 +31,13 @@ fn main() -> Result<(), Report> {
|
||||||
storage: get_root_disk_usage()?,
|
storage: get_root_disk_usage()?,
|
||||||
colors: print_dots(),
|
colors: print_dots(),
|
||||||
};
|
};
|
||||||
print_system_info(&fields);
|
print_system_info(&fields)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Struct to hold all the fields we need to print
|
// 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 {
|
struct Fields {
|
||||||
user_info: String,
|
user_info: String,
|
||||||
os_name: String,
|
os_name: String,
|
||||||
|
@ -55,7 +50,19 @@ struct Fields {
|
||||||
colors: String,
|
colors: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_system_info(fields: &Fields) {
|
const LOGO: [&str; 9] = [
|
||||||
|
" ▟█▖ ▝█▙ ▗█▛",
|
||||||
|
" ▗▄▄▟██▄▄▄▄▄▝█▙█▛ ▖",
|
||||||
|
" ▀▀▀▀▀▀▀▀▀▀▀▘▝██ ▟█▖",
|
||||||
|
" ▟█▛ ▝█▘▟█▛",
|
||||||
|
"▟█████▛ ▟█████▛",
|
||||||
|
" ▟█▛▗█▖ ▟█▛",
|
||||||
|
" ▝█▛ ██▖▗▄▄▄▄▄▄▄▄▄▄▄",
|
||||||
|
" ▝ ▟█▜█▖▀▀▀▀▀██▛▀▀▘",
|
||||||
|
" ▟█▘ ▜█▖ ▝█▛ ",
|
||||||
|
];
|
||||||
|
|
||||||
|
fn print_system_info(fields: &Fields) -> io::Result<()> {
|
||||||
let Fields {
|
let Fields {
|
||||||
user_info,
|
user_info,
|
||||||
os_name,
|
os_name,
|
||||||
|
@ -68,16 +75,35 @@ fn print_system_info(fields: &Fields) {
|
||||||
colors,
|
colors,
|
||||||
} = fields;
|
} = fields;
|
||||||
|
|
||||||
let _ = std::io::stdout().write_all(format!(
|
// Labels and values to be printed
|
||||||
"
|
let system_info = [
|
||||||
{CYAN} ▟█▖ {BLUE}▝█▙ ▗█▛ {user_info} ~{RESET}
|
("", "System", os_name),
|
||||||
{CYAN} ▗▄▄▟██▄▄▄▄▄{BLUE}▝█▙█▛ {CYAN}▖ {CYAN} {BLUE}System{RESET} {os_name}
|
("", "Kernel", kernel_version),
|
||||||
{CYAN} ▀▀▀▀▀▀▀▀▀▀▀▘{BLUE}▝██ {CYAN}▟█▖ {CYAN} {BLUE}Kernel{RESET} {kernel_version}
|
("", "Shell", shell),
|
||||||
{BLUE} ▟█▛ {BLUE}▝█▘{CYAN}▟█▛ {CYAN} {BLUE}Shell{RESET} {shell}
|
("", "Uptime", uptime),
|
||||||
{BLUE}▟█████▛ {CYAN}▟█████▛ {CYAN} {BLUE}Uptime{RESET} {uptime}
|
("", "Desktop", desktop),
|
||||||
{BLUE} ▟█▛{CYAN}▗█▖ {CYAN}▟█▛ {CYAN} {BLUE}Desktop{RESET} {desktop}
|
("", "Memory", memory_usage),
|
||||||
{BLUE} ▝█▛ {CYAN}██▖{BLUE}▗▄▄▄▄▄▄▄▄▄▄▄ {CYAN} {BLUE}Memory{RESET} {memory_usage}
|
("", "Storage (/)", storage),
|
||||||
{BLUE} ▝ {CYAN}▟█▜█▖{BLUE}▀▀▀▀▀██▛▀▀▘ {CYAN} {BLUE}Storage (/){RESET} {storage}
|
("", "Colors", colors),
|
||||||
{CYAN} ▟█▘ ▜█▖ {BLUE}▝█▛ {CYAN} {BLUE}Colors{RESET} {colors}
|
];
|
||||||
").as_bytes());
|
|
||||||
|
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