diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-03-07 22:04:01 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-03-07 22:04:01 -0500 |
commit | 5dd712dbda2007fe16d9addc2497f72593df7a47 (patch) | |
tree | 293e5c26d9cb8342bd9f4b6fa669971b879e686b | |
parent | 193e1963afc4e9e78122573cd5b9831f9a847345 (diff) | |
download | textmode-5dd712dbda2007fe16d9addc2497f72593df7a47.tar.gz textmode-5dd712dbda2007fe16d9addc2497f72593df7a47.zip |
also don't use the block_in_place stuff for output
-rw-r--r-- | src/input.rs | 6 | ||||
-rw-r--r-- | 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(); + } } } |