From 747da41fd3f192038c2e3194b4de041f7969f7a8 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 10 Nov 2021 13:14:44 -0500 Subject: simplify --- src/main.rs | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 97624df..666b936 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,11 +4,46 @@ #![allow(clippy::unused_self)] mod history; -mod nbsh; -mod repl; +mod readline; +mod state; +mod util; async fn async_main() -> anyhow::Result<()> { - nbsh::run().await + let mut input = textmode::Input::new().await?; + let mut output = textmode::Output::new().await?; + + // avoid the guards getting stuck in a task that doesn't run to + // completion + let _input_guard = input.take_raw_guard(); + let _output_guard = output.take_screen_guard(); + + let (action_w, action_r) = async_std::channel::unbounded(); + + let state = util::mutex(state::State::new(action_w)); + + state.lock_arc().await.render(&mut output).await.unwrap(); + + { + let state = async_std::sync::Arc::clone(&state); + async_std::task::spawn(async move { + while let Ok(action) = action_r.recv().await { + state + .lock_arc() + .await + .handle_action(action, &mut output) + .await; + } + }); + } + + loop { + let key = input.read_key().await.unwrap(); + if state.lock_arc().await.handle_input(key).await { + break; + } + } + + Ok(()) } fn main() { -- cgit v1.2.3-54-g00ecf