use super::super::theme::{accent, secondary};
use ratatui::{
style::{Modifier, Style},
text::{Line, Span},
};
pub(crate) const NO_DATABASE_HEADLINE: &str = "No database is configured yet.";
pub(in crate::interactive::tui) const NO_DATABASE_STEPS: [&str; 3] = [
"Run `saya config init` — it prints where it wrote the files.",
"Add your database there, then `saya connection test <name>`.",
"Restart saya to pick it up.",
];
pub(in crate::interactive::tui) const NO_DATABASE_FOOTER: &str =
"`saya config doctor` explains anything still missing.";
pub(crate) const NO_WORKSPACE_LINES: [&str; 2] = [
"No workspace is bound: file tools are unavailable;",
"launch inside a git worktree or pass `--workspace <dir>`.",
];
const SPLASH_ART: [&str; 8] = [
" \u{2584}\u{2584} \u{2584}\u{2584} ",
" \u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588} ",
" \u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588} ",
" \u{2588}\u{2588}\u{2588} \u{2590} \u{2588}\u{2588}\u{2588} \u{258c} \u{2588}\u{2588}\u{2588} ",
" \u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{25bc}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588} ",
" \u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588} ",
" \u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588} ",
" \u{2580}\u{2580} \u{2580}\u{2580} ",
];
const SPLASH_ART_COMPACT: [&str; 5] = [
" \u{2584} \u{2584} ",
" \u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588} ",
" \u{2588}\u{2588} \u{2590} \u{258c} \u{2588}\u{2588} ",
" \u{2588}\u{2588}\u{2588}\u{2588}\u{25bc}\u{2588}\u{2588}\u{2588}\u{2588} ",
" \u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588}\u{2588} ",
];
pub(super) fn splash_art(
available_height: usize,
content_len: usize,
) -> Option<Vec<Line<'static>>> {
if available_height > content_len + SPLASH_ART.len() {
Some(art_lines(&SPLASH_ART))
} else if available_height > content_len + SPLASH_ART_COMPACT.len() {
Some(art_lines(&SPLASH_ART_COMPACT))
} else {
None
}
}
fn glyph_style(ch: char) -> Style {
match ch {
'\u{258c}' | '\u{2590}' => Style::default().add_modifier(Modifier::BOLD),
'\u{25bc}' | '\u{2580}' => Style::default().fg(secondary()),
_ => Style::default().fg(accent()),
}
}
fn art_lines(rows: &[&'static str]) -> Vec<Line<'static>> {
rows.iter()
.map(|row| {
let mut spans: Vec<Span<'static>> = Vec::new();
for ch in row.chars() {
let style = glyph_style(ch);
match spans.last_mut() {
Some(last) if last.style == style => last.content.to_mut().push(ch),
_ => spans.push(Span::styled(ch.to_string(), style)),
}
}
Line::from(spans)
})
.collect()
}
#[cfg(test)]
#[path = "splash_tests.rs"]
mod tests;