mirror of https://github.com/helix-editor/helix
statusline: Avoid unnecessary allocations for `&'static str` spans
Previously the statusline `write` function only accepted a string and optional Style, so all rendering functions converted text to strings. Some elements write spans with `&'static str`s, however, making this unnecessary since `Span<'a>` is a wrapper around `Cow<'a, str>` and style, and a `Span<'static>` would outlive all required lifetimes. Moreover many elements could produce `Span<'a>` according to the lifetime in `RenderContext` in the future, potentially re-borrowing from the Editor borrow, so this change could save allocations for many file-type elements (with more future changes). This is not explored in this patch since the statusline functions currently add bespoke padding per-element, but with a future refactor to make spacing consistent this could be possible. This change refactors the write function to accept a `Span<'a>` and rewrites some related code to fit the codebase better (preferring `for` to iterator's `for_each` for example). The new code is more complicated lifetime-wise but avoids allocations in these cases: * spacer for mode name when a pane is not focused * LSP spinner frames * '●' (workspace) diagnostic indicators * " W " workspace diagnostic prefix * file modification indicators * read-only indicators * spacer element ... and opens the door to avoid allocation for file name elements in the future.pull/12326/head
parent
b0528bbac4
commit
702b1d0a0f
|
@ -1,3 +1,5 @@
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use helix_core::{coords_at_pos, encoding, Position};
|
use helix_core::{coords_at_pos, encoding, Position};
|
||||||
use helix_lsp::lsp::DiagnosticSeverity;
|
use helix_lsp::lsp::DiagnosticSeverity;
|
||||||
use helix_view::document::DEFAULT_LANGUAGE_NAME;
|
use helix_view::document::DEFAULT_LANGUAGE_NAME;
|
||||||
|
@ -58,25 +60,16 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface
|
||||||
|
|
||||||
surface.set_style(viewport.with_height(1), base_style);
|
surface.set_style(viewport.with_height(1), base_style);
|
||||||
|
|
||||||
let write_left = |context: &mut RenderContext, text, style| {
|
|
||||||
append(&mut context.parts.left, text, &base_style, style)
|
|
||||||
};
|
|
||||||
let write_center = |context: &mut RenderContext, text, style| {
|
|
||||||
append(&mut context.parts.center, text, &base_style, style)
|
|
||||||
};
|
|
||||||
let write_right = |context: &mut RenderContext, text, style| {
|
|
||||||
append(&mut context.parts.right, text, &base_style, style)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Left side of the status line.
|
// Left side of the status line.
|
||||||
|
|
||||||
let config = context.editor.config();
|
let config = context.editor.config();
|
||||||
|
|
||||||
let element_ids = &config.statusline.left;
|
for element_id in &config.statusline.left {
|
||||||
element_ids
|
let render = get_render_function(*element_id);
|
||||||
.iter()
|
(render)(context, |context, span| {
|
||||||
.map(|element_id| get_render_function(*element_id))
|
append(&mut context.parts.left, span, base_style)
|
||||||
.for_each(|render| render(context, write_left));
|
});
|
||||||
|
}
|
||||||
|
|
||||||
surface.set_spans(
|
surface.set_spans(
|
||||||
viewport.x,
|
viewport.x,
|
||||||
|
@ -87,11 +80,12 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface
|
||||||
|
|
||||||
// Right side of the status line.
|
// Right side of the status line.
|
||||||
|
|
||||||
let element_ids = &config.statusline.right;
|
for element_id in &config.statusline.right {
|
||||||
element_ids
|
let render = get_render_function(*element_id);
|
||||||
.iter()
|
(render)(context, |context, span| {
|
||||||
.map(|element_id| get_render_function(*element_id))
|
append(&mut context.parts.right, span, base_style)
|
||||||
.for_each(|render| render(context, write_right));
|
})
|
||||||
|
}
|
||||||
|
|
||||||
surface.set_spans(
|
surface.set_spans(
|
||||||
viewport.x
|
viewport.x
|
||||||
|
@ -105,11 +99,12 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface
|
||||||
|
|
||||||
// Center of the status line.
|
// Center of the status line.
|
||||||
|
|
||||||
let element_ids = &config.statusline.center;
|
for element_id in &config.statusline.center {
|
||||||
element_ids
|
let render = get_render_function(*element_id);
|
||||||
.iter()
|
(render)(context, |context, span| {
|
||||||
.map(|element_id| get_render_function(*element_id))
|
append(&mut context.parts.center, span, base_style)
|
||||||
.for_each(|render| render(context, write_center));
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Width of the empty space between the left and center area and between the center and right area.
|
// Width of the empty space between the left and center area and between the center and right area.
|
||||||
let spacing = 1u16;
|
let spacing = 1u16;
|
||||||
|
@ -126,16 +121,14 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append(buffer: &mut Spans, text: String, base_style: &Style, style: Option<Style>) {
|
fn append<'a>(buffer: &mut Spans<'a>, mut span: Span<'a>, base_style: Style) {
|
||||||
buffer.0.push(Span::styled(
|
span.style = base_style.patch(span.style);
|
||||||
text,
|
buffer.0.push(span);
|
||||||
style.map_or(*base_style, |s| (*base_style).patch(s)),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_render_function<F>(element_id: StatusLineElementID) -> impl Fn(&mut RenderContext, F)
|
fn get_render_function<'a, F>(element_id: StatusLineElementID) -> impl Fn(&mut RenderContext<'a>, F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
match element_id {
|
match element_id {
|
||||||
helix_view::editor::StatusLineElement::Mode => render_mode,
|
helix_view::editor::StatusLineElement::Mode => render_mode,
|
||||||
|
@ -166,44 +159,42 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_mode<F>(context: &mut RenderContext, write: F)
|
fn render_mode<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let visible = context.focused;
|
let visible = context.focused;
|
||||||
let config = context.editor.config();
|
let config = context.editor.config();
|
||||||
let modenames = &config.statusline.mode;
|
let modenames = &config.statusline.mode;
|
||||||
write(
|
let content = if visible {
|
||||||
context,
|
Cow::Owned(format!(
|
||||||
format!(
|
|
||||||
" {} ",
|
" {} ",
|
||||||
if visible {
|
|
||||||
match context.editor.mode() {
|
match context.editor.mode() {
|
||||||
Mode::Insert => &modenames.insert,
|
Mode::Insert => &modenames.insert,
|
||||||
Mode::Select => &modenames.select,
|
Mode::Select => &modenames.select,
|
||||||
Mode::Normal => &modenames.normal,
|
Mode::Normal => &modenames.normal,
|
||||||
}
|
}
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
// If not focused, explicitly leave an empty space instead of returning None.
|
// If not focused, explicitly leave an empty space instead of returning None.
|
||||||
" "
|
Cow::Borrowed(" ")
|
||||||
}
|
};
|
||||||
),
|
let style = if visible && config.color_modes {
|
||||||
if visible && config.color_modes {
|
|
||||||
match context.editor.mode() {
|
match context.editor.mode() {
|
||||||
Mode::Insert => Some(context.editor.theme.get("ui.statusline.insert")),
|
Mode::Insert => context.editor.theme.get("ui.statusline.insert"),
|
||||||
Mode::Select => Some(context.editor.theme.get("ui.statusline.select")),
|
Mode::Select => context.editor.theme.get("ui.statusline.select"),
|
||||||
Mode::Normal => Some(context.editor.theme.get("ui.statusline.normal")),
|
Mode::Normal => context.editor.theme.get("ui.statusline.normal"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
Style::default()
|
||||||
},
|
};
|
||||||
);
|
write(context, Span::styled(content, style));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO think about handling multiple language servers
|
// TODO think about handling multiple language servers
|
||||||
fn render_lsp_spinner<F>(context: &mut RenderContext, write: F)
|
fn render_lsp_spinner<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let language_server = context.doc.language_servers().next();
|
let language_server = context.doc.language_servers().next();
|
||||||
write(
|
write(
|
||||||
|
@ -217,14 +208,13 @@ where
|
||||||
})
|
})
|
||||||
// Even if there's no spinner; reserve its space to avoid elements frequently shifting.
|
// Even if there's no spinner; reserve its space to avoid elements frequently shifting.
|
||||||
.unwrap_or(" ")
|
.unwrap_or(" ")
|
||||||
.to_string(),
|
.into(),
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_diagnostics<F>(context: &mut RenderContext, write: F)
|
fn render_diagnostics<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
use helix_core::diagnostic::Severity;
|
use helix_core::diagnostic::Severity;
|
||||||
let (hints, info, warnings, errors) =
|
let (hints, info, warnings, errors) =
|
||||||
|
@ -245,45 +235,35 @@ where
|
||||||
for sev in &context.editor.config().statusline.diagnostics {
|
for sev in &context.editor.config().statusline.diagnostics {
|
||||||
match sev {
|
match sev {
|
||||||
Severity::Hint if hints > 0 => {
|
Severity::Hint if hints > 0 => {
|
||||||
write(
|
write(context, Span::styled("●", context.editor.theme.get("hint")));
|
||||||
context,
|
write(context, format!(" {} ", hints).into());
|
||||||
"●".to_string(),
|
|
||||||
Some(context.editor.theme.get("hint")),
|
|
||||||
);
|
|
||||||
write(context, format!(" {} ", hints), None);
|
|
||||||
}
|
}
|
||||||
Severity::Info if info > 0 => {
|
Severity::Info if info > 0 => {
|
||||||
write(
|
write(context, Span::styled("●", context.editor.theme.get("info")));
|
||||||
context,
|
write(context, format!(" {} ", info).into());
|
||||||
"●".to_string(),
|
|
||||||
Some(context.editor.theme.get("info")),
|
|
||||||
);
|
|
||||||
write(context, format!(" {} ", info), None);
|
|
||||||
}
|
}
|
||||||
Severity::Warning if warnings > 0 => {
|
Severity::Warning if warnings > 0 => {
|
||||||
write(
|
write(
|
||||||
context,
|
context,
|
||||||
"●".to_string(),
|
Span::styled("●", context.editor.theme.get("warning")),
|
||||||
Some(context.editor.theme.get("warning")),
|
|
||||||
);
|
);
|
||||||
write(context, format!(" {} ", warnings), None);
|
write(context, format!(" {} ", warnings).into());
|
||||||
}
|
}
|
||||||
Severity::Error if errors > 0 => {
|
Severity::Error if errors > 0 => {
|
||||||
write(
|
write(
|
||||||
context,
|
context,
|
||||||
"●".to_string(),
|
Span::styled("●", context.editor.theme.get("error")),
|
||||||
Some(context.editor.theme.get("error")),
|
|
||||||
);
|
);
|
||||||
write(context, format!(" {} ", errors), None);
|
write(context, format!(" {} ", errors).into());
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_workspace_diagnostics<F>(context: &mut RenderContext, write: F)
|
fn render_workspace_diagnostics<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
use helix_core::diagnostic::Severity;
|
use helix_core::diagnostic::Severity;
|
||||||
let (hints, info, warnings, errors) = context.editor.diagnostics.values().flatten().fold(
|
let (hints, info, warnings, errors) = context.editor.diagnostics.values().flatten().fold(
|
||||||
|
@ -317,68 +297,56 @@ where
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
write(context, " W ".into(), None);
|
write(context, " W ".into());
|
||||||
|
|
||||||
for sev in sevs_to_show {
|
for sev in sevs_to_show {
|
||||||
match sev {
|
match sev {
|
||||||
Severity::Hint if hints > 0 => {
|
Severity::Hint if hints > 0 => {
|
||||||
write(
|
write(context, Span::styled("●", context.editor.theme.get("hint")));
|
||||||
context,
|
write(context, format!(" {} ", hints).into());
|
||||||
"●".to_string(),
|
|
||||||
Some(context.editor.theme.get("hint")),
|
|
||||||
);
|
|
||||||
write(context, format!(" {} ", hints), None);
|
|
||||||
}
|
}
|
||||||
Severity::Info if info > 0 => {
|
Severity::Info if info > 0 => {
|
||||||
write(
|
write(context, Span::styled("●", context.editor.theme.get("info")));
|
||||||
context,
|
write(context, format!(" {} ", info).into());
|
||||||
"●".to_string(),
|
|
||||||
Some(context.editor.theme.get("info")),
|
|
||||||
);
|
|
||||||
write(context, format!(" {} ", info), None);
|
|
||||||
}
|
}
|
||||||
Severity::Warning if warnings > 0 => {
|
Severity::Warning if warnings > 0 => {
|
||||||
write(
|
write(
|
||||||
context,
|
context,
|
||||||
"●".to_string(),
|
Span::styled("●", context.editor.theme.get("warning")),
|
||||||
Some(context.editor.theme.get("warning")),
|
|
||||||
);
|
);
|
||||||
write(context, format!(" {} ", warnings), None);
|
write(context, format!(" {} ", warnings).into());
|
||||||
}
|
}
|
||||||
Severity::Error if errors > 0 => {
|
Severity::Error if errors > 0 => {
|
||||||
write(
|
write(
|
||||||
context,
|
context,
|
||||||
"●".to_string(),
|
Span::styled("●", context.editor.theme.get("error")),
|
||||||
Some(context.editor.theme.get("error")),
|
|
||||||
);
|
);
|
||||||
write(context, format!(" {} ", errors), None);
|
write(context, format!(" {} ", errors).into());
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_selections<F>(context: &mut RenderContext, write: F)
|
fn render_selections<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let count = context.doc.selection(context.view.id).len();
|
let count = context.doc.selection(context.view.id).len();
|
||||||
write(
|
write(
|
||||||
context,
|
context,
|
||||||
format!(" {} sel{} ", count, if count == 1 { "" } else { "s" }),
|
format!(" {} sel{} ", count, if count == 1 { "" } else { "s" }).into(),
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_primary_selection_length<F>(context: &mut RenderContext, write: F)
|
fn render_primary_selection_length<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let tot_sel = context.doc.selection(context.view.id).primary().len();
|
let tot_sel = context.doc.selection(context.view.id).primary().len();
|
||||||
write(
|
write(
|
||||||
context,
|
context,
|
||||||
format!(" {} char{} ", tot_sel, if tot_sel == 1 { "" } else { "s" }),
|
format!(" {} char{} ", tot_sel, if tot_sel == 1 { "" } else { "s" }).into(),
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,54 +361,52 @@ fn get_position(context: &RenderContext) -> Position {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_position<F>(context: &mut RenderContext, write: F)
|
fn render_position<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let position = get_position(context);
|
let position = get_position(context);
|
||||||
write(
|
write(
|
||||||
context,
|
context,
|
||||||
format!(" {}:{} ", position.row + 1, position.col + 1),
|
format!(" {}:{} ", position.row + 1, position.col + 1).into(),
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_total_line_numbers<F>(context: &mut RenderContext, write: F)
|
fn render_total_line_numbers<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let total_line_numbers = context.doc.text().len_lines();
|
let total_line_numbers = context.doc.text().len_lines();
|
||||||
|
|
||||||
write(context, format!(" {} ", total_line_numbers), None);
|
write(context, format!(" {} ", total_line_numbers).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_position_percentage<F>(context: &mut RenderContext, write: F)
|
fn render_position_percentage<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let position = get_position(context);
|
let position = get_position(context);
|
||||||
let maxrows = context.doc.text().len_lines();
|
let maxrows = context.doc.text().len_lines();
|
||||||
write(
|
write(
|
||||||
context,
|
context,
|
||||||
format!("{}%", (position.row + 1) * 100 / maxrows),
|
format!("{}%", (position.row + 1) * 100 / maxrows).into(),
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_file_encoding<F>(context: &mut RenderContext, write: F)
|
fn render_file_encoding<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let enc = context.doc.encoding();
|
let enc = context.doc.encoding();
|
||||||
|
|
||||||
if enc != encoding::UTF_8 {
|
if enc != encoding::UTF_8 {
|
||||||
write(context, format!(" {} ", enc.name()), None);
|
write(context, format!(" {} ", enc.name()).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_file_line_ending<F>(context: &mut RenderContext, write: F)
|
fn render_file_line_ending<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
use helix_core::LineEnding::*;
|
use helix_core::LineEnding::*;
|
||||||
let line_ending = match context.doc.line_ending {
|
let line_ending = match context.doc.line_ending {
|
||||||
|
@ -460,21 +426,21 @@ where
|
||||||
PS => "PS", // U+2029 -- ParagraphSeparator
|
PS => "PS", // U+2029 -- ParagraphSeparator
|
||||||
};
|
};
|
||||||
|
|
||||||
write(context, format!(" {} ", line_ending), None);
|
write(context, format!(" {} ", line_ending).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_file_type<F>(context: &mut RenderContext, write: F)
|
fn render_file_type<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let file_type = context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME);
|
let file_type = context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME);
|
||||||
|
|
||||||
write(context, format!(" {} ", file_type), None);
|
write(context, format!(" {} ", file_type).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_file_name<F>(context: &mut RenderContext, write: F)
|
fn render_file_name<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let title = {
|
let title = {
|
||||||
let rel_path = context.doc.relative_path();
|
let rel_path = context.doc.relative_path();
|
||||||
|
@ -485,12 +451,12 @@ where
|
||||||
format!(" {} ", path)
|
format!(" {} ", path)
|
||||||
};
|
};
|
||||||
|
|
||||||
write(context, title, None);
|
write(context, title.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_file_absolute_path<F>(context: &mut RenderContext, write: F)
|
fn render_file_absolute_path<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let title = {
|
let title = {
|
||||||
let path = context.doc.path();
|
let path = context.doc.path();
|
||||||
|
@ -501,39 +467,37 @@ where
|
||||||
format!(" {} ", path)
|
format!(" {} ", path)
|
||||||
};
|
};
|
||||||
|
|
||||||
write(context, title, None);
|
write(context, title.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_file_modification_indicator<F>(context: &mut RenderContext, write: F)
|
fn render_file_modification_indicator<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let title = (if context.doc.is_modified() {
|
let title = if context.doc.is_modified() {
|
||||||
"[+]"
|
"[+]"
|
||||||
} else {
|
} else {
|
||||||
" "
|
" "
|
||||||
})
|
};
|
||||||
.to_string();
|
|
||||||
|
|
||||||
write(context, title, None);
|
write(context, title.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_read_only_indicator<F>(context: &mut RenderContext, write: F)
|
fn render_read_only_indicator<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let title = if context.doc.readonly {
|
let title = if context.doc.readonly {
|
||||||
" [readonly] "
|
" [readonly] "
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
}
|
};
|
||||||
.to_string();
|
write(context, title.into());
|
||||||
write(context, title, None);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_file_base_name<F>(context: &mut RenderContext, write: F)
|
fn render_file_base_name<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let title = {
|
let title = {
|
||||||
let rel_path = context.doc.relative_path();
|
let rel_path = context.doc.relative_path();
|
||||||
|
@ -544,32 +508,29 @@ where
|
||||||
format!(" {} ", path)
|
format!(" {} ", path)
|
||||||
};
|
};
|
||||||
|
|
||||||
write(context, title, None);
|
write(context, title.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_separator<F>(context: &mut RenderContext, write: F)
|
fn render_separator<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let sep = &context.editor.config().statusline.separator;
|
let sep = &context.editor.config().statusline.separator;
|
||||||
|
let style = context.editor.theme.get("ui.statusline.separator");
|
||||||
|
|
||||||
write(
|
write(context, Span::styled(sep.to_string(), style));
|
||||||
context,
|
|
||||||
sep.to_string(),
|
|
||||||
Some(context.editor.theme.get("ui.statusline.separator")),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_spacer<F>(context: &mut RenderContext, write: F)
|
fn render_spacer<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
write(context, String::from(" "), None);
|
write(context, " ".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_version_control<F>(context: &mut RenderContext, write: F)
|
fn render_version_control<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
let head = context
|
let head = context
|
||||||
.doc
|
.doc
|
||||||
|
@ -577,14 +538,14 @@ where
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
write(context, head, None);
|
write(context, head.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_register<F>(context: &mut RenderContext, write: F)
|
fn render_register<'a, F>(context: &mut RenderContext<'a>, write: F)
|
||||||
where
|
where
|
||||||
F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
|
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
|
||||||
{
|
{
|
||||||
if let Some(reg) = context.editor.selected_register {
|
if let Some(reg) = context.editor.selected_register {
|
||||||
write(context, format!(" reg={} ", reg), None)
|
write(context, format!(" reg={} ", reg).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue