diff --git a/src/helpers/print.rs b/src/helpers/print.rs index 4bd4849..4f916f6 100644 --- a/src/helpers/print.rs +++ b/src/helpers/print.rs @@ -1,17 +1,25 @@ -use crate::{helpers, system}; +use super::{file::file_open, colors::print_cyan_bold}; +use crate::helpers::{self, colors::print_bold}; -use super::file::file_open; +pub fn print_detail(title: &str, value: String, introduction: bool) { + print!(" "); + + if introduction { + print_bold(&format!( + "{}@{}", + title, + value + ), true); + } else { + helpers::colors::print_cyan_bold(&title, true); + for _ in 0..(10 - title.len()) { + print!(" "); + } -pub fn print_detail(title: &str, value: String) { - helpers::colors::print_cyan_bold(&title, true); - for _ in 0..(8 - title.len()) { - print!(" "); + helpers::colors::print_bold(" : ", true); + + print!("{}", &value); } - - helpers::colors::print_bold(" : ", true); - - print!("{}", &value); - println!(); } pub fn print_ponyline(line: u16, pony: &str) { @@ -20,6 +28,6 @@ pub fn print_ponyline(line: u16, pony: &str) { .skip(line as usize) .take(1) .for_each(|line| { - print!("{}", line); + print_cyan_bold(line, true); }); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5f68524..3bfb8c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,64 @@ mod helpers; mod system; +struct Action<'a> { + name: &'a str, + func: fn() -> String, +} + +static ACTIONS: [Action; 8] = [ + Action { + name: "Distro", + func: system::host::get_distro, + }, + Action { + name: "Kernel", + func: system::specs::get_kernel, + }, + Action { + name: "Uptime", + func: system::host::get_uptime, + }, + Action { + name: "Shell", + func: system::host::get_shell, + }, + Action { + name: "Resolution", + func: system::host::get_resolution, + }, + Action { + name: "IP", + func: system::net::get_ipaddr, + }, + Action { + name: "CPU", + func: system::specs::get_cpu, + }, + Action { + name: "RAM", + func: system::specs::get_ram_used, + } +]; + fn main() { - for i in 0..31 { - helpers::print::print_ponyline(i, "celestia"); - helpers::print::print_detail("User", system::host::get_user()); + for i in 0..12 { + helpers::print::print_ponyline(i, "rainbowdash"); + + if i == 0 { + helpers::print::print_detail( + &system::host::get_user(), + system::host::get_hostname(), + true + ); + } else if ACTIONS.len() > (i as usize) && i != 0 { + helpers::print::print_detail( + ACTIONS[i as usize - 1].name, + (ACTIONS[i as usize - 1].func)(), + false + ); + } + + println!(); } } diff --git a/src/system/host.rs b/src/system/host.rs index 7dd7564..649374c 100644 --- a/src/system/host.rs +++ b/src/system/host.rs @@ -60,7 +60,7 @@ pub fn get_distro() -> String { #[cfg(target_os = "linux")] pub fn get_uptime() -> String { - let mut temp_buf: String = file_open("/proc/uptime"); + let temp_buf: String = file_open("/proc/uptime"); let uptime: u128 = temp_buf.split(".") .collect::>()[0]