input: add InputMap; dsl/output/tui: Atom->Dsl
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-04-28 04:49:00 +03:00
parent 47b7f7e7f9
commit 35ad371205
15 changed files with 374 additions and 277 deletions

View file

@ -1,36 +0,0 @@
use crate::*;
use std::time::Duration;
use std::thread::JoinHandle;
/// Event source
pub trait Input: Send + Sync + Sized {
/// Type of input event
type Event;
/// Result of handling input
type Handled; // TODO: make this an Option<Box dyn Command<Self>> containing the undo
/// Currently handled event
fn event (&self) -> &Self::Event;
/// Whether component should exit
fn is_done (&self) -> bool;
/// Mark component as done
fn done (&self);
}
/// Input thread entrypoint.
pub trait InputRun<T> {
fn run_input (engine: T, state: Self, timer: Duration) -> JoinHandle<()>;
}
/// Handle input through a mutable reference.
pub trait Handle<E: Input>: Send + Sync {
fn handle (&mut self, _input: &E) -> Perhaps<E::Handled> {
Ok(None)
}
}
/// Handle input through an immutable reference (e.g. [Arc<RwLock>] or [Arc<Mutex>])
pub trait HandleRef<E: Input>: Send + Sync {
fn handle (&self, _input: &E) -> Perhaps<E::Handled> {
Ok(None)
}
}