From 36a6ec1e12894a6ff04eecc263f9638150a512ad Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 17 Jul 2019 11:58:40 +0200 Subject: [PATCH] Adds some os detection, ubuntu logo --- src/lib.rs | 26 +++++++++++++++++++++++++- src/logos/mod.rs | 1 + src/logos/ubuntu.rs | 20 ++++++++++++++++++++ src/main.rs | 2 +- 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/logos/ubuntu.rs diff --git a/src/lib.rs b/src/lib.rs index 60c8ec7..39dc43b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,28 +6,51 @@ pub mod logos; #[derive(Copy, Clone, Debug)] pub enum Os { ArchLinux, + Debian, + Manjaro, + Mint, + Suse, + Ubuntu, } impl Os { pub fn detect() -> Option { - Some(Os::ArchLinux) + let lsb_release = lsb_release().unwrap(); + + match lsb_release.trim() { + "archlinux" | "Arch Linux" | "arch" | "Arch" | "archarm" => Some(Os::ArchLinux), + "Debian" => Some(Os::Debian), + "ManjaroLinux" => Some(Os::Manjaro), + "LinuxMint" => Some(Os::Mint), + "openSUSE" | "openSUSE project" | "SUSE LINUX" | "SUSE" => Some(Os::Suse), + "Ubuntu" => Some(Os::Ubuntu), + + _ => None, + } + } pub fn ascii_logo(self) -> &'static str { match self { Os::ArchLinux => logos::archlinux::ASCII_LOGO, + Os::Ubuntu => logos::ubuntu::ASCII_LOGO, + _ => unimplemented!(), } } pub fn name(self) -> &'static str { match self { Os::ArchLinux => "Arch Linux", + Os::Ubuntu => "Ubuntu", + _ => unimplemented!(), } } pub fn style(self) -> &'static str { match self { Os::ArchLinux => "\x1B[36;1m", + Os::Ubuntu => "\x1B[31;1m", + _ => unimplemented!(), } } @@ -49,4 +72,5 @@ macro_rules! define_command_function { define_command_function!(kernel, "uname", ["-msr"]); define_command_function!(uptime, "uptime", ["-p"]); +define_command_function!(lsb_release, "lsb_release", ["-si"]); diff --git a/src/logos/mod.rs b/src/logos/mod.rs index cb334e4..3a52bff 100644 --- a/src/logos/mod.rs +++ b/src/logos/mod.rs @@ -1 +1,2 @@ pub mod archlinux; +pub mod ubuntu; diff --git a/src/logos/ubuntu.rs b/src/logos/ubuntu.rs new file mode 100644 index 0000000..29eac35 --- /dev/null +++ b/src/logos/ubuntu.rs @@ -0,0 +1,20 @@ +pub const ASCII_LOGO: &'static str = " \ +\n \x1B[31;1m./+o+-\x1B[0m \ +\n \x1B[1myyyyy-\x1B[0m \x1B[31;1m-yyyyyy+\x1B[0m \ +\n \x1B[1m://+//////\x1B[31;1m-yyyyyyo\x1B[0m \ +\n \x1B[33;1m.++ \x1B[0;1m.:/++++++/-\x1B[31;1m.+sss/`\x1B[0m \ +\n \x1B[33;1m.:++o: \x1B[0;1m/++++++++/:--:/-\x1B[0m \ +\n \x1B[33;1mo:+o+:++.\x1B[0;1m`..```.-/oo+++++/\x1B[0m \ +\n \x1B[33;1m.:+o:+o/.\x1B[0m \x1B[1m`+sssoo+/\x1B[0m \ +\n \x1B[0;1m.++/+:\x1B[33;1m+oo+o:`\x1B[0m \x1B[1m/sssooo.\x1B[0m \ +\n/\x1B[0;1m+++//+:\x1B[33;1m`oo+o\x1B[0m \x1B[1m/::--:.\x1B[0m \ +\n\x1B[0;1m\\+/+o+++\x1B[33;1m`o++o\x1B[0m \x1B[31;1m++////.\x1B[0m \ +\n \x1B[0;1m.++.o+\x1B[33;1m++oo+:`\x1B[0m \x1B[31;1m/dddhhh.\x1B[0m \ +\n \x1B[33;1m.+.o+oo:.\x1B[0m \x1B[31;1m`oddhhhh+\x1B[0m \ +\n \x1B[33;1m\\+.++o+o`\x1B[31;1m`-````.:ohdhhhhh+\x1B[0m \ +\n \x1B[33;1m`:o+++ \x1B[31;1m`ohhhhhhhhyo++os:\x1B[0m \ +\n \x1B[33;1m.o:\x1B[31;1m`.syhhhhhhh/\x1B[33;1m.oo++o`\x1B[0m \ +\n \x1B[31;1m/osyyyyyyo\x1B[33;1m++ooo+++/\x1B[0m \ +\n \x1B[31;1m````` \x1B[33;1m+oo+++o\\:\x1B[0m \ +\n \x1B[33;1m`oo++.\x1B[0m \ +\n"; diff --git a/src/main.rs b/src/main.rs index 5d3837e..cbcc3fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,7 @@ pub fn main() { info.push(format!("{style}{}:{unstyle} {}\n", split[0], split[1], style = style, unstyle = unstyle)); } - let mut logo_iterator = Os::ArchLinux.ascii_logo().lines(); + let mut logo_iterator = os.ascii_logo().lines(); let mut info_iterator = info.iter(); loop {