jobber 1.1.2-alpha

Minimalistic console work time tracker
//! Entity console views

pub(crate) use bill_view::*;
pub(crate) use calendar_view::*;
pub(crate) use client_view::*;
pub(crate) use company_view::*;
pub(crate) use info_view::*;
pub(crate) use invoice_view::*;
pub(crate) use job_view::*;
pub(crate) use tag_view::*;
pub(crate) use work_view::*;
pub(crate) use worker_view::*;

use serde::{Deserialize, Serialize};

mod bill_view;
mod calendar_view;
mod client_view;
mod company_view;
mod info_view;
mod invoice_view;
mod job_view;
mod tag_view;
mod work_view;
mod worker_view;

#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
pub(crate) enum TableStyle {
    Empty,
    Markdown,
    #[default]
    Rounded,
}

impl TableStyle {
    fn table_theme(&self) -> Theme {
        match self {
            TableStyle::Empty => Theme::from_style(Style::empty()),
            TableStyle::Markdown => Theme::from_style(Style::markdown()),
            TableStyle::Rounded => Theme::from_style(Style::rounded()),
        }
    }
}

use tabled::{
    Table,
    settings::{Style, Theme},
};

pub(crate) trait ApplyTableStyle<'a> {
    fn style(&'a mut self, style: &TableStyle) -> &'a mut Self;
}

impl<'a> ApplyTableStyle<'a> for Table {
    fn style(&'a mut self, style: &TableStyle) -> &'a mut Self {
        self.with(style.table_theme())
    }
}