Skip to content

Commit

Permalink
Merge pull request #122 from sachaos/set-color
Browse files Browse the repository at this point in the history
Enable to set some styles
  • Loading branch information
sachaos authored Aug 17, 2024
2 parents cbade64 + 3af2936 commit 4a00525
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .config/config.json5
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
},
"styles": {
"All": {
"secondary_text": "rgb111",
"timemachine_selector": "white on rgb111",
"border": "rgb111",
"title": "rgb111",
"scrollbar": "rgb111",
Expand Down
2 changes: 2 additions & 0 deletions src/components/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/components/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 17 additions & 11 deletions src/widget/history_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Local>, duration: Duration) -> Self {
pub fn new(
id: ExecutionId,
start_time: DateTime<Local>,
duration: Duration,
selector_style: Style,
secondary_text_style: Style,
) -> Self {
Self {
id,
start_time,
Expand All @@ -27,6 +35,8 @@ impl HisotryItem {
style: Style::default(),
interval: duration,
count: 1,
selector_style,
secondary_text_style,
}
}

Expand All @@ -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
Expand All @@ -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)
};
Expand All @@ -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)
Expand All @@ -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));
Expand All @@ -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,
));
}

Expand Down

0 comments on commit 4a00525

Please sign in to comment.