on master help sign in
ui: Refactor styling a bit, ensure infobox is stylable
commit68626b8f7844381c7fdfc8ddeffcbe5e84f1db04 authorBlaž Hrastnik <blaz@mxxn.io> dateFri 20 Aug 2021, 10:58 (5 years ago) parentcbd39d6
3 files changed+13−11
helix-term/src/ui/info.rs+7−4 helix-term/src/ui/prompt.rs+5−6 theme.toml+1−1
helix-term/src/ui/info.rs+7−4
@@ -6,7 +6,8 @@ use tui::widgets::{Block, Borders, Paragraph, Widget};
66
77impl Component for Info {
88 fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) {
9− let style = cx.editor.theme.get("ui.popup");
9+ let text_style = cx.editor.theme.get("ui.text.focus");
10+ let popup_style = text_style.patch(cx.editor.theme.get("ui.popup"));
1011
1112 // Calculate the area of the terminal to modify. Because we want to
1213 // render at the bottom right, we use the viewport's width and height
@@ -19,12 +20,12 @@ impl Component for Info {
1920 width,
2021 height,
2122 ));
22− surface.clear_with(area, style);
23+ surface.clear_with(area, popup_style);
2324
2425 let block = Block::default()
2526 .title(self.title.as_str())
2627 .borders(Borders::ALL)
27− .border_style(style);
28+ .border_style(popup_style);
2829
2930 let margin = Margin {
3031 vertical: 0,
@@ -33,6 +34,8 @@ impl Component for Info {
3334 let inner = block.inner(area).inner(&margin);
3435 block.render(area, surface);
3536
36− Paragraph::new(self.text.as_str()).render(inner, surface);
37+ Paragraph::new(self.text.as_str())
38+ .style(text_style)
39+ .render(inner, surface);
3740 }
3841}
helix-term/src/ui/prompt.rs+5−6
@@ -284,7 +284,8 @@ const BASE_WIDTH: u16 = 30;
284284impl Prompt {
285285 pub fn render_prompt(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
286286 let theme = &cx.editor.theme;
287− let text_color = theme.get("ui.text.focus");
287+ let prompt_color = theme.get("ui.text");
288+ let completion_color = theme.get("ui.statusline");
288289 let selected_color = theme.get("ui.menu.selected");
289290 // completion
290291
@@ -326,15 +327,13 @@ impl Prompt {
326327 let mut row = 0;
327328 let mut col = 0;
328329
329− // TODO: paginate
330330 for (i, (_range, completion)) in
331331 self.completion.iter().enumerate().skip(offset).take(items)
332332 {
333333 let color = if Some(i) == self.selection {
334− // Style::default().bg(Color::Rgb(104, 60, 232))
335334 selected_color // TODO: just invert bg
336335 } else {
337− text_color
336+ completion_color
338337 };
339338 surface.set_stringn(
340339 area.x + col * (1 + col_width),
@@ -377,12 +376,12 @@ impl Prompt {
377376
378377 let line = area.height - 1;
379378 // render buffer text
380− surface.set_string(area.x, area.y + line, &self.prompt, text_color);
379+ surface.set_string(area.x, area.y + line, &self.prompt, prompt_color);
381380 surface.set_string(
382381 area.x + self.prompt.len() as u16,
383382 area.y + line,
384383 &self.line,
385− text_color,
384+ prompt_color,
386385 );
387386 }
388387}
theme.toml+1−1
@@ -42,7 +42,7 @@ module = "#ff0000"
4242"ui.help" = { bg = "#7958DC", fg = "#171452" }
4343
4444"ui.text" = { fg = "lavender" }
45−"ui.text.focus" = { fg = "lilac" }
45+"ui.text.focus" = { fg = "white" }
4646
4747"ui.selection" = { bg = "#540099" }
4848"ui.selection.primary" = { bg = "#540099" }