From 6b59f81f20195602d177ce3dfbf1bfb4318b880a Mon Sep 17 00:00:00 2001 From: Yifan Song Date: Tue, 26 Sep 2023 13:15:27 +0200 Subject: [PATCH] Add which color into theme system --- app/src/which/layout.rs | 12 +++++++----- app/src/which/side.rs | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/src/which/layout.rs b/app/src/which/layout.rs index 686bf8be..17ae1779 100644 --- a/app/src/which/layout.rs +++ b/app/src/which/layout.rs @@ -1,8 +1,8 @@ -use core::Ctx; - -use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, style::{Color, Style}, widgets::{Block, Clear, Widget}}; +use config::THEME; +use ratatui::{layout, prelude::{Buffer, Constraint, Direction, Rect}, style::Style, widgets::{Block, Clear, Widget}}; use super::Side; +use crate::Ctx; pub(crate) struct Which<'a> { cx: &'a Ctx, @@ -35,11 +35,13 @@ impl Widget for Which<'_> { let chunks = layout::Layout::new() .direction(Direction::Horizontal) - .constraints([Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)]) + .constraints( + [Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)].as_ref(), + ) .split(area); Clear.render(area, buf); - Block::new().style(Style::new().bg(Color::Rgb(47, 51, 73))).render(area, buf); + Block::new().style(Style::new().bg(*THEME.which.block)).render(area, buf); Side::new(which.times, cands.0).render(chunks[0], buf); Side::new(which.times, cands.1).render(chunks[1], buf); Side::new(which.times, cands.2).render(chunks[2], buf); diff --git a/app/src/which/side.rs b/app/src/which/side.rs index da14f5c2..404c68b4 100644 --- a/app/src/which/side.rs +++ b/app/src/which/side.rs @@ -1,5 +1,5 @@ -use config::keymap::Control; -use ratatui::{prelude::{Buffer, Rect}, style::{Color, Style}, text::{Line, Span}, widgets::{Block, List, ListItem, Padding, Widget}}; +use config::{keymap::Control, THEME}; +use ratatui::{prelude::{Buffer, Rect}, style::Style, text::{Line, Span}, widgets::{Block, List, ListItem, Padding, Widget}}; pub(super) struct Side<'a> { times: usize, @@ -21,19 +21,19 @@ impl Widget for Side<'_> { // Keys let keys = c.on[self.times..].iter().map(ToString::to_string).collect::>(); spans.push(Span::raw(" ".repeat(10usize.saturating_sub(keys.join("").len())))); - spans.push(Span::styled(keys[0].clone(), Style::new().fg(Color::LightCyan))); + spans.push(Span::styled(keys[0].clone(), THEME.which.key.get())); spans.extend( - keys - .iter() - .skip(1) - .map(|k| Span::styled(k.to_string(), Style::new().fg(Color::DarkGray))), + keys.iter().skip(1).map(|k| Span::styled(k.to_string(), THEME.which.extend.get())), ); // Separator - spans.push(Span::styled("  ".to_string(), Style::new().fg(Color::DarkGray))); + spans.push(Span::styled( + THEME.which.separator.separator.to_string(), + Style::new().fg(*THEME.which.separator.color), + )); - // Exec - spans.push(Span::styled(c.desc_or_exec(), Style::new().fg(Color::Magenta))); + // Exec, + spans.push(Span::styled(c.desc_or_exec(), THEME.which.desc.get())); ListItem::new(Line::from(spans)) })