diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-07-06 17:55:19 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-07-06 17:55:19 -0400 |
commit | a850e3039ab8480846d8407b1c7fbb4439974f76 (patch) | |
tree | f8e1830b58c4d71f5a28701845b82a881676e31f | |
parent | fa2aef91c23ade9b1a4ef4bf7e00f3202d543854 (diff) | |
download | nbsh-old-a850e3039ab8480846d8407b1c7fbb4439974f76.tar.gz nbsh-old-a850e3039ab8480846d8407b1c7fbb4439974f76.zip |
make sure the ptys that we spawn commands in has a size
-rw-r--r-- | src/process.rs | 29 |
1 files changed, 29 insertions, 0 deletions
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::Item, Self::Error> { + self.pty.resize(self.rows, self.cols) + } +} + impl RunningProcess { fn new(cmd: &str, args: &[String]) -> Result<Self> { 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); |