diff options
| author | denis <denismaximov98@gmail.com> | 2021-04-22 11:45:29 +0300 |
|---|---|---|
| committer | denis <denismaximov98@gmail.com> | 2021-04-22 11:45:29 +0300 |
| commit | 8d98ca7da0bc278a832e4e7de23ff63a84deb529 (patch) | |
| tree | e7fdfaa6c1ae25e7737dbb36bd1dbcb94d62ab47 /src/client/tab.rs | |
| parent | wip: fixing the first arrow (diff) | |
| parent | fix(cargo): reduce crate size by 4.8MB using `cargo diet`, to 77kB (diff) | |
| download | sl0ppij-8d98ca7da0bc278a832e4e7de23ff63a84deb529.tar.gz sl0ppij-8d98ca7da0bc278a832e4e7de23ff63a84deb529.tar.xz sl0ppij-8d98ca7da0bc278a832e4e7de23ff63a84deb529.zip | |
wip: merge main in
Diffstat (limited to 'src/client/tab.rs')
| -rw-r--r-- | src/client/tab.rs | 171 |
1 files changed, 67 insertions, 104 deletions
diff --git a/src/client/tab.rs b/src/client/tab.rs index 35fc3915..656c6093 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -20,7 +20,10 @@ use std::{io::Write, sync::mpsc::channel}; use zellij_tile::data::{colors, Event, InputMode, ModeInfo, Palette}; const CURSOR_HEIGHT_WIDTH_RATIO: usize = 4; // this is not accurate and kind of a magic number, TODO: look into this -const MIN_TERMINAL_HEIGHT: usize = 2; + +// MIN_TERMINAL_HEIGHT here must be larger than the height of any of the status bars +// this is a dirty hack until we implement fixed panes +const MIN_TERMINAL_HEIGHT: usize = 3; const MIN_TERMINAL_WIDTH: usize = 4; type BorderAndPaneIds = (usize, Vec<PaneId>); @@ -67,7 +70,6 @@ pub struct Tab { pub send_pty_instructions: SenderWithContext<PtyInstruction>, pub send_plugin_instructions: SenderWithContext<PluginInstruction>, pub send_app_instructions: SenderWithContext<AppInstruction>, - expansion_boundary: Option<PositionAndSize>, should_clear_display_before_rendering: bool, pub mode_info: ModeInfo, pub input_mode: InputMode, @@ -208,6 +210,7 @@ pub trait Pane { impl Tab { // FIXME: Too many arguments here! Maybe bundle all of the senders for the whole program in a struct? + #[allow(clippy::too_many_arguments)] pub fn new( index: usize, position: usize, @@ -250,7 +253,6 @@ impl Tab { send_app_instructions, send_pty_instructions, send_plugin_instructions, - expansion_boundary: None, should_clear_display_before_rendering: false, mode_info, input_mode, @@ -293,9 +295,6 @@ impl Tab { let mut new_pids = new_pids.iter(); for (layout, position_and_size) in positions_and_size { // Just a regular terminal - if layout.expansion_boundary { - self.expansion_boundary = Some(*position_and_size); - } if let Some(plugin) = &layout.plugin { let (pid_tx, pid_rx) = channel(); self.send_plugin_instructions @@ -365,9 +364,7 @@ impl Tab { let (id_of_terminal_to_check, terminal_to_check) = id_and_terminal_to_check; let terminal_size = (terminal_to_check.rows() * CURSOR_HEIGHT_WIDTH_RATIO) * terminal_to_check.columns(); - let terminal_pos_and_size = terminal_to_check.position_and_size(); let terminal_can_be_split = terminal_to_check.columns() >= MIN_TERMINAL_WIDTH - && self.pos_and_size_is_within_expansion_boundary(terminal_pos_and_size) && terminal_to_check.rows() >= MIN_TERMINAL_HEIGHT && ((terminal_to_check.columns() > terminal_to_check.min_width() * 2) || (terminal_to_check.rows() > terminal_to_check.min_height() * 2)); @@ -627,19 +624,17 @@ impl Tab { let active_terminal = self.panes.get_mut(&active_pane_id).unwrap(); active_terminal.reset_size_and_position_override(); } else { - let expand_to = self.expansion_boundary.unwrap_or(self.full_screen_ws); let panes = self.get_panes(); - let pane_ids_to_hide = panes.filter_map(|(&id, pane)| { - let position_and_size_for_pane = pane.position_and_size(); - if id != active_pane_id - && self - .pos_and_size_is_within_expansion_boundary(position_and_size_for_pane) - { - Some(id) - } else { - None - } - }); + let pane_ids_to_hide = + panes.filter_map( + |(&id, _)| { + if id != active_pane_id { + Some(id) + } else { + None + } + }, + ); self.panes_to_hide = pane_ids_to_hide.collect(); if self.panes_to_hide.is_empty() { // nothing to do, pane is already as fullscreen as it can be, let's bail @@ -647,9 +642,9 @@ impl Tab { } else { let active_terminal = self.panes.get_mut(&active_pane_id).unwrap(); active_terminal.override_size_and_position( - expand_to.x, - expand_to.y, - &expand_to, + self.full_screen_ws.x, + self.full_screen_ws.y, + &self.full_screen_ws, ); } } @@ -1503,21 +1498,6 @@ impl Tab { self.increase_pane_width_left(&terminal_id, count); } } - fn pos_and_size_is_within_expansion_boundary(&self, pos_and_size: PositionAndSize) -> bool { - match self.expansion_boundary { - Some(expansion_boundary) => { - pos_and_size.x >= expansion_boundary.x - && pos_and_size.x < expansion_boundary.x + expansion_boundary.columns - && pos_and_size.y >= expansion_boundary.y - && pos_and_size.y < expansion_boundary.y + expansion_boundary.rows - && pos_and_size.x + pos_and_size.columns - <= expansion_boundary.x + expansion_boundary.columns - && pos_and_size.y + pos_and_size.rows - <= expansion_boundary.y + expansion_boundary.rows - } - None => true, // no expansion boundary, no problem - } - } fn can_increase_pane_and_surroundings_right( &self, pane_id: &PaneId, @@ -1533,17 +1513,11 @@ impl Tab { } let mut new_pos_and_size_for_pane = pane.position_and_size(); new_pos_and_size_for_pane.columns += increase_by; - if !self.pos_and_size_is_within_expansion_boundary(new_pos_and_size_for_pane) { - return false; - } if let Some(panes_to_the_right) = self.pane_ids_directly_right_of(&pane_id) { return panes_to_the_right.iter().all(|id| { let p = self.panes.get(id).unwrap(); - let position_and_size_for_pane = p.position_and_size(); - self.pos_and_size_is_within_expansion_boundary(position_and_size_for_pane) - && p.columns() > increase_by - && p.columns() - increase_by >= p.min_width() + p.columns() > increase_by && p.columns() - increase_by >= p.min_width() }); } else { false @@ -1564,17 +1538,11 @@ impl Tab { } let mut new_pos_and_size_for_pane = pane.position_and_size(); new_pos_and_size_for_pane.x = new_pos_and_size_for_pane.x.saturating_sub(increase_by); - if !self.pos_and_size_is_within_expansion_boundary(new_pos_and_size_for_pane) { - return false; - } if let Some(panes_to_the_left) = self.pane_ids_directly_left_of(&pane_id) { return panes_to_the_left.iter().all(|id| { let p = self.panes.get(id).unwrap(); - let position_and_size_for_pane = p.position_and_size(); - self.pos_and_size_is_within_expansion_boundary(position_and_size_for_pane) - && p.columns() > increase_by - && p.columns() - increase_by >= p.min_width() + p.columns() > increase_by && p.columns() - increase_by >= p.min_width() }); } else { false @@ -1595,17 +1563,11 @@ impl Tab { } let mut new_pos_and_size_for_pane = pane.position_and_size(); new_pos_and_size_for_pane.rows += increase_by; - if !self.pos_and_size_is_within_expansion_boundary(new_pos_and_size_for_pane) { - return false; - } if let Some(panes_below) = self.pane_ids_directly_below(&pane_id) { return panes_below.iter().all(|id| { let p = self.panes.get(id).unwrap(); - let position_and_size_for_pane = p.position_and_size(); - self.pos_and_size_is_within_expansion_boundary(position_and_size_for_pane) - && p.rows() > increase_by - && p.rows() - increase_by >= p.min_height() + p.rows() > increase_by && p.rows() - increase_by >= p.min_height() }); } else { false @@ -1622,17 +1584,11 @@ impl Tab { } let mut new_pos_and_size_for_pane = pane.position_and_size(); new_pos_and_size_for_pane.y = new_pos_and_size_for_pane.y.saturating_sub(increase_by); - if !self.pos_and_size_is_within_expansion_boundary(new_pos_and_size_for_pane) { - return false; - } if let Some(panes_above) = self.pane_ids_directly_above(&pane_id) { return panes_above.iter().all(|id| { let p = self.panes.get(id).unwrap(); - let position_and_size_for_pane = p.position_and_size(); - self.pos_and_size_is_within_expansion_boundary(position_and_size_for_pane) - && p.rows() > increase_by - && p.rows() - increase_by >= p.min_height() + p.rows() > increase_by && p.rows() - increase_by >= p.min_height() }); } else { false @@ -1649,11 +1605,9 @@ impl Tab { if let Some(panes_to_the_left) = self.pane_ids_directly_left_of(&pane_id) { return panes_to_the_left.iter().all(|id| { let p = self.panes.get(id).unwrap(); - let position_and_size_for_pane = p.position_and_size(); - self.pos_and_size_is_within_expansion_boundary(position_and_size_for_pane) - && p.max_width() - .map(|max_width| p.columns() + reduce_by <= max_width) - .unwrap_or(true) // no max width, increase to your heart's content + p.max_width() + .map(|max_width| p.columns() + reduce_by <= max_width) + .unwrap_or(true) // no max width, increase to your heart's content }); } else { false @@ -1670,11 +1624,9 @@ impl Tab { if let Some(panes_to_the_right) = self.pane_ids_directly_right_of(&pane_id) { return panes_to_the_right.iter().all(|id| { let p = self.panes.get(id).unwrap(); - let position_and_size_for_pane = p.position_and_size(); - self.pos_and_size_is_within_expansion_boundary(position_and_size_for_pane) - && p.max_width() - .map(|max_width| p.columns() + reduce_by <= max_width) - .unwrap_or(true) // no max width, increase to your heart's content + p.max_width() + .map(|max_width| p.columns() + reduce_by <= max_width) + .unwrap_or(true) // no max width, increase to your heart's content }); } else { false @@ -1691,11 +1643,9 @@ impl Tab { if let Some(panes_above) = self.pane_ids_directly_above(&pane_id) { return panes_above.iter().all(|id| { let p = self.panes.get(id).unwrap(); - let position_and_size_for_pane = p.position_and_size(); - self.pos_and_size_is_within_expansion_boundary(position_and_size_for_pane) - && p.max_height() - .map(|max_height| p.rows() + reduce_by <= max_height) - .unwrap_or(true) // no max height, increase to your heart's content + p.max_height() + .map(|max_height| p.rows() + reduce_by <= max_height) + .unwrap_or(true) // no max height, increase to your heart's content }); } else { false @@ -1712,11 +1662,9 @@ impl Tab { if let Some(panes_below) = self.pane_ids_directly_below(&pane_id) { return panes_below.iter().all(|id| { let p = self.panes.get(id).unwrap(); - let position_and_size_for_pane = p.position_and_size(); - self.pos_and_size_is_within_expansion_boundary(position_and_size_for_pane) - && p.max_height() - .map(|max_height| p.rows() + reduce_by <= max_height) - .unwrap_or(true) // no max height, increase to your heart's content + p.max_height() + .map(|max_height| p.rows() + reduce_by <= max_height) + .unwrap_or(true) // no max height, increase to your heart's content }); } else { false @@ -1724,27 +1672,18 @@ impl Tab { } pub fn resize_whole_tab(&mut self, new_screen_size: PositionAndSize) { if self.fullscreen_is_active { - // this is not ideal but until we get rid of expansion_boundary, it's a necessity + // this is not ideal, we can improve this self.toggle_active_pane_fullscreen(); } - match PaneResizer::new(&mut self.panes, &mut self.os_api) - .resize(self.full_screen_ws, new_screen_size) + if let Some((column_difference, row_difference)) = + PaneResizer::new(&mut self.panes, &mut self.os_api) + .resize(self.full_screen_ws, new_screen_size) { - Some((column_difference, row_difference)) => { - self.should_clear_display_before_rendering = true; - self.expansion_boundary.as_mut().map(|expansion_boundary| { - // TODO: this is not always accurate - expansion_boundary.columns = - (expansion_boundary.columns as isize + column_difference) as usize; - expansion_boundary.rows = - (expansion_boundary.rows as isize + row_difference) as usize; - }); - self.full_screen_ws.columns = - (self.full_screen_ws.columns as isize + column_difference) as usize; - self.full_screen_ws.rows = - (self.full_screen_ws.rows as isize + row_difference) as usize; - } - None => {} + self.should_clear_display_before_rendering = true; + self.full_screen_ws.columns = + (self.full_screen_ws.columns as isize + column_difference) as usize; + self.full_screen_ws.rows = + (self.full_screen_ws.rows as isize + row_difference) as usize; }; } pub fn resize_left(&mut self) { @@ -2242,6 +2181,30 @@ impl Tab { self.render(); } } + pub fn scroll_active_terminal_up_page(&mut self) { + if let Some(active_terminal_id) = self.get_active_terminal_id() { + let active_terminal = self + .panes + .get_mut(&PaneId::Terminal(active_terminal_id)) + .unwrap(); + // prevent overflow when row == 0 + let scroll_columns = active_terminal.rows().max(1) - 1; + active_terminal.scroll_up(scroll_columns); + self.render(); + } + } + pub fn scroll_active_terminal_down_page(&mut self) { + if let Some(active_terminal_id) = self.get_active_terminal_id() { + let active_terminal = self + .panes + .get_mut(&PaneId::Terminal(active_terminal_id)) + .unwrap(); + // prevent overflow when row == 0 + let scroll_columns = active_terminal.rows().max(1) - 1; + active_terminal.scroll_down(scroll_columns); + self.render(); + } + } pub fn clear_active_terminal_scroll(&mut self) { if let Some(active_terminal_id) = self.get_active_terminal_id() { let active_terminal = self |
