summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-11-10 13:14:44 -0500
committerJesse Luehrs <doy@tozt.net>2021-11-10 13:14:44 -0500
commit747da41fd3f192038c2e3194b4de041f7969f7a8 (patch)
tree5436c8b77a9bfcbefc90885513ea4ed0ec5b5d51 /src/main.rs
parent847f8834ae051c1c6177e9166cac855ccff113f0 (diff)
downloadnbsh-747da41fd3f192038c2e3194b4de041f7969f7a8.tar.gz
nbsh-747da41fd3f192038c2e3194b4de041f7969f7a8.zip
simplify
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs41
1 files changed, 38 insertions, 3 deletions
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() {