diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-11-11 15:19:31 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-11-11 15:19:31 -0500 |
commit | e7fa88dcd4b261af643a9aedfce0f0a1d9a97462 (patch) | |
tree | 60cc330de5c038c4f1534b142c600a6e0a87f624 /src/main.rs | |
parent | 7a411e269b59cb7754eadacaf29a18e02845040b (diff) | |
download | nbsh-e7fa88dcd4b261af643a9aedfce0f0a1d9a97462.tar.gz nbsh-e7fa88dcd4b261af643a9aedfce0f0a1d9a97462.zip |
handle dynamic terminal sizes
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index a0e4bd0..aa5fc35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![warn(clippy::pedantic)] #![warn(clippy::nursery)] #![allow(clippy::missing_const_for_fn)] +#![allow(clippy::too_many_lines)] #![allow(clippy::unused_self)] mod action; @@ -9,6 +10,8 @@ mod readline; mod state; mod util; +use async_std::stream::StreamExt as _; + async fn async_main() -> anyhow::Result<()> { let mut input = textmode::Input::new().await?; let mut output = textmode::Output::new().await?; @@ -27,6 +30,20 @@ async fn async_main() -> anyhow::Result<()> { { let state = async_std::sync::Arc::clone(&state); + let mut signals = signal_hook_async_std::Signals::new(&[ + signal_hook::consts::signal::SIGWINCH, + ])?; + async_std::task::spawn(async move { + while signals.next().await.is_some() { + state.lock_arc().await.resize().await; + } + }); + } + + state.lock_arc().await.resize().await; + + { + let state = async_std::sync::Arc::clone(&state); async_std::task::spawn(async move { let debouncer = crate::action::debounce(action_r); while let Some(action) = debouncer.recv().await { |