#![allow(clippy::must_use_candidate)]
#![allow(clippy::pedantic)]
#![allow(clippy::nursery)]
#![allow(dead_code)]
use std::io::IsTerminal;
use miette::ThemeCharacters;
use owo_colors::Style;
#[derive(Debug, Clone)]
pub struct GraphicalTheme {
pub characters: ThemeCharacters,
pub styles: ThemeStyles,
}
impl GraphicalTheme {
pub fn ascii() -> Self {
Self { characters: ThemeCharacters::ascii(), styles: ThemeStyles::ansi() }
}
pub fn unicode() -> Self {
Self { characters: ThemeCharacters::unicode(), styles: ThemeStyles::rgb() }
}
pub fn unicode_nocolor() -> Self {
Self { characters: ThemeCharacters::unicode(), styles: ThemeStyles::none() }
}
pub fn none() -> Self {
Self { characters: ThemeCharacters::ascii(), styles: ThemeStyles::none() }
}
}
impl Default for GraphicalTheme {
fn default() -> Self {
match std::env::var("NO_COLOR") {
_ if !std::io::stdout().is_terminal() || !std::io::stderr().is_terminal() => {
Self::none()
}
Ok(string) if string != "0" => Self::unicode_nocolor(),
_ => Self::unicode(),
}
}
}
#[derive(Debug, Clone)]
pub struct ThemeStyles {
pub error: Style,
pub warning: Style,
pub advice: Style,
pub help: Style,
pub link: Style,
pub linum: Style,
pub highlights: Vec<Style>,
}
fn style() -> Style {
Style::new()
}
impl ThemeStyles {
pub fn rgb() -> Self {
Self {
error: style().fg_rgb::<225, 80, 80>().bold(), warning: style().fg_rgb::<244, 191, 117>().bold(),
advice: style().fg_rgb::<106, 159, 181>(),
help: style().fg_rgb::<106, 159, 181>(),
link: style().fg_rgb::<92, 157, 255>().bold(),
linum: style().dimmed(),
highlights: vec![
style().fg_rgb::<246, 87, 248>(),
style().fg_rgb::<30, 201, 212>(),
style().fg_rgb::<145, 246, 111>(),
],
}
}
pub fn ansi() -> Self {
Self {
error: style().red(),
warning: style().yellow(),
advice: style().cyan(),
help: style().cyan(),
link: style().cyan().underline().bold(),
linum: style().dimmed(),
highlights: vec![
style().magenta().bold(),
style().yellow().bold(),
style().green().bold(),
],
}
}
pub fn none() -> Self {
Self {
error: style(),
warning: style(),
advice: style(),
help: style(),
link: style(),
linum: style(),
highlights: vec![style()],
}
}
}