From 5cb4e76432aea4e07056bdd4174324073691da67 Mon Sep 17 00:00:00 2001 From: etienne-k <2804556+etienne-k@users.noreply.github.com> Date: Fri, 1 Jul 2022 22:18:05 +0200 Subject: [PATCH] refactor(statusline): refactor some code following the code review 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`. --- helix-term/src/ui/statusline.rs | 47 ++++++--------------------------- helix-view/src/editor.rs | 4 +-- 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index a65f2220e..dc4c7b8c2 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -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) @@ -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)) @@ -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)) @@ -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)) @@ -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(context: &mut RenderContext, write: F) - where - F: Fn(&mut RenderContext, String, Option