group tui_engine and tui_content; cargo update

This commit is contained in:
🪞👃🪞 2025-03-16 23:33:27 +02:00
parent 877b344765
commit 71dead5150
13 changed files with 150 additions and 72 deletions

36
input/src/input.rs Normal file
View file

@ -0,0 +1,36 @@
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)
}
}