From 4394d5eb54cbd5cc6831422e8fdae4ca976b4ef5 Mon Sep 17 00:00:00 2001 From: Atsukoro1 Date: Fri, 2 Dec 2022 19:37:26 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20init=20system=20in?= =?UTF-8?q?fo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/print.rs | 2 +- src/main.rs | 9 ++++++++- src/system/host.rs | 13 +++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/helpers/print.rs b/src/helpers/print.rs index f1edae0..1d77bf6 100644 --- a/src/helpers/print.rs +++ b/src/helpers/print.rs @@ -7,7 +7,7 @@ pub fn print_detail(title: &str, value: String, atype: ActionType, color: &str) match atype { ActionType::Details => { print(&title, true, &(color.to_owned() + "_bold")); - for _ in 0..(10 - title.len()) { + for _ in 0..(12 - title.len()) { print!(" "); } diff --git a/src/main.rs b/src/main.rs index 4aa8832..786a4d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ pub struct Action<'a> { func: Option String>, } -const ACTIONS: [Action; 12] = [ +const ACTIONS: [Action; 13] = [ Action { action_type: ActionType::HostInfo, name: None, @@ -71,6 +71,11 @@ const ACTIONS: [Action; 12] = [ name: Some("RAM"), func: Some(system::specs::get_ram_used), }, + Action { + action_type: ActionType::Details, + name: Some("Init System"), + func: Some(system::host::get_init_system), + }, Action { action_type: ActionType::Delimiter, name: None, @@ -86,6 +91,8 @@ const ACTIONS: [Action; 12] = [ fn main() { let args: Args = Args::parse(); + println!("{}", system::host::get_init_system()); + let line_count = helpers::file::get_file_linecount( &format!("{}{}.txt", helpers::paths::get_pony_path(), &args.pony) ); diff --git a/src/system/host.rs b/src/system/host.rs index 649374c..bcae436 100644 --- a/src/system/host.rs +++ b/src/system/host.rs @@ -114,4 +114,17 @@ pub fn get_resolution() -> String { }); final_str +} + +#[cfg(target_os = "linux")] +pub fn get_init_system() -> String { + Command::new("ps") + .args(&["-p", "1", "-o", "comm="]) + .output() + .unwrap() + .stdout + .iter() + .map(|&c| c as char) + .collect::() + .trim().to_string() } \ No newline at end of file