tfetch/src/lib.rs

53 lines
1.1 KiB
Rust

use std::io;
use std::process::Command;
pub mod logos;
#[derive(Copy, Clone, Debug)]
pub enum Os {
ArchLinux,
}
impl Os {
pub fn detect() -> Option<Os> {
Some(Os::ArchLinux)
}
pub fn ascii_logo(self) -> &'static str {
match self {
Os::ArchLinux => logos::archlinux::ASCII_LOGO,
}
}
pub fn name(self) -> &'static str {
match self {
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"]);