diff options
author | Aram Drevekenin <aram@poor.dev> | 2021-08-12 14:50:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-12 14:50:00 +0200 |
commit | a37d3e5889476bbac209d20f89886daa3e9d3992 (patch) | |
tree | c02fbf779dda57b615a852fd6a43818b20722b19 /zellij-utils | |
parent | 426cee728a3b8c84edbc2d02cbc22f4840fc6a28 (diff) |
feat(ui): pane frames (new pane UI) (#643)
* work
* resize working
* move focus working
* close pane working
* selection and fullscreen working
* pane title line
* titles and conditional scroll title
* whole tab resize working
* plugin frames working
* plugin splitting working
* truncate pane frame titles
* cleanup
* panes always draw their own borders - also fix gap
* toggle pane frames
* move toggle to screen and fix some bugs
* fix plugin frame toggle
* fix terminal window resize
* fix scrolling and fullscreen bugs
* unit tests passing
* e2e tests passing and new test for new frames added
* refactor: TerminalPane and PluginPane
* refactor: Tab
* refactor: moar Tab
* refactor: Boundaries
* only render and calculate boundaries when there are no pane frames
* refactor: Layout
* fix(grid): properly resize when coming back from alternative viewport
* style: remove commented code
* style: fmt
* style: fmt
* style: fmt + clippy
* docs(changelog): update change
Diffstat (limited to 'zellij-utils')
-rw-r--r-- | zellij-utils/assets/config/default.yaml | 2 | ||||
-rw-r--r-- | zellij-utils/assets/layouts/default.yaml | 2 | ||||
-rw-r--r-- | zellij-utils/assets/layouts/disable-status-bar.yaml | 1 | ||||
-rw-r--r-- | zellij-utils/assets/layouts/strider.yaml | 2 | ||||
-rw-r--r-- | zellij-utils/src/errors.rs | 1 | ||||
-rw-r--r-- | zellij-utils/src/input/actions.rs | 2 | ||||
-rw-r--r-- | zellij-utils/src/input/layout.rs | 22 | ||||
-rw-r--r-- | zellij-utils/src/input/mod.rs | 1 | ||||
-rw-r--r-- | zellij-utils/src/input/options.rs | 5 | ||||
-rw-r--r-- | zellij-utils/src/pane_size.rs | 14 | ||||
-rw-r--r-- | zellij-utils/src/shared.rs | 2 |
11 files changed, 46 insertions, 8 deletions
diff --git a/zellij-utils/assets/config/default.yaml b/zellij-utils/assets/config/default.yaml index 24ee95f59..4654cee90 100644 --- a/zellij-utils/assets/config/default.yaml +++ b/zellij-utils/assets/config/default.yaml @@ -105,6 +105,8 @@ keybinds: key: [Char: 'x',] - action: [ToggleFocusFullscreen,] key: [Char: 'f',] + - action: [TogglePaneFrames,] + key: [Char: 'z',] - action: [FocusPreviousPane,] key: [ Alt: '[',] - action: [FocusNextPane,] diff --git a/zellij-utils/assets/layouts/default.yaml b/zellij-utils/assets/layouts/default.yaml index 96bf1809c..b163821de 100644 --- a/zellij-utils/assets/layouts/default.yaml +++ b/zellij-utils/assets/layouts/default.yaml @@ -2,12 +2,14 @@ direction: Horizontal parts: - direction: Vertical + borderless: true split_size: Fixed: 1 run: plugin: tab-bar - direction: Vertical - direction: Vertical + borderless: true split_size: Fixed: 2 run: diff --git a/zellij-utils/assets/layouts/disable-status-bar.yaml b/zellij-utils/assets/layouts/disable-status-bar.yaml index b990ba500..a03c71c3a 100644 --- a/zellij-utils/assets/layouts/disable-status-bar.yaml +++ b/zellij-utils/assets/layouts/disable-status-bar.yaml @@ -2,6 +2,7 @@ direction: Horizontal parts: - direction: Vertical + borderless: true split_size: Fixed: 1 run: diff --git a/zellij-utils/assets/layouts/strider.yaml b/zellij-utils/assets/layouts/strider.yaml index 9bbe5772f..288143894 100644 --- a/zellij-utils/assets/layouts/strider.yaml +++ b/zellij-utils/assets/layouts/strider.yaml @@ -2,6 +2,7 @@ direction: Horizontal parts: - direction: Vertical + borderless: true split_size: Fixed: 1 run: @@ -15,6 +16,7 @@ parts: plugin: strider - direction: Horizontal - direction: Vertical + borderless: true split_size: Fixed: 2 run: diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index 6a053038a..c0891d52d 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -209,6 +209,7 @@ pub enum ScreenContext { CloseFocusedPane, ToggleActiveSyncTab, ToggleActiveTerminalFullscreen, + TogglePaneFrames, SetSelectable, SetInvisibleBorders, SetFixedHeight, diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index 431a09bf7..3e86409bc 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -56,6 +56,8 @@ pub enum Action { PageScrollDown, /// Toggle between fullscreen focus pane and normal layout. ToggleFocusFullscreen, + /// Toggle frames around panes in the UI + TogglePaneFrames, /// Toggle between sending text commands to all panes on the current tab and normal mode. ToggleActiveSyncTab, /// Open a new pane in the specified direction (relative to focus). diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 090ccb13f..33e08bfdb 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -50,6 +50,8 @@ pub struct Layout { pub parts: Vec<Layout>, pub split_size: Option<SplitSize>, pub run: Option<Run>, + #[serde(default)] + pub borderless: bool, } type LayoutResult = Result<Layout, ConfigError>; @@ -141,6 +143,14 @@ impl Layout { total_panes } + pub fn total_borderless_panes(&self) -> usize { + let mut total_borderless_panes = 0; + total_borderless_panes += self.parts.iter().filter(|p| p.borderless).count(); + for part in self.parts.iter() { + total_borderless_panes += part.total_borderless_panes(); + } + total_borderless_panes + } pub fn extract_run_instructions(&self) -> Vec<Option<Run>> { let mut run_instructions = vec![]; if self.parts.is_empty() { @@ -168,7 +178,7 @@ fn split_space_to_parts_vertically( let mut split_parts = Vec::new(); let mut current_x_position = space_to_split.x; let mut current_width = 0; - let max_width = space_to_split.cols - (sizes.len() - 1); // minus space for gaps + let max_width = space_to_split.cols; let mut parts_to_grow = Vec::new(); @@ -192,7 +202,7 @@ fn split_space_to_parts_vertically( ..Default::default() }); current_width += columns; - current_x_position += columns + 1; // 1 for gap + current_x_position += columns; } if current_width > max_width { @@ -210,7 +220,7 @@ fn split_space_to_parts_vertically( last_flexible_index = idx; } current_width += part.cols; - current_x_position += part.cols + 1; // 1 for gap + current_x_position += part.cols; } } @@ -233,7 +243,7 @@ fn split_space_to_parts_horizontally( let mut split_parts = Vec::new(); let mut current_y_position = space_to_split.y; let mut current_height = 0; - let max_height = space_to_split.rows - (sizes.len() - 1); // minus space for gaps + let max_height = space_to_split.rows; let mut parts_to_grow = Vec::new(); @@ -256,7 +266,7 @@ fn split_space_to_parts_horizontally( ..Default::default() }); current_height += rows; - current_y_position += rows + 1; // 1 for gap + current_y_position += rows; } if current_height > max_height { @@ -275,7 +285,7 @@ fn split_space_to_parts_horizontally( last_flexible_index = idx; } current_height += part.rows; - current_y_position += part.rows + 1; // 1 for gap + current_y_position += part.rows; } } diff --git a/zellij-utils/src/input/mod.rs b/zellij-utils/src/input/mod.rs index 746d58619..87d72db8a 100644 --- a/zellij-utils/src/input/mod.rs +++ b/zellij-utils/src/input/mod.rs @@ -30,6 +30,7 @@ pub fn get_mode_info( ("r".to_string(), "Right split".to_string()), ("x".to_string(), "Close".to_string()), ("f".to_string(), "Fullscreen".to_string()), + ("z".to_string(), "Frames".to_string()), ], InputMode::Tab => vec![ ("←↓↑→".to_string(), "Move focus".to_string()), diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs index a2f9231cd..94994e1e3 100644 --- a/zellij-utils/src/input/options.rs +++ b/zellij-utils/src/input/options.rs @@ -58,6 +58,9 @@ pub struct Options { #[serde(default)] /// Disable handling of mouse events pub disable_mouse_mode: bool, + #[structopt(long)] + #[serde(default)] + pub no_pane_frames: bool, /// Set behaviour on force close (quit or detach) #[structopt(long)] pub on_force_close: Option<OnForceClose>, @@ -80,6 +83,7 @@ impl Options { let simplified_ui = merge_bool(other.simplified_ui, self.simplified_ui); let disable_mouse_mode = merge_bool(other.disable_mouse_mode, self.disable_mouse_mode); + let no_pane_frames = merge_bool(other.no_pane_frames, self.no_pane_frames); let default_mode = other.default_mode.or(self.default_mode); let default_shell = other.default_shell.or_else(|| self.default_shell.clone()); @@ -94,6 +98,7 @@ impl Options { default_shell, layout_dir, disable_mouse_mode, + no_pane_frames, on_force_close, } } diff --git a/zellij-utils/src/pane_size.rs b/zellij-utils/src/pane_size.rs index da165d4e6..db439b612 100644 --- a/zellij-utils/src/pane_size.rs +++ b/zellij-utils/src/pane_size.rs @@ -5,7 +5,7 @@ use crate::position::Position; /// Contains the position and size of a [`Pane`], or more generally of any terminal, measured /// in character rows and columns. -#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq)] pub struct PositionAndSize { pub x: usize, pub y: usize, @@ -34,4 +34,16 @@ impl PositionAndSize { let row = point.line.0 as usize; self.x <= col && col < self.x + self.cols && self.y <= row && row < self.y + self.rows } + pub fn reduce_outer_frame(mut self, frame_width: usize) -> Self { + self.x += frame_width; + self.rows -= frame_width * 2; + self.y += frame_width; + self.cols -= frame_width * 2; + self + } + pub fn reduce_top_line(mut self) -> Self { + self.y += 1; + self.rows -= 1; + self + } } diff --git a/zellij-utils/src/shared.rs b/zellij-utils/src/shared.rs index a741cc10b..b1edb97fd 100644 --- a/zellij-utils/src/shared.rs +++ b/zellij-utils/src/shared.rs @@ -18,7 +18,7 @@ pub fn set_permissions(path: &Path) -> io::Result<()> { fs::set_permissions(path, permissions) } -fn ansi_len(s: &str) -> usize { +pub fn ansi_len(s: &str) -> usize { from_utf8(&strip(s.as_bytes()).unwrap()) .unwrap() .chars() |