From 80b00191c7c24507c6a4827e655edf32f7bfb2af Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Wed, 15 Feb 2023 17:06:19 +0100 Subject: style(fmt): rustfmt --- zellij-server/src/lib.rs | 15 +- zellij-server/src/os_input_output.rs | 8 +- .../src/panes/floating_panes/floating_pane_grid.rs | 4 +- zellij-server/src/panes/floating_panes/mod.rs | 19 +- zellij-server/src/panes/plugin_pane.rs | 6 +- zellij-server/src/panes/terminal_pane.rs | 6 +- zellij-server/src/panes/tiled_panes/mod.rs | 134 ++- .../src/panes/tiled_panes/pane_resizer.rs | 33 +- .../src/panes/tiled_panes/stacked_panes.rs | 397 ++++++--- .../src/panes/tiled_panes/tiled_pane_grid.rs | 114 ++- zellij-server/src/plugins/mod.rs | 8 +- zellij-server/src/pty.rs | 2 +- zellij-server/src/route.rs | 18 +- zellij-server/src/screen.rs | 21 +- zellij-server/src/tab/layout_applier.rs | 184 +++- zellij-server/src/tab/mod.rs | 132 ++- zellij-server/src/tab/swap_layouts.rs | 166 +++- .../src/tab/unit/tab_integration_tests.rs | 959 +++++++++++++++++---- zellij-server/src/tab/unit/tab_tests.rs | 2 +- zellij-server/src/thread_bus.rs | 5 +- zellij-server/src/ui/pane_boundaries_frame.rs | 13 +- zellij-server/src/unit/screen_tests.rs | 6 +- 22 files changed, 1759 insertions(+), 493 deletions(-) (limited to 'zellij-server') diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index 40fa1c36e..6c57e1b32 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -357,7 +357,10 @@ pub fn start_server(mut os_input: Box, socket_path: PathBuf) { Some(tab_layout.clone()), floating_panes_layout.clone(), tab_name, - (layout.swap_tiled_layouts.clone(), layout.swap_floating_layouts.clone()) + ( + layout.swap_tiled_layouts.clone(), + layout.swap_floating_layouts.clone(), + ), ); } @@ -375,7 +378,15 @@ pub fn start_server(mut os_input: Box, socket_path: PathBuf) { .unwrap(); } } else { - spawn_tabs(None, layout.template.map(|t| t.1).clone().unwrap_or_default(), None, (layout.swap_tiled_layouts.clone(), layout.swap_floating_layouts.clone())); + spawn_tabs( + None, + layout.template.map(|t| t.1).clone().unwrap_or_default(), + None, + ( + layout.swap_tiled_layouts.clone(), + layout.swap_floating_layouts.clone(), + ), + ); } session_data .read() diff --git a/zellij-server/src/os_input_output.rs b/zellij-server/src/os_input_output.rs index 70a994850..817e5e008 100644 --- a/zellij-server/src/os_input_output.rs +++ b/zellij-server/src/os_input_output.rs @@ -371,10 +371,10 @@ pub struct ServerOsInputOutput { orig_termios: Arc>, client_senders: Arc>>, terminal_id_to_raw_fd: Arc>>>, // A value of None means the - // terminal_id exists but is - // not connected to an fd (eg. - // a command pane with a - // non-existing command) + // terminal_id exists but is + // not connected to an fd (eg. + // a command pane with a + // non-existing command) cached_resizes: Arc>>>, // } diff --git a/zellij-server/src/panes/floating_panes/floating_pane_grid.rs b/zellij-server/src/panes/floating_panes/floating_pane_grid.rs index 9f034956d..afeecc8d2 100644 --- a/zellij-server/src/panes/floating_panes/floating_pane_grid.rs +++ b/zellij-server/src/panes/floating_panes/floating_pane_grid.rs @@ -743,9 +743,7 @@ impl<'a> FloatingPaneGrid<'a> { a_pane.y().cmp(&b_pane.y()) } }); - let active_pane_position = panes - .iter() - .position(|(id, _)| id == current_pane_id)?; + let active_pane_position = panes.iter().position(|(id, _)| id == current_pane_id)?; let last_pane = panes.last()?; let previous_active_pane_id = if active_pane_position == 0 { diff --git a/zellij-server/src/panes/floating_panes/mod.rs b/zellij-server/src/panes/floating_panes/mod.rs index a96b156a8..cb277729d 100644 --- a/zellij-server/src/panes/floating_panes/mod.rs +++ b/zellij-server/src/panes/floating_panes/mod.rs @@ -206,7 +206,9 @@ impl FloatingPanes { // returns the focused pane of any client_id - should be safe because the way things are // set up at the time of writing, all clients are focused on the same floating pane due to // z_index issues - client_id.and_then(|client_id| self.active_panes.get(&client_id).copied()).or_else(|| self.panes.keys().next().copied()) + client_id + .and_then(|client_id| self.active_panes.get(&client_id).copied()) + .or_else(|| self.panes.keys().next().copied()) } pub fn toggle_show_panes(&mut self, should_show_floating_panes: bool) { self.show_panes = should_show_floating_panes; @@ -224,7 +226,8 @@ impl FloatingPanes { } pub fn add_next_geom(&mut self, next_geom: PaneGeom) { // TODO: removeme - if true { // TODO: config flag to cancel this behaviour - classic_pane_algorithm? + if true { + // TODO: config flag to cancel this behaviour - classic_pane_algorithm? self.next_geoms.push_back(next_geom); } } @@ -241,7 +244,7 @@ impl FloatingPanes { viewport, ); floating_pane_grid.find_room_for_new_pane() - } + }, } } pub fn position_floating_pane_layout( @@ -592,7 +595,12 @@ impl FloatingPanes { self.set_force_render(); } } - pub fn move_active_pane(&mut self, search_backwards: bool, os_api: &mut Box, client_id: ClientId) { + pub fn move_active_pane( + &mut self, + search_backwards: bool, + os_api: &mut Box, + client_id: ClientId, + ) { let active_pane_id = self.get_active_pane_id(client_id).unwrap(); let new_position_id = { @@ -821,7 +829,8 @@ impl FloatingPanes { } } pub fn reapply_pane_focus(&mut self) { - if let Some(focused_pane) = self.first_active_floating_pane_id() { // floating pane focus is the same for all clients + if let Some(focused_pane) = self.first_active_floating_pane_id() { + // floating pane focus is the same for all clients self.focus_pane_for_all_clients(focused_pane); } } diff --git a/zellij-server/src/panes/plugin_pane.rs b/zellij-server/src/panes/plugin_pane.rs index 841104214..c6896f90d 100644 --- a/zellij-server/src/panes/plugin_pane.rs +++ b/zellij-server/src/panes/plugin_pane.rs @@ -13,10 +13,10 @@ use std::rc::Rc; use zellij_utils::pane_size::{Offset, SizeInPixels}; use zellij_utils::position::Position; use zellij_utils::{ - input::layout::Run, channels::SenderWithContext, data::{Event, InputMode, Mouse, Palette, PaletteColor, Style}, errors::prelude::*, + input::layout::Run, pane_size::PaneGeom, shared::make_terminal_title, vte, @@ -277,7 +277,9 @@ impl Pane for PluginPane { let mut frame_geom = self.current_geom(); if !frame_params.should_draw_pane_frames { // in this case the width of the frame needs not include the pane corners - frame_geom.cols.set_inner(frame_geom.cols.as_usize().saturating_sub(1)); + frame_geom + .cols + .set_inner(frame_geom.cols.as_usize().saturating_sub(1)); } let mut frame = PaneFrame::new( frame_geom.into(), diff --git a/zellij-server/src/panes/terminal_pane.rs b/zellij-server/src/panes/terminal_pane.rs index 960476d5e..1b9644aa7 100644 --- a/zellij-server/src/panes/terminal_pane.rs +++ b/zellij-server/src/panes/terminal_pane.rs @@ -16,9 +16,9 @@ use std::time::{self, Instant}; use zellij_utils::input::command::RunCommand; use zellij_utils::pane_size::Offset; use zellij_utils::{ - input::layout::Run, data::{InputMode, Palette, PaletteColor, Style}, errors::prelude::*, + input::layout::Run, pane_size::PaneGeom, pane_size::SizeInPixels, position::Position, @@ -362,7 +362,9 @@ impl Pane for TerminalPane { let mut frame_geom = self.current_geom(); if !frame_params.should_draw_pane_frames { // in this case the width of the frame needs not include the pane corners - frame_geom.cols.set_inner(frame_geom.cols.as_usize().saturating_sub(1)); + frame_geom + .cols + .set_inner(frame_geom.cols.as_usize().saturating_sub(1)); } let mut frame = PaneFrame::new( frame_geom.into(), diff --git a/zellij-server/src/panes/tiled_panes/mod.rs b/zellij-server/src/panes/tiled_panes/mod.rs index 6f7d714dd..bd6470c90 100644 --- a/zellij-server/src/panes/tiled_panes/mod.rs +++ b/zellij-server/src/panes/tiled_panes/mod.rs @@ -1,6 +1,6 @@ mod pane_resizer; -mod tiled_pane_grid; mod stacked_panes; +mod tiled_pane_grid; use crate::resize_pty; use tiled_pane_grid::{split, TiledPaneGrid, RESIZE_PERCENT}; @@ -298,7 +298,9 @@ impl TiledPanes { if let Some(active_pane_id) = &self.active_panes.get(&client_id) { if let Some(active_pane) = self.panes.get_mut(active_pane_id) { let full_pane_size = active_pane.position_and_size(); - if full_pane_size.rows.as_usize() < MIN_TERMINAL_HEIGHT * 2 || full_pane_size.is_stacked { + if full_pane_size.rows.as_usize() < MIN_TERMINAL_HEIGHT * 2 + || full_pane_size.is_stacked + { return false; } else { return split(SplitDirection::Horizontal, &full_pane_size).is_some(); @@ -311,7 +313,9 @@ impl TiledPanes { if let Some(active_pane_id) = &self.active_panes.get(&client_id) { if let Some(active_pane) = self.panes.get_mut(active_pane_id) { let full_pane_size = active_pane.position_and_size(); - if full_pane_size.cols.as_usize() < MIN_TERMINAL_WIDTH * 2 || full_pane_size.is_stacked { + if full_pane_size.cols.as_usize() < MIN_TERMINAL_WIDTH * 2 + || full_pane_size.is_stacked + { return false; } return split(SplitDirection::Vertical, &full_pane_size).is_some(); @@ -385,8 +389,14 @@ impl TiledPanes { let connected_clients: Vec = self.connected_clients.borrow().iter().copied().collect(); for client_id in connected_clients { - if self.panes.get(&pane_id).map(|p| p.current_geom().is_stacked).unwrap_or(false) { - let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide).focus_pane(&pane_id); + if self + .panes + .get(&pane_id) + .map(|p| p.current_geom().is_stacked) + .unwrap_or(false) + { + let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) + .focus_pane(&pane_id); } self.active_panes .insert(client_id, pane_id, &mut self.panes); @@ -401,8 +411,15 @@ impl TiledPanes { for client_id in connected_clients { match &self.active_panes.get(&client_id).copied() { Some(pane_id) => { - if self.panes.get(&pane_id).map(|p| p.current_geom().is_stacked).unwrap_or(false) { - let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide).focus_pane(&pane_id); + if self + .panes + .get(&pane_id) + .map(|p| p.current_geom().is_stacked) + .unwrap_or(false) + { + let _ = + StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) + .focus_pane(&pane_id); } self.active_panes .insert(client_id, *pane_id, &mut self.panes); @@ -411,23 +428,37 @@ impl TiledPanes { None => { if let Some(first_pane_id) = self.first_selectable_pane_id() { let pane_id = first_pane_id; // TODO: combine with above - if self.panes.get(&pane_id).map(|p| p.current_geom().is_stacked).unwrap_or(false) { - let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide).focus_pane(&pane_id); + if self + .panes + .get(&pane_id) + .map(|p| p.current_geom().is_stacked) + .unwrap_or(false) + { + let _ = StackedPanes::new_from_btreemap( + &mut self.panes, + &self.panes_to_hide, + ) + .focus_pane(&pane_id); } self.active_panes .insert(client_id, pane_id, &mut self.panes); self.set_pane_active_at(pane_id); } - - } + }, } } self.set_force_render(); self.reapply_pane_frames(); } pub fn focus_pane(&mut self, pane_id: PaneId, client_id: ClientId) { - if self.panes.get(&pane_id).map(|p| p.current_geom().is_stacked).unwrap_or(false) { - let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide).focus_pane(&pane_id); + if self + .panes + .get(&pane_id) + .map(|p| p.current_geom().is_stacked) + .unwrap_or(false) + { + let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) + .focus_pane(&pane_id); self.reapply_pane_frames(); } @@ -445,10 +476,17 @@ impl TiledPanes { self.reset_boundaries(); } pub fn focus_pane_at_position(&mut self, position_and_size: PaneGeom, client_id: ClientId) { - if let Some(pane_id) = self.panes.iter().find(|(_pid, pane)| pane.position_and_size() == position_and_size).map(|(pid, _p)| *pid) { + if let Some(pane_id) = self + .panes + .iter() + .find(|(_pid, pane)| pane.position_and_size() == position_and_size) + .map(|(pid, _p)| *pid) + { if let Some(currently_active_pane_id) = self.active_panes.get(&client_id) { let prev_geom = { - if let Some(currently_focused_pane) = self.panes.get_mut(currently_active_pane_id) { + if let Some(currently_focused_pane) = + self.panes.get_mut(currently_active_pane_id) + { let prev_geom = currently_focused_pane.position_and_size(); currently_focused_pane.set_geom(position_and_size); Some(prev_geom) @@ -531,12 +569,16 @@ impl TiledPanes { }; let (stacked_pane_ids_under_flexible_pane, stacked_pane_ids_over_flexible_pane) = { // TODO: do not recalculate this every time on render - StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide).stacked_pane_ids_under_and_over_flexible_panes().unwrap() // TODO: no unwrap + StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) + .stacked_pane_ids_under_and_over_flexible_panes() + .unwrap() // TODO: no unwrap }; for (kind, pane) in self.panes.iter_mut() { if !self.panes_to_hide.contains(&pane.pid()) { - let pane_is_stacked_under = stacked_pane_ids_under_flexible_pane.contains(&pane.pid()); - let pane_is_stacked_over = stacked_pane_ids_over_flexible_pane.contains(&pane.pid()); + let pane_is_stacked_under = + stacked_pane_ids_under_flexible_pane.contains(&pane.pid()); + let pane_is_stacked_over = + stacked_pane_ids_over_flexible_pane.contains(&pane.pid()); let should_draw_pane_frames = self.draw_pane_frames; let pane_is_stacked = pane.current_geom().is_stacked; let mut pane_contents_and_ui = PaneContentsAndUi::new( @@ -750,8 +792,14 @@ impl TiledPanes { ); pane_grid.next_selectable_pane_id(&active_pane_id) }; - if self.panes.get(&next_active_pane_id).map(|p| p.current_geom().is_stacked).unwrap_or(false) { - let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide).focus_pane(&next_active_pane_id); + if self + .panes + .get(&next_active_pane_id) + .map(|p| p.current_geom().is_stacked) + .unwrap_or(false) + { + let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) + .focus_pane(&next_active_pane_id); self.reapply_pane_frames(); } @@ -776,8 +824,14 @@ impl TiledPanes { pane_grid.previous_selectable_pane_id(&active_pane_id) }; - if self.panes.get(&next_active_pane_id).map(|p| p.current_geom().is_stacked).unwrap_or(false) { - let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide).focus_pane(&next_active_pane_id); + if self + .panes + .get(&next_active_pane_id) + .map(|p| p.current_geom().is_stacked) + .unwrap_or(false) + { + let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) + .focus_pane(&next_active_pane_id); self.reapply_pane_frames(); } for client_id in connected_clients { @@ -860,14 +914,16 @@ impl TiledPanes { .get_mut(self.active_panes.get(&client_id).unwrap()) .unwrap(); - let previously_active_pane_is_stacked = previously_active_pane.current_geom().is_stacked; + let previously_active_pane_is_stacked = + previously_active_pane.current_geom().is_stacked; previously_active_pane.set_should_render(true); // we render the full viewport to remove any ui elements that might have been // there before (eg. another user's cursor) previously_active_pane.render_full_viewport(); let next_active_pane = self.panes.get_mut(&p).unwrap(); - let next_active_pane_is_stacked = next_active_pane.current_geom().is_stacked; + let next_active_pane_is_stacked = + next_active_pane.current_geom().is_stacked; next_active_pane.set_should_render(true); // we render the full viewport to remove any ui elements that might have been // there before (eg. another user's cursor) @@ -900,7 +956,8 @@ impl TiledPanes { *self.display_area.borrow(), *self.viewport.borrow(), ); - let next_index = pane_grid.next_selectable_pane_id_above(&active_pane_id) + let next_index = pane_grid + .next_selectable_pane_id_above(&active_pane_id) .or_else(|| pane_grid.progress_stack_up_if_in_stack(&active_pane_id)); match next_index { Some(p) => { @@ -911,14 +968,16 @@ impl TiledPanes { .get_mut(self.active_panes.get(&client_id).unwrap()) .unwrap(); - let previously_active_pane_is_stacked = previously_active_pane.current_geom().is_stacked; + let previously_active_pane_is_stacked = + previously_active_pane.current_geom().is_stacked; previously_active_pane.set_should_render(true); // we render the full viewport to remove any ui elements that might have been // there before (eg. another user's cursor) previously_active_pane.render_full_viewport(); let next_active_pane = self.panes.get_mut(&p).unwrap(); - let next_active_pane_is_stacked = next_active_pane.current_geom().is_stacked; + let next_active_pane_is_stacked = + next_active_pane.current_geom().is_stacked; next_active_pane.set_should_render(true); // we render the full viewport to remove any ui elements that might have been // there before (eg. another user's cursor) @@ -1032,8 +1091,14 @@ impl TiledPanes { pane_grid.next_selectable_pane_id(&active_pane_id) } }; - if self.panes.get(&new_position_id).map(|p| p.current_geom().is_stacked).unwrap_or(false) { - let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide).focus_pane(&new_position_id); + if self + .panes + .get(&new_position_id) + .map(|p| p.current_geom().is_stacked) + .unwrap_or(false) + { + let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) + .focus_pane(&new_position_id); self.reapply_pane_frames(); } @@ -1228,11 +1293,16 @@ impl TiledPanes { .last() .map(|(pane_id, _pane)| **pane_id); - match next_active_pane_id { Some(next_active_pane_id) => { - if self.panes.get(&next_active_pane_id).map(|p| p.current_geom().is_stacked).unwrap_or(false) { - let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide).focus_pane(&next_active_pane_id); + if self + .panes + .get(&next_active_pane_id) + .map(|p| p.current_geom().is_stacked) + .unwrap_or(false) + { + let _ = StackedPanes::new_from_btreemap(&mut self.panes, &self.panes_to_hide) + .focus_pane(&next_active_pane_id); self.reapply_pane_frames(); } for (client_id, active_pane_id) in active_panes { diff --git a/zellij-server/src/panes/tiled_panes/pane_resizer.rs b/zellij-server/src/panes/tiled_panes/pane_resizer.rs index cc5e70e19..2a2b5b6f9 100644 --- a/zellij-server/src/panes/tiled_panes/pane_resizer.rs +++ b/zellij-server/src/panes/tiled_panes/pane_resizer.rs @@ -132,9 +132,17 @@ impl<'a> PaneResizer<'a> { let err_context = || format!("Failed to apply spans"); let mut geoms_changed = false; for span in spans { - let pane_is_stacked = self.panes.borrow().get(&span.pid).unwrap().current_geom().is_stacked; + let pane_is_stacked = self + .panes + .borrow() + .get(&span.pid) + .unwrap() + .current_geom() + .is_stacked; if pane_is_stacked { - let current_geom = StackedPanes::new(self.panes.clone()).position_and_size_of_stack(&span.pid).unwrap(); + let current_geom = StackedPanes::new(self.panes.clone()) + .position_and_size_of_stack(&span.pid) + .unwrap(); let new_geom = match span.direction { SplitDirection::Horizontal => PaneGeom { x: span.pos, @@ -222,16 +230,14 @@ impl<'a> PaneResizer<'a> { .panes .borrow() .values() - .filter(|p| { - match self.get_span(!direction, p.as_ref()) { - Some(s) => { - let span_bounds = (s.pos, s.pos + s.size.as_usize()); - bwn(span_bounds.0, boundary) - || (bwn(boundary.0, span_bounds) - && (bwn(boundary.1, span_bounds) || boundary.1 == span_bounds.1)) - }, - None => false - } + .filter(|p| match self.get_span(!direction, p.as_ref()) { + Some(s) => { + let span_bounds = (s.pos, s.pos + s.size.as_usize()); + bwn(span_bounds.0, boundary) + || (bwn(boundary.0, span_bounds) + && (bwn(boundary.1, span_bounds) || boundary.1 == span_bounds.1)) + }, + None => false, }) .filter_map(|p| self.get_span(direction, p.as_ref())) .collect(); @@ -296,7 +302,8 @@ fn constrain_spans(space: usize, spans: &[Span]) -> HashSet constraints.insert(span.size_var | EQ(REQUIRED) | s as f64), - Constraint::Percent(p) => constraints.insert((span.size_var / new_flex_space as f64) | EQ(STRONG) | (p / 100.0)), + Constraint::Percent(p) => constraints + .insert((span.size_var / new_flex_space as f64) | EQ(STRONG) | (p / 100.0)), }; } diff --git a/zellij-server/src/panes/tiled_panes/stacked_panes.rs b/zellij-server/src/panes/tiled_panes/stacked_panes.rs index dfdba6099..00b193f69 100644 --- a/zellij-server/src/panes/tiled_panes/stacked_panes.rs +++ b/zellij-server/src/panes/tiled_panes/stacked_panes.rs @@ -1,21 +1,19 @@ use crate::{panes::PaneId, tab::Pane}; +use std::cell::RefCell; +use std::collections::{HashMap, HashSet}; +use std::rc::Rc; use zellij_utils::{ errors::prelude::*, pane_size::{Dimension, PaneGeom}, }; -use std::cell::RefCell; -use std::rc::Rc; -use std::collections::{HashMap, HashSet}; -pub struct StackedPanes <'a>{ +pub struct StackedPanes<'a> { panes: Rc>>>, } -impl <'a>StackedPanes <'a>{ +impl<'a> StackedPanes<'a> { pub fn new(panes: Rc>>>) -> Self { - StackedPanes { - panes - } + StackedPanes { panes } } pub fn new_from_btreemap( panes: impl IntoIterator)>, @@ -27,14 +25,28 @@ impl <'a>StackedPanes <'a>{ .map(|(p_id, p)| (*p_id, p)) .collect(); let panes = Rc::new(RefCell::new(panes)); - StackedPanes { - panes - } + StackedPanes { panes } } - pub fn move_down(&mut self, source_pane_id: &PaneId, destination_pane_id: &PaneId) -> Result<()> { + pub fn move_down( + &mut self, + source_pane_id: &PaneId, + destination_pane_id: &PaneId, + ) -> Result<()> { let err_context = || format!("Failed to move stacked pane focus down"); - let source_pane_is_stacked = self.panes.borrow().get(source_pane_id).with_context(err_context)?.position_and_size().is_stacked; - let destination_pane_is_stacked = self.panes.borrow().get(destination_pane_id).with_context(err_context)?.position_and_size().is_stacked; + let source_pane_is_stacked = self + .panes + .borrow() + .get(source_pane_id) + .with_context(err_context)? + .position_and_size() + .is_stacked; + let destination_pane_is_stacked = self + .panes + .borrow() + .get(destination_pane_id) + .with_context(err_context)? + .position_and_size() + .is_stacked; if source_pane_is_stacked && destination_pane_is_stacked { let mut panes = self.panes.borrow_mut(); let source_pane = panes.get_mut(source_pane_id).with_context(err_context)?; @@ -43,7 +55,9 @@ impl <'a>StackedPanes <'a>{ destination_pane_geom.y = source_pane_geom.y + 1; source_pane_geom.rows = Dimension::fixed(1); source_pane.set_geom(source_pane_geom); - let destination_pane = panes.get_mut(&destination_pane_id).with_context(err_context)?; + let destination_pane = panes + .get_mut(&destination_pane_id) + .with_context(err_context)?; destination_pane.set_geom(destination_pane_geom); } else if destination_pane_is_stacked { // we're moving down to the highest pane in the stack, we need to expand it and shrink the @@ -54,8 +68,20 @@ impl <'a>StackedPanes <'a>{ } pub fn move_up(&mut self, source_pane_id: &PaneId, destination_pane_id: &PaneId) -> Result<()> { let err_context = || format!("Failed to move stacked pane focus up"); - let source_pane_is_stacked = self.panes.borrow().get(source_pane_id).with_context(err_context)?.position_and_size().is_stacked; - let destination_pane_is_stacked = self.panes.borrow().get(destination_pane_id).with_context(err_context)?.position_and_size().is_stacked; + let source_pane_is_stacked = self + .panes + .borrow() + .get(source_pane_id) + .with_context(err_context)? + .position_and_size() + .is_stacked; + let destination_pane_is_stacked = self + .panes + .borrow() + .get(destination_pane_id) + .with_context(err_context)? + .position_and_size() + .is_stacked; if source_pane_is_stacked && destination_pane_is_stacked { let mut panes = self.panes.borrow_mut(); let source_pane = panes.get_mut(source_pane_id).with_context(err_context)?; @@ -65,7 +91,9 @@ impl <'a>StackedPanes <'a>{ source_pane_geom.rows = Dimension::fixed(1); source_pane.set_geom(source_pane_geom); destination_pane_geom.y -= 1; - let destination_pane = panes.get_mut(&destination_pane_id).with_context(err_context)?; + let destination_pane = panes + .get_mut(&destination_pane_id) + .with_context(err_context)?; destination_pane.set_geom(destination_pane_geom); } else if destination_pane_is_stacked { // we're moving up to the lowest pane in the stack, we need to expand it and shrink the @@ -78,19 +106,41 @@ impl <'a>StackedPanes <'a>{ // this function doesn't actually change the focus (since it is controlled elsewhere) // but rather makes sure pane_id is flexible if it were a one-liner before let err_context = || format!("Failed to focus stacked pane"); - let all_stacked_pane_positions = self.positions_in_stack(pane_id).with_context(err_context)?; + let all_stacked_pane_positions = + self.positions_in_stack(pane_id).with_context(err_context)?; - let position_of_flexible_pane = self.position_of_flexible_pane(&all_stacked_pane_positions).with_context(err_context)?; - let (flexible_pane_id, mut flexible_pane) = *all_stacked_pane_positions.iter().nth(position_of_flexible_pane).with_context(err_context)?; + let position_of_flexible_pane = self + .position_of_flexible_pane(&all_stacked_pane_positions) + .with_context(err_context)?; + let (flexible_pane_id, mut flexible_pane) = *all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane) + .with_context(err_context)?; if flexible_pane_id != *pane_id { let mut panes = self.panes.borrow_mut(); - let height_of_flexible_pane = all_stacked_pane_positions.iter().nth(position_of_flexible_pane).map(|(_pid, p)| p.rows).with_context(err_context)?; - let position_of_pane_to_focus = all_stacked_pane_positions.iter().position(|(pid, _p)| pid == pane_id).with_context(err_context)?; - let (_, mut pane_to_focus) = *all_stacked_pane_positions.iter().nth(position_of_pane_to_focus).with_context(err_context)?; + let height_of_flexible_pane = all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane) + .map(|(_pid, p)| p.rows) + .with_context(err_context)?; + let position_of_pane_to_focus = all_stacked_pane_positions + .iter() + .position(|(pid, _p)| pid == pane_id) + .with_context(err_context)?; + let (_, mut pane_to_focus) = *all_stacked_pane_positions + .iter() + .nth(position_of_pane_to_focus) + .with_context(err_context)?; pane_to_focus.rows = height_of_flexible_pane; - panes.get_mut(pane_id).with_context(err_context)?.set_geom(pane_to_focus); + panes + .get_mut(pane_id) + .with_context(err_context)? + .set_geom(pane_to_focus); flexible_pane.rows = Dimension::fixed(1); - panes.get_mut(&flexible_pane_id).with_context(err_context)?.set_geom(flexible_pane); + panes + .get_mut(&flexible_pane_id) + .with_context(err_context)? + .set_geom(flexible_pane); for (i, (pid, _position)) in all_stacked_pane_positions.iter().enumerate() { if i > position_of_pane_to_focus && i <= position_of_flexible_pane { @@ -112,31 +162,38 @@ impl <'a>StackedPanes <'a>{ } pub fn flexible_pane_id_in_stack(&self, pane_id_in_stack: &PaneId) -> Option { let all_stacked_pane_positions = self.positions_in_stack(pane_id_in_stack).ok()?; - all_stacked_pane_positions.iter().find(|(_pid, p)| p.rows.is_percent()).map(|(pid, _p)| *pid) + all_stacked_pane_positions + .iter() + .find(|(_pid, p)| p.rows.is_percent()) + .map(|(pid, _p)| *pid) } pub fn position_and_size_of_stack(&self, id: &PaneId) -> Option { let all_stacked_pane_positions = self.positions_in_stack(id).ok()?; - let position_of_flexible_pane = self.position_of_flexible_pane(&all_stacked_pane_positions).ok()?; - let (_flexible_pane_id, flexible_pane) = all_stacked_pane_positions.iter().nth(position_of_flexible_pane)?; + let position_of_flexible_pane = self + .position_of_flexible_pane(&all_stacked_pane_positions) + .ok()?; + let (_flexible_pane_id, flexible_pane) = all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane)?; let (_, first_pane_in_stack) = all_stacked_pane_positions.first()?; let (_, last_pane_in_stack) = all_stacked_pane_positions.last()?; let mut rows = flexible_pane.rows; - rows.set_inner((last_pane_in_stack.y - first_pane_in_stack.y) + last_pane_in_stack.rows.as_usize()); + rows.set_inner( + (last_pane_in_stack.y - first_pane_in_stack.y) + last_pane_in_stack.rows.as_usize(), + ); Some(PaneGeom { y: first_pane_in_stack.y, x: first_pane_in_stack.x, cols: first_pane_in_stack.cols, rows, is_stacked: true, // important because otherwise the minimum stack size will not be - // respected + // respected ..Default::default() }) } pub fn increase_stack_width(&mut self, id: &PaneId, percent: f64) -> Result<()> { let err_context = || format!("Failed to resize panes in stack"); - let all_stacked_pane_positions = self - .positions_in_stack(id) - .with_context(err_context)?; + let all_stacked_pane_positions = self.positions_in_stack(id).with_context(err_context)?; for (pane_id, _pane_position) in all_stacked_pane_positions { self.panes .borrow_mut() @@ -148,9 +205,7 @@ impl <'a>StackedPanes <'a>{ } pub fn reduce_stack_width(&mut self, id: &PaneId, percent: f64) -> Result<()> { let err_context = || format!("Failed to resize panes in stack"); - let all_stacked_pane_positions = self - .positions_in_stack(id) - .with_context(err_context)?; + let all_stacked_pane_positions = self.positions_in_stack(id).with_context(err_context)?; for (pane_id, _pane_position) in all_stacked_pane_positions { self.panes .borrow_mut() @@ -163,17 +218,35 @@ impl <'a>StackedPanes <'a>{ pub fn increase_stack_height(&mut self, id: &PaneId, percent: f64) -> Result<()> { let err_context = || format!("Failed to increase_stack_height"); let all_stacked_pane_positions = self.positions_in_stack(id).with_context(err_context)?; - let position_of_flexible_pane = self.position_of_flexible_pane(&all_stacked_pane_positions).with_context(err_context)?; - let (flexible_pane_id, _flexible_pane) = all_stacked_pane_positions.iter().nth(position_of_flexible_pane).with_context(err_context)?; - self.panes.borrow_mut().get_mut(flexible_pane_id).with_context(err_context)?.increase_height(percent); + let position_of_flexible_pane = self + .position_of_flexible_pane(&all_stacked_pane_positions) + .with_context(err_context)?; + let (flexible_pane_id, _flexible_pane) = all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane) + .with_context(err_context)?; + self.panes + .borrow_mut() + .get_mut(flexible_pane_id) + .with_context(err_context)? + .increase_height(percent); Ok(()) } pub fn reduce_stack_height(&mut self, id: &PaneId, percent: f64) -> Result<()> { let err_context = || format!("Failed to increase_stack_height"); let all_stacked_pane_positions = self.positions_in_stack(id).with_context(err_context)?; - let position_of_flexible_pane = self.position_of_flexible_pane(&all_stacked_pane_positions).with_context(err_context)?; - let (flexible_pane_id, _flexible_pane) = all_stacked_pane_positions.iter().nth(position_of_flexible_pane).with_context(err_context)?; - self.panes.borrow_mut().get_mut(flexible_pane_id).with_context(err_context)?.reduce_height(percent); + let position_of_flexible_pane = self + .position_of_flexible_pane(&all_stacked_pane_positions) + .with_context(err_context)?; + let (flexible_pane_id, _flexible_pane) = all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane) + .with_context(err_context)?; + self.panes + .borrow_mut() + .get_mut(flexible_pane_id) + .with_context(err_context)? + .reduce_height(percent); Ok(()) } pub fn min_stack_height(&mut self, id: &PaneId) -> Result { @@ -181,11 +254,19 @@ impl <'a>StackedPanes <'a>{ let all_stacked_pane_positions = self.positions_in_stack(id).with_context(err_context)?; Ok(all_stacked_pane_positions.len()) } - pub fn resize_panes_in_stack(&mut self, id: &PaneId, new_full_stack_geom: PaneGeom) -> Result<()> { + pub fn resize_panes_in_stack( + &mut self, + id: &PaneId, + new_full_stack_geom: PaneGeom, + ) -> Result<()> { let err_context = || format!("Failed to resize panes in stack"); let all_stacked_pane_positions = self.positions_in_stack(id).with_context(err_context)?; - let position_of_flexible_pane = self.position_of_flexible_pane(&all_stacked_pane_positions)?; - let (flexible_pane_id, flexible_pane) = all_stacked_pane_positions.iter().nth(position_of_flexible_pane).with_context(err_context)?; + let position_of_flexible_pane = + self.position_of_flexible_pane(&all_stacked_pane_positions)?; + let (flexible_pane_id, flexible_pane) = all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane) + .with_context(err_context)?; let current_rows = all_stacked_pane_positions.len() + (flexible_pane.rows.as_usize() - 1); let new_rows = new_full_stack_geom.rows.as_usize(); @@ -204,7 +285,11 @@ impl <'a>StackedPanes <'a>{ } else { new_pane_geom.y = new_full_stack_geom.y + i + (new_flexible_pane_geom_rows - 1); } - self.panes.borrow_mut().get_mut(&pane_id).with_context(err_context)?.set_geom(new_pane_geom); + self.panes + .borrow_mut() + .get_mut(&pane_id) + .with_context(err_context)? + .set_geom(new_pane_geom); } Ok(()) }; @@ -212,8 +297,14 @@ impl <'a>StackedPanes <'a>{ if new_rows >= current_rows { let extra_rows = new_rows - current_rows; let mut new_flexible_pane_geom = *flexible_pane; - new_flexible_pane_geom.rows.set_inner(new_flexible_pane_geom.rows.as_usize() + extra_rows); - self.panes.borrow_mut().get_mut(&flexible_pane_id).with_context(err_context)?.set_geom(new_flexible_pane_geom); + new_flexible_pane_geom + .rows + .set_inner(new_flexible_pane_geom.rows.as_usize() + extra_rows); + self.panes + .borrow_mut() + .get_mut(&flexible_pane_id) + .with_context(err_context)? + .set_geom(new_flexible_pane_geom); adjust_stack_geoms(new_flexible_pane_geom)?; } else { if new_rows < all_stacked_pane_positions.len() { @@ -222,12 +313,17 @@ impl <'a>StackedPanes <'a>{ } let rows_deficit = current_rows - new_rows; let mut new_flexible_pane_geom = *flexible_pane; - new_flexible_pane_geom.rows.set_inner(new_flexible_pane_geom.rows.as_usize() - rows_deficit); - self.panes.borrow_mut().get_mut(&flexible_pane_id).with_context(err_context)?.set_geom(new_flexible_pane_geom); + new_flexible_pane_geom + .rows + .set_inner(new_flexible_pane_geom.rows.as_usize() - rows_deficit); + self.panes + .borrow_mut() + .get_mut(&flexible_pane_id) + .with_context(err_context)? + .set_geom(new_flexible_pane_geom); adjust_stack_geoms(new_flexible_pane_geom)?; } Ok(()) - } fn pane_is_one_liner(&self, id: &PaneId) -> Result { let err_context = || format!("Cannot determin if pane is one liner or not"); @@ -243,30 +339,50 @@ impl <'a>StackedPanes <'a>{ let mut all_stacked_pane_positions: Vec<(PaneId, PaneGeom)> = panes .iter() .filter(|(_pid, p)| p.position_and_size().is_stacked) - .filter(|(_pid, p)| p.position_and_size().x == pane_in_stack.position_and_size().x && p.position_and_size().cols == pane_in_stack.position_and_size().cols) + .filter(|(_pid, p)| { + p.position_and_size().x == pane_in_stack.position_and_size().x + && p.position_and_size().cols == pane_in_stack.position_and_size().cols + }) .map(|(pid, p)| (*pid, p.position_and_size())) .collect(); - all_stacked_pane_positions.sort_by(|(_a_pid, a), (_b_pid, b)| { - a.y.cmp(&b.y) - }); + all_stacked_pane_positions.sort_by(|(_a_pid, a), (_b_pid, b)| a.y.cmp(&b.y)); Ok(all_stacked_pane_positions) } - fn position_of_current_and_flexible_pane(&self, current_pane_id: &PaneId) -> Result<(usize, usize)> { // (current_pane, flexible_pane) + fn position_of_current_and_flexible_pane( + &self, + current_pane_id: &PaneId, + ) -> Result<(usize, usize)> { + // (current_pane, flexible_pane) let err_context = || format!("Failed to position_of_current_and_flexible_pane"); let all_stacked_pane_positions = self.positions_in_stack(current_pane_id)?; let panes = self.panes.borrow(); let pane_to_close = panes.get(current_pane_id).with_context(err_context)?; - let position_of_current_pane = self.position_of_current_pane(&all_stacked_pane_positions, &pane_to_close)?; - let position_of_flexible_pane = self.position_of_flexible_pane(&all_stacked_pane_positions)?; + let position_of_current_pane = + self.position_of_current_pane(&all_stacked_pane_positions, &pane_to_close)?; + let position_of_flexible_pane = + self.position_of_flexible_pane(&all_stacked_pane_positions)?; Ok((position_of_current_pane, position_of_flexible_pane)) } - fn position_of_current_pane(&self, all_stacked_pane_positions: &Vec<(PaneId, PaneGeom)>, pane_to_close: &Box) -> Result { + fn position_of_current_pane( + &self, + all_stacked_pane_positions: &Vec<(PaneId, PaneGeom)>, + pane_to_close: &Box, + ) -> Result { let err_context = || format!("Failed to find position of current pane"); - all_stacked_pane_positions.iter().position(|(pid, _p)| pid == &pane_to_close.pid()).with_context(err_context) + all_stacked_pane_positions + .iter() + .position(|(pid, _p)| pid == &pane_to_close.pid()) + .with_context(err_context) } - fn position_of_flexible_pane(&self, all_stacked_pane_positions: &Vec<(PaneId, PaneGeom)>) -> Result { + fn position_of_flexible_pane( + &self, + all_stacked_pane_positions: &Vec<(PaneId, PaneGeom)>, + ) -> Result { let err_context = || format!("Failed to find position of flexible pane"); - all_stacked_pane_positions.iter().position(|(_pid, p)| p.rows.is_percent()).with_context(err_context) + all_stacked_pane_positions + .iter() + .position(|(_pid, p)| p.rows.is_percent()) + .with_context(err_context) } pub fn fill_space_over_pane_in_stack(&mut self, id: &PaneId) -> Result { if self.pane_is_one_liner(id)? { @@ -275,11 +391,20 @@ impl <'a>StackedPanes <'a>{ self.fill_space_over_visible_stacked_pane(id) } } - pub fn stacked_pane_ids_under_and_over_flexible_panes(&self) -> Result<(HashSet, HashSet)> { + pub fn stacked_pane_ids_under_and_over_flexible_panes( + &self, + ) -> Result<(HashSet, HashSet)> { let mut stacked_pane_ids_under_flexible_panes = HashSet::new(); let mut stacked_pane_ids_over_flexible_panes = HashSet::new(); let mut seen = HashSet::new(); - let pane_ids_in_stacks: Vec = { self.panes.borrow().iter().filter(|(_p_id, p)| p.position_and_size().is_stacked).map(|(p_id, _p)| *p_id).collect() }; + let pane_ids_in_stacks: Vec = { + self.panes + .borrow() + .iter() + .filter(|(_p_id, p)| p.position_and_size().is_stacked) + .map(|(p_id, _p)| *p_id) + .collect() + }; for pane_id in pane_ids_in_stacks { if !seen.contains(&pane_id) { let mut current_pane_is_above_stack = true; @@ -289,7 +414,7 @@ impl <'a>StackedPanes <'a>{ if pane_geom.rows.is_percent() { // this is the flexible pane current_pane_is_above_stack = false; - continue + continue; } if current_pane_is_above_stack { stacked_pane_ids_over_flexible_panes.insert(pane_id); @@ -300,10 +425,14 @@ impl <'a>StackedPanes <'a>{ seen.insert(pane_id); } } - Ok((stacked_pane_ids_under_flexible_panes, stacked_pane_ids_over_flexible_panes)) + Ok(( + stacked_pane_ids_under_flexible_panes, + stacked_pane_ids_over_flexible_panes, + )) } fn fill_space_over_one_liner_pane(&mut self, id: &PaneId) -> Result { - let (position_of_current_pane, position_of_flexible_pane) = self.position_of_current_and_flexible_pane(id)?; + let (position_of_current_pane, position_of_flexible_pane) = + self.position_of_current_and_flexible_pane(id)?; if position_of_current_pane > position_of_flexible_pane { self.fill_space_over_one_liner_pane_above_flexible_pane(id) } else { @@ -315,19 +444,32 @@ impl <'a>StackedPanes <'a>{ let all_stacked_pane_positions = self.positions_in_stack(id)?; let mut panes = self.panes.borrow_mut(); let pane_to_close = panes.get(id).with_context(err_context)?; - let position_of_current_pane = self.position_of_current_pane(&all_stacked_pane_positions, &pane_to_close)?; + let position_of_current_pane = + self.position_of_current_pane(&all_stacked_pane_positions, &pane_to_close)?; if all_stacked_pane_positions.len() > position_of_current_pane + 1 { let mut pane_to_close_position_and_size = pane_to_close.position_and_size(); - pane_to_close_position_and_size.rows.set_inner(pane_to_close_position_and_size.rows.as_usize() + 1); - let pane_id_below = all_stacked_pane_positions.iter().nth(position_of_current_pane + 1).map(|(pid, _)| *pid).with_context(err_context)?; + pane_to_close_position_and_size + .rows + .set_inner(pane_to_close_position_and_size.rows.as_usize() + 1); + let pane_id_below = all_stacked_pane_positions + .iter() + .nth(position_of_current_pane + 1) + .map(|(pid, _)| *pid) + .with_context(err_context)?; let pane_below = panes.get_mut(&pane_id_below).with_context(err_context)?; pane_below.set_geom(pane_to_close_position_and_size); return Ok(true); } else if position_of_current_pane > 0 { let mut pane_to_close_position_and_size = pane_to_close.position_and_size(); - pane_to_close_position_and_size.rows.set_inner(pane_to_close_position_and_size.rows.as_usize() + 1); + pane_to_close_position_and_size + .rows + .set_inner(pane_to_close_position_and_size.rows.as_usize() + 1); pane_to_close_position_and_size.y -= 1; - let pane_id_above = all_stacked_pane_positions.iter().nth(position_of_current_pane - 1).map(|(pid, _)| *pid).with_context(err_context)?; + let pane_id_above = all_stacked_pane_positions + .iter() + .nth(position_of_current_pane - 1) + .map(|(pid, _)| *pid) + .with_context(err_context)?; let pane_above = panes.get_mut(&pane_id_above).with_context(err_context)?; pane_above.set_geom(pane_to_close_position_and_size); return Ok(true); @@ -336,16 +478,27 @@ impl <'a>StackedPanes <'a>{ } } fn fill_space_over_one_liner_pane_above_flexible_pane(&mut self, id: &PaneId) -> Result { - let err_context = || format!("Failed to fill_space_over_one_liner_pane_above_flexible_pane"); + let err_context = + || format!("Failed to fill_space_over_one_liner_pane_above_flexible_pane"); let all_stacked_pane_positions = self.positions_in_stack(id)?; let mut panes = self.panes.borrow_mut(); let pane_to_close = panes.get(id).with_context(err_context)?; - let position_of_current_pane = self.position_of_current_pane(&all_stacked_pane_positions, &pane_to_close)?; - let position_of_flexible_pane = self.position_of_flexible_pane(&all_stacked_pane_positions)?; - let id_of_flexible_pane = all_stacked_pane_positions.iter().nth(position_of_flexible_pane).map(|(pid, _p)| *pid).with_context(err_context)?; - let flexible_pane = panes.get_mut(&id_of_flexible_pane).with_context(err_context)?; + let position_of_current_pane = + self.position_of_current_pane(&all_stacked_pane_positions, &pane_to_close)?; + let position_of_flexible_pane = + self.position_of_flexible_pane(&all_stacked_pane_positions)?; + let id_of_flexible_pane = all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane) + .map(|(pid, _p)| *pid) + .with_context(err_context)?; + let flexible_pane = panes + .get_mut(&id_of_flexible_pane) + .with_context(err_context)?; let mut flexible_pane_position_and_size = flexible_pane.position_and_size(); - flexible_pane_position_and_size.rows.set_inner(flexible_pane_position_and_size.rows.as_usize() + 1); + flexible_pane_position_and_size + .rows + .set_inner(flexible_pane_position_and_size.rows.as_usize() + 1); flexible_pane.set_geom(flexible_pane_position_and_size); for (i, (pid, _position)) in all_stacked_pane_positions.iter().enumerate() { if i > position_of_flexible_pane && i < position_of_current_pane { @@ -358,16 +511,27 @@ impl <'a>StackedPanes <'a>{ Ok(true) } fn fill_space_over_one_liner_pane_below_flexible_pane(&mut self, id: &PaneId) -> Result { - let err_context = || format!("Failed to fill_space_over_one_liner_pane_below_flexible_pane"); + let err_context = + || format!("Failed to fill_space_over_one_liner_pane_below_flexible_pane"); let all_stacked_pane_positions = self.positions_in_stack(id)?; let mut panes = self.panes.borrow_mut(); let pane_to_close = panes.get(id).with_context(err_context)?; - let position_of_current_pane = self.position_of_current_pane(&all_stacked_pane_positions, &pane_to_close)?; - let position_of_flexible_pane = self.position_of_flexible_pane(&all_stacked_pane_positions)?; - let id_of_flexible_pane = all_stacked_pane_positions.iter().nth(position_of_flexible_pane).map(|(pid, _p)| *pid).with_context(err_context)?; - let flexible_pane = panes.get_mut(&id_of_flexible_pane).with_context(err_context)?; + let position_of_current_pane = + self.position_of_current_pane(&all_stacked_pane_positions, &pane_to_close)?; + let position_of_flexible_pane = + self.position_of_flexible_pane(&all_stacked_pane_positions)?; + let id_of_flexible_pane = all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane) + .map(|(pid, _p)| *pid) + .with_context(err_context)?; + let flexible_pane = panes + .get_mut(&id_of_flexible_pane) + .with_context(err_context)?; let mut flexible_pane_position_and_size = flexible_pane.position_and_size(); - flexible_pane_position_and_size.rows.set_inner(flexible_pane_position_and_size.rows.as_usize() + 1); + flexible_pane_position_and_size + .rows + .set_inner(flexible_pane_position_and_size.rows.as_usize() + 1); flexible_pane.set_geom(flexible_pane_position_and_size); for (i, (pid, _position)) in all_stacked_pane_positions.iter().enumerate() { if i > position_of_current_pane && i <= position_of_flexible_pane { @@ -382,21 +546,39 @@ impl <'a>StackedPanes <'a>{ fn make_lowest_pane_in_stack_flexible(&mut self, destination_pane_id: &PaneId) -> Result<()> { let err_context = || format!("Failed to make_lowest_pane_flexible"); let mut all_stacked_pane_positions = self.positions_in_stack(destination_pane_id)?; - let position_of_flexible_pane = self.position_of_flexible_pane(&all_stacked_pane_positions)?; + let position_of_flexible_pane = + self.position_of_flexible_pane(&all_stacked_pane_positions)?; if position_of_flexible_pane != all_stacked_pane_positions.len().saturating_sub(1) { let mut panes = self.panes.borrow_mut(); - let height_of_flexible_pane = all_stacked_pane_positions.iter().nth(position_of_flexible_pane).map(|(_pid, p)| p.rows).with_context(err_context)?; - let (lowest_pane_id, mut lowest_pane_geom) = all_stacked_pane_positions.last_mut().with_context(err_context)?; + let height_of_flexible_pane = all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane) + .map(|(_pid, p)| p.rows) + .with_context(err_context)?; + let (lowest_pane_id, mut lowest_pane_geom) = all_stacked_pane_positions + .last_mut() + .with_context(err_context)?; lowest_pane_geom.rows = height_of_flexible_pane; - panes.get_mut(lowest_pane_id).with_context(err_context)?.set_geom(lowest_pane_geom); - let (flexible_pane_id, mut flexible_pane_geom) = all_stacked_pane_positions.iter().nth(position_of_flexible_pane).with_context(err_context)?; + panes + .get_mut(lowest_pane_id) + .with_context(err_context)? + .set_geom(lowest_pane_geom); + let (flexible_pane_id, mut flexible_pane_geom) = all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane) + .with_context(err_context)?; flexible_pane_geom.rows = Dimension::fixed(1); - panes.get_mut(flexible_pane_id).with_context(err_context)?.set_geom(flexible_pane_geom); + panes + .get_mut(flexible_pane_id) + .with_context(err_context)? + .set_geom(flexible_pane_geom); for (i, (pid, _position)) in all_stacked_pane_positions.iter().enumerate() { if i > position_of_flexible_pane { let pane = panes.get_mut(pid).with_context(err_context)?; let mut pane_position_and_size = pane.position_and_size(); - pane_position_and_size.y = pane_position_and_size.y.saturating_sub(height_of_flexible_pane.as_usize() - 1); + pane_position_and_size.y = pane_position_and_size + .y + .saturating_sub(height_of_flexible_pane.as_usize() - 1); pane.set_geom(pane_position_and_size); } } @@ -406,22 +588,39 @@ impl <'a>StackedPanes <'a>{ fn make_highest_pane_in_stack_flexible(&mut self, destination_pane_id: &PaneId) -> Result<()> { let err_context = || format!("Failed to make_lowest_pane_flexible"); let mut all_stacked_pane_positions = self.positions_in_stack(destination_pane_id)?; - let position_of_flexible_pane = self.position_of_flexible_pane(&all_stacked_pane_positions)?; + let position_of_flexible_pane = + self.position_of_flexible_pane(&all_stacked_pane_positions)?; if position_of_flexible_pane != 0 { let mut panes = self.panes.borrow_mut(); - let height_of_flexible_pane = all_stacked_pane_positions.iter().nth(position_of_flexible_pane).map(|(_pid, p)| p.rows).with_context(err_context)?; - let (highest_pane_id, mut highest_pane_geom) = all_stacked_pane_positions.first_mut().with_context(err_context)?; + let height_of_flexible_pane = all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane) + .map(|(_pid, p)| p.rows) + .with_context(err_context)?; + let (highest_pane_id, mut highest_pane_geom) = all_stacked_pane_positions + .first_mut() + .with_context(err_context)?; let y_of_whole_stack = highest_pane_geom.y; highest_pane_geom.rows = height_of_flexible_pane; - panes.get_mut(highest_pane_id).with_context(err_context)?.set_geom(highest_pane_geom); - let (flexible_pane_id, mut flexible_pane_geom) = all_stacked_pane_positions.iter().nth(position_of_flexible_pane).with_context(err_context)?; + panes + .get_mut(highest_pane_id) + .with_context(err_context)? + .set_geom(highest_pane_geom); + let (flexible_pane_id, mut flexible_pane_geom) = all_stacked_pane_positions + .iter() + .nth(position_of_flexible_pane) + .with_context(err_context)?; flexible_pane_geom.rows = Dimension::fixed(1); - panes.get_mut(flexible_pane_id).with_context(err_context)?.set_geom(flexible_pane_geom); + panes + .get_mut(flexible_pane_id) + .with_context(err_context)? + .set_geom(flexible_pane_geom); for (i, (pid, _position)) in all_stacked_pane_positions.iter().enumerate() { if i > 0 { let pane = panes.get_mut(pid).with_context(err_context)?; let mut pane_position_and_size = pane.position_and_size(); - pane_position_and_size.y = y_of_whole_stack + height_of_flexible_pane.as_usize() + (i - 1); + pane_position_and_size.y = + y_of_whole_stack + height_of_flexible_pane.as_usize() + (i - 1); pane.set_geom(pane_position_and_size); } } diff --git a/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs b/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs index 6f650ce22..087bc2145 100644 --- a/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs +++ b/zellij-server/src/panes/tiled_panes/tiled_pane_grid.rs @@ -1,6 +1,6 @@ -use super::stacked_panes::StackedPanes; use super::is_inside_viewport; use super::pane_resizer::PaneResizer; +use super::stacked_panes::StackedPanes; use crate::tab::{MIN_TERMINAL_HEIGHT, MIN_TERMINAL_WIDTH}; use crate::{panes::PaneId, tab::Pane}; use std::cmp::Reverse; @@ -69,7 +69,8 @@ impl<'a> TiledPaneGrid<'a> { let err_context = || format!("failed to determine if pane {pane_id:?} is flexible in {direction:?}"); - let pane_geom = self.get_pane_geom(pane_id) + let pane_geom = self + .get_pane_geom(pane_id) .with_context(|| no_pane_id(pane_id)) .with_context(err_context)?; Ok(!match direction { @@ -460,8 +461,12 @@ impl<'a> TiledPaneGrid<'a> { // TODO: instead of unwrap_or(false) here we need to do the same with the fixed // panes error above, only make sure that we only error if we cannot resize in // any directions and have blocking fixed panes - if self.can_change_pane_size(pane_id, &main_strategy, change_by).unwrap_or(false) - && self.can_change_pane_size(pane_id, &sub_strategy, change_by).unwrap_or(false) + if self + .can_change_pane_size(pane_id, &main_strategy, change_by) + .