diff options
| author | Aram Drevekenin <aram@poor.dev> | 2026-06-29 18:10:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-29 18:10:59 +0200 |
| commit | 245f5141c9bb7eb91f003efac4defc94470243fd (patch) | |
| tree | 52ae6d003366f97e41c8a1450602aef63c8fdca2 /default-plugins/tab-bar/src | |
| parent | feat: reload config on theme change (#5135) (diff) | |
| download | sl0ppij-245f5141c9bb7eb91f003efac4defc94470243fd.tar.gz sl0ppij-245f5141c9bb7eb91f003efac4defc94470243fd.tar.xz sl0ppij-245f5141c9bb7eb91f003efac4defc94470243fd.zip | |
Title frames (#5318)
* initial implementation
* improve single line title design
* hint text plugin infra
* add proto regen task
* display alt text in status bar
* don't display text with full frames
* style alt hover text
* fix + style control own pane hover
* make multiplayer indications responsive
* update snapshots
* plugin api
* single pane as tab
* better scroll styling
* fix tests
* tab-bar plus hover
* plugin surface tests
* integration tests
* adjust all integration tests
* reduce hover noise
* add pane id to in place
* more integration tests
* style: rustfmt
* update plugin assets
* update assets and snapshots
* add pr
Diffstat (limited to 'default-plugins/tab-bar/src')
| -rw-r--r-- | default-plugins/tab-bar/src/line.rs | 74 | ||||
| -rw-r--r-- | default-plugins/tab-bar/src/main.rs | 49 | ||||
| -rw-r--r-- | default-plugins/tab-bar/src/tab.rs | 13 |
3 files changed, 132 insertions, 4 deletions
diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs index aa76ce27..99b85f05 100644 --- a/default-plugins/tab-bar/src/line.rs +++ b/default-plugins/tab-bar/src/line.rs @@ -224,7 +224,10 @@ pub fn tab_line( mode_info: &ModeInfo, hide_swap_layout_indicator: bool, background: &PaletteColor, -) -> Vec<LinePart> { + active_pane_scroll: Option<(usize, usize)>, + is_alternate_tab: bool, + new_tab_button_is_hovered: bool, +) -> (Vec<LinePart>, Option<(usize, usize)>) { let mut tabs_after_active = all_tabs.split_off(active_tab_index); let mut tabs_before_active = all_tabs; let active_tab = if !tabs_after_active.is_empty() { @@ -249,6 +252,9 @@ pub fn tab_line( ) }) }; + if swap_layout_indicator.is_none() { + swap_layout_indicator = active_pane_scroll.map(|scroll| scroll_status(scroll, palette)); + } // Drop indicator if it would cause wrapping (active tab always rendered unconditionally) let prefix_len = get_current_title_len(&prefix); @@ -279,6 +285,33 @@ pub fn tab_line( tab_index: None, }]); + let supports_arrow_fonts = !capabilities.arrow_fonts; + let new_tab_button_background = if supports_arrow_fonts { + if new_tab_button_is_hovered { + palette.ribbon_unselected.emphasis_1 + } else { + palette.ribbon_unselected.background + } + } else if is_alternate_tab { + palette.ribbon_unselected.emphasis_1 + } else { + palette.ribbon_unselected.background + }; + let new_tab_button = new_tab_button_line_part(palette, capabilities, new_tab_button_background); + let used = prefix.iter().map(|p| p.len).sum::<usize>(); + let current_indicator_len = swap_layout_indicator.as_ref().map(|s| s.len).unwrap_or(0); + let room = cols + .saturating_sub(used) + .saturating_sub(current_indicator_len); + let new_tab_button_range = if room >= new_tab_button.len { + let button_start = used; + let button_end = button_start + new_tab_button.len; + prefix.push(new_tab_button); + Some((button_start, button_end)) + } else { + None + }; + if let Some(mut swap_layout_indicator) = swap_layout_indicator.take() { let remaining_space = cols .saturating_sub(prefix.iter().fold(0, |len, part| len + part.len)) @@ -301,7 +334,7 @@ pub fn tab_line( prefix.push(swap_layout_indicator); } - prefix + (prefix, new_tab_button_range) } fn swap_layout_status( @@ -329,6 +362,43 @@ fn swap_layout_status( } } +fn scroll_status(scroll: (usize, usize), palette: Styling) -> LinePart { + let (position, length) = scroll; + let text = format!("[ SCROLL {}/{} ]", position, length); + let text_color = palette.text_unselected.base; + let bg_color = palette.text_unselected.background; + let styled_text = style!(text_color, bg_color).bold().paint(&text); + LinePart { + part: styled_text.to_string(), + len: text.width(), + tab_index: None, + } +} + +fn new_tab_button_line_part( + palette: Styling, + capabilities: PluginCapabilities, + background_color: PaletteColor, +) -> LinePart { + let separator = tab_separator(capabilities); + let separator_width = separator.width(); + let foreground_color = palette.ribbon_unselected.base; + let separator_fill_color = palette.text_unselected.background; + let left_separator = style!(separator_fill_color, background_color).paint(separator); + let right_separator = style!(background_color, separator_fill_color).paint(separator); + let text = "+"; + let styled_text = style!(foreground_color, background_color) + .bold() + .paint(format!(" {} ", text)); + let part = ANSIStrings(&[left_separator, styled_text, right_separator]).to_string(); + let len = text.width() + (separator_width * 2) + 2; + LinePart { + part, + len, + tab_index: None, + } +} + pub fn ribbon_as_line_part(text: &str, is_selected: bool, supports_arrow_fonts: bool) -> LinePart { let ribbon_text = if is_selected { Text::new(text).selected() diff --git a/default-plugins/tab-bar/src/main.rs b/default-plugins/tab-bar/src/main.rs index 6a3db351..6fa92c75 100644 --- a/default-plugins/tab-bar/src/main.rs +++ b/default-plugins/tab-bar/src/main.rs @@ -33,6 +33,10 @@ struct State { tab_line: Vec<LinePart>, hide_swap_layout_indication: bool, cached_keybinds: KeybindsVec, + active_pane_scroll: Option<(usize, usize)>, + new_tab_button_range: Option<(usize, usize)>, + hovered_tab_idx: Option<usize>, + hovered_new_tab_button: bool, } static ARROW_SEPARATOR: &str = ""; @@ -51,6 +55,7 @@ impl ZellijPlugin for State { EventType::ModeUpdate, EventType::Mouse, EventType::InitialKeybinds, + EventType::ActivePaneScroll, ]); } @@ -89,13 +94,48 @@ impl ZellijPlugin for State { eprintln!("Could not find active tab."); } }, + Event::ActivePaneScroll(scroll) => { + if self.active_pane_scroll != scroll { + should_render = true; + } + self.active_pane_scroll = scroll; + }, Event::Mouse(me) => match me { Mouse::LeftClick(_, col) => { + if let Some((start, end)) = self.new_tab_button_range { + if col >= start && col < end { + new_tab::<&str>(None, None); + return should_render; + } + } let tab_to_focus = get_tab_to_focus(&self.tab_line, self.active_tab_idx, col); if let Some(idx) = tab_to_focus { switch_tab_to(idx.try_into().unwrap()); } }, + Mouse::Hover(_, col) => { + let simplified_ui = self.mode_info.capabilities.arrow_fonts; + let mut new_hovered_new_tab_button = false; + let mut new_hovered_tab_idx = None; + if !simplified_ui { + if let Some((start, end)) = self.new_tab_button_range { + if col >= start && col < end { + new_hovered_new_tab_button = true; + } + } + if !new_hovered_new_tab_button { + new_hovered_tab_idx = + get_tab_to_focus(&self.tab_line, self.active_tab_idx, col); + } + } + if self.hovered_new_tab_button != new_hovered_new_tab_button + || self.hovered_tab_idx != new_hovered_tab_idx + { + self.hovered_new_tab_button = new_hovered_new_tab_button; + self.hovered_tab_idx = new_hovered_tab_idx; + should_render = true; + } + }, Mouse::ScrollUp(_) => { switch_tab_to(min(self.active_tab_idx + 1, self.tabs.len()) as u32); }, @@ -133,10 +173,12 @@ impl ZellijPlugin for State { } else if t.active { active_tab_index = t.position; } + let is_hovered = self.hovered_tab_idx == Some(t.position + 1); let tab = tab_style( tabname, t, is_alternate_tab, + is_hovered, self.mode_info.style.colors, self.mode_info.capabilities, ); @@ -146,7 +188,7 @@ impl ZellijPlugin for State { let background = self.mode_info.style.colors.text_unselected.background; - self.tab_line = tab_line( + let (line, new_tab_button_range) = tab_line( self.mode_info.session_name.as_deref(), all_tabs, active_tab_index, @@ -158,7 +200,12 @@ impl ZellijPlugin for State { &self.mode_info, self.hide_swap_layout_indication, &background, + self.active_pane_scroll, + is_alternate_tab, + self.hovered_new_tab_button, ); + self.tab_line = line; + self.new_tab_button_range = new_tab_button_range; let output = self .tab_line diff --git a/default-plugins/tab-bar/src/tab.rs b/default-plugins/tab-bar/src/tab.rs index d211d142..3db1bbb6 100644 --- a/default-plugins/tab-bar/src/tab.rs +++ b/default-plugins/tab-bar/src/tab.rs @@ -24,6 +24,7 @@ pub fn render_tab( text: String, tab: &TabInfo, is_alternate_tab: bool, + is_hovered: bool, palette: Styling, separator: &str, ) -> LinePart { @@ -37,6 +38,8 @@ pub fn render_tab( }; let background_color = if tab.active { palette.ribbon_selected.background + } else if is_hovered { + palette.ribbon_unselected.emphasis_1 } else if is_alternate_tab { alternate_tab_color } else { @@ -98,6 +101,7 @@ pub fn tab_style( mut tabname: String, tab: &TabInfo, mut is_alternate_tab: bool, + is_hovered: bool, palette: Styling, capabilities: PluginCapabilities, ) -> LinePart { @@ -116,7 +120,14 @@ pub fn tab_style( is_alternate_tab = false; } - render_tab(tabname, tab, is_alternate_tab, palette, separator) + render_tab( + tabname, + tab, + is_alternate_tab, + is_hovered, + palette, + separator, + ) } pub(crate) fn get_tab_to_focus( |
