diff options
author | Dan Näsman <30578250+dannasman@users.noreply.github.com> | 2022-10-19 16:49:13 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-19 22:49:13 +0900 |
commit | 2e70a4c67216150671bfeb2e1369e97c6a59e61f (patch) | |
tree | 6fc3f92247dfeda9f33114a095553f2f6cdf3b00 /zellij-server | |
parent | 5878e9f6f87534811564c571f299570c99a56ef5 (diff) |
allow dump_screen() to only dump the viewport (#1794)
* allow dump_screen() to only dump the viewport
* add additional implementations
* set full default as false
Diffstat (limited to 'zellij-server')
-rw-r--r-- | zellij-server/src/panes/grid.rs | 7 | ||||
-rw-r--r-- | zellij-server/src/panes/terminal_pane.rs | 4 | ||||
-rw-r--r-- | zellij-server/src/route.rs | 4 | ||||
-rw-r--r-- | zellij-server/src/screen.rs | 11 | ||||
-rw-r--r-- | zellij-server/src/tab/mod.rs | 17 | ||||
-rw-r--r-- | zellij-server/src/tab/unit/tab_integration_tests.rs | 2 | ||||
-rw-r--r-- | zellij-server/src/unit/screen_tests.rs | 1 |
7 files changed, 31 insertions, 15 deletions
diff --git a/zellij-server/src/panes/grid.rs b/zellij-server/src/panes/grid.rs index 12849f813..5ff02c145 100644 --- a/zellij-server/src/panes/grid.rs +++ b/zellij-server/src/panes/grid.rs @@ -985,9 +985,12 @@ impl Grid { } } - pub fn dump_screen(&mut self) -> String { - let mut scrollback: String = dump_screen!(self.lines_above); + pub fn dump_screen(&mut self, full: bool) -> String { let viewport: String = dump_screen!(self.viewport); + if !full { + return viewport; + } + let mut scrollback: String = dump_screen!(self.lines_above); if !scrollback.is_empty() { scrollback.push('\n'); } diff --git a/zellij-server/src/panes/terminal_pane.rs b/zellij-server/src/panes/terminal_pane.rs index 3285348ae..766cfaa2b 100644 --- a/zellij-server/src/panes/terminal_pane.rs +++ b/zellij-server/src/panes/terminal_pane.rs @@ -512,8 +512,8 @@ impl Pane for TerminalPane { self.geom.y -= count; self.reflow_lines(); } - fn dump_screen(&mut self, _client_id: ClientId) -> String { - self.grid.dump_screen() + fn dump_screen(&mut self, _client_id: ClientId, full: bool) -> String { + self.grid.dump_screen(full) } fn scroll_up(&mut self, count: usize, _client_id: ClientId) { self.grid.move_viewport_up(count); diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index 1fae23186..d51694992 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -157,10 +157,10 @@ pub(crate) fn route_action( }; session.senders.send_to_screen(screen_instr).unwrap(); }, - Action::DumpScreen(val) => { + Action::DumpScreen(val, full) => { session .senders - .send_to_screen(ScreenInstruction::DumpScreen(val, client_id)) + .send_to_screen(ScreenInstruction::DumpScreen(val, client_id, full)) .unwrap(); }, Action::EditScrollback => { diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 3ab1521a4..804bdf91f 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -147,7 +147,7 @@ pub enum ScreenInstruction { MovePaneRight(ClientId), MovePaneLeft(ClientId), Exit, - DumpScreen(String, ClientId), + DumpScreen(String, ClientId, bool), EditScrollback(ClientId), ScrollUp(ClientId), ScrollUpAt(Position, ClientId), @@ -1437,12 +1437,15 @@ pub(crate) fn screen_thread_main( screen.render()?; screen.unblock_input()?; }, - ScreenInstruction::DumpScreen(file, client_id) => { + ScreenInstruction::DumpScreen(file, client_id, full) => { active_tab_and_connected_client_id!( screen, client_id, - |tab: &mut Tab, client_id: ClientId| tab - .dump_active_terminal_screen(Some(file.to_string()), client_id) + |tab: &mut Tab, client_id: ClientId| tab.dump_active_terminal_screen( + Some(file.to_string()), + client_id, + full + ) ); screen.render()?; screen.unblock_input()?; diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs index e8809b8ee..da2fcda60 100644 --- a/zellij-server/src/tab/mod.rs +++ b/zellij-server/src/tab/mod.rs @@ -165,7 +165,7 @@ pub trait Pane { fn push_right(&mut self, count: usize); fn pull_left(&mut self, count: usize); fn pull_up(&mut self, count: usize); - fn dump_screen(&mut self, _client_id: ClientId) -> String { + fn dump_screen(&mut self, _client_id: ClientId, _full: bool) -> String { "".to_owned() } fn scroll_up(&mut self, count: usize, client_id: ClientId); @@ -1800,16 +1800,25 @@ impl Tab { } Ok(()) } - pub fn dump_active_terminal_screen(&mut self, file: Option<String>, client_id: ClientId) { + pub fn dump_active_terminal_screen( + &mut self, + file: Option<String>, + client_id: ClientId, + full: bool, + ) { if let Some(active_pane) = self.get_active_pane_or_floating_pane_mut(client_id) { - let dump = active_pane.dump_screen(client_id); + let dump = active_pane.dump_screen(client_id, full); self.os_api.write_to_file(dump, file); } } pub fn edit_scrollback(&mut self, client_id: ClientId) -> Result<()> { let mut file = temp_dir(); file.push(format!("{}.dump", Uuid::new_v4())); - self.dump_active_terminal_screen(Some(String::from(file.to_string_lossy())), client_id); + self.dump_active_terminal_screen( + Some(String::from(file.to_string_lossy())), + client_id, + true, + ); let line_number = self .get_active_pane(client_id) .and_then(|a_t| a_t.get_line_number()); diff --git a/zellij-server/src/tab/unit/tab_integration_tests.rs b/zellij-server/src/tab/unit/tab_integration_tests.rs index 0d780d156..ab552cebc 100644 --- a/zellij-server/src/tab/unit/tab_integration_tests.rs +++ b/zellij-server/src/tab/unit/tab_integration_tests.rs @@ -507,7 +507,7 @@ fn dump_screen() { tab.handle_pty_bytes(2, Vec::from("scratch".as_bytes())) .unwrap(); let file = "/tmp/log.sh"; - tab.dump_active_terminal_screen(Some(file.to_string()), client_id); + tab.dump_active_terminal_screen(Some(file.to_string()), client_id, false); assert_eq!( map.lock().unwrap().get(file).unwrap(), "scratch", diff --git a/zellij-server/src/unit/screen_tests.rs b/zellij-server/src/unit/screen_tests.rs index c19f364ee..5bbb56b81 100644 --- a/zellij-server/src/unit/screen_tests.rs +++ b/zellij-server/src/unit/screen_tests.rs @@ -1190,6 +1190,7 @@ pub fn send_cli_dump_screen_action() { ); let cli_action = CliAction::DumpScreen { path: PathBuf::from("/tmp/foo"), + full: true, }; let _ = mock_screen.to_screen.send(ScreenInstruction::PtyBytes( 0, |