Merge pull request #12 from RubixDev/main

feat: add DietPi logo and support all 256 ANSI colors
This commit is contained in:
Adrian Groh 2023-02-25 21:30:32 +01:00 committed by GitHub
commit 3d2854ec7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 37 deletions

View File

@ -18,12 +18,13 @@ into problems, please open an issue._
**Included Logos:** Alpine Linux, Android, Arch Linux, ArcoLinux, Artix Linux,
Bedrock Linux, Buildroot, CelOS, CentOS, Crystal Linux, dahliaOS, Debian,
Devuan, DragonflyBSD, Elementary OS, EndeavourOS, Fedora, FreeBSD, Garuda Linux,
Gentoo Linux, Gnu, Guix, Haiku, HydroOS, Hyperbola, instantOS, IRIX, KDE neon,
Linux Lite, Linux, Mint, macOS, Mageia, Manjaro, Minix, MX Linux, NetBSD, NixOS,
OpenBSD, openSUSE Tumbleweed, openSUSE Leap, OpenWrt, Parabola, Pop!\_OS
(updated), PureOS, Raspbian, SerenityOS, Slackware, Solus, Solaris, Ubuntu, Void
Linux, Xeonix Linux, Fiwix (new), MorphOS (new), AmogOS (new), Aperio (new)
Devuan, DietPi, DragonflyBSD, Elementary OS, EndeavourOS, Fedora, FreeBSD,
Garuda Linux, Gentoo Linux, Gnu, Guix, Haiku, HydroOS, Hyperbola, instantOS,
IRIX, KDE neon, Linux Lite, Linux, Mint, macOS, Mageia, Manjaro, Minix, MX
Linux, NetBSD, NixOS, OpenBSD, openSUSE Tumbleweed, openSUSE Leap, OpenWrt,
Parabola, Pop!\_OS (updated), PureOS, Raspbian, SerenityOS, Slackware, Solus,
Solaris, Ubuntu, Void Linux, Xeonix Linux, Fiwix (new), MorphOS (new), AmogOS
(new)
For all other distributions, a penguin will be displayed.
@ -160,5 +161,4 @@ XDG_CURRENT_DESKTOP=""
# Skip package managers that take "long" to query package count (like nix)
PF_FAST_PKG_COUNT=1
```

View File

@ -178,6 +178,17 @@ case ${1:-${PF_ASCII:-${distro:-$os}}} in
EOF
;;
[Dd]iet[Pp]i*)
read_ascii 8 2 <<- EOF
${c2} __ __
${c2} (_\\)(/_)
${c8} (______)
${c8}(_${c2}<>${c8}__${c2}<>${c8}_)
${c8} (__${c2}''${c8}__)
${c8} (__)
EOF
;;
[Dd]ragon[Ff]ly*)
read_ascii 1 <<- EOF
,${c1}_${c7},
@ -693,7 +704,7 @@ case ${1:-${PF_ASCII:-${distro:-$os}}} in
${c6}/____/ ${c4}/____/
EOF
;;
[Mm]orphOS*)
[Mm]orph[Oo][Ss]*)
read_ascii 1 <<- EOF
${c4} __ \/ __
${c4} /o \{}/ o\\

View File

@ -63,17 +63,10 @@ fn parse_logo(input: &str) -> Option<(bool, proc_macro2::TokenStream)> {
let mut logo_parts = vec![];
for logo_part in logo.split("${") {
if let Some((new_color, rest)) = logo_part.split_once('}') {
let new_color: u8 = match new_color {
"c0" => 0,
"c1" => 1,
"c2" => 2,
"c3" => 3,
"c4" => 4,
"c5" => 5,
"c6" => 6,
"c7" => 7,
_ => panic!("Unknown color: {new_color}"),
};
let new_color: u8 = new_color
.get(1..)
.and_then(|num| num.parse().ok())
.unwrap_or_else(|| panic!("Invalid color: {new_color}"));
let rest = rest.replace("\\\\", "\\");
let rest = rest.replace("\\`", "`");
let lines = rest.split('\n').collect::<Vec<_>>();
@ -83,11 +76,11 @@ fn parse_logo(input: &str) -> Option<(bool, proc_macro2::TokenStream)> {
if index != last_index {
line += "\n";
}
logo_parts.push(quote! { (Color(#new_color), #line) });
logo_parts.push(quote! { (Color(Some(#new_color)), #line) });
}
} else if !logo_part.is_empty() {
let logo_part = logo_part.replace("\\\\", "\\");
logo_parts.push(quote! { (Color(9), #logo_part) });
logo_parts.push(quote! { (Color(None), #logo_part) });
}
}
@ -95,8 +88,8 @@ fn parse_logo(input: &str) -> Option<(bool, proc_macro2::TokenStream)> {
pattern == "[Ll]inux*",
quote! {
Logo {
primary_color: Color(#primary_color),
secondary_color: Color(#secondary_color),
primary_color: Color(Some(#primary_color)),
secondary_color: Color(Some(#secondary_color)),
pattern: #pattern,
logo_parts: &[#(#logo_parts),*],
}

View File

@ -18,6 +18,7 @@ crystallinux
dahlia
debian
devuan
dietpi
dragonfly
elementary
endeavour
@ -62,5 +63,4 @@ xeonix
fiwix
morphos
amogos
aperio
EOF

View File

@ -8,12 +8,15 @@ use libmacchina::{
};
use pfetch_extractor::parse_logos;
#[derive(Clone, Copy)]
pub struct Color(pub u8);
#[derive(Clone, Copy, Debug)]
pub struct Color(pub Option<u8>);
impl Display for Color {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "\x1b[3{}m", self.0)
match self.0 {
Some(color) => write!(f, "\x1b[38;5;{color}m"),
None => write!(f, "\x1b[39m"),
}
}
}
@ -21,16 +24,7 @@ impl FromStr for Color {
type Err = String;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
match s.parse::<u8>() {
Ok(color) => {
if color >= 9 {
Err(format!("Invalid color: {color}"))
} else {
Ok(Color(color))
}
}
Err(_) => Err(format!("Not a valid color: {s}")),
}
Ok(Color(s.parse::<u8>().ok()))
}
}