From 6709022e6d86c19c0d7bbeb851d95c4a164fc1a5 Mon Sep 17 00:00:00 2001 From: Atsukoro1 Date: Thu, 1 Dec 2022 14:00:06 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Printing=20info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 4 +--- src/helpers/colors.rs | 23 +++++++++++++++++++++++ src/helpers/mod.rs | 4 +++- src/helpers/print.rs | 13 +++++++++++++ src/main.rs | 9 ++++++++- src/system/net.rs | 6 ++---- src/system/specs.rs | 1 + 7 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 src/helpers/colors.rs create mode 100644 src/helpers/print.rs diff --git a/Cargo.toml b/Cargo.toml index 4a4ab0b..e2382f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,4 @@ [package] name = "ponyfetch" version = "0.1.0" -edition = "2021" - -[dependencies] \ No newline at end of file +edition = "2021" \ No newline at end of file diff --git a/src/helpers/colors.rs b/src/helpers/colors.rs new file mode 100644 index 0000000..6f45bfb --- /dev/null +++ b/src/helpers/colors.rs @@ -0,0 +1,23 @@ +pub fn print_cyan(text: &str, inline: bool) { + if inline { + print!("\x1b[36m{}\x1b[0m", text); + } else { + println!("\x1b[36m{}\x1b[0m", text); + } +} + +pub fn print_cyan_bold(text: &str, inline: bool) { + if inline { + print!("\x1b[36m\x1b[1m{}\x1b[0m", text); + } else { + println!("\x1b[36m\x1b[1m{}\x1b[0m", text); + } +} + +pub fn print_bold(text: &str, inline: bool) { + if inline { + print!("\x1b[1m{}\x1b[0m", text); + } else { + println!("\x1b[1m{}\x1b[0m", text); + } +} \ No newline at end of file diff --git a/src/helpers/mod.rs b/src/helpers/mod.rs index e0d1abe..dc90cec 100644 --- a/src/helpers/mod.rs +++ b/src/helpers/mod.rs @@ -1 +1,3 @@ -pub mod file; \ No newline at end of file +pub mod file; +pub mod colors; +pub mod print; \ No newline at end of file diff --git a/src/helpers/print.rs b/src/helpers/print.rs new file mode 100644 index 0000000..4ce238d --- /dev/null +++ b/src/helpers/print.rs @@ -0,0 +1,13 @@ +use crate::{helpers, system}; + +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); + println!(); +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 7e97b1d..d8dfd7d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,5 +2,12 @@ mod helpers; mod system; fn main() { - println!("{}", system::specs::get_kernel()); + helpers::print::print_detail("User", system::host::get_user()); + helpers::print::print_detail("Hostname", system::host::get_hostname()); + helpers::print::print_detail("IP", system::net::get_ipaddr()); + helpers::print::print_detail("Kernel", system::specs::get_kernel()); + helpers::print::print_detail("RAM", system::specs::get_ram_used()); + helpers::print::print_detail("CPU", system::specs::get_cpu()); + helpers::print::print_detail("Distro", system::host::get_distro()); + helpers::print::print_detail("Shell", system::host::get_shell()); } diff --git a/src/system/net.rs b/src/system/net.rs index 8a4b251..06e5a20 100644 --- a/src/system/net.rs +++ b/src/system/net.rs @@ -1,12 +1,10 @@ +use crate::helpers::file::file_open; use std::process::Command; use std::sync::Mutex; +use std::ops::Add; #[cfg(target_os = "linux")] pub fn get_ipaddr() -> String { - use std::ops::Add; - - use crate::helpers::file::file_open; - let final_str: Mutex = Mutex::new(String::new()); let intr = file_open("/proc/net/route"); diff --git a/src/system/specs.rs b/src/system/specs.rs index 6e8eff8..3bcd62b 100644 --- a/src/system/specs.rs +++ b/src/system/specs.rs @@ -20,6 +20,7 @@ pub fn get_cpu() -> String { .collect::>()[1].to_string() .replace("\t", "") ); + cpu = Rc::new(cpu.replacen(" ", "", 1)); } });