diff --git a/book/src/configuration.md b/book/src/configuration.md index 36e2fee2e420..7192f7c9ed48 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -60,7 +60,7 @@ Its settings will be merged with the configuration directory `config.toml` and t | `undercurl` | Set to `true` to override automatic detection of terminal undercurl support in the event of a false negative | `false` | | `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file | `[]` | | `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` | -| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` | +| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `true` | | `text-width` | Maximum line length. Used for the `:reflow` command and soft-wrapping if `soft-wrap.wrap-at-text-width` is set | `80` | | `workspace-lsp-roots` | Directories relative to the workspace root that are treated as LSP roots. Should only be set in `.helix/config.toml` | `[]` | | `default-line-ending` | The line ending to use for new documents. Can be `native`, `lf`, `crlf`, `ff`, `cr` or `nel`. `native` uses the platform's native line ending (`crlf` on Windows, otherwise `lf`). | `native` | @@ -94,11 +94,11 @@ The `[editor.statusline]` key takes the following sub-keys: | --- | --- | --- | | `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name", "read-only-indicator", "file-modification-indicator"]` | | `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"]` | +| `right` | A list of elements aligned to the right of the statusline | `["diagnostics", "selections", "register", "position", "file-encoding", "spacer"]` | | `separator` | The character used to separate elements in the 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"` | +| `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 "` | The following statusline elements can be configured: diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index 52dd49f9e212..093cca706c17 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -4,11 +4,11 @@ use helix_view::document::DEFAULT_LANGUAGE_NAME; use helix_view::{ document::{Mode, SCRATCH_BUFFER_NAME}, graphics::Rect, - theme::Style, Document, Editor, View, }; use crate::ui::ProgressSpinners; +use crate::ui::Spinner; use helix_view::editor::StatusLineElement as StatusLineElementID; use tui::buffer::Buffer as Surface; @@ -49,6 +49,17 @@ pub struct RenderBuffer<'a> { pub right: Spans<'a>, } +fn join_with_spaces<'a, I: Iterator>>(iter: I) -> Spans<'a> { + let mut spans = Vec::new(); + for elem in iter { + if !spans.is_empty() { + spans.push(Span::raw(" ")); + } + spans.push(elem); + } + spans.into() +} + pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface) { let base_style = if context.focused { context.editor.theme.get("ui.statusline") @@ -58,25 +69,17 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface 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. let config = context.editor.config(); let element_ids = &config.statusline.left; - element_ids - .iter() - .map(|element_id| get_render_function(*element_id)) - .for_each(|render| render(context, write_left)); + context.parts.left = join_with_spaces( + element_ids + .iter() + .map(|element_id| get_render_function(*element_id)) + .flat_map(|render| render(context).0), + ); surface.set_spans( viewport.x, @@ -88,10 +91,12 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface // Right side of the status line. let element_ids = &config.statusline.right; - element_ids - .iter() - .map(|element_id| get_render_function(*element_id)) - .for_each(|render| render(context, write_right)); + context.parts.right = join_with_spaces( + element_ids + .iter() + .map(|element_id| get_render_function(*element_id)) + .flat_map(|render| render(context).0), + ); surface.set_spans( viewport.x @@ -106,10 +111,12 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface // Center of the status line. let element_ids = &config.statusline.center; - element_ids - .iter() - .map(|element_id| get_render_function(*element_id)) - .for_each(|render| render(context, write_center)); + context.parts.center = join_with_spaces( + element_ids + .iter() + .map(|element_id| get_render_function(*element_id)) + .flat_map(|render| render(context).0), + ); // Width of the empty space between the left and center area and between the center and right area. let spacing = 1u16; @@ -126,17 +133,9 @@ pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface ); } -fn append(buffer: &mut Spans, text: String, base_style: &Style, style: Option