From e7fa88dcd4b261af643a9aedfce0f0a1d9a97462 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 11 Nov 2021 15:19:31 -0500 Subject: handle dynamic terminal sizes --- src/main.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/main.rs') 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?; @@ -25,6 +28,20 @@ async fn async_main() -> anyhow::Result<()> { let state = util::mutex(state); + { + 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 { -- cgit v1.2.3-54-g00ecf