From a850e3039ab8480846d8407b1c7fbb4439974f76 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 6 Jul 2019 17:55:19 -0400 Subject: make sure the ptys that we spawn commands in has a size --- src/process.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/process.rs b/src/process.rs index 6863b3e..4845bef 100644 --- a/src/process.rs +++ b/src/process.rs @@ -12,6 +12,9 @@ pub enum Error { #[snafu(display("failed to spawn process for `{}`: {}", cmd, source))] SpawnProcess { cmd: String, source: std::io::Error }, + #[snafu(display("failed to resize pty: {}", source))] + ResizePty { source: std::io::Error }, + #[snafu(display("failed to write to pty: {}", source))] WriteToPty { source: std::io::Error }, @@ -55,6 +58,23 @@ pub struct RunningProcess { _screen: crossterm::RawScreen, } +struct Resizer<'a, T> { + rows: u16, + cols: u16, + pty: &'a T, +} + +impl<'a, T: tokio_pty_process::PtyMaster> futures::future::Future + for Resizer<'a, T> +{ + type Item = (); + type Error = std::io::Error; + + fn poll(&mut self) -> futures::Poll { + self.pty.resize(self.rows, self.cols) + } +} + impl RunningProcess { fn new(cmd: &str, args: &[String]) -> Result { let pty = @@ -65,6 +85,15 @@ impl RunningProcess { .spawn_pty_async(&pty) .context(SpawnProcess { cmd })?; + let (cols, rows) = crossterm::terminal().terminal_size(); + Resizer { + rows: rows + 1, + cols: cols + 1, + pty: &pty, + } + .wait() + .context(ResizePty)?; + // TODO: tokio::io::stdin is broken (it's blocking) // let input = tokio::io::stdin(); let input = tokio::reactor::PollEvented2::new(EventedStdin); -- cgit v1.2.3-54-g00ecf