Merge pull request #12 from RubixDev/main
feat: add DietPi logo and support all 256 ANSI colors
This commit is contained in:
commit
3d2854ec7d
14
README.md
14
README.md
@ -18,12 +18,13 @@ into problems, please open an issue._
|
|||||||
|
|
||||||
**Included Logos:** Alpine Linux, Android, Arch Linux, ArcoLinux, Artix Linux,
|
**Included Logos:** Alpine Linux, Android, Arch Linux, ArcoLinux, Artix Linux,
|
||||||
Bedrock Linux, Buildroot, CelOS, CentOS, Crystal Linux, dahliaOS, Debian,
|
Bedrock Linux, Buildroot, CelOS, CentOS, Crystal Linux, dahliaOS, Debian,
|
||||||
Devuan, DragonflyBSD, Elementary OS, EndeavourOS, Fedora, FreeBSD, Garuda Linux,
|
Devuan, DietPi, DragonflyBSD, Elementary OS, EndeavourOS, Fedora, FreeBSD,
|
||||||
Gentoo Linux, Gnu, Guix, Haiku, HydroOS, Hyperbola, instantOS, IRIX, KDE neon,
|
Garuda Linux, Gentoo Linux, Gnu, Guix, Haiku, HydroOS, Hyperbola, instantOS,
|
||||||
Linux Lite, Linux, Mint, macOS, Mageia, Manjaro, Minix, MX Linux, NetBSD, NixOS,
|
IRIX, KDE neon, Linux Lite, Linux, Mint, macOS, Mageia, Manjaro, Minix, MX
|
||||||
OpenBSD, openSUSE Tumbleweed, openSUSE Leap, OpenWrt, Parabola, Pop!\_OS
|
Linux, NetBSD, NixOS, OpenBSD, openSUSE Tumbleweed, openSUSE Leap, OpenWrt,
|
||||||
(updated), PureOS, Raspbian, SerenityOS, Slackware, Solus, Solaris, Ubuntu, Void
|
Parabola, Pop!\_OS (updated), PureOS, Raspbian, SerenityOS, Slackware, Solus,
|
||||||
Linux, Xeonix Linux, Fiwix (new), MorphOS (new), AmogOS (new), Aperio (new)
|
Solaris, Ubuntu, Void Linux, Xeonix Linux, Fiwix (new), MorphOS (new), AmogOS
|
||||||
|
(new)
|
||||||
|
|
||||||
For all other distributions, a penguin will be displayed.
|
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)
|
# Skip package managers that take "long" to query package count (like nix)
|
||||||
PF_FAST_PKG_COUNT=1
|
PF_FAST_PKG_COUNT=1
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@ -178,6 +178,17 @@ case ${1:-${PF_ASCII:-${distro:-$os}}} in
|
|||||||
EOF
|
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*)
|
[Dd]ragon[Ff]ly*)
|
||||||
read_ascii 1 <<- EOF
|
read_ascii 1 <<- EOF
|
||||||
,${c1}_${c7},
|
,${c1}_${c7},
|
||||||
@ -693,7 +704,7 @@ case ${1:-${PF_ASCII:-${distro:-$os}}} in
|
|||||||
${c6}/____/ ${c4}/____/
|
${c6}/____/ ${c4}/____/
|
||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
[Mm]orphOS*)
|
[Mm]orph[Oo][Ss]*)
|
||||||
read_ascii 1 <<- EOF
|
read_ascii 1 <<- EOF
|
||||||
${c4} __ \/ __
|
${c4} __ \/ __
|
||||||
${c4} /o \{}/ o\\
|
${c4} /o \{}/ o\\
|
||||||
|
|||||||
@ -63,17 +63,10 @@ fn parse_logo(input: &str) -> Option<(bool, proc_macro2::TokenStream)> {
|
|||||||
let mut logo_parts = vec![];
|
let mut logo_parts = vec![];
|
||||||
for logo_part in logo.split("${") {
|
for logo_part in logo.split("${") {
|
||||||
if let Some((new_color, rest)) = logo_part.split_once('}') {
|
if let Some((new_color, rest)) = logo_part.split_once('}') {
|
||||||
let new_color: u8 = match new_color {
|
let new_color: u8 = new_color
|
||||||
"c0" => 0,
|
.get(1..)
|
||||||
"c1" => 1,
|
.and_then(|num| num.parse().ok())
|
||||||
"c2" => 2,
|
.unwrap_or_else(|| panic!("Invalid color: {new_color}"));
|
||||||
"c3" => 3,
|
|
||||||
"c4" => 4,
|
|
||||||
"c5" => 5,
|
|
||||||
"c6" => 6,
|
|
||||||
"c7" => 7,
|
|
||||||
_ => panic!("Unknown color: {new_color}"),
|
|
||||||
};
|
|
||||||
let rest = rest.replace("\\\\", "\\");
|
let rest = rest.replace("\\\\", "\\");
|
||||||
let rest = rest.replace("\\`", "`");
|
let rest = rest.replace("\\`", "`");
|
||||||
let lines = rest.split('\n').collect::<Vec<_>>();
|
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 {
|
if index != last_index {
|
||||||
line += "\n";
|
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() {
|
} else if !logo_part.is_empty() {
|
||||||
let logo_part = logo_part.replace("\\\\", "\\");
|
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*",
|
pattern == "[Ll]inux*",
|
||||||
quote! {
|
quote! {
|
||||||
Logo {
|
Logo {
|
||||||
primary_color: Color(#primary_color),
|
primary_color: Color(Some(#primary_color)),
|
||||||
secondary_color: Color(#secondary_color),
|
secondary_color: Color(Some(#secondary_color)),
|
||||||
pattern: #pattern,
|
pattern: #pattern,
|
||||||
logo_parts: &[#(#logo_parts),*],
|
logo_parts: &[#(#logo_parts),*],
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ crystallinux
|
|||||||
dahlia
|
dahlia
|
||||||
debian
|
debian
|
||||||
devuan
|
devuan
|
||||||
|
dietpi
|
||||||
dragonfly
|
dragonfly
|
||||||
elementary
|
elementary
|
||||||
endeavour
|
endeavour
|
||||||
@ -62,5 +63,4 @@ xeonix
|
|||||||
fiwix
|
fiwix
|
||||||
morphos
|
morphos
|
||||||
amogos
|
amogos
|
||||||
aperio
|
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
20
src/lib.rs
20
src/lib.rs
@ -8,12 +8,15 @@ use libmacchina::{
|
|||||||
};
|
};
|
||||||
use pfetch_extractor::parse_logos;
|
use pfetch_extractor::parse_logos;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Color(pub u8);
|
pub struct Color(pub Option<u8>);
|
||||||
|
|
||||||
impl Display for Color {
|
impl Display for Color {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
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;
|
type Err = String;
|
||||||
|
|
||||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||||
match s.parse::<u8>() {
|
Ok(Color(s.parse::<u8>().ok()))
|
||||||
Ok(color) => {
|
|
||||||
if color >= 9 {
|
|
||||||
Err(format!("Invalid color: {color}"))
|
|
||||||
} else {
|
|
||||||
Ok(Color(color))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => Err(format!("Not a valid color: {s}")),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user