From 752a4df8b0501a3cdca89e6d0a9274683ee2deef Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee <107522312+lavafroth@users.noreply.github.com> Date: Thu, 20 Mar 2025 14:16:48 +0530 Subject: [PATCH] feat: respond to window resizes --- src/main.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index dc0bcbf..952d642 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,6 +41,8 @@ pub enum Error { Russh(#[from] russh::Error), #[error("failed to read authorization file")] Authfile(#[from] authfile::Error), + #[error("failed to resize frame as requested by client {id}")] + FrameResize { source: std::io::Error, id: usize }, } pub struct Client { @@ -48,7 +50,6 @@ pub struct Client { handle: Handle, terminal: SshTerminal, textarea: TextArea<'static>, - // entity: Arc, } struct TerminalHandle { @@ -334,7 +335,7 @@ impl Handler for AppServer { return Err(russh::Error::Disconnect.into()); } - // Alt+Return + // Alt-Return if data == [27, 13] { let text = { let mut clients = self.clients.lock().await; @@ -382,6 +383,7 @@ impl Handler for AppServer { Ok(()) } + /// The client requests a pseudo-terminal with the given specifications. async fn pty_request( &mut self, channel: ChannelId, @@ -411,6 +413,40 @@ impl Handler for AppServer { Ok(()) } + + /// The client's pseudo-terminal window size has changed. + async fn window_change_request( + &mut self, + _: ChannelId, + col_width: u32, + row_height: u32, + _: u32, + _: u32, + _: &mut Session, + ) -> Result<(), Self::Error> { + let rect = Rect { + x: 0, + y: 0, + width: col_width as u16, + height: row_height as u16, + }; + + { + let mut clients = self.clients.lock().await; + match clients.get_mut(&self.id).unwrap().terminal.resize(rect) { + Ok(_) => {} + Err(e) => { + return Err(Error::FrameResize { + source: e, + id: self.id, + }); + } + }; + } + self.render().await; + + Ok(()) + } } impl Drop for AppServer {