Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always visible statusline (under prompt) #7635

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,20 @@ separator = "│"
mode.normal = "NORMAL"
mode.insert = "INSERT"
mode.select = "SELECT"
under-prompt = true
```
The `[editor.statusline]` key takes the following sub-keys:

| Key | Description | Default |
| --- | --- | --- |
| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name"]` |
| `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", "position", "file-encoding"]` |
| `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"` |
| Key | Description | Default |
| --- | --- | --- |
| `left` | A list of elements aligned to the left of the statusline | `["mode", "spinner", "file-name"]` |
| `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", "position", "file-encoding"]` |
| `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"` |
| `under-prompt` | Whether the statusline is below the prompt when it appears (so it is always visible) | `false` |

The following statusline elements can be configured:

Expand Down
21 changes: 15 additions & 6 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,17 @@ impl EditorView {

Self::render_diagnostics(doc, view, inner, surface, theme);

let statusline_area = view
.area
.clip_top(view.area.height.saturating_sub(1))
.clip_bottom(1); // -1 from bottom to remove commandline

// if we're not at the bottom of the screen, draw the statusline higher, otherwise
// it'll overlap with the next view
let statusline_area = if editor.config().statusline.under_prompt == true
&& (viewport.bottom() - 1) == view.area.bottom()
{
view.area.clip_top(view.area.height)
} else {
view.area
.clip_top(view.area.height.saturating_sub(1))
.clip_bottom(1)
};
let mut context =
statusline::RenderContext::new(editor, doc, view, is_focused, &self.spinners);

Expand Down Expand Up @@ -1434,7 +1440,10 @@ impl Component for EditorView {

surface.set_string(
area.x,
area.y + area.height.saturating_sub(1),
area.y
+ area
.height
.saturating_sub(cx.editor.config().statusline.under_prompt as u16 + 1),
status_msg,
style,
);
Expand Down
10 changes: 7 additions & 3 deletions helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ impl Prompt {

let completion_area = Rect::new(
area.x,
(area.height - height).saturating_sub(1),
(area.height - height)
.saturating_sub(cx.editor.config().statusline.under_prompt as u16 + 1),
area.width,
height,
);
Expand Down Expand Up @@ -450,7 +451,9 @@ impl Prompt {
text.render(inner, surface, cx);
}

let line = area.height - 1;
let line = area
.height
.saturating_sub(cx.editor.config().statusline.under_prompt as u16 + 1);
// render buffer text
surface.set_string(area.x, area.y + line, &self.prompt, prompt_color);

Expand Down Expand Up @@ -652,7 +655,8 @@ impl Component for Prompt {
}

fn cursor(&self, area: Rect, _editor: &Editor) -> (Option<Position>, CursorKind) {
let line = area.height as usize - 1;
let line = (area.height as usize)
.saturating_sub(_editor.config().statusline.under_prompt as usize + 1);
(
Some(Position::new(
area.y as usize + line,
Expand Down
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ pub struct StatusLineConfig {
pub right: Vec<StatusLineElement>,
pub separator: String,
pub mode: ModeConfig,
// TODO name suggestions? always_visible?
pub under_prompt: bool,
}

impl Default for StatusLineConfig {
Expand All @@ -416,6 +418,7 @@ impl Default for StatusLineConfig {
],
separator: String::from("│"),
mode: ModeConfig::default(),
under_prompt: false,
}
}
}
Expand Down