use rat_ftable::TableStyle; use rat_scrolled::ScrollStyle; use ratatui::style::{Color, Style, Stylize}; #[derive(Debug, Default, Clone)] pub struct Scheme { pub white: [Color; 4], pub black: [Color; 4], pub gray: [Color; 4], pub red: [Color; 4], pub orange: [Color; 4], pub yellow: [Color; 4], pub limegreen: [Color; 4], pub green: [Color; 4], pub bluegreen: [Color; 4], pub cyan: [Color; 4], pub blue: [Color; 4], pub deepblue: [Color; 4], pub purple: [Color; 4], pub magenta: [Color; 4], pub redpink: [Color; 4], pub primary: [Color; 4], pub secondary: [Color; 4], } impl Scheme { /// Create a style from the given white shade. /// n is `0..=3` pub fn white(&self, n: usize) -> Style { self.style(self.white[n]) } /// Create a style from the given black shade. /// n is `0..=3` pub fn black(&self, n: usize) -> Style { self.style(self.black[n]) } /// Create a style from the given gray shade. /// n is `0..=3` pub fn gray(&self, n: usize) -> Style { self.style(self.gray[n]) } /// Create a style from the given red shade. /// n is `0..=3` pub fn red(&self, n: usize) -> Style { self.style(self.red[n]) } /// Create a style from the given orange shade. /// n is `0..=3` pub fn orange(&self, n: usize) -> Style { self.style(self.orange[n]) } /// Create a style from the given yellow shade. /// n is `0..=3` pub fn yellow(&self, n: usize) -> Style { self.style(self.yellow[n]) } /// Create a style from the given limegreen shade. /// n is `0..=3` pub fn limegreen(&self, n: usize) -> Style { self.style(self.limegreen[n]) } /// Create a style from the given green shade. /// n is `0..=3` pub fn green(&self, n: usize) -> Style { self.style(self.green[n]) } /// Create a style from the given bluegreen shade. /// n is `0..=3` pub fn bluegreen(&self, n: usize) -> Style { self.style(self.bluegreen[n]) } /// Create a style from the given cyan shade. /// n is `0..=3` pub fn cyan(&self, n: usize) -> Style { self.style(self.cyan[n]) } /// Create a style from the given blue shade. /// n is `0..=3` pub fn blue(&self, n: usize) -> Style { self.style(self.blue[n]) } /// Create a style from the given deepblue shade. /// n is `0..=3` pub fn deepblue(&self, n: usize) -> Style { self.style(self.deepblue[n]) } /// Create a style from the given purple shade. /// n is `0..=3` pub fn purple(&self, n: usize) -> Style { self.style(self.purple[n]) } /// Create a style from the given magenta shade. /// n is `0..=3` pub fn magenta(&self, n: usize) -> Style { self.style(self.magenta[n]) } /// Create a style from the given redpink shade. /// n is `0..=3` pub fn redpink(&self, n: usize) -> Style { self.style(self.redpink[n]) } /// Create a style from the given primary shade. /// n is `0..=3` pub fn primary(&self, n: usize) -> Style { self.style(self.primary[n]) } /// Create a style from the given secondary shade. /// n is `0..=3` pub fn secondary(&self, n: usize) -> Style { self.style(self.secondary[n]) } /// Focus style pub fn focus(&self) -> Style { let bg = self.primary[2]; Style::default().fg(self.text_color(bg)).bg(bg) } /// Selection style pub fn select(&self) -> Style { let bg = self.secondary[1]; Style::default().fg(self.text_color(bg)).bg(bg) } /// Text field style. pub fn text_input(&self) -> Style { self.style(self.gray[2]) } /// Focus style pub fn text_input_focus(&self) -> Style { let bg = self.primary[2]; Style::default().fg(self.text_color(bg)).bg(bg).underlined() } pub fn block(&self) -> Style { Style::default().fg(self.gray[1]).bg(self.black[1]) } pub fn block_title(&self) -> Style { Style::default().fg(self.secondary[1]).bg(self.black[1]) } pub fn scroll_base(&self) -> Style { Style::default().fg(self.gray[0]).bg(self.black[1]) } pub fn table(&self) -> Style { Style::default().fg(self.white[1]).bg(self.black[0]) } pub fn table_header(&self) -> Style { Style::default().fg(self.white[1]).bg(self.blue[2]) } pub fn table_footer(&self) -> Style { Style::default().fg(self.white[1]).bg(self.blue[2]) } /// Focused text field style. pub fn text_focus(&self) -> Style { let bg = self.primary[0]; Style::default().fg(self.text_color(bg)).bg(bg) } /// Text selection style. pub fn text_select(&self) -> Style { let bg = self.secondary[0]; Style::default().fg(self.text_color(bg)).bg(bg) } /// Data display style. Used for lists, tables, ... pub fn data(&self) -> Style { Style::default().fg(self.white[0]).bg(self.black[1]) } /// Background for dialogs. pub fn dialog_style(&self) -> Style { Style::default().fg(self.white[2]).bg(self.gray[1]) } /// Style for the status line. pub fn status_style(&self) -> Style { Style::default().fg(self.white[0]).bg(self.black[2]) } /// Complete FTableStyle pub fn table_style(&self) -> TableStyle { let title_style = self.style(self.black[3]); TableStyle { style: self.data(), select_row: Some(self.select()), show_row_focus: true, focus_style: Some(self.focus()), scroll: Some(self.scrolled_style()), header: Some(title_style), footer: Some(title_style), ..Default::default() } } /// Complete ListStyle pub fn list_style(&self) -> Style { self.data() } /// Complete ButtonStyle pub fn button_style(&self) -> Style { Style::default().fg(self.white[0]).bg(self.primary[0]) } pub fn armed_style(&self) -> Style { Style::default().fg(self.black[0]).bg(self.secondary[0]) } /// Complete ScrolledStyle pub fn scrolled_style(&self) -> ScrollStyle { let arrow_style = Style::default().fg(self.secondary[0]).bg(self.black[1]); ScrollStyle { thumb_style: Some(self.scroll_base()), track_style: Some(self.scroll_base()), min_style: Some(self.scroll_base()), begin_style: Some(arrow_style), end_style: Some(arrow_style), ..Default::default() } } /// Complete StatusLineStyle for a StatusLine with 3 indicator fields. /// This is what I need for the /// [minimal](https://github.com/thscharler/rat-salsa/blob/master/examples/minimal.rs) /// example, which shows timings for Render/Event/Action. pub fn statusline_style(&self) -> Vec