use crate::bar::Bar;
use crate::spinner::Spinner;
#[derive(Clone)]
pub struct Theme<'a> {
pub(crate) spinner: Spinner<'a>,
pub(crate) bar: Bar<'a>,
pub(crate) bar_width: Option<usize>,
}
impl<'a> Default for Theme<'a> {
fn default() -> Self {
Self::new()
}
}
impl<'a> Theme<'a> {
pub const fn new() -> Self {
Self {
spinner: Spinner::inactive(),
bar: Bar::empty(),
bar_width: None,
}
}
pub const fn with_spinner(mut self, spinner: Spinner<'a>) -> Self {
self.spinner = spinner;
self
}
pub const fn with_bar(mut self, bar: Bar<'a>) -> Self {
self.bar = bar;
self
}
pub const fn with_bar_width(mut self, width: usize) -> Self {
self.bar_width = Some(width);
self
}
pub(crate) fn effective_bar_width(&self) -> usize {
self.bar_width.unwrap_or_else(|| {
terminal_size::terminal_size()
.map(|(w, _)| (w.0 as usize).saturating_sub(20).clamp(10, 80))
.unwrap_or(40)
})
}
}
impl<'a> From<Spinner<'a>> for Theme<'a> {
fn from(spinner: Spinner<'a>) -> Self {
Theme::default().with_spinner(spinner)
}
}