Skip to content

Commit

Permalink
Add style configuration for tabline, make tabline compatible with buf…
Browse files Browse the repository at this point in the history
…ferline
  • Loading branch information
nrabulinski committed Jul 1, 2023
1 parent a3abe82 commit e45ca04
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
40 changes: 31 additions & 9 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,28 +519,31 @@ impl EditorView {
viewport,
editor
.theme
.try_get("ui.bufferline.background")
.try_get("ui.tabline.background")
.or_else(|| editor.theme.try_get("ui.bufferline.background"))
.unwrap_or_else(|| editor.theme.get("ui.statusline")),
);

let bufferline_active = editor
let tabline_active = editor
.theme
.try_get("ui.bufferline.active")
.try_get("ui.tabline.active")
.or_else(|| editor.theme.try_get("ui.bufferline.active"))
.unwrap_or_else(|| editor.theme.get("ui.statusline.active"));

let bufferline_inactive = editor
let tabline_inactive = editor
.theme
.try_get("ui.bufferline")
.try_get("ui.tabline")
.or_else(|| editor.theme.try_get("ui.bufferline"))
.unwrap_or_else(|| editor.theme.get("ui.statusline.inactive"));

let mut x = viewport.x;

let current_tab = editor.tabs.focus;
for (id, tab) in editor.tabs.iter_tabs() {
let style = if current_tab == id {
bufferline_active
tabline_active
} else {
bufferline_inactive
tabline_inactive
};

let text = format!(" {} ", tab.name);
Expand Down Expand Up @@ -1429,6 +1432,14 @@ impl Component for EditorView {
surface.set_style(area, cx.editor.theme.get("ui.background"));
let config = cx.editor.config();

// check if tabline should be rendered
use helix_view::editor::TabLine;
let use_tabline = if let TabLine::Multiple = config.tabline {
cx.editor.tabs.len() > 1
} else {
true
};

// check if bufferline should be rendered
use helix_view::editor::BufferLine;
let use_bufferline = match config.bufferline {
Expand All @@ -1437,19 +1448,30 @@ impl Component for EditorView {
_ => false,
};

// -1 for commandline and -1 for bufferline
// -1 for commandline and -1 for tabline
let mut bufferline_area = area;
let mut editor_area = area.clip_bottom(1);
if use_tabline {
editor_area = editor_area.clip_top(1);
bufferline_area = bufferline_area.clip_top(1);
}

// -1 for bufferline
if use_bufferline {
editor_area = editor_area.clip_top(1);
}

// if the terminal size suddenly changed, we need to trigger a resize
cx.editor.resize(editor_area);

if use_bufferline {
if use_tabline {
Self::render_tabline(cx.editor, area.with_height(1), surface);
}

if use_bufferline {
Self::render_bufferline(cx.editor, bufferline_area.with_height(1), surface);
}

for (view, is_focused) in cx.editor.tabs.curr_tree().views() {
let doc = cx.editor.document(view.doc).unwrap();
self.render_view(cx.editor, doc, view, area, surface, is_focused);
Expand Down
16 changes: 15 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ pub struct Config {
pub rulers: Vec<u16>,
#[serde(default)]
pub whitespace: WhitespaceConfig,
/// Display open tabs along the top
pub tabline: TabLine,
/// Persistently display open buffers along the top
pub bufferline: BufferLine,
/// Vertical indent width guides.
Expand Down Expand Up @@ -554,6 +556,17 @@ impl Default for CursorShapeConfig {
}
}

/// tabline render modes
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum TabLine {
/// Always render
Always,
/// Only if multiple tabs are open
#[default]
Multiple,
}

/// bufferline render modes
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -703,7 +716,7 @@ pub struct WhitespaceCharacters {
impl Default for WhitespaceCharacters {
fn default() -> Self {
Self {
space: '·', // U+00B7
space: '·', // U+00B7
nbsp: '⍽', // U+237D
tab: '→', // U+2192
newline: '⏎', // U+23CE
Expand Down Expand Up @@ -809,6 +822,7 @@ impl Default for Config {
terminal: get_terminal_provider(),
rulers: Vec::new(),
whitespace: WhitespaceConfig::default(),
tabline: TabLine::default(),
bufferline: BufferLine::default(),
indent_guides: IndentGuidesConfig::default(),
color_modes: false,
Expand Down
10 changes: 10 additions & 0 deletions helix-view/src/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,14 @@ impl Tabs {
self.focus = id;
id
}

#[inline]
pub fn len(&self) -> usize {
self.tabs.len()
}

#[inline]
pub fn is_empty(&self) -> bool {
self.tabs.is_empty()
}
}

0 comments on commit e45ca04

Please sign in to comment.