pub use crate::assets::{get_ascii, list_ascii};
use crate::constants::DEFAULT_ASCII_ART;
use std::str::FromStr;
#[derive(Debug, Clone)]
pub struct Ascii {
pub name: String,
}
pub fn get_default_art_by_os() -> &'static str {
match () {
_ if cfg!(target_os = "macos") => "Apple",
_ if cfg!(target_os = "windows") => "Windows7",
_ if cfg!(target_os = "linux") => get_art_by_linux_distro(),
_ => DEFAULT_ASCII_ART,
}
}
fn get_art_by_linux_distro() -> &'static str {
let os_release = match std::fs::read_to_string("/etc/os-release") {
Ok(content) => content,
Err(_) => return DEFAULT_ASCII_ART,
};
for line in os_release.lines() {
if let Some(id) = line.strip_prefix("ID=") {
let id = id.trim_matches('"').trim();
return match id {
"arch" if is_potentially_omarchy() => "Omarchy",
"arch" => "Arch Linux",
"manjaro" => "Manjaro Linux",
"ubuntu" => "Ubuntu Linux",
"debian" => "Debian Linux",
"fedora" => "Fedora Linux",
"gentoo" => "Gentoo Linux",
"void" => "Void Linux",
"nixos" => "NixOS",
"kali" => "Kali Linux",
"linuxmint" => "Linux Mint",
"omarchy" => "Omarchy",
_ => "GNU",
};
}
}
DEFAULT_ASCII_ART
}
fn is_potentially_omarchy() -> bool {
if let Ok(path) = std::env::var("OMARCHY_PATH") {
if std::path::Path::new(&path).exists() {
return true;
}
}
if std::path::Path::new(&format!(
"{}/.local/share/omarchy",
std::env::var("HOME").unwrap_or_default()
))
.exists()
{
return true;
}
std::process::Command::new("omarchy-version")
.output()
.is_ok()
}
impl FromStr for Ascii {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if get_ascii(s).is_some() {
Ok(Ascii {
name: s.to_string(),
})
} else {
Err(format!("Ascii art '{}' not found", s))
}
}
}