add Input and Output traits to Engine

This commit is contained in:
🪞👃🪞 2024-09-15 15:57:24 +03:00
parent c2e91fb432
commit d9535b707f
2 changed files with 35 additions and 18 deletions

View file

@ -21,12 +21,12 @@ pub struct Tui {
}
impl Engine for Tui {
type Unit = u16;
type Size = [Self::Unit;2];
type Area = [Self::Unit;4];
type Input = Self;
type Handled = bool;
type Output = Self;
type Unit = u16;
type Size = [Self::Unit;2];
type Area = [Self::Unit;4];
type Input = Self;
type Handled = bool;
type Output = Self;
fn exited (&self) -> bool {
self.exited.fetch_and(true, Ordering::Relaxed)
}
@ -48,7 +48,19 @@ impl Engine for Tui {
disable_raw_mode().map_err(Into::into)
}
}
impl RenderTarget<Tui> for Tui {
impl Input<Tui> for Tui {
type Event = TuiEvent;
fn event (&self) -> TuiEvent {
self.event.read().unwrap().clone().unwrap()
}
fn is_done (&self) -> bool {
self.exited.fetch_and(true, Ordering::Relaxed)
}
fn done (&self) {
self.exited.store(true, Ordering::Relaxed);
}
}
impl Output<Tui> for Tui {
#[inline] fn area (&self) -> <Self as Engine>::Area {
self.area
}
@ -136,9 +148,6 @@ impl Tui {
std::thread::sleep(sleep);
})
}
pub fn event (&self) -> TuiEvent {
self.event.read().unwrap().clone().unwrap()
}
pub fn buffer (&mut self) -> &mut Buffer {
&mut self.buffers[self.buffer]
}