diff --git a/book/src/editor.md b/book/src/editor.md index 7f1de68bb..8d0d34526 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -120,6 +120,7 @@ The `[editor.statusline]` key takes the following sub-keys: | `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"` | +| `merge-with-commandline` | If set, the command line and statusline will merge into a single line. Status text will replace the statusline briefly | `false` | | `diagnostics` | A list of severities which are displayed for the current buffer | `["warning", "error"]` | | `workspace-diagnostics` | A list of severities which are displayed for the workspace | `["warning", "error"]` | diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 82cad8386..91bd9e8ce 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -3728,6 +3728,11 @@ pub(super) fn command_mode(cx: &mut Context) { } }, ); + if cx.editor.config().statusline.merge_with_commandline { + // command line prompt has the same background as the statusline when + // the statusline and the command line are merged + prompt.background = Some(cx.editor.theme.get("ui.statusline")) + } prompt.doc_fn = Box::new(command_line_doc); // Calculate initial completion diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 9343d55d4..5f601beb4 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -222,7 +222,7 @@ impl EditorView { let mut context = statusline::RenderContext::new(editor, doc, view, is_focused, &self.spinners); - statusline::render(&mut context, statusline_area, surface); + statusline::render(&mut context, statusline_area, surface) } pub fn render_rulers( @@ -1501,8 +1501,15 @@ impl Component for EditorView { _ => false, }; - // -1 for commandline and -1 for bufferline - let mut editor_area = area.clip_bottom(1); + // If merge_with_commandline option is set, then status message renders on top of the statusline, in which case we will not show the statusline + // Otherwise, status message renders in a separate line, so we give it 1 line of vertical space + let mut editor_area = area.clip_bottom(if config.statusline.merge_with_commandline { + 0 + } else { + 1 + }); + + // Editor area decreases by 1, to give 1 line of vertical space for bufferline if use_bufferline { editor_area = editor_area.clip_top(1); } @@ -1564,9 +1571,15 @@ impl Component for EditorView { } else { 0 }; + let y_offset = if config.statusline.merge_with_commandline { + // render macros and key sequences 1 line above + 1 + } else { + 0 + }; surface.set_string( area.x + area.width.saturating_sub(key_width + macro_width), - area.y + area.height.saturating_sub(1), + (area.y + area.height.saturating_sub(1)).saturating_sub(y_offset), disp.get(disp.len().saturating_sub(key_width as usize)..) .unwrap_or(&disp), style, @@ -1578,7 +1591,7 @@ impl Component for EditorView { .add_modifier(Modifier::BOLD); surface.set_string( area.x + area.width.saturating_sub(3), - area.y + area.height.saturating_sub(1), + (area.y + area.height.saturating_sub(1)).saturating_sub(y_offset), &disp, style, ); diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index ff4ca1fcc..e35c242ae 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -32,6 +32,7 @@ pub struct Prompt { prompt: Cow<'static, str>, line: String, cursor: usize, + pub background: Option, // Fields used for Component callbacks and rendering: line_area: Rect, anchor: usize, @@ -98,6 +99,7 @@ impl Prompt { selection: None, history_register, history_pos: None, + background: None, completion_fn: Box::new(completion_fn), callback_fn: Box::new(callback_fn), doc_fn: Box::new(|_| None), @@ -407,7 +409,9 @@ impl Prompt { let completion_color = theme.get("ui.menu"); let selected_color = theme.get("ui.menu.selected"); let suggestion_color = theme.get("ui.text.inactive"); - let background = theme.get("ui.background"); + let background = self + .background + .unwrap_or_else(|| theme.get("ui.background")); // completion let max_len = self diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 57e130881..3645b09b7 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -510,6 +510,7 @@ pub struct StatusLineConfig { pub right: Vec, pub separator: String, pub mode: ModeConfig, + pub merge_with_commandline: bool, pub diagnostics: Vec, pub workspace_diagnostics: Vec, } @@ -536,6 +537,7 @@ impl Default for StatusLineConfig { ], separator: String::from("│"), mode: ModeConfig::default(), + merge_with_commandline: false, diagnostics: vec![Severity::Warning, Severity::Error], workspace_diagnostics: vec![Severity::Warning, Severity::Error], }