Skip to content

Commit

Permalink
refactor(statusline): refactor some code following the code review
Browse files Browse the repository at this point in the history
Avoid very small helper functions for the diagnositcs and inline them
instead.
Rename the config field `status_line` to `statusline` to remain
consistent with `bufferline`.
  • Loading branch information
usagi-flow committed Jul 1, 2022
1 parent f93ee65 commit c0a1870
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 41 deletions.
47 changes: 8 additions & 39 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl StatusLine {
context.theme.get("ui.statusline.inactive")
};

surface.set_style(viewport.with_height(1), base_style);
surface.set_style(viewport, base_style);

let write_left = |context: &mut RenderContext, text, style| {
Self::append(&mut context.parts.left, text, &base_style, style)
Expand All @@ -76,7 +76,7 @@ impl StatusLine {

// Left side of the status line.

let element_ids = &editor.config().status_line.left;
let element_ids = &editor.config().statusline.left;
element_ids
.iter()
.map(|element_id| Self::get_render_function(*element_id))
Expand All @@ -91,7 +91,7 @@ impl StatusLine {

// Right side of the status line.

let element_ids = &editor.config().status_line.right;
let element_ids = &editor.config().statusline.right;
element_ids
.iter()
.map(|element_id| Self::get_render_function(*element_id))
Expand All @@ -109,7 +109,7 @@ impl StatusLine {

// Center of the status line.

let element_ids = &editor.config().status_line.center;
let element_ids = &editor.config().statusline.center;
element_ids
.iter()
.map(|element_id| Self::get_render_function(*element_id))
Expand Down Expand Up @@ -220,47 +220,16 @@ impl StatusLine {
});

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

if errors > 0 {
Self::render_diagnostics_error_state(context, write);
Self::render_diagnostics_error_count(context, errors, write);
write(context, "●".to_string(), Some(context.theme.get("error")));
write(context, format!(" {} ", errors), None);
}
}

fn render_diagnostics_warning_state<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
write(context, "●".to_string(), Some(context.theme.get("warning")));
}

fn render_diagnostics_warning_count<F>(
context: &mut RenderContext,
warning_count: usize,
write: F,
) where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
write(context, format!(" {} ", warning_count), None);
}

fn render_diagnostics_error_state<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
write(context, "●".to_string(), Some(context.theme.get("error")));
}

fn render_diagnostics_error_count<F>(context: &mut RenderContext, error_count: usize, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
{
write(context, format!(" {} ", error_count), None);
}

fn render_selections<F>(context: &mut RenderContext, write: F)
where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
Expand Down
4 changes: 2 additions & 2 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub struct Config {
pub auto_info: bool,
pub file_picker: FilePickerConfig,
/// Configuration of the statusline elements
pub status_line: StatusLineConfig,
pub statusline: StatusLineConfig,
/// Shape for cursor in each mode
pub cursor_shape: CursorShapeConfig,
/// Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. Defaults to `false`.
Expand Down Expand Up @@ -431,7 +431,7 @@ impl Default for Config {
completion_trigger_len: 2,
auto_info: true,
file_picker: FilePickerConfig::default(),
status_line: StatusLineConfig::default(),
statusline: StatusLineConfig::default(),
cursor_shape: CursorShapeConfig::default(),
true_color: false,
search: SearchConfig::default(),
Expand Down

0 comments on commit c0a1870

Please sign in to comment.