diff --git a/ponies/celestia.txt b/ponies/celestia.txt new file mode 100644 index 0000000..9bd9dfe --- /dev/null +++ b/ponies/celestia.txt @@ -0,0 +1,31 @@ + ,'/ + . / ___ + ___/\ / /'`_ `'. + __ _ .-' :v :u/ /-'` \ ) + .-'`` \` \ .'.') ) /\ / / : | + .'` .--. ) .)/ / /-'__\// / | | + .'` .-'` .| .'.|: @_-'`` \ \/\..--. | ( _.-._ + ,' .'` |' | |'| ( /. '-.__\ ) ( `''.-'` `. + .'.-` | .| | | \ ) \__. | | `---`` ) + .' (_.' | |'.| | ('` ,_ `. : .--. / + .' / . | | |' ( \ `\-.-' \ .-'` | \ + - . (_.-' | | | \ |\ \ __ `` | `''--., + .` .' . / / | | : \| `-._ \.'` '. .--. `-..-'``'. ) + '-'/ / ( / | : ( |'-, `-.)\ \ .' ) __ ) ) + / / /``( .' ( ( '..-':' `-, A ) \_.' (_ .---: )| / + / / / '`' . \ '---''` \ V )`-. .-` '.((( | + ' / / / `'`(_. `'' .'` )-' `-..___..-'` \ ``.' | + ( / / / / / / / ,'-` | | \ ''` | + '`/ / / / / /.''`.' | : \ | + / / / / /`-' / ..---. | '. \ | + ( // / /(_/ _ /. . , )/|. '. \ | + `-'( / / .-'` ( -(_)- / '| '. (\ | + `-'`--' /` \' ' ` .' |. ('.` \ ,.---. | + (_ `--''`````\ '| .-` \.-'`_ \ | + / ___ / '..''``''`` `\ . | + (``''''`` \ `--'` \ | ..--. | + \ (__,..-'` ___ ( '\ .-`__\ \ .--. | + '-..----.., ,.-'`` `-. \__.'''` ,' ``--`` '.' | + \ .-'` __ .--.-''. .-'``''` | + \.-'` .-' `\`'`.'` \_.-' | + '.__________.-'` `'` \ No newline at end of file diff --git a/src/helpers/file.rs b/src/helpers/file.rs new file mode 100644 index 0000000..a9059c2 --- /dev/null +++ b/src/helpers/file.rs @@ -0,0 +1,10 @@ +use std::{fs::File, io::Read}; + +pub fn file_open(path: &str) -> String { + let mut temp_buf: String = String::new(); + + let mut file = File::open(path).unwrap(); + file.read_to_string(&mut temp_buf).unwrap(); + + temp_buf +} \ No newline at end of file diff --git a/src/helpers/mod.rs b/src/helpers/mod.rs new file mode 100644 index 0000000..e0d1abe --- /dev/null +++ b/src/helpers/mod.rs @@ -0,0 +1 @@ +pub mod file; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e66ca52..7e97b1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ +mod helpers; mod system; fn main() { - println!("{}", system::host::get_shell()); + println!("{}", system::specs::get_kernel()); } diff --git a/src/system/host.rs b/src/system/host.rs index 0076ca2..7dd7564 100644 --- a/src/system/host.rs +++ b/src/system/host.rs @@ -1,13 +1,10 @@ +use crate::helpers::file::file_open; use std::{fs::File, io::Read}; use std::process::Command; #[cfg(target_os = "linux")] pub fn get_hostname() -> String { - let mut hostname = String::new(); - - let mut f = File::open("/etc/hostname").unwrap(); - f.read_to_string(&mut hostname).unwrap(); - + let mut hostname = file_open("/etc/hostname"); hostname.pop(); hostname @@ -63,12 +60,12 @@ pub fn get_distro() -> String { #[cfg(target_os = "linux")] pub fn get_uptime() -> String { - let mut temp_buf: String = String::new(); + let mut temp_buf: String = file_open("/proc/uptime"); - let mut file = File::open("/proc/uptime").unwrap(); - file.read_to_string(&mut temp_buf).unwrap(); - - let uptime: u128 = temp_buf.split(".").collect::>()[0].parse().unwrap(); + let uptime: u128 = temp_buf.split(".") + .collect::>()[0] + .parse() + .unwrap(); let days = uptime / 86400; let hours = (uptime % 86400) / 3600; @@ -80,11 +77,8 @@ pub fn get_uptime() -> String { #[cfg(target_os = "linux")] pub fn get_shell() -> String { + let temp_buf: String = file_open("/etc/passwd"); let mut final_str = String::new(); - let mut temp_buf: String = String::new(); - - let mut f = File::open("/etc/passwd").unwrap(); - f.read_to_string(&mut temp_buf).unwrap(); let lines: &Vec<&str> = &temp_buf.lines().collect(); @@ -96,5 +90,28 @@ pub fn get_shell() -> String { } }); + final_str +} + +#[cfg(target_os = "linux")] +pub fn get_resolution() -> String { + let mut final_str = String::new(); + + let output = Command::new("xrandr") + .output() + .expect("Failed to execute xrandr"); + + let output = String::from_utf8(output.stdout).unwrap(); + + let lines: &Vec<&str> = &output.lines().collect(); + + lines.into_iter().for_each(|line| { + if line.contains(" connected") { + final_str = line.split(" ") + .collect::>()[2] + .to_string(); + } + }); + final_str } \ No newline at end of file diff --git a/src/system/net.rs b/src/system/net.rs index d7eb97e..8a4b251 100644 --- a/src/system/net.rs +++ b/src/system/net.rs @@ -1,4 +1,3 @@ -use std::{fs::File, io::Read}; use std::process::Command; use std::sync::Mutex; @@ -6,12 +5,10 @@ use std::sync::Mutex; pub fn get_ipaddr() -> String { use std::ops::Add; - let mut final_str: Mutex = Mutex::new(String::new()); + use crate::helpers::file::file_open; - let mut f = File::open("/proc/net/route").unwrap(); - let mut intr = String::new(); - - f.read_to_string(&mut intr).unwrap(); + let final_str: Mutex = Mutex::new(String::new()); + let intr = file_open("/proc/net/route"); let lines: &Vec<&str> = &intr.lines().collect(); let mut interface = String::new(); diff --git a/src/system/specs.rs b/src/system/specs.rs index 145235a..6e8eff8 100644 --- a/src/system/specs.rs +++ b/src/system/specs.rs @@ -1,3 +1,4 @@ +use crate::helpers::file::file_open; use std::fs::File; use std::io::Read; use std::rc::Rc; @@ -27,10 +28,7 @@ pub fn get_cpu() -> String { #[cfg(target_os = "linux")] pub fn get_ram_used() -> String { - let mut temp_buf: String = String::new(); - - let mut file = File::open("/proc/meminfo").unwrap(); - file.read_to_string(&mut temp_buf).unwrap(); + let temp_buf: String = file_open("/proc/meminfo"); let lines: &Vec<&str> = &temp_buf.lines().collect(); @@ -63,4 +61,13 @@ fn eval_ram(line: String) -> u128 { .unwrap(); (kbs / 1000) +} + +#[cfg(target_os = "linux")] +pub fn get_kernel() -> String { + let temp_buf: String = file_open("/proc/version"); + + temp_buf.split(" ") + .collect::>()[2] + .to_string() } \ No newline at end of file