diff options
author | a-kenji <aks.kenji@protonmail.com> | 2021-05-09 16:44:05 +0200 |
---|---|---|
committer | a-kenji <aks.kenji@protonmail.com> | 2021-05-10 16:03:06 +0200 |
commit | 088bcf3dd8aab4e522cface84c0a260b5b37a87c (patch) | |
tree | 5ed94988521c3caa2eefc00277569345e0f0d8f6 /default-plugins/tab-bar | |
parent | 7b5e728f9db7d82d9282265bb8fa35d7b05e5622 (diff) |
Add Option for Simplified Layout
* the simplified layout omits the Nerdfonts characters that are not
found in every Fontset
* add an optional config option to opt into the simplified ui
`simplified_ui: bool`
* add a config flag that allows opting into the simplified ui
`zellij options --simplified-ui`
* move the `clean` flag to the `setup` subcommand
Diffstat (limited to 'default-plugins/tab-bar')
-rw-r--r-- | default-plugins/tab-bar/src/line.rs | 37 | ||||
-rw-r--r-- | default-plugins/tab-bar/src/main.rs | 9 | ||||
-rw-r--r-- | default-plugins/tab-bar/src/tab.rs | 20 |
3 files changed, 46 insertions, 20 deletions
diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs index 89a7aa1b3..574edb78d 100644 --- a/default-plugins/tab-bar/src/line.rs +++ b/default-plugins/tab-bar/src/line.rs @@ -48,7 +48,7 @@ fn populate_tabs_in_tab_line( } } -fn left_more_message(tab_count_to_the_left: usize, palette: Palette) -> LinePart { +fn left_more_message(tab_count_to_the_left: usize, palette: Palette, separator: &str) -> LinePart { if tab_count_to_the_left == 0 { return LinePart { part: String::new(), @@ -62,11 +62,11 @@ fn left_more_message(tab_count_to_the_left: usize, palette: Palette) -> LinePart }; // 238 let more_text_len = more_text.chars().count() + 2; // 2 for the arrows - let left_separator = style!(palette.bg, palette.orange).paint(ARROW_SEPARATOR); + let left_separator = style!(palette.bg, palette.orange).paint(separator); let more_styled_text = style!(palette.black, palette.orange) .bold() .paint(more_text); - let right_separator = style!(palette.orange, palette.bg).paint(ARROW_SEPARATOR); + let right_separator = style!(palette.orange, palette.bg).paint(separator); let more_styled_text = format!( "{}", ANSIStrings(&[left_separator, more_styled_text, right_separator,]) @@ -77,7 +77,11 @@ fn left_more_message(tab_count_to_the_left: usize, palette: Palette) -> LinePart } } -fn right_more_message(tab_count_to_the_right: usize, palette: Palette) -> LinePart { +fn right_more_message( + tab_count_to_the_right: usize, + palette: Palette, + separator: &str, +) -> LinePart { if tab_count_to_the_right == 0 { return LinePart { part: String::new(), @@ -90,11 +94,11 @@ fn right_more_message(tab_count_to_the_right: usize, palette: Palette) -> LinePa " +many → ".to_string() }; let more_text_len = more_text.chars().count() + 1; // 2 for the arrow - let left_separator = style!(palette.bg, palette.orange).paint(ARROW_SEPARATOR); + let left_separator = style!(palette.bg, palette.orange).paint(separator); let more_styled_text = style!(palette.black, palette.orange) .bold() .paint(more_text); - let right_separator = style!(palette.orange, palette.bg).paint(ARROW_SEPARATOR); + let right_separator = style!(palette.orange, palette.bg).paint(separator); let more_styled_text = format!( "{}", ANSIStrings(&[left_separator, more_styled_text, right_separator,]) @@ -111,14 +115,15 @@ fn add_previous_tabs_msg( title_bar: &mut Vec<LinePart>, cols: usize, palette: Palette, + separator: &str, ) { while get_current_title_len(&tabs_to_render) - + left_more_message(tabs_before_active.len(), palette).len + + left_more_message(tabs_before_active.len(), palette, separator).len >= cols { tabs_before_active.push(tabs_to_render.remove(0)); } - let left_more_message = left_more_message(tabs_before_active.len(), palette); + let left_more_message = left_more_message(tabs_before_active.len(), palette, separator); title_bar.push(left_more_message); } @@ -127,14 +132,15 @@ fn add_next_tabs_msg( title_bar: &mut Vec<LinePart>, cols: usize, palette: Palette, + separator: &str, ) { while get_current_title_len(&title_bar) - + right_more_message(tabs_after_active.len(), palette).len + + right_more_message(tabs_after_active.len(), palette, separator).len >= cols { tabs_after_active.insert(0, title_bar.pop().unwrap()); } - let right_more_message = right_more_message(tabs_after_active.len(), palette); + let right_more_message = right_more_message(tabs_after_active.len(), palette, separator); title_bar.push(right_more_message); } @@ -148,11 +154,20 @@ fn tab_line_prefix(palette: Palette) -> LinePart { } } +pub fn tab_separator(capabilities: PluginCapabilities) -> &'static str { + if !capabilities.arrow_fonts { + ARROW_SEPARATOR + } else { + &"" + } +} + pub fn tab_line( mut all_tabs: Vec<LinePart>, active_tab_index: usize, cols: usize, palette: Palette, + capabilities: PluginCapabilities, ) -> Vec<LinePart> { let mut tabs_to_render: Vec<LinePart> = vec![]; let mut tabs_after_active = all_tabs.split_off(active_tab_index); @@ -180,6 +195,7 @@ pub fn tab_line( &mut tab_line, cols - prefix.len, palette, + tab_separator(capabilities), ); } tab_line.append(&mut tabs_to_render); @@ -189,6 +205,7 @@ pub fn tab_line( &mut tab_line, cols - prefix.len, palette, + tab_separator(capabilities), ); } tab_line.insert(0, prefix); diff --git a/default-plugins/tab-bar/src/main.rs b/default-plugins/tab-bar/src/main.rs index c62770137..00ff4bd96 100644 --- a/default-plugins/tab-bar/src/main.rs +++ b/default-plugins/tab-bar/src/main.rs @@ -60,10 +60,17 @@ impl ZellijPlugin for State { t.position, t.is_sync_panes_active, self.mode_info.palette, + self.mode_info.capabilities, ); all_tabs.push(tab); } - let tab_line = tab_line(all_tabs, active_tab_index, cols, self.mode_info.palette); + let tab_line = tab_line( + all_tabs, + active_tab_index, + cols, + self.mode_info.palette, + self.mode_info.capabilities, + ); let mut s = String::new(); for bar_part in tab_line { s = format!("{}{}", s, bar_part.part); diff --git a/default-plugins/tab-bar/src/tab.rs b/default-plugins/tab-bar/src/tab.rs index 7c1fe6b32..85e2c378d 100644 --- a/default-plugins/tab-bar/src/tab.rs +++ b/default-plugins/tab-bar/src/tab.rs @@ -1,15 +1,15 @@ -use crate::{LinePart, ARROW_SEPARATOR}; +use crate::{line::tab_separator, LinePart}; use ansi_term::ANSIStrings; use zellij_tile::prelude::*; use zellij_tile_utils::style; -pub fn active_tab(text: String, palette: Palette) -> LinePart { - let left_separator = style!(palette.bg, palette.green).paint(ARROW_SEPARATOR); +pub fn active_tab(text: String, palette: Palette, separator: &str) -> LinePart { + let left_separator = style!(palette.bg, palette.green).paint(separator); let tab_text_len = text.chars().count() + 4; // 2 for left and right separators, 2 for the text padding let tab_styled_text = style!(palette.black, palette.green) .bold() .paint(format!(" {} ", text)); - let right_separator = style!(palette.green, palette.bg).paint(ARROW_SEPARATOR); + let right_separator = style!(palette.green, palette.bg).paint(separator); let tab_styled_text = format!( "{}", ANSIStrings(&[left_separator, tab_styled_text, right_separator,]) @@ -20,13 +20,13 @@ pub fn active_tab(text: String, palette: Palette) -> LinePart { } } -pub fn non_active_tab(text: String, palette: Palette) -> LinePart { - let left_separator = style!(palette.bg, palette.fg).paint(ARROW_SEPARATOR); +pub fn non_active_tab(text: String, palette: Palette, separator: &str) -> LinePart { + let left_separator = style!(palette.bg, palette.fg).paint(separator); let tab_text_len = text.chars().count() + 4; // 2 for left and right separators, 2 for the padding let tab_styled_text = style!(palette.black, palette.fg) .bold() .paint(format!(" {} ", text)); - let right_separator = style!(palette.fg, palette.bg).paint(ARROW_SEPARATOR); + let right_separator = style!(palette.fg, palette.bg).paint(separator); let tab_styled_text = format!( "{}", ANSIStrings(&[left_separator, tab_styled_text, right_separator,]) @@ -43,7 +43,9 @@ pub fn tab_style( position: usize, is_sync_panes_active: bool, palette: Palette, + capabilities: PluginCapabilities, ) -> LinePart { + let separator = tab_separator(capabilities); let mut tab_text = if text.is_empty() { format!("Tab #{}", position + 1) } else { @@ -53,8 +55,8 @@ pub fn tab_style( tab_text.push_str(" (Sync)"); } if is_active_tab { - active_tab(tab_text, palette) + active_tab(tab_text, palette, separator) } else { - non_active_tab(tab_text, palette) + non_active_tab(tab_text, palette, separator) } } |