From 3af29367cf7e9c7d21570e7d1c845529712c25ee Mon Sep 17 00:00:00 2001 From: Takumasa Sakao Date: Fri, 16 Aug 2024 14:03:36 +0900 Subject: [PATCH] Enable to set some styles --- .config/config.json5 | 2 ++ src/components/history.rs | 2 ++ src/components/status.rs | 2 +- src/widget/history_item.rs | 28 +++++++++++++++++----------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.config/config.json5 b/.config/config.json5 index f4b65cb..6883563 100644 --- a/.config/config.json5 +++ b/.config/config.json5 @@ -50,6 +50,8 @@ }, "styles": { "All": { + "secondary_text": "rgb111", + "timemachine_selector": "white on rgb111", "border": "rgb111", "title": "rgb111", "scrollbar": "rgb111", diff --git a/src/components/history.rs b/src/components/history.rs index 81ae4b8..8909979 100644 --- a/src/components/history.rs +++ b/src/components/history.rs @@ -72,6 +72,8 @@ impl History { id, start_time, self.runtime_config.interval, + self.config.get_style("timemachine_selector"), + self.config.get_style("secondary_text"), ))); self.index.insert(id, Rc::clone(&item)); self.items.push_front(item); diff --git a/src/components/status.rs b/src/components/status.rs index 09d0a13..d209ae5 100644 --- a/src/components/status.rs +++ b/src/components/status.rs @@ -60,7 +60,7 @@ impl Component for Status { fn draw(&mut self, f: &mut Frame<'_>, area: Rect) -> Result<()> { let enabled_style = Style::default().fg(Color::White).bold(); - let disabled_style = Style::default().fg(Color::DarkGray); + let disabled_style = self.config.get_style("secondary_text"); let mut status = vec![Span::styled( "[F]old", diff --git a/src/widget/history_item.rs b/src/widget/history_item.rs index 0c2ed26..b73a304 100644 --- a/src/widget/history_item.rs +++ b/src/widget/history_item.rs @@ -2,7 +2,7 @@ use chrono::{DateTime, Duration, Local}; use ratatui::prelude::*; use tui_widget_list::{List, ListState, PreRender, PreRenderContext}; -use crate::types::ExecutionId; +use crate::{config::Config, types::ExecutionId}; #[derive(Debug, Clone)] pub struct HisotryItem { @@ -14,10 +14,18 @@ pub struct HisotryItem { pub style: Style, pub interval: Duration, pub count: usize, + pub selector_style: Style, + pub secondary_text_style: Style, } impl HisotryItem { - pub fn new(id: ExecutionId, start_time: DateTime, duration: Duration) -> Self { + pub fn new( + id: ExecutionId, + start_time: DateTime, + duration: Duration, + selector_style: Style, + secondary_text_style: Style, + ) -> Self { Self { id, start_time, @@ -27,6 +35,8 @@ impl HisotryItem { style: Style::default(), interval: duration, count: 1, + selector_style, + secondary_text_style, } } @@ -44,9 +54,7 @@ impl HisotryItem { impl PreRender for HisotryItem { fn pre_render(&mut self, context: &PreRenderContext) -> u16 { if context.is_selected { - self.style = Style::default() - .bg(Color::DarkGray) - .fg(Color::Rgb(28, 28, 32)); + self.style = self.selector_style; }; 1 @@ -56,7 +64,7 @@ impl PreRender for HisotryItem { impl Widget for HisotryItem { fn render(self, area: Rect, buf: &mut Buffer) { let time_style = if self.is_running { - Style::default().fg(Color::DarkGray) + self.secondary_text_style } else { Style::default().fg(Color::White) }; @@ -69,7 +77,7 @@ impl Widget for HisotryItem { }); if self.is_running { - spans.push(Span::raw(" Running").style(Style::default().fg(Color::DarkGray))); + spans.push(Span::raw(" Running").style(self.secondary_text_style)); Line::from("") .spans(spans) .style(self.style) @@ -86,9 +94,7 @@ impl Widget for HisotryItem { spans.push(exit_code); } else { match self.diff { - Some((0, 0)) => { - spans.push(Span::styled(" ±0", Style::default().fg(Color::DarkGray))) - } + Some((0, 0)) => spans.push(Span::styled(" ±0", self.secondary_text_style)), Some((diff_add, diff_delete)) => { let add = Span::styled(format!(" +{}", diff_add), Style::default().fg(Color::Green)); @@ -106,7 +112,7 @@ impl Widget for HisotryItem { if self.count > 1 { spans.push(Span::styled( format!(" *{}", self.count), - Style::default().fg(Color::DarkGray), + self.secondary_text_style, )); }