51 lines
1.6 KiB
Rust
51 lines
1.6 KiB
Rust
use std::env::{args, 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 mut info = vec![
|
|
String::from("\n"),
|
|
username,
|
|
osname,
|
|
kernel,
|
|
uptime,
|
|
];
|
|
|
|
for arg in args().skip(1) {
|
|
let split = arg.split(":").collect::<Vec<_>>();
|
|
if split.len() != 2 {
|
|
eprintln!("\x1B[33;1mwarning:\x1B[0m argument must be formatted like \"key:value\"");
|
|
continue;
|
|
}
|
|
info.push(format!("{style}{}:{unstyle} {}\n", split[0], split[1], style = style, unstyle = unstyle));
|
|
}
|
|
|
|
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,
|
|
}
|
|
}
|
|
}
|