tfetch/src/main.rs

42 lines
1.3 KiB
Rust

use std::env::var;
use std::fs::File;
use std::io::Read;
use tfetch::{kernel, uptime, Os};
pub fn main() {
let mut hostname = String::new();
let mut hostname_file = File::open("/etc/hostname").unwrap();
hostname_file.read_to_string(&mut hostname).unwrap();
let os = Os::detect().unwrap();
let style = os.style();
let unstyle = os.unstyle();
let username = format!("{style}{}{unstyle}@{style}{}{unstyle}", var("USER").unwrap(), hostname, style = style, unstyle = unstyle);
let osname = format!("{style}OS:{unstyle} {}\n", Os::ArchLinux.name(), style = style, unstyle = unstyle);
let kernel = format!("{style}Kernel:{unstyle} {}", kernel().unwrap(), style = style, unstyle = unstyle);
let uptime = format!("{style}Uptime:{unstyle} {}", &uptime().unwrap()[3..], style = style, unstyle = unstyle);
let info = [
String::from("\n"),
username,
osname,
kernel,
uptime,
];
let mut logo_iterator = Os::ArchLinux.ascii_logo().lines();
let mut info_iterator = info.iter();
loop {
match (logo_iterator.next(), info_iterator.next()) {
(Some(logo), Some(info)) => print!("{} {}", logo, info),
(Some(logo), None) => println!("{}", logo),
_ => break,
}
}
}