diff --git a/zellij-server/src/panes/grid.rs b/zellij-server/src/panes/grid.rs index a238f087..fc815afd 100644 --- a/zellij-server/src/panes/grid.rs +++ b/zellij-server/src/panes/grid.rs @@ -342,6 +342,7 @@ pub struct Grid { scrollback_buffer_lines: usize, pub mouse_mode: bool, pub search_results: SearchResult, + pub pending_clipboard_update: Option, } impl Debug for Grid { @@ -447,6 +448,7 @@ impl Grid { character_cell_size, search_results: Default::default(), sixel_grid, + pending_clipboard_update: None, } } pub fn render_full_viewport(&mut self) { @@ -1890,8 +1892,12 @@ impl Perform for Grid { b"?" => { // TBD: paste from own clipboard - currently unsupported }, - _base64 => { - // TBD: copy to own clipboard - currently unsupported + base64 => { + if let Ok(bytes) = base64::decode(base64) { + if let Ok(string) = String::from_utf8(bytes) { + self.pending_clipboard_update = Some(string); + } + }; }, } }, diff --git a/zellij-server/src/panes/terminal_pane.rs b/zellij-server/src/panes/terminal_pane.rs index 666260e6..6f34a864 100644 --- a/zellij-server/src/panes/terminal_pane.rs +++ b/zellij-server/src/panes/terminal_pane.rs @@ -484,6 +484,10 @@ impl Pane for TerminalPane { self.grid.pending_messages_to_pty.drain(..).collect() } + fn drain_clipboard_update(&mut self) -> Option { + self.grid.pending_clipboard_update.take() + } + fn start_selection(&mut self, start: &Position, _client_id: ClientId) { self.grid.start_selection(start); self.set_should_render(true); diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs index eb611a1e..44c2a480 100644 --- a/zellij-server/src/tab/mod.rs +++ b/zellij-server/src/tab/mod.rs @@ -258,6 +258,9 @@ pub trait Pane { // we should probably refactor away from this trait at some point vec![] } + fn drain_clipboard_update(&mut self) -> Option { + None + } fn render_full_viewport(&mut self) {} fn relative_position(&self, position_on_screen: &Position) -> Position { position_on_screen.relative_to(self.get_content_y(), self.get_content_x()) @@ -955,9 +958,13 @@ impl Tab { { terminal_output.handle_pty_bytes(bytes); let messages_to_pty = terminal_output.drain_messages_to_pty(); + let clipboard_update = terminal_output.drain_clipboard_update(); for message in messages_to_pty { self.write_to_pane_id(message, PaneId::Terminal(pid)); } + if let Some(string) = clipboard_update { + self.write_selection_to_clipboard(&string); + } } } pub fn write_to_terminals_on_current_tab(&mut self, input_bytes: Vec) {