mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
unify edn_view entrypoint
This commit is contained in:
parent
df50bb9f47
commit
9cd6e9f195
16 changed files with 603 additions and 541 deletions
|
|
@ -1,7 +1,8 @@
|
|||
use tek::*;
|
||||
use tek_tui::{*, tek_input::*, tek_output::*};
|
||||
use tek_edn::*;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use crossterm::event::{*, KeyCode::*};
|
||||
use crate::ratatui::style::Color;
|
||||
|
||||
const EDN: &'static [&'static str] = &[
|
||||
include_str!("edn01.edn"),
|
||||
|
|
@ -25,26 +26,15 @@ fn main () -> Usually<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub struct Example(usize, Measure<TuiOut>);
|
||||
#[derive(Debug)] pub struct Example(usize, Measure<TuiOut>);
|
||||
|
||||
impl EdnViewData<TuiOut> for &Example {
|
||||
fn get_content <'a> (&'a self, item: EdnItem<&'a str>) -> RenderBox<'a, TuiOut> {
|
||||
use EdnItem::*;
|
||||
match item {
|
||||
Nil => Box::new(()),
|
||||
Exp(items) => Box::new(EdnView::from_items(*self, items.as_slice())),
|
||||
//Sym(name) => self.get_sym(name), TODO
|
||||
Sym(":title") => Tui::bg(Color::Rgb(60,10,10), Push::y(1,
|
||||
Align::n(format!("Example {}/{}:", self.0 + 1, EDN.len())))).boxed(),
|
||||
Sym(":code") => Tui::bg(Color::Rgb(10,60,10), Push::y(2,
|
||||
Align::n(format!("{}", EDN[self.0])))).boxed(),
|
||||
Sym(":hello-world") => "Hello world!".boxed(),
|
||||
Sym(":hello") => Tui::bg(Color::Rgb(10, 100, 10), "Hello").boxed(),
|
||||
Sym(":world") => Tui::bg(Color::Rgb(100, 10, 10), "world").boxed(),
|
||||
_ => panic!("no content for {item:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
edn_provide_content!(|self: Example|{
|
||||
":title" => Tui::bg(Color::Rgb(60,10,10), Push::y(1, Align::n(format!("Example {}/{}:", self.0 + 1, EDN.len())))).boxed(),
|
||||
":code" => Tui::bg(Color::Rgb(10,60,10), Push::y(2, Align::n(format!("{}", EDN[self.0])))).boxed(),
|
||||
":hello-world" => "Hello world!".boxed(),
|
||||
":hello" => Tui::bg(Color::Rgb(10, 100, 10), "Hello").boxed(),
|
||||
":world" => Tui::bg(Color::Rgb(100, 10, 10), "world").boxed(),
|
||||
});
|
||||
|
||||
impl Content<TuiOut> for Example {
|
||||
fn content (&self) -> impl Render<TuiOut> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue