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`.
pull/2434/head
etienne-k 2 years ago
parent 2dc4d343ae
commit 5cb4e76432

@ -62,7 +62,7 @@ impl StatusLine {
context.theme.get("ui.statusline.inactive") 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| { let write_left = |context: &mut RenderContext, text, style| {
Self::append(&mut context.parts.left, text, &base_style, style) Self::append(&mut context.parts.left, text, &base_style, style)
@ -76,7 +76,7 @@ impl StatusLine {
// Left side of the status line. // Left side of the status line.
let element_ids = &editor.config().status_line.left; let element_ids = &editor.config().statusline.left;
element_ids element_ids
.iter() .iter()
.map(|element_id| Self::get_render_function(*element_id)) .map(|element_id| Self::get_render_function(*element_id))
@ -91,7 +91,7 @@ impl StatusLine {
// Right side of the status line. // Right side of the status line.
let element_ids = &editor.config().status_line.right; let element_ids = &editor.config().statusline.right;
element_ids element_ids
.iter() .iter()
.map(|element_id| Self::get_render_function(*element_id)) .map(|element_id| Self::get_render_function(*element_id))
@ -109,7 +109,7 @@ impl StatusLine {
// Center of the status line. // Center of the status line.
let element_ids = &editor.config().status_line.center; let element_ids = &editor.config().statusline.center;
element_ids element_ids
.iter() .iter()
.map(|element_id| Self::get_render_function(*element_id)) .map(|element_id| Self::get_render_function(*element_id))
@ -220,47 +220,16 @@ impl StatusLine {
}); });
if warnings > 0 { if warnings > 0 {
Self::render_diagnostics_warning_state(context, write); write(context, "●".to_string(), Some(context.theme.get("warning")));
Self::render_diagnostics_warning_count(context, warnings, write); write(context, format!(" {} ", warnings), None);
} }
if errors > 0 { if errors > 0 {
Self::render_diagnostics_error_state(context, write); write(context, "●".to_string(), Some(context.theme.get("error")));
Self::render_diagnostics_error_count(context, errors, write); 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) fn render_selections<F>(context: &mut RenderContext, write: F)
where where
F: Fn(&mut RenderContext, String, Option<Style>) + Copy, F: Fn(&mut RenderContext, String, Option<Style>) + Copy,

@ -148,7 +148,7 @@ pub struct Config {
pub auto_info: bool, pub auto_info: bool,
pub file_picker: FilePickerConfig, pub file_picker: FilePickerConfig,
/// Configuration of the statusline elements /// Configuration of the statusline elements
pub status_line: StatusLineConfig, pub statusline: StatusLineConfig,
/// Shape for cursor in each mode /// Shape for cursor in each mode
pub cursor_shape: CursorShapeConfig, 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`. /// Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. Defaults to `false`.
@ -459,7 +459,7 @@ impl Default for Config {
completion_trigger_len: 2, completion_trigger_len: 2,
auto_info: true, auto_info: true,
file_picker: FilePickerConfig::default(), file_picker: FilePickerConfig::default(),
status_line: StatusLineConfig::default(), statusline: StatusLineConfig::default(),
cursor_shape: CursorShapeConfig::default(), cursor_shape: CursorShapeConfig::default(),
true_color: false, true_color: false,
search: SearchConfig::default(), search: SearchConfig::default(),

Loading…
Cancel
Save