mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +01:00
separate Input and Output impls
This commit is contained in:
parent
a6efde40f8
commit
0e821e098f
77 changed files with 465 additions and 454 deletions
|
|
@ -1,45 +0,0 @@
|
|||
use tek_tui::{*, tek_layout::{*, tek_engine::*}};
|
||||
use tek_edn::*;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use crossterm::event::{*, KeyCode::*};
|
||||
|
||||
const EDN: &'static [&'static str] = &[
|
||||
include_str!("edn01.edn"),
|
||||
include_str!("edn02.edn"),
|
||||
];
|
||||
|
||||
fn main () -> Usually<()> {
|
||||
let state = Arc::new(RwLock::new(Example(0)));
|
||||
Tui::new().unwrap().run(&state)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct Example(usize);
|
||||
|
||||
impl EdnViewData<Tui> for &Example {
|
||||
fn get_content <'a> (&'a self, sym: &'a str) -> RenderBox<'a, Tui> {
|
||||
Box::new(Thunk::new(move||match sym {
|
||||
":hello-world" => "Hello world!",
|
||||
":hello" => "Hello",
|
||||
":world" => "world",
|
||||
_ => ""
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl Content<Tui> for Example {
|
||||
fn content (&self) -> impl Render<Tui> {
|
||||
EdnView::new(self, EDN[self.0]).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<Tui> for Example {
|
||||
fn handle (&mut self, input: &TuiIn) -> Perhaps<bool> {
|
||||
match input.event() {
|
||||
kpat!(Right) => self.0 = (self.0 + 1) % EDN.len(),
|
||||
kpat!(Left) => self.0 = if self.0 > 0 { self.0 - 1 } else { EDN.len() - 1 },
|
||||
_ => return Ok(None)
|
||||
}
|
||||
Ok(Some(true))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue