From 5dd712dbda2007fe16d9addc2497f72593df7a47 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 7 Mar 2022 22:04:01 -0500 Subject: also don't use the block_in_place stuff for output --- src/input.rs | 6 ++++-- src/output.rs | 23 ++++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/input.rs b/src/input.rs index 7f434f5..89061f7 100644 --- a/src/input.rs +++ b/src/input.rs @@ -79,8 +79,10 @@ impl Drop for RawGuard { // doesn't literally call `cleanup`, because calling spawn_blocking // while the tokio runtime is in the process of shutting down doesn't // work (spawn_blocking tasks are cancelled if the runtime starts - // shutting down before the task body starts running), but should be - // kept in sync with the actual things that `cleanup` does. + // shutting down before the task body starts running), and using + // block_in_place/block_on doesn't work on the current_thread runtime, + // but should be kept in sync with the actual things that `cleanup` + // does. if let Some(termios) = self.termios.take() { let stdin = std::io::stdin().as_raw_fd(); let _ = nix::sys::termios::tcsetattr( diff --git a/src/output.rs b/src/output.rs index 378b7d4..483de6b 100644 --- a/src/output.rs +++ b/src/output.rs @@ -38,13 +38,22 @@ impl Drop for ScreenGuard { /// of an async drop mechanism. If this could be a problem, you should /// call `cleanup` manually instead. fn drop(&mut self) { - tokio::task::block_in_place(move || { - tokio::runtime::Handle::current().block_on(async { - // https://github.com/rust-lang/rust-clippy/issues/8003 - #[allow(clippy::let_underscore_drop)] - let _ = self.cleanup().await; - }); - }); + // doesn't literally call `cleanup`, because calling spawn_blocking + // while the tokio runtime is in the process of shutting down doesn't + // work (spawn_blocking tasks are cancelled if the runtime starts + // shutting down before the task body starts running), and using + // block_in_place/block_on doesn't work on the current_thread runtime, + // but should be kept in sync with the actual things that `cleanup` + // does. + use std::io::Write as _; + + if !self.cleaned_up { + let mut stdout = std::io::stdout(); + #[allow(clippy::let_underscore_drop)] + let _ = stdout.write_all(crate::DEINIT); + #[allow(clippy::let_underscore_drop)] + let _ = stdout.flush(); + } } } -- cgit v1.2.3