mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
wip: big flat pt.2: extract engine crate
This commit is contained in:
parent
4a3de618d0
commit
a5628fb663
31 changed files with 1738 additions and 888 deletions
62
engine/src/lib.rs
Normal file
62
engine/src/lib.rs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
mod component; pub use self::component::*;
|
||||
mod engine; pub use self::engine::*;
|
||||
mod input; pub use self::input::*;
|
||||
mod output; pub use self::output::*;
|
||||
mod tui; pub use self::tui::*;
|
||||
|
||||
pub use std::error::Error;
|
||||
|
||||
/// Standard result type.
|
||||
pub type Usually<T> = Result<T, Box<dyn Error>>;
|
||||
|
||||
/// Standard optional result type.
|
||||
pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
|
||||
|
||||
#[cfg(test)] #[test] fn test_stub_engine () -> Usually<()> {
|
||||
struct TestEngine(bool);
|
||||
struct TestInput(bool);
|
||||
struct TestOutput([u16;4]);
|
||||
enum TestEvent { Test1 }
|
||||
impl Engine for TestEngine {
|
||||
type Input = TestInput;
|
||||
type Handled = ();
|
||||
type Output = TestOutput;
|
||||
type Unit = u16;
|
||||
type Size = [u16;2];
|
||||
type Area = [u16;4];
|
||||
fn exited (&self) -> bool {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
impl Input<TestEngine> for TestInput {
|
||||
type Event = TestEvent;
|
||||
fn event (&self) -> &Self::Event {
|
||||
&TestEvent::Test1
|
||||
}
|
||||
fn is_done (&self) -> bool {
|
||||
self.0
|
||||
}
|
||||
fn done (&self) {}
|
||||
}
|
||||
impl Output<TestEngine> for TestOutput {
|
||||
fn area (&self) -> [u16;4] {
|
||||
self.0
|
||||
}
|
||||
fn area_mut (&mut self) -> &mut [u16;4] {
|
||||
&mut self.0
|
||||
}
|
||||
fn render_in (&mut self, _: [u16;4], _: &dyn Render<TestEngine>) -> Usually<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl Render<TestEngine> for String {
|
||||
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
|
||||
Ok(Some([self.len() as u16, 1]))
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_tui_engine () -> Usually<()> {
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue