From 8fbbb547ca638f16617210b9a4f6c40b131c0de9 Mon Sep 17 00:00:00 2001 From: Yifan Song Date: Wed, 27 Sep 2023 01:26:11 +0200 Subject: [PATCH] Move help colors into THEME system --- app/src/help/bindings.rs | 19 +++++++++++++------ app/src/help/layout.rs | 10 +++++----- config/preset/theme.toml | 7 +++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/src/help/bindings.rs b/app/src/help/bindings.rs index 2bb6c64f..2a0f4fa7 100644 --- a/app/src/help/bindings.rs +++ b/app/src/help/bindings.rs @@ -1,6 +1,7 @@ -use core::Ctx; +use config::THEME; +use ratatui::{layout::{self, Constraint}, prelude::{Buffer, Direction, Rect}, widgets::{List, ListItem, Widget}}; -use ratatui::{layout::{self, Constraint}, prelude::{Buffer, Direction, Rect}, style::{Color, Style, Stylize}, widgets::{List, ListItem, Widget}}; +use crate::context::Ctx; pub(super) struct Bindings<'a> { cx: &'a Ctx, @@ -17,19 +18,25 @@ impl Widget for Bindings<'_> { return; } + // Key let col1 = bindings .iter() - .map(|c| ListItem::new(c.on()).style(Style::new().fg(Color::Yellow))) + .map(|c| ListItem::new(c.on()).style(THEME.help.key.get())) .collect::>(); + // Execution let col2 = bindings .iter() - .map(|c| ListItem::new(c.exec()).style(Style::new().fg(Color::Cyan))) + .map(|c| ListItem::new(c.exec()).style(THEME.help.exec.get())) .collect::>(); + // Description let col3 = bindings .iter() - .map(|c| ListItem::new(if let Some(ref desc) = c.desc { desc } else { "-" })) + .map(|c| { + ListItem::new(if let Some(ref desc) = c.desc { desc } else { "-" }) + .style(THEME.help.desc.get()) + }) .collect::>(); let chunks = layout::Layout::new() @@ -40,7 +47,7 @@ impl Widget for Bindings<'_> { let cursor = self.cx.help.rel_cursor() as u16; buf.set_style( Rect { x: area.x, y: area.y + cursor, width: area.width, height: 1 }, - Style::new().bg(Color::Black).bold(), + THEME.help.curr.get(), ); List::new(col1).render(chunks[0], buf); diff --git a/app/src/help/layout.rs b/app/src/help/layout.rs index d12acdb8..f0f32cfd 100644 --- a/app/src/help/layout.rs +++ b/app/src/help/layout.rs @@ -1,8 +1,8 @@ -use core::Ctx; - -use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, style::{Color, Style}, widgets::{Clear, Paragraph, Widget}}; +use config::THEME; +use ratatui::{buffer::Buffer, layout::{self, Rect}, prelude::{Constraint, Direction}, widgets::{Clear, Paragraph, Widget}}; use super::Bindings; +use crate::Ctx; pub(crate) struct Layout<'a> { cx: &'a Ctx, @@ -16,14 +16,14 @@ impl<'a> Widget for Layout<'a> { fn render(self, area: Rect, buf: &mut Buffer) { let chunks = layout::Layout::new() .direction(Direction::Vertical) - .constraints([Constraint::Min(0), Constraint::Length(1)]) + .constraints([Constraint::Min(0), Constraint::Length(1)].as_ref()) .split(area); Clear.render(area, buf); let help = &self.cx.help; Paragraph::new(help.keyword().unwrap_or_else(|| format!("{}.help", help.layer()))) - .style(Style::new().fg(Color::Black).bg(Color::White)) + .style(THEME.help.btm.get()) .render(chunks[1], buf); Bindings::new(self.cx).render(chunks[0], buf); diff --git a/config/preset/theme.toml b/config/preset/theme.toml index 6e35b1ac..1934524b 100644 --- a/config/preset/theme.toml +++ b/config/preset/theme.toml @@ -38,6 +38,13 @@ cut = { fg = "#FF84A9", bg = "#FF84A9" } hovered = { underline = true } syntect_theme = "~/.config/bat/themes/Catppuccin-macchiato.tmTheme" +[help] +key = { fg = "#E5E510" } +exec = { fg = "#11A8CD" } +desc = { fg = "#E5E5E5" } +curr = { bg = "#666666", bold = true } +btm = { fg = "#666666", bg = "#E5E5E5" } + [filetype] rules = [