From f0712479cbdff239347049461be1901e13950044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Fri, 7 May 2021 17:38:25 +0900 Subject: [PATCH] Define text color (mostly) in theme.toml. --- helix-term/src/ui/editor.rs | 11 +++++------ helix-term/src/ui/markdown.rs | 2 +- helix-term/src/ui/menu.rs | 2 +- helix-term/src/ui/mod.rs | 6 ------ helix-term/src/ui/picker.rs | 2 +- helix-term/src/ui/prompt.rs | 3 +-- helix-term/src/ui/text.rs | 2 +- theme.toml | 3 +++ 8 files changed, 13 insertions(+), 18 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 79a6ede2a..58378eaf4 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -3,7 +3,7 @@ use crate::{ compositor::{Component, Compositor, Context, EventResult}, key, keymap::{self, Keymaps}, - ui::{text_color, Completion}, + ui::Completion, }; use helix_core::{ @@ -150,7 +150,7 @@ impl EditorView { // first rule that matches (rule.all(|scope| scopes.contains(scope))) let style = match spans.first() { Some(span) => theme.get(theme.scopes()[span.0].as_str()), - None => Style::default().fg(Color::Rgb(164, 160, 232)), // lavender + None => theme.get("ui.text"), }; // TODO: we could render the text to a surface, then cache that, that @@ -409,11 +409,10 @@ impl EditorView { Mode::Select => "SEL", Mode::Normal => "NOR", }; - // TODO: share text_color styles inside theme let text_color = if is_focused { - Style::default().fg(Color::Rgb(219, 191, 239)) // lilac + theme.get("ui.text.focus") } else { - Style::default().fg(Color::Rgb(164, 160, 232)) // lavender + theme.get("ui.text") }; // statusline surface.set_style( @@ -632,7 +631,7 @@ impl Component for EditorView { let style = if *severity == Severity::Error { cx.editor.theme.get("error") } else { - Style::default().fg(Color::Rgb(164, 160, 232)) // lavender + cx.editor.theme.get("ui.text") }; surface.set_string( diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index 0b41e0444..8d14841e1 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -104,7 +104,7 @@ fn parse<'a>(contents: &'a str, theme: Option<&Theme>) -> tui::text::Text<'a> { Some(span) => { theme.get(theme.scopes()[span.0].as_str()) } - None => Style::default().fg(Color::Rgb(164, 160, 232)), // lavender + None => text_style, }; let mut slice = &text[start..end]; diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index f8f6f2693..d055d0d08 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -240,7 +240,7 @@ impl Component for Menu { } fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) { - let style = Style::default().fg(Color::Rgb(164, 160, 232)); // lavender + let style = cx.editor.theme.get("ui.text"); let selected = Style::default().fg(Color::Rgb(255, 255, 255)); let scroll = self.scroll; diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index a16b7ef0f..dc1ec6b65 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -24,12 +24,6 @@ use helix_view::{Document, Editor, View}; use std::path::{Path, PathBuf}; -// TODO: temp -#[inline(always)] -pub fn text_color() -> Style { - Style::default().fg(Color::Rgb(219, 191, 239)) // lilac -} - pub fn regex_prompt( cx: &mut crate::commands::Context, prompt: String, diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 39580f66f..73cbf07f4 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -245,7 +245,7 @@ impl Component for Picker { // -- Render the contents: - let style = Style::default().fg(Color::Rgb(164, 160, 232)); // lavender + let style = cx.editor.theme.get("ui.text"); let selected = Style::default().fg(Color::Rgb(255, 255, 255)); let rows = inner.height - 2; // -1 for search bar diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index f199115f2..b7cf4d94e 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -103,11 +103,10 @@ use tui::{ }; const BASE_WIDTH: u16 = 30; -use crate::ui::text_color; impl Prompt { pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) { - let text_color = text_color(); + let text_color = theme.get("ui.text.focus"); // completion if !self.completion.is_empty() { // TODO: find out better way of clearing individual lines of the screen diff --git a/helix-term/src/ui/text.rs b/helix-term/src/ui/text.rs index 588e12c42..6225e7690 100644 --- a/helix-term/src/ui/text.rs +++ b/helix-term/src/ui/text.rs @@ -25,7 +25,7 @@ impl Component for Text { use tui::widgets::{Paragraph, Widget, Wrap}; let contents = tui::text::Text::from(self.contents.clone()); - let style = Style::default().fg(Color::Rgb(164, 160, 232)); // lavender + let style = cx.editor.theme.get("ui.text"); let par = Paragraph::new(contents).wrap(Wrap { trim: false }); // .scroll(x, y) offsets diff --git a/theme.toml b/theme.toml index 0d4e0857f..8659d400f 100644 --- a/theme.toml +++ b/theme.toml @@ -43,6 +43,9 @@ "ui.popup" = { bg = "#281733" } # revolver "ui.window" = { bg = "#452859" } # bossa nova +"ui.text" = { fg = "#a4a0e8"} # lavender +"ui.text.focus" = { fg = "#dbbfef"} # lilac + "warning" = "#ffcd1c" "error" = "#f47868" "info" = "#6F44F0"