use std::sync::OnceLock;
use ratatui::symbols::border;
#[derive(Debug, Clone, Copy)]
pub struct Glyphs {
pub spinner: &'static [&'static str],
pub bar_fill: &'static str,
pub bar_partials: &'static [&'static str],
pub bar_track: &'static str,
pub down: &'static str,
pub up: &'static str,
pub latency: &'static str,
pub check: &'static str,
pub repeat: &'static str,
pub cursor: &'static str,
pub active: &'static str,
pub border: border::Set<'static>,
pub fancy: bool,
}
pub const UNICODE: Glyphs = Glyphs {
spinner: &["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
bar_fill: "█",
bar_partials: &["▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"],
bar_track: "╌",
down: "↓",
up: "↑",
latency: "⇄",
check: "✓",
repeat: "⟳",
cursor: "▸ ",
active: " ●",
border: border::ROUNDED,
fancy: true,
};
pub const ASCII: Glyphs = Glyphs {
spinner: &["|", "/", "-", "\\"],
bar_fill: "#",
bar_partials: &["#"],
bar_track: "-",
down: "v",
up: "^",
latency: "<>",
check: "OK",
repeat: "~",
cursor: "> ",
active: " *",
border: border::Set {
top_left: "+",
top_right: "+",
bottom_left: "+",
bottom_right: "+",
vertical_left: "|",
vertical_right: "|",
horizontal_top: "-",
horizontal_bottom: "-",
},
fancy: false,
};
static ACTIVE: OnceLock<&'static Glyphs> = OnceLock::new();
pub fn select(ascii: bool) {
let _ = ACTIVE.set(if ascii { &ASCII } else { &UNICODE });
}
#[must_use]
pub fn current() -> &'static Glyphs {
ACTIVE.get().copied().unwrap_or(&UNICODE)
}
impl Glyphs {
#[must_use]
pub fn spinner_frame(&self, tick: u64) -> &'static str {
self.spinner[(tick as usize) % self.spinner.len()]
}
}