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

Add mode separator to statusline #5022

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
42 changes: 33 additions & 9 deletions helix-term/src/ui/statusline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use helix_view::{

use crate::ui::ProgressSpinners;

use helix_view::editor::ModeSeparator;
use helix_view::editor::StatusLineElement as StatusLineElementID;
use tui::buffer::Buffer as Surface;
use tui::text::{Span, Spans};
Expand Down Expand Up @@ -164,6 +165,15 @@ where
let visible = context.focused;
let config = context.editor.config();
let modenames = &config.statusline.mode;
let mode_style = if visible && config.color_modes {
match context.editor.mode() {
Mode::Insert => Some(context.editor.theme.get("ui.statusline.insert")),
Mode::Select => Some(context.editor.theme.get("ui.statusline.select")),
Mode::Normal => Some(context.editor.theme.get("ui.statusline.normal")),
}
} else {
None
};
write(
context,
format!(
Expand All @@ -179,16 +189,30 @@ where
" "
}
),
if visible && config.color_modes {
match context.editor.mode() {
Mode::Insert => Some(context.editor.theme.get("ui.statusline.insert")),
Mode::Select => Some(context.editor.theme.get("ui.statusline.select")),
Mode::Normal => Some(context.editor.theme.get("ui.statusline.normal")),
}
} else {
None
},
mode_style,
);

match config.statusline.mode_separator {
ModeSeparator::Flat => {}
_ => {
// invert the mode style background and foreground
let mode_separator_style = mode_style.map(|s| {
let mut c = s.clone();
c.fg = s.bg;
c.bg = s.fg;
0xrsp marked this conversation as resolved.
Show resolved Hide resolved
c
});

let mode_separator = match config.statusline.mode_separator {
ModeSeparator::Angled => "",
ModeSeparator::Slanted => "",
ModeSeparator::Round => "",
ModeSeparator::Flat => unreachable!(),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the current separator, this can just be specified as an arbitrary string rather than presets

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but I also think the presents are very reasonable and most 90% of people would be using one of the presents. I think it would be best to do a hybrid approach that lets arbitrary strings be used but also provides presets. See commit 1c2b828 for what this might look like.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These presets require a patched font to work (they're in the private use area of unicode) which is not acceptable for core. See #2211 (comment), #2377 (comment). A free-form string allows these without building it in to core.


write(context, mode_separator.to_string(), mode_separator_style);
}
};
}

fn render_lsp_spinner<F>(context: &mut RenderContext, write: F)
Expand Down
11 changes: 11 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ pub struct StatusLineConfig {
pub right: Vec<StatusLineElement>,
pub separator: String,
pub mode: ModeConfig,
pub mode_separator: ModeSeparator,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum ModeSeparator {
Flat,
Angled,
Round,
Slanted,
}

impl Default for StatusLineConfig {
Expand All @@ -283,6 +293,7 @@ impl Default for StatusLineConfig {
right: vec![E::Diagnostics, E::Selections, E::Position, E::FileEncoding],
separator: String::from("│"),
mode: ModeConfig::default(),
mode_separator: ModeSeparator::Flat,
}
}
}
Expand Down