Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 47 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -68,16 +75,36 @@ 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);

let mut handle = io::stdout().lock();
writeln!(handle, "{:<27} {} ~{RESET}", LOGO[0], user_info)?;
for (logo_line, (icon, label, value)) in LOGO[1..].iter().zip(system_info.iter()) {
writeln!(
handle,
"{:<27} {CYAN}{:<2} {BLUE}{:<width$}{RESET}  {value}{RESET}",
logo_line,
icon,
label,
width = label_width
)?;
}

Ok(())
}