From 6aa58c49baf87421cf15e5ff886203cdaab5b3b9 Mon Sep 17 00:00:00 2001 From: Erasin Date: Sat, 20 Jul 2024 13:13:49 +0800 Subject: [PATCH] Hide Commandline Add config `commandline=false` for hide commandline. --- book/src/editor.md | 1 + helix-term/src/ui/editor.rs | 21 +++++++++++++-------- helix-term/src/ui/mod.rs | 4 +++- helix-view/src/editor.rs | 5 ++++- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/book/src/editor.md b/book/src/editor.md index 00db71d27..3db3246a1 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -48,6 +48,7 @@ | `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` | +| `commandline` | CommandLine Display. | `true` | | `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` | | `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` | `[]` | diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 9343d55d4..488b1ac45 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -217,7 +217,7 @@ impl EditorView { let statusline_area = view .area .clip_top(view.area.height.saturating_sub(1)) - .clip_bottom(1); // -1 from bottom to remove commandline + .clip_bottom(config.commandline as u16); // -1 from bottom to remove commandline let mut context = statusline::RenderContext::new(editor, doc, view, is_focused, &self.spinners); @@ -1501,11 +1501,13 @@ impl Component for EditorView { _ => false, }; - // -1 for commandline and -1 for bufferline - let mut editor_area = area.clip_bottom(1); - if use_bufferline { - editor_area = editor_area.clip_top(1); + let editor_area = if use_bufferline { + // -1 for bufferline + area.clip_top(1) + } else { + area } + .clip_bottom(config.commandline as u16); // -1 for commandline // if the terminal size suddenly changed, we need to trigger a resize cx.editor.resize(editor_area); @@ -1529,6 +1531,9 @@ impl Component for EditorView { let key_width = 15u16; // for showing pending keys let mut status_msg_width = 0; + // commandline + let commandline_msg_pos = if config.commandline { 1 } else { 2 }; + // render status msg if let Some((status_msg, severity)) = &cx.editor.status_msg { status_msg_width = status_msg.width(); @@ -1541,7 +1546,7 @@ impl Component for EditorView { surface.set_string( area.x, - area.y + area.height.saturating_sub(1), + area.y + area.height.saturating_sub(commandline_msg_pos), status_msg, style, ); @@ -1566,7 +1571,7 @@ impl Component for EditorView { }; 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(commandline_msg_pos), disp.get(disp.len().saturating_sub(key_width as usize)..) .unwrap_or(&disp), style, @@ -1578,7 +1583,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(commandline_msg_pos), &disp, style, ); diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 106bfbfb8..56ba7757b 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -152,6 +152,8 @@ pub fn raw_regex_prompt( doc.set_selection(view.id, snapshot.clone()); doc.set_view_offset(view.id, offset_snapshot); + let commandline = config.commandline as usize; + if event == PromptEvent::Validate { let callback = async move { let call: job::Callback = Callback::EditorCompositor(Box::new( @@ -160,7 +162,7 @@ pub fn raw_regex_prompt( let size = compositor.size(); let popup = Popup::new("invalid-regex", contents) .position(Some(helix_core::Position::new( - size.height as usize - 2, // 2 = statusline + commandline + size.height as usize - 1 - commandline, // 2 = statusline + commandline 0, ))) .auto_close(true); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index bc811b88b..1852038c3 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -335,6 +335,8 @@ pub struct Config { pub whitespace: WhitespaceConfig, /// Persistently display open buffers along the top pub bufferline: BufferLine, + /// Commandline display, Default true. + pub commandline: bool, /// Vertical indent width guides. pub indent_guides: IndentGuidesConfig, /// Whether to color modes with different colors. Defaults to `false`. @@ -1005,6 +1007,7 @@ impl Default for Config { rulers: Vec::new(), whitespace: WhitespaceConfig::default(), bufferline: BufferLine::default(), + commandline: true, indent_guides: IndentGuidesConfig::default(), color_modes: false, soft_wrap: SoftWrap { @@ -1207,7 +1210,7 @@ impl Editor { let auto_pairs = (&conf.auto_pairs).into(); // HAXX: offset the render area height by 1 to account for prompt/commandline - area.height -= 1; + area.height -= conf.commandline as u16; Self { mode: Mode::Normal,