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

feat(ui): global status line option #2263

Closed
wants to merge 2 commits 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
37 changes: 31 additions & 6 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use helix_core::{
};
use helix_view::{
document::{Mode, SCRATCH_BUFFER_NAME},
editor::{CompleteAction, CursorShapeConfig},
editor::{CompleteAction, CursorShapeConfig, StatusLineRenderValue},
graphics::{CursorKind, Modifier, Rect, Style},
input::KeyEvent,
keyboard::{KeyCode, KeyModifiers},
Expand Down Expand Up @@ -154,11 +154,25 @@ 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
self.render_statusline(doc, view, statusline_area, surface, theme, is_focused);
if editor.config().status_line.render == StatusLineRenderValue::Always {
let statusline_area = view
.area
.clip_top(view.area.height.saturating_sub(1))
.clip_bottom(1); // -1 from bottom to remove commandline
self.render_statusline(doc, view, statusline_area, surface, theme, is_focused);
} else {
let area = view
.area
.clip_top(view.area.height.saturating_sub(1))
.clip_bottom(1); // -1 from bottom to remove commandline
let y = area.bottom();
let border_style = theme.get("ui.window");
for x in area.left()..area.right() {
surface[(x, y)]
.set_symbol(tui::symbols::line::HORIZONTAL)
.set_style(border_style);
}
}
}

pub fn render_rulers(
Expand Down Expand Up @@ -1300,6 +1314,17 @@ impl Component for EditorView {
self.render_view(cx.editor, doc, view, area, surface, is_focused);
}

if config.status_line.render == StatusLineRenderValue::Single {
let view = cx.editor.tree.get(cx.editor.tree.focus);
let doc = cx.editor.document(view.doc).unwrap();
let theme = &cx.editor.theme;
let statusline_area = area.clip_top(area.height.saturating_sub(2));
// all views have border at the bottom, the most-bottom one is not needed
// so override the bottom border anddraw the statusline over it
surface.clear_with(statusline_area, cx.editor.theme.get("ui.background"));
self.render_statusline(doc, view, statusline_area, surface, theme, true);
}

if config.auto_info {
if let Some(mut info) = cx.editor.autoinfo.take() {
info.render(area, surface, cx);
Expand Down
29 changes: 29 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,32 @@ where
)
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum StatusLineRenderValue {
// Do not render status line at all.
Never,
// Render status line for every window.
Always,
// Render single status line at the bottom instead of one for each window.
Single,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct StatusLineConfig {
// When/how should the status line be rendered.
pub render: StatusLineRenderValue,
}

impl Default for StatusLineConfig {
fn default() -> Self {
Self {
render: StatusLineRenderValue::Always,
}
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct FilePickerConfig {
Expand Down Expand Up @@ -142,6 +168,8 @@ pub struct Config {
pub file_picker: FilePickerConfig,
/// Shape for cursor in each mode
pub cursor_shape: CursorShapeConfig,
/// Status line configuration
pub status_line: StatusLineConfig,
/// Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. Defaults to `false`.
pub true_color: bool,
/// Search configuration.
Expand Down Expand Up @@ -381,6 +409,7 @@ impl Default for Config {
completion_trigger_len: 2,
auto_info: true,
file_picker: FilePickerConfig::default(),
status_line: StatusLineConfig::default(),
cursor_shape: CursorShapeConfig::default(),
true_color: false,
search: SearchConfig::default(),
Expand Down