diff options
-rw-r--r-- | default-plugins/tab-bar/src/line.rs | 32 | ||||
-rw-r--r-- | default-plugins/tab-bar/src/main.rs | 19 | ||||
-rw-r--r-- | default-plugins/tab-bar/src/tab.rs | 44 |
3 files changed, 55 insertions, 40 deletions
diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs index 8341f142f..1022cda46 100644 --- a/default-plugins/tab-bar/src/line.rs +++ b/default-plugins/tab-bar/src/line.rs @@ -26,8 +26,24 @@ fn populate_tabs_in_tab_line( loop { let left_count = tabs_before_active.len(); let right_count = tabs_after_active.len(); - let collapsed_left = left_more_message(left_count, palette, tab_separator(capabilities)); - let collapsed_right = right_more_message(right_count, palette, tab_separator(capabilities)); + + // left_more_tab_index is first tab to the left of the leftmost visible tab + let left_more_tab_index = left_count.saturating_sub(1); + let collapsed_left = left_more_message( + left_count, + palette, + tab_separator(capabilities), + left_more_tab_index, + ); + + // right_more_tab_index is the first tab to the right of the rightmost visible tab + let right_more_tab_index = left_count + tabs_to_render.len(); + let collapsed_right = right_more_message( + right_count, + palette, + tab_separator(capabilities), + right_more_tab_index, + ); let total_size = collapsed_left.len + middle_size + collapsed_right.len; @@ -90,7 +106,12 @@ fn populate_tabs_in_tab_line( } } -fn left_more_message(tab_count_to_the_left: usize, palette: Palette, separator: &str) -> LinePart { +fn left_more_message( + tab_count_to_the_left: usize, + palette: Palette, + separator: &str, + tab_index: usize, +) -> LinePart { if tab_count_to_the_left == 0 { return LinePart::default(); } @@ -114,6 +135,7 @@ fn left_more_message(tab_count_to_the_left: usize, palette: Palette, separator: LinePart { part: more_styled_text, len: more_text_len, + tab_index: Some(tab_index), } } @@ -121,6 +143,7 @@ fn right_more_message( tab_count_to_the_right: usize, palette: Palette, separator: &str, + tab_index: usize, ) -> LinePart { if tab_count_to_the_right == 0 { return LinePart::default(); @@ -144,6 +167,7 @@ fn right_more_message( LinePart { part: more_styled_text, len: more_text_len, + tab_index: Some(tab_index), } } @@ -163,6 +187,7 @@ fn tab_line_prefix(session_name: Option<&str>, palette: Palette, cols: usize) -> let mut parts = vec![LinePart { part: prefix_styled_text.to_string(), len: prefix_text_len, + tab_index: None, }]; if let Some(name) = session_name { let name_part = format!("({}) ", name); @@ -176,6 +201,7 @@ fn tab_line_prefix(session_name: Option<&str>, palette: Palette, cols: usize) -> parts.push(LinePart { part: name_part_styled_text.to_string(), len: name_part_len, + tab_index: None, }) } } diff --git a/default-plugins/tab-bar/src/main.rs b/default-plugins/tab-bar/src/main.rs index b11ab87c2..562e27793 100644 --- a/default-plugins/tab-bar/src/main.rs +++ b/default-plugins/tab-bar/src/main.rs @@ -13,6 +13,7 @@ use crate::tab::tab_style; pub struct LinePart { part: String, len: usize, + tab_index: Option<usize>, } #[derive(Default)] @@ -88,12 +89,10 @@ impl ZellijPlugin for State { } let tab = tab_style( tabname, - t.active, + t, is_alternate_tab, - t.is_sync_panes_active, self.mode_info.style.colors, self.mode_info.capabilities, - t.other_focused_clients.as_slice(), ); is_alternate_tab = !is_alternate_tab; all_tabs.push(tab); @@ -108,17 +107,17 @@ impl ZellijPlugin for State { ); let mut s = String::new(); let mut len_cnt = 0; - for (idx, bar_part) in tab_line.iter().enumerate() { + for bar_part in tab_line { s = format!("{}{}", s, &bar_part.part); if self.should_render - && self.mouse_click_pos > len_cnt - && self.mouse_click_pos <= len_cnt + bar_part.len - && idx > 2 + && self.mouse_click_pos >= len_cnt + && self.mouse_click_pos < len_cnt + bar_part.len + && bar_part.tab_index.is_some() { - // First three elements of tab_line are "Zellij", session name and empty thing, hence the idx > 2 condition. - // Tabs are indexed starting from 1, therefore we need subtract 2 below. - switch_tab_to(TryInto::<u32>::try_into(idx).unwrap() - 2); + // Tabs are indexed starting from 1, therefore we need add 1 to tab_index. + let tab_index: u32 = bar_part.tab_index.unwrap().try_into().unwrap(); + switch_tab_to(tab_index + 1); } len_cnt += bar_part.len; } diff --git a/default-plugins/tab-bar/src/tab.rs b/default-plugins/tab-bar/src/tab.rs index a87d04081..82e8ad194 100644 --- a/default-plugins/tab-bar/src/tab.rs +++ b/default-plugins/tab-bar/src/tab.rs @@ -19,19 +19,19 @@ fn cursors(focused_clients: &[ClientId], palette: Palette) -> (Vec<ANSIString>, pub fn render_tab( text: String, + tab: &TabInfo, + is_alternate_tab: bool, palette: Palette, separator: &str, - focused_clients: &[ClientId], - active: bool, - is_alternate_tab: bool, ) -> LinePart { + let focused_clients = tab.other_focused_clients.as_slice(); let separator_width = separator.width(); let alternate_tab_color = match palette.theme_hue { // TODO: only do this if we don't have the arrow capabilities ThemeHue::Dark => palette.white, ThemeHue::Light => palette.black, }; - let background_color = if active { + let background_color = if tab.active { palette.green } else if is_alternate_tab { alternate_tab_color @@ -43,8 +43,7 @@ pub fn render_tab( ThemeHue::Light => palette.white, }; let left_separator = style!(foreground_color, background_color).paint(separator); - let mut tab_text_len = - text.width() + (separator_width * 2) + separator_width * (separator_width * 2); // 2 for left and right separators, 2 for the text padding + let mut tab_text_len = text.width() + (separator_width * 2) + 2; // +2 for padding let tab_styled_text = style!(foreground_color, background_color) .bold() .paint(format!(" {} ", text)); @@ -77,35 +76,26 @@ pub fn render_tab( LinePart { part: tab_styled_text, len: tab_text_len, + tab_index: Some(tab.position), } } pub fn tab_style( - text: String, - is_active_tab: bool, - is_alternate_tab: bool, - is_sync_panes_active: bool, + mut tabname: String, + tab: &TabInfo, + mut is_alternate_tab: bool, palette: Palette, capabilities: PluginCapabilities, - focused_clients: &[ClientId], ) -> LinePart { let separator = tab_separator(capabilities); - let mut tab_text = text; - if is_sync_panes_active { - tab_text.push_str(" (Sync)"); + + if tab.is_sync_panes_active { + tabname.push_str(" (Sync)"); } // we only color alternate tabs differently if we can't use the arrow fonts to separate them - let is_alternate_tab = if !capabilities.arrow_fonts { - false - } else { - is_alternate_tab - }; - render_tab( - tab_text, - palette, - separator, - focused_clients, - is_active_tab, - is_alternate_tab, - ) + if !capabilities.arrow_fonts { + is_alternate_tab = false; + } + + render_tab(tabname, tab, is_alternate_tab, palette, separator) } |