diff options
Diffstat (limited to 'src/pane.rs')
| -rw-r--r-- | src/pane.rs | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/pane.rs b/src/pane.rs index 48928034..c71665f5 100644 --- a/src/pane.rs +++ b/src/pane.rs @@ -1181,24 +1181,29 @@ impl PaneRuntimeIo { } } - fn send_bytes_after(&self, bytes: Bytes, delay: std::time::Duration) { + fn queue_user_input_submission( + &self, + text: Bytes, + enter: Bytes, + delay: std::time::Duration, + ) -> std::io::Result<std::sync::mpsc::Receiver<std::io::Result<()>>> { match self { - PaneRuntimeIo::Actor(actor) => { - let actor = actor.clone(); - tokio::spawn(async move { - tokio::time::sleep(delay).await; - if let Err(err) = actor.write_user_input(bytes).await { - warn!(error = %err, "failed to send delayed PTY input"); - } - }); - } + PaneRuntimeIo::Actor(actor) => actor.queue_user_input_submission(text, enter, delay), #[cfg(test)] PaneRuntimeIo::TestChannel { sender, .. } => { let sender = sender.clone(); - tokio::spawn(async move { - tokio::time::sleep(delay).await; - let _ = sender.send(bytes).await; + let (reply_tx, reply_rx) = std::sync::mpsc::channel(); + std::thread::spawn(move || { + let result = sender + .try_send(text) + .map_err(std::io::Error::other) + .and_then(|()| { + std::thread::sleep(delay); + sender.try_send(enter).map_err(std::io::Error::other) + }); + let _ = reply_tx.send(result); }); + Ok(reply_rx) } } } @@ -2856,8 +2861,13 @@ impl PaneRuntime { self.io.try_send_bytes(bytes) } - pub fn send_bytes_after(&self, bytes: Bytes, delay: std::time::Duration) { - self.io.send_bytes_after(bytes, delay); + pub fn queue_user_input_submission( + &self, + text: Bytes, + enter: Bytes, + delay: std::time::Duration, + ) -> std::io::Result<std::sync::mpsc::Receiver<std::io::Result<()>>> { + self.io.queue_user_input_submission(text, enter, delay) } pub fn try_send_paste(&self, text: String) -> Result<(), mpsc::error::TrySendError<Bytes>> { |
