feat: render bufferline separator

Closes #11372
This commit is contained in:
ayn2op 2024-09-16 00:20:50 +05:30
parent 5ce77de0dc
commit 1958efb9e6
2 changed files with 47 additions and 21 deletions

View File

@ -615,7 +615,7 @@ pub fn render_bufferline(editor: &Editor, viewport: Rect, surface: &mut Surface)
let mut x = viewport.x; let mut x = viewport.x;
let current_doc = view!(editor).doc; let current_doc = view!(editor).doc;
for doc in editor.documents() { for (idx, doc) in editor.documents().enumerate() {
let fname = doc let fname = doc
.path() .path()
.unwrap_or(&scratch) .unwrap_or(&scratch)
@ -630,6 +630,16 @@ pub fn render_bufferline(editor: &Editor, viewport: Rect, surface: &mut Surface)
bufferline_inactive bufferline_inactive
}; };
// Render the separator before the text if the current document is not first.
if idx > 0 {
let used_width = viewport.x.saturating_sub(x);
let rem_width = surface.area.width.saturating_sub(used_width);
let sep = &editor.config().bufferline.separator;
x = surface
.set_stringn(x, viewport.y, sep, rem_width as usize, bufferline_inactive)
.0;
}
let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" }); let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" });
let used_width = viewport.x.saturating_sub(x); let used_width = viewport.x.saturating_sub(x);
let rem_width = surface.area.width.saturating_sub(used_width); let rem_width = surface.area.width.saturating_sub(used_width);
@ -1479,10 +1489,10 @@ fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
let config = cx.editor.config(); let config = cx.editor.config();
// check if bufferline should be rendered // check if bufferline should be rendered
use helix_view::editor::BufferLine; use helix_view::editor::BufferLineRenderMode;
let use_bufferline = match config.bufferline { let use_bufferline = match config.bufferline.render_mode {
BufferLine::Always => true, BufferLineRenderMode::Always => true,
BufferLine::Multiple if cx.editor.documents.len() > 1 => true, BufferLineRenderMode::Multiple if cx.editor.documents.len() > 1 => true,
_ => false, _ => false,
}; };

View File

@ -299,6 +299,8 @@ pub struct Config {
/// Whether to display infoboxes. Defaults to true. /// Whether to display infoboxes. Defaults to true.
pub auto_info: bool, pub auto_info: bool,
pub file_picker: FilePickerConfig, pub file_picker: FilePickerConfig,
/// Configuration of the bufferline
pub bufferline: BufferLineConfig,
/// Configuration of the statusline elements /// Configuration of the statusline elements
pub statusline: StatusLineConfig, pub statusline: StatusLineConfig,
/// Shape for cursor in each mode /// Shape for cursor in each mode
@ -316,8 +318,6 @@ pub struct Config {
pub rulers: Vec<u16>, pub rulers: Vec<u16>,
#[serde(default)] #[serde(default)]
pub whitespace: WhitespaceConfig, pub whitespace: WhitespaceConfig,
/// Persistently display open buffers along the top
pub bufferline: BufferLine,
/// Vertical indent width guides. /// Vertical indent width guides.
pub indent_guides: IndentGuidesConfig, pub indent_guides: IndentGuidesConfig,
/// Whether to color modes with different colors. Defaults to `false`. /// Whether to color modes with different colors. Defaults to `false`.
@ -458,6 +458,35 @@ pub struct SearchConfig {
pub wrap_around: bool, pub wrap_around: bool,
} }
/// bufferline render modes
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum BufferLineRenderMode {
/// Don't render bufferline
#[default]
Never,
/// Always render
Always,
/// Only if multiple buffers are open
Multiple,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct BufferLineConfig {
pub render_mode: BufferLineRenderMode,
pub separator: String,
}
impl Default for BufferLineConfig {
fn default() -> Self {
Self {
render_mode: BufferLineRenderMode::default(),
separator: String::from(""),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct StatusLineConfig { pub struct StatusLineConfig {
@ -633,19 +662,6 @@ fn default() -> Self {
} }
} }
/// bufferline render modes
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum BufferLine {
/// Don't render bufferline
#[default]
Never,
/// Always render
Always,
/// Only if multiple buffers are open
Multiple,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
pub enum LineNumber { pub enum LineNumber {
@ -952,6 +968,7 @@ fn default() -> Self {
completion_trigger_len: 2, completion_trigger_len: 2,
auto_info: true, auto_info: true,
file_picker: FilePickerConfig::default(), file_picker: FilePickerConfig::default(),
bufferline: BufferLineConfig::default(),
statusline: StatusLineConfig::default(), statusline: StatusLineConfig::default(),
cursor_shape: CursorShapeConfig::default(), cursor_shape: CursorShapeConfig::default(),
true_color: false, true_color: false,
@ -961,7 +978,6 @@ fn default() -> Self {
terminal: get_terminal_provider(), terminal: get_terminal_provider(),
rulers: Vec::new(), rulers: Vec::new(),
whitespace: WhitespaceConfig::default(), whitespace: WhitespaceConfig::default(),
bufferline: BufferLine::default(),
indent_guides: IndentGuidesConfig::default(), indent_guides: IndentGuidesConfig::default(),
color_modes: false, color_modes: false,
soft_wrap: SoftWrap { soft_wrap: SoftWrap {