feat: 🎸 Basics complete

This commit is contained in:
Atsukoro1 2022-12-01 21:03:10 +01:00
parent a79f4e4d8c
commit da7121e889
2 changed files with 91 additions and 48 deletions

View file

@ -1,25 +1,31 @@
use super::{file::file_open, colors::print_cyan_bold}; use super::{file::file_open, colors::print_cyan_bold};
use crate::helpers::{self, colors::print_bold}; use crate::{helpers::{self, colors::print_bold}, ActionType};
pub fn print_detail(title: &str, value: String, introduction: bool) { pub fn print_detail(title: &str, value: String, atype: ActionType) {
print!(" "); print!(" ");
if introduction { match atype {
print_bold(&format!( ActionType::Details => {
"{}@{}", helpers::colors::print_cyan_bold(&title, true);
title, for _ in 0..(10 - title.len()) {
value print!(" ");
), true); }
} else {
helpers::colors::print_cyan_bold(&title, true); helpers::colors::print_bold(" : ", true);
for _ in 0..(10 - title.len()) {
print!(" "); print!("{}", &value);
},
ActionType::Delimiter => {
print_bold("-----------------------------", true);
},
ActionType::HostInfo => {
print_bold(&format!(
"{}@{}",
title,
value
), true);
} }
};
helpers::colors::print_bold(" : ", true);
print!("{}", &value);
}
} }
pub fn print_ponyline(line: u16, pony: &str) { pub fn print_ponyline(line: u16, pony: &str) {

View file

@ -1,6 +1,7 @@
mod helpers; mod helpers;
mod system; mod system;
#[derive(Clone, Copy)]
pub enum ActionType { pub enum ActionType {
HostInfo, HostInfo,
Delimiter, Delimiter,
@ -8,42 +9,61 @@ pub enum ActionType {
} }
pub struct Action<'a> { pub struct Action<'a> {
name: &'a str, action_type: ActionType,
func: fn() -> String, name: Option<&'a str>,
func: Option<fn() -> String>,
} }
const ACTIONS: [Action; 8] = [ const ACTIONS: [Action; 10] = [
Action { Action {
name: "Distro", action_type: ActionType::HostInfo,
func: system::host::get_distro, name: None,
func: Some(system::host::get_hostname),
}, },
Action { Action {
name: "Kernel", action_type: ActionType::Delimiter,
func: system::specs::get_kernel, name: None,
func: None,
}, },
Action { Action {
name: "Uptime", action_type: ActionType::Details,
func: system::host::get_uptime, name: Some("Distro"),
func: Some(system::host::get_distro),
}, },
Action { Action {
name: "Shell", action_type: ActionType::Details,
func: system::host::get_shell, name: Some("Kernel"),
func: Some(system::specs::get_kernel),
}, },
Action { Action {
name: "Resolution", action_type: ActionType::Details,
func: system::host::get_resolution, name: Some("Uptime"),
func: Some(system::host::get_uptime),
}, },
Action { Action {
name: "IP", action_type: ActionType::Details,
func: system::net::get_ipaddr, name: Some("Shell"),
func: Some(system::host::get_shell),
}, },
Action { Action {
name: "CPU", action_type: ActionType::Details,
func: system::specs::get_cpu, name: Some("Resolution"),
func: Some(system::host::get_resolution),
}, },
Action { Action {
name: "RAM", action_type: ActionType::Details,
func: system::specs::get_ram_used, name: Some("IP"),
func: Some(system::net::get_ipaddr),
},
Action {
action_type: ActionType::Details,
name: Some("CPU"),
func: Some(system::specs::get_cpu),
},
Action {
action_type: ActionType::Details,
name: Some("RAM"),
func: Some(system::specs::get_ram_used),
} }
]; ];
@ -51,18 +71,35 @@ fn main() {
for i in 0..12 { for i in 0..12 {
helpers::print::print_ponyline(i, "rainbowdash"); helpers::print::print_ponyline(i, "rainbowdash");
if i == 0 { if ACTIONS.get(i as usize).is_none() {
helpers::print::print_detail( println!();
&system::host::get_user(), continue;
system::host::get_hostname(), }
true
); match ACTIONS[i as usize].action_type {
} else if ACTIONS.len() > (i as usize) && i != 0 { ActionType::HostInfo => {
helpers::print::print_detail( helpers::print::print_detail(
ACTIONS[i as usize - 1].name, &system::host::get_user(),
(ACTIONS[i as usize - 1].func)(), system::host::get_hostname(),
false ActionType::HostInfo
); );
},
ActionType::Delimiter => {
helpers::print::print_detail(
"",
"".to_string(),
ActionType::Delimiter
);
},
ActionType::Details => {
helpers::print::print_detail(
ACTIONS[i as usize].name.unwrap(),
ACTIONS[i as usize].func.unwrap()(),
ACTIONS[i as usize].action_type
);
}
} }
println!(); println!();