summaryrefslogtreecommitdiffstats
path: root/default-plugins/tab-bar
diff options
context:
space:
mode:
authorBrooks Rady <b.j.rady@gmail.com>2021-08-28 17:46:24 +0100
committerGitHub <noreply@github.com>2021-08-28 17:46:24 +0100
commit76a5bc8a05c33fb3f46cff1ce95aa1af694b9927 (patch)
treeaa0c9e4b317d9d01906d11817b3b57f0047d7be8 /default-plugins/tab-bar
parent1544de266501bb7dbb0b044a04283b4fd5f59c6e (diff)
feat(ui): overhauled resize and layout systems
* refactor(panes): move to parametric pane sizes * Fixed the simpler errors by casting to usize * The least I can do is pass the formatting check... * Move to stable toolchain * Well, it compiles? * And now it doesn't! ;) * Baseline functionality with the new Dimension type * Working POC for percent-based resizing * REVERT THIS COMMIT – DELETES TESTS * Perfected the discrete resize algorithm * Fixed fixed-size panes * Basic bidirectional resize * feat(resize): finalised parametric resize algorithm * Reduce the logging level a bit * Fixed nested layouts using percents * Bug squishing for implicit sizing * Here is a funky (read: rubbish) rounding approach * And now it's gone again! * Improve discretisation algorithm to fix rounding errors * Fix the last layout bug (maybe?) * Mixed explicit and implied percents work now * Let's pretend that didn't happen... * Make things a bit less crashy * Crash slightly more for now (to find bugs) * Manaually splitting of panes works now * Start moving to percent-based resizes * Everything but fullscreen seems to be working * Fix compilatation errors * Culled a massive amount of border code * Why not pause to please rustfmt? * Turns out I was still missing a few tests... * Bringing back even more tests! * Fix tests and pane boarders * Fix the resize system without gaps * Fix content offset * Fixed a bug with pane closing * Add a hack to fix setting of the viewport * Fix toggling between shared borders and frames * fix(tests): make e2e properly use PaneGeom * style(fmt): make rustfmt happy * Revert unintentional rounding of borders * Purge some old borderless stuff * Fix busted tab-bar shrinking * Update E2E tests * Finish implementing fullscreen! * Don't crash anymore? * Fix (almost) all tests * Fix a lack of tab-stops * All tests passing * I really can't be bothered to debug a CI issue * Tie up loose ends * Knock out some lingering FIXMEs * Continue to clean things up * Change some naming and address FIXMEs * Cull more code + FIXMEs * Refactor of the resize system + polish * Only draw frames when absolutely necessary * Fix the tab-bar crash * Fix rendering of boarders on reattach * Fix resizing at small pane sizes * Deduplicate code in the layout system * Update tab-bar WASM * Fixed the pinching of panes during resize * Unexpose needlessly public type * Add back a lost test * Re-add tab tests and get them to compile * All tabs need layouts * Start fixing tests + bug in main * Stabilize the resize algorithm rounding * All tests from main are now passing * Cull more dead code
Diffstat (limited to 'default-plugins/tab-bar')
-rw-r--r--default-plugins/tab-bar/src/line.rs44
-rw-r--r--default-plugins/tab-bar/src/main.rs2
2 files changed, 27 insertions, 19 deletions
diff --git a/default-plugins/tab-bar/src/line.rs b/default-plugins/tab-bar/src/line.rs
index fc18abfd1..b92f7573a 100644
--- a/default-plugins/tab-bar/src/line.rs
+++ b/default-plugins/tab-bar/src/line.rs
@@ -5,9 +5,7 @@ use zellij_tile::prelude::*;
use zellij_tile_utils::style;
fn get_current_title_len(current_title: &[LinePart]) -> usize {
- current_title
- .iter()
- .fold(0, |acc, title_part| acc + title_part.len)
+ current_title.iter().map(|p| p.len).sum()
}
fn populate_tabs_in_tab_line(
@@ -144,20 +142,29 @@ fn add_next_tabs_msg(
title_bar.push(right_more_message);
}
-fn tab_line_prefix(session_name: Option<&str>, palette: Palette) -> LinePart {
- let mut prefix_text = " Zellij ".to_string();
- if let Some(name) = session_name {
- prefix_text.push_str(&format!("({}) ", name));
- }
+fn tab_line_prefix(session_name: Option<&str>, palette: Palette, cols: usize) -> Vec<LinePart> {
+ let prefix_text = " Zellij ".to_string();
let prefix_text_len = prefix_text.chars().count();
let prefix_styled_text = style!(palette.white, palette.cyan)
.bold()
.paint(prefix_text);
- LinePart {
+ let mut parts = vec![LinePart {
part: format!("{}", prefix_styled_text),
len: prefix_text_len,
+ }];
+ if let Some(name) = session_name {
+ let name_part = format!("({}) ", name);
+ let name_part_len = name_part.chars().count();
+ let name_part_styled_text = style!(palette.white, palette.cyan).bold().paint(name_part);
+ if cols.saturating_sub(prefix_text_len) >= name_part_len {
+ parts.push(LinePart {
+ part: format!("{}", name_part_styled_text),
+ len: name_part_len,
+ })
+ }
}
+ parts
}
pub fn tab_separator(capabilities: PluginCapabilities) -> &'static str {
@@ -176,7 +183,7 @@ pub fn tab_line(
palette: Palette,
capabilities: PluginCapabilities,
) -> Vec<LinePart> {
- let mut tabs_to_render: Vec<LinePart> = vec![];
+ let mut tabs_to_render = Vec::new();
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() {
@@ -184,14 +191,17 @@ pub fn tab_line(
} else {
tabs_before_active.pop().unwrap()
};
- tabs_to_render.push(active_tab);
+ let mut prefix = tab_line_prefix(session_name, palette, cols);
+ let prefix_len = get_current_title_len(&prefix);
+ if prefix_len + active_tab.len <= cols {
+ tabs_to_render.push(active_tab);
+ }
- let prefix = tab_line_prefix(session_name, palette);
populate_tabs_in_tab_line(
&mut tabs_before_active,
&mut tabs_after_active,
&mut tabs_to_render,
- cols.saturating_sub(prefix.len),
+ cols.saturating_sub(prefix_len),
);
let mut tab_line: Vec<LinePart> = vec![];
@@ -200,7 +210,7 @@ pub fn tab_line(
&mut tabs_before_active,
&mut tabs_to_render,
&mut tab_line,
- cols.saturating_sub(prefix.len),
+ cols.saturating_sub(prefix_len),
palette,
tab_separator(capabilities),
);
@@ -210,11 +220,11 @@ pub fn tab_line(
add_next_tabs_msg(
&mut tabs_after_active,
&mut tab_line,
- cols.saturating_sub(prefix.len),
+ cols.saturating_sub(prefix_len),
palette,
tab_separator(capabilities),
);
}
- tab_line.insert(0, prefix);
- tab_line
+ prefix.append(&mut tab_line);
+ prefix
}
diff --git a/default-plugins/tab-bar/src/main.rs b/default-plugins/tab-bar/src/main.rs
index a185ccc33..3256c13c2 100644
--- a/default-plugins/tab-bar/src/main.rs
+++ b/default-plugins/tab-bar/src/main.rs
@@ -25,8 +25,6 @@ register_plugin!(State);
impl ZellijPlugin for State {
fn load(&mut self) {
set_selectable(false);
- set_invisible_borders(true);
- set_fixed_height(1);
subscribe(&[EventType::TabUpdate, EventType::ModeUpdate]);
}