More stuff
This commit is contained in:
parent
2f3751f968
commit
bf3114d1e0
33
src/lib.rs
33
src/lib.rs
|
@ -1,10 +1,18 @@
|
||||||
|
use std::io;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
pub mod logos;
|
pub mod logos;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum Os {
|
pub enum Os {
|
||||||
ArchLinux,
|
ArchLinux,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Os {
|
impl Os {
|
||||||
|
pub fn detect() -> Option<Os> {
|
||||||
|
Some(Os::ArchLinux)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ascii_logo(self) -> &'static str {
|
pub fn ascii_logo(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Os::ArchLinux => logos::archlinux::ASCII_LOGO,
|
Os::ArchLinux => logos::archlinux::ASCII_LOGO,
|
||||||
|
@ -16,4 +24,29 @@ impl Os {
|
||||||
Os::ArchLinux => "Arch Linux",
|
Os::ArchLinux => "Arch Linux",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn style(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Os::ArchLinux => "\x1B[36;1m",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unstyle(self) -> &'static str {
|
||||||
|
"\x1B[0m"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! define_command_function {
|
||||||
|
($name: ident, $command: expr, $args: expr) => {
|
||||||
|
pub fn $name() -> io::Result<String> {
|
||||||
|
Ok(String::from(std::str::from_utf8(&Command::new($command)
|
||||||
|
.args(&$args)
|
||||||
|
.output()?
|
||||||
|
.stdout).unwrap()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
define_command_function!(kernel, "uname", ["-msr"]);
|
||||||
|
define_command_function!(uptime, "uptime", ["-p"]);
|
||||||
|
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -2,7 +2,7 @@ use std::env::var;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use tfetch::Os;
|
use tfetch::{kernel, uptime, Os};
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
|
||||||
|
@ -10,13 +10,22 @@ pub fn main() {
|
||||||
let mut hostname_file = File::open("/etc/hostname").unwrap();
|
let mut hostname_file = File::open("/etc/hostname").unwrap();
|
||||||
hostname_file.read_to_string(&mut hostname).unwrap();
|
hostname_file.read_to_string(&mut hostname).unwrap();
|
||||||
|
|
||||||
let username = format!("\x1B[36;1m{}\x1B[0m@\x1B[36;1m{}\x1B[0m", var("USER").unwrap(), hostname);
|
let os = Os::detect().unwrap();
|
||||||
let osname = format!("\x1B[36;1mOS:\x1B[0m {}\n", Os::ArchLinux.name());
|
let style = os.style();
|
||||||
|
let unstyle = os.unstyle();
|
||||||
|
|
||||||
|
let username = format!("{style}{}{unstyle}@{style}{}{unstyle}", var("USER").unwrap(), hostname, style = style, unstyle = unstyle);
|
||||||
|
let osname = format!("{style}OS:{unstyle} {}\n", Os::ArchLinux.name(), style = style, unstyle = unstyle);
|
||||||
|
|
||||||
|
let kernel = format!("{style}Kernel:{unstyle} {}", kernel().unwrap(), style = style, unstyle = unstyle);
|
||||||
|
let uptime = format!("{style}Uptime:{unstyle} {}", &uptime().unwrap()[3..], style = style, unstyle = unstyle);
|
||||||
|
|
||||||
let info = [
|
let info = [
|
||||||
String::from("\n"),
|
String::from("\n"),
|
||||||
username,
|
username,
|
||||||
osname,
|
osname,
|
||||||
|
kernel,
|
||||||
|
uptime,
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut logo_iterator = Os::ArchLinux.ascii_logo().lines();
|
let mut logo_iterator = Os::ArchLinux.ascii_logo().lines();
|
||||||
|
|
Loading…
Reference in New Issue