Skip to content

Commit

Permalink
fix(statusline): restore the configurability of color modes
Browse files Browse the repository at this point in the history
The configuration was ignored after reintegrating the changes of #2676
in 8d28f95.
  • Loading branch information
usagi-flow committed Jul 6, 2022
1 parent fae2348 commit 2cb20ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ impl EditorView {
.clip_bottom(1); // -1 from bottom to remove commandline

let mut context =
statusline::RenderContext::new(doc, view, &editor.theme, is_focused, &self.spinners);
statusline::RenderContext::new(editor, doc, view, is_focused, &self.spinners);

statusline::render(editor, &mut context, statusline_area, surface);
statusline::render(&mut context, statusline_area, surface);
}

pub fn render_rulers(
Expand Down
40 changes: 24 additions & 16 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use helix_view::{
document::{Mode, SCRATCH_BUFFER_NAME},
graphics::Rect,
theme::Style,
Document, Editor, Theme, View,
Document, Editor, View,
};

use crate::ui::ProgressSpinners;
Expand All @@ -13,26 +13,26 @@ use tui::buffer::Buffer as Surface;
use tui::text::{Span, Spans};

pub struct RenderContext<'a> {
pub editor: &'a Editor,
pub doc: &'a Document,
pub view: &'a View,
pub theme: &'a Theme,
pub focused: bool,
pub spinners: &'a ProgressSpinners,
pub parts: RenderBuffer<'a>,
}

impl<'a> RenderContext<'a> {
pub fn new(
editor: &'a Editor,
doc: &'a Document,
view: &'a View,
theme: &'a Theme,
focused: bool,
spinners: &'a ProgressSpinners,
) -> Self {
RenderContext {
editor,
doc,
view,
theme,
focused,
spinners,
parts: RenderBuffer::default(),
Expand All @@ -47,11 +47,11 @@ pub struct RenderBuffer<'a> {
pub right: Spans<'a>,
}

pub fn render(editor: &Editor, context: &mut RenderContext, viewport: Rect, surface: &mut Surface) {
pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface) {
let base_style = if context.focused {
context.theme.get("ui.statusline")
context.editor.theme.get("ui.statusline")
} else {
context.theme.get("ui.statusline.inactive")
context.editor.theme.get("ui.statusline.inactive")
};

surface.set_style(viewport.with_height(1), base_style);
Expand All @@ -68,7 +68,7 @@ pub fn render(editor: &Editor, context: &mut RenderContext, viewport: Rect, surf

// Left side of the status line.

let element_ids = &editor.config().statusline.left;
let element_ids = &context.editor.config().statusline.left;
element_ids
.iter()
.map(|element_id| get_render_function(*element_id))
Expand All @@ -83,7 +83,7 @@ pub fn render(editor: &Editor, context: &mut RenderContext, viewport: Rect, surf

// Right side of the status line.

let element_ids = &editor.config().statusline.right;
let element_ids = &context.editor.config().statusline.right;
element_ids
.iter()
.map(|element_id| get_render_function(*element_id))
Expand All @@ -101,7 +101,7 @@ pub fn render(editor: &Editor, context: &mut RenderContext, viewport: Rect, surf

// Center of the status line.

let element_ids = &editor.config().statusline.center;
let element_ids = &context.editor.config().statusline.center;
element_ids
.iter()
.map(|element_id| get_render_function(*element_id))
Expand Down Expand Up @@ -166,11 +166,11 @@ where
" "
}
),
if visible {
if visible && context.editor.config().color_modes {
match context.doc.mode() {
Mode::Insert => Some(context.theme.get("ui.statusline.insert")),
Mode::Select => Some(context.theme.get("ui.statusline.select")),
Mode::Normal => Some(context.theme.get("ui.statusline.normal")),
Mode::Insert => Some(context.editor.theme.get("ui.statusline.insert")),
Mode::Select => Some(context.editor.theme.get("ui.statusline.select")),
Mode::Normal => Some(context.editor.theme.get("ui.statusline.normal")),
}
} else {
None
Expand Down Expand Up @@ -219,12 +219,20 @@ where
});

if warnings > 0 {
write(context, "●".to_string(), Some(context.theme.get("warning")));
write(
context,
"●".to_string(),
Some(context.editor.theme.get("warning")),
);
write(context, format!(" {} ", warnings), None);
}

if errors > 0 {
write(context, "●".to_string(), Some(context.theme.get("error")));
write(
context,
"●".to_string(),
Some(context.editor.theme.get("error")),
);
write(context, format!(" {} ", errors), None);
}
}
Expand Down

0 comments on commit 2cb20ff

Please sign in to comment.