diff --git a/book/src/editor.md b/book/src/editor.md index ba03e90e5..1c0ca6c09 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -79,6 +79,9 @@ The `[editor.statusline]` key takes the following sub-keys: | `center` | A list of elements aligned to the middle of the statusline | `[]` | | `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "register", "position", "file-encoding"]` | | `separator` | The character used to separate elements in the statusline | `"│"` | +| `separator.left` | The character used to separate elements in the left statusline | `"│"` | +| `separator.center` | The character used to separate elements in the center statusline | `"│"` | +| `separator.right` | The character used to separate elements in the right statusline | `"│"` | | `mode.normal` | The text shown in the `mode` element for normal mode | `"NOR"` | | `mode.insert` | The text shown in the `mode` element for insert mode | `"INS"` | | `mode.select` | The text shown in the `mode` element for select mode | `"SEL"` | @@ -104,7 +107,7 @@ The following statusline elements can be configured: | `primary-selection-length` | The number of characters currently in primary selection | | `position` | The cursor position | | `position-percentage` | The cursor position as a percentage of the total number of lines | -| `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) | +| `separator` | The string defined in `editor.statusline.separator` (defaults to `"│"`) (`separator`/`separator.left`/`separator.center`/`separator.right`/) | | `spacer` | Inserts a space between elements (multiple/contiguous spacers may be specified) | | `version-control` | The current branch name or detached commit hash of the opened workspace | | `register` | The current selected register | diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index 7437cbd07..9fba1c120 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -15,6 +15,7 @@ use tui::buffer::Buffer as Surface; use tui::text::{Span, Spans}; pub struct RenderContext<'a> { + pub position: RenderPosition, pub editor: &'a Editor, pub doc: &'a Document, pub view: &'a View, @@ -37,11 +38,20 @@ impl<'a> RenderContext<'a> { view, focused, spinners, + position: RenderPosition::default(), parts: RenderBuffer::default(), } } } +#[derive(Default)] +pub enum RenderPosition { + #[default] + Left, + Center, + Right, +} + #[derive(Default)] pub struct RenderBuffer<'a> { pub left: Spans<'a>, @@ -76,7 +86,10 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface element_ids .iter() .map(|element_id| get_render_function(*element_id)) - .for_each(|render| render(context, write_left)); + .for_each(|render| { + context.position = RenderPosition::Left; + render(context, write_left) + }); surface.set_spans( viewport.x, @@ -91,7 +104,10 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface element_ids .iter() .map(|element_id| get_render_function(*element_id)) - .for_each(|render| render(context, write_right)); + .for_each(|render| { + context.position = RenderPosition::Right; + render(context, write_right) + }); surface.set_spans( viewport.x @@ -109,7 +125,10 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface element_ids .iter() .map(|element_id| get_render_function(*element_id)) - .for_each(|render| render(context, write_center)); + .for_each(|render| { + context.position = RenderPosition::Center; + render(context, write_center) + }); // Width of the empty space between the left and center area and between the center and right area. let spacing = 1u16; @@ -495,6 +514,11 @@ where F: Fn(&mut RenderContext, String, Option