mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 11:46:42 +01:00
tabula rasa
This commit is contained in:
commit
47b3413d7d
76 changed files with 7000 additions and 0 deletions
144
tui/examples/demo.rs.old
Normal file
144
tui/examples/demo.rs.old
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
use tek::*;
|
||||
|
||||
fn main () -> Usually<()> {
|
||||
Tui::run(Arc::new(RwLock::new(Demo::new())))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct Demo<E: Engine> {
|
||||
index: usize,
|
||||
items: Vec<Box<dyn Render<Engine = E>>>
|
||||
}
|
||||
|
||||
impl Demo<Tui> {
|
||||
fn new () -> Self {
|
||||
Self {
|
||||
index: 0,
|
||||
items: vec![
|
||||
//Box::new(tek_sequencer::TransportPlayPauseButton {
|
||||
//_engine: Default::default(),
|
||||
//transport: None,
|
||||
//value: Some(TransportState::Stopped),
|
||||
//focused: true
|
||||
//}),
|
||||
//Box::new(tek_sequencer::TransportPlayPauseButton {
|
||||
//_engine: Default::default(),
|
||||
//transport: None,
|
||||
//value: Some(TransportState::Rolling),
|
||||
//focused: false
|
||||
//}),
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Content for Demo<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> dyn Render<Engine = Tui> {
|
||||
let border_style = Style::default().fg(Color::Rgb(0,0,0));
|
||||
Align::Center(Layers::new(move|add|{
|
||||
|
||||
add(&Background(Color::Rgb(0,128,128)))?;
|
||||
|
||||
add(&Margin::XY(1, 1, Stack::down(|add|{
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(128,96,0)))?;
|
||||
add(&Border(Square(border_style)))?;
|
||||
add(&Margin::XY(2, 1, "..."))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(128,64,0)))?;
|
||||
add(&Border(Lozenge(border_style)))?;
|
||||
add(&Margin::XY(4, 2, "---"))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(96,64,0)))?;
|
||||
add(&Border(SquareBold(border_style)))?;
|
||||
add(&Margin::XY(6, 3, "~~~"))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
Ok(())
|
||||
})).debug())?;
|
||||
|
||||
Ok(())
|
||||
|
||||
}))
|
||||
//Align::Center(Margin::X(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(128,0,0)))?;
|
||||
//add(&Stack::down(|add|{
|
||||
//add(&Margin::Y(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(0,128,0)))?;
|
||||
//add(&Align::Center("12345"))?;
|
||||
//add(&Align::Center("FOO"))
|
||||
//})))?;
|
||||
//add(&Margin::XY(1, 1, Layers::new(|add|{
|
||||
//add(&Align::Center("1234567"))?;
|
||||
//add(&Align::Center("BAR"))?;
|
||||
//add(&Background(Color::Rgb(0,0,128)))
|
||||
//})))
|
||||
//}))
|
||||
//})))
|
||||
|
||||
//Align::Y(Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(128,0,0)))?;
|
||||
//add(&Margin::X(1, Align::Center(Stack::down(|add|{
|
||||
//add(&Align::X(Margin::Y(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(0,128,0)))?;
|
||||
//add(&Align::Center("12345"))?;
|
||||
//add(&Align::Center("FOO"))
|
||||
//})))?;
|
||||
//add(&Margin::XY(1, 1, Layers::new(|add|{
|
||||
//add(&Align::Center("1234567"))?;
|
||||
//add(&Align::Center("BAR"))?;
|
||||
//add(&Background(Color::Rgb(0,0,128)))
|
||||
//})))?;
|
||||
//Ok(())
|
||||
//})))))
|
||||
//}))
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<TuiIn> for Demo<Tui> {
|
||||
fn handle (&mut self, from: &TuiIn) -> Perhaps<bool> {
|
||||
use KeyCode::{PageUp, PageDown};
|
||||
match from.event() {
|
||||
kexp!(PageUp) => {
|
||||
self.index = (self.index + 1) % self.items.len();
|
||||
},
|
||||
kexp!(PageDown) => {
|
||||
self.index = if self.index > 1 {
|
||||
self.index - 1
|
||||
} else {
|
||||
self.items.len() - 1
|
||||
};
|
||||
},
|
||||
_ => return Ok(None)
|
||||
}
|
||||
Ok(Some(true))
|
||||
}
|
||||
}
|
||||
|
||||
//lisp!(CONTENT Demo (LET
|
||||
//(BORDER-STYLE (STYLE (FG (RGB 0 0 0))))
|
||||
//(BG-COLOR-0 (RGB 0 128 128))
|
||||
//(BG-COLOR-1 (RGB 128 96 0))
|
||||
//(BG-COLOR-2 (RGB 128 64 0))
|
||||
//(BG-COLOR-3 (RGB 96 64 0))
|
||||
//(CENTER (LAYERS
|
||||
//(BACKGROUND BG-COLOR-0)
|
||||
//(OUTSET-XY 1 1 (SPLIT-DOWN
|
||||
//(LAYERS (BACKGROUND BG-COLOR-1)
|
||||
//(BORDER SQUARE BORDER-STYLE)
|
||||
//(OUTSET-XY 2 1 "..."))
|
||||
//(LAYERS (BACKGROUND BG-COLOR-2)
|
||||
//(BORDER LOZENGE BORDER-STYLE)
|
||||
//(OUTSET-XY 4 2 "---"))
|
||||
//(LAYERS (BACKGROUND BG-COLOR-3)
|
||||
//(BORDER SQUARE-BOLD BORDER-STYLE)
|
||||
//(OUTSET-XY 2 1 "~~~"))))))))
|
||||
1
tui/examples/edn01.edn
Normal file
1
tui/examples/edn01.edn
Normal file
|
|
@ -0,0 +1 @@
|
|||
:hello-world
|
||||
1
tui/examples/edn02.edn
Normal file
1
tui/examples/edn02.edn
Normal file
|
|
@ -0,0 +1 @@
|
|||
(bsp/s :hello :world)
|
||||
1
tui/examples/edn03.edn
Normal file
1
tui/examples/edn03.edn
Normal file
|
|
@ -0,0 +1 @@
|
|||
(fill/xy :hello-world)
|
||||
1
tui/examples/edn04.edn
Normal file
1
tui/examples/edn04.edn
Normal file
|
|
@ -0,0 +1 @@
|
|||
(fixed/xy 20 10 :hello-world)
|
||||
1
tui/examples/edn05.edn
Normal file
1
tui/examples/edn05.edn
Normal file
|
|
@ -0,0 +1 @@
|
|||
(bsp/s (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))
|
||||
1
tui/examples/edn06.edn
Normal file
1
tui/examples/edn06.edn
Normal file
|
|
@ -0,0 +1 @@
|
|||
(bsp/e (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))
|
||||
1
tui/examples/edn07.edn
Normal file
1
tui/examples/edn07.edn
Normal file
|
|
@ -0,0 +1 @@
|
|||
(bsp/n (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))
|
||||
1
tui/examples/edn08.edn
Normal file
1
tui/examples/edn08.edn
Normal file
|
|
@ -0,0 +1 @@
|
|||
(bsp/w (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))
|
||||
1
tui/examples/edn09.edn
Normal file
1
tui/examples/edn09.edn
Normal file
|
|
@ -0,0 +1 @@
|
|||
(bsp/a (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))
|
||||
1
tui/examples/edn10.edn
Normal file
1
tui/examples/edn10.edn
Normal file
|
|
@ -0,0 +1 @@
|
|||
(bsp/b (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))
|
||||
11
tui/examples/edn11.edn
Normal file
11
tui/examples/edn11.edn
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(bsp/s
|
||||
(bsp/e (align/nw (fixed/xy 5 3 :hello))
|
||||
(bsp/e (align/n (fixed/xy 5 3 :hello))
|
||||
(align/ne (fixed/xy 5 3 :hello))))
|
||||
(bsp/s
|
||||
(bsp/e (align/w (fixed/xy 5 3 :hello))
|
||||
(bsp/e (align/c (fixed/xy 5 3 :hello))
|
||||
(align/e (fixed/xy 5 3 :hello))))
|
||||
(bsp/e (align/sw (fixed/xy 5 3 :hello))
|
||||
(bsp/e (align/s (fixed/xy 5 3 :hello))
|
||||
(align/se (fixed/xy 5 3 :hello))))))
|
||||
11
tui/examples/edn12.edn
Normal file
11
tui/examples/edn12.edn
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(bsp/s
|
||||
(bsp/e (fixed/xy 8 5 (align/nw :hello))
|
||||
(bsp/e (fixed/xy 8 5 (align/n :hello))
|
||||
(fixed/xy 8 5 (align/ne :hello))))
|
||||
(bsp/s
|
||||
(bsp/e (fixed/xy 8 5 (align/w :hello))
|
||||
(bsp/e (fixed/xy 8 5 (align/c :hello))
|
||||
(fixed/xy 8 5 (align/e :hello))))
|
||||
(bsp/e (fixed/xy 8 5 (align/sw :hello))
|
||||
(bsp/e (fixed/xy 8 5 (align/s :hello))
|
||||
(fixed/xy 8 5 (align/se :hello))))))
|
||||
11
tui/examples/edn13.edn
Normal file
11
tui/examples/edn13.edn
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(bsp/s
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/nw :hello)))
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/n :hello)))
|
||||
(grow/xy 1 1 (fixed/xy 8 5 (align/ne :hello)))))
|
||||
(bsp/s
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/w :hello)))
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/c :hello)))
|
||||
(grow/xy 1 1 (fixed/xy 8 5 (align/e :hello)))))
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/sw :hello)))
|
||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/s :hello)))
|
||||
(grow/xy 1 1 (fixed/xy 8 5 (align/se :hello)))))))
|
||||
73
tui/examples/edn99.edn
Normal file
73
tui/examples/edn99.edn
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
(align/c (bg/behind :bg0 (margin/xy 1 1 (col
|
||||
(bg/behind :bg1 (border/around :border1 (margin/xy 2 1 :label1)))
|
||||
(bg/behind :bg2 (border/around :border2 (margin/xy 4 2 :label2)))
|
||||
(bg/behind :bg3 (border/around :border3 (margin/xy 6 3 :label3)))))))
|
||||
|
||||
fn content (&self) -> dyn Render<Engine = Tui> {
|
||||
let border_style = Style::default().fg(Color::Rgb(0,0,0));
|
||||
Align::Center(Layers::new(move|add|{
|
||||
|
||||
add(&Background(Color::Rgb(0,128,128)))?;
|
||||
|
||||
add(&Margin::XY(1, 1, Stack::down(|add|{
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(128,96,0)))?;
|
||||
add(&Border(Square(border_style)))?;
|
||||
add(&Margin::XY(2, 1, "..."))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(128,64,0)))?;
|
||||
add(&Border(Lozenge(border_style)))?;
|
||||
add(&Margin::XY(4, 2, "---"))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
add(&Layers::new(|add|{
|
||||
add(&Background(Color::Rgb(96,64,0)))?;
|
||||
add(&Border(SquareBold(border_style)))?;
|
||||
add(&Margin::XY(6, 3, "~~~"))?;
|
||||
Ok(())
|
||||
}).debug())?;
|
||||
|
||||
Ok(())
|
||||
})).debug())?;
|
||||
|
||||
Ok(())
|
||||
|
||||
}))
|
||||
//Align::Center(Margin::X(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(128,0,0)))?;
|
||||
//add(&Stack::down(|add|{
|
||||
//add(&Margin::Y(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(0,128,0)))?;
|
||||
//add(&Align::Center("12345"))?;
|
||||
//add(&Align::Center("FOO"))
|
||||
//})))?;
|
||||
//add(&Margin::XY(1, 1, Layers::new(|add|{
|
||||
//add(&Align::Center("1234567"))?;
|
||||
//add(&Align::Center("BAR"))?;
|
||||
//add(&Background(Color::Rgb(0,0,128)))
|
||||
//})))
|
||||
//}))
|
||||
//})))
|
||||
|
||||
//Align::Y(Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(128,0,0)))?;
|
||||
//add(&Margin::X(1, Align::Center(Stack::down(|add|{
|
||||
//add(&Align::X(Margin::Y(1, Layers::new(|add|{
|
||||
//add(&Background(Color::Rgb(0,128,0)))?;
|
||||
//add(&Align::Center("12345"))?;
|
||||
//add(&Align::Center("FOO"))
|
||||
//})))?;
|
||||
//add(&Margin::XY(1, 1, Layers::new(|add|{
|
||||
//add(&Align::Center("1234567"))?;
|
||||
//add(&Align::Center("BAR"))?;
|
||||
//add(&Background(Color::Rgb(0,0,128)))
|
||||
//})))?;
|
||||
//Ok(())
|
||||
//})))))
|
||||
//}))
|
||||
}
|
||||
66
tui/examples/tui.rs
Normal file
66
tui/examples/tui.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
use tek_tui::{*, tek_input::*, tek_output::*};
|
||||
use tek_edn::*;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use crossterm::event::{*, KeyCode::*};
|
||||
use crate::ratatui::style::Color;
|
||||
fn main () -> Usually<()> {
|
||||
let state = Arc::new(RwLock::new(Example(10, Measure::new())));
|
||||
Tui::new().unwrap().run(&state)?;
|
||||
Ok(())
|
||||
}
|
||||
#[derive(Debug)] pub struct Example(usize, Measure<TuiOut>);
|
||||
const KEYMAP: &str = "(:left prev) (:right next)";
|
||||
handle!(TuiIn: |self: Example, input|{
|
||||
let keymap = SourceIter::new(KEYMAP);
|
||||
let command = keymap.command::<_, ExampleCommand, _>(self, input);
|
||||
if let Some(command) = command {
|
||||
command.execute(self)?;
|
||||
return Ok(Some(true))
|
||||
}
|
||||
return Ok(None)
|
||||
});
|
||||
enum ExampleCommand { Next, Previous }
|
||||
atom_command!(ExampleCommand: |app: Example| {
|
||||
(":prev" [] Some(Self::Previous))
|
||||
(":next" [] Some(Self::Next))
|
||||
});
|
||||
command!(|self: ExampleCommand, state: Example|match self {
|
||||
Self::Next =>
|
||||
{ state.0 = (state.0 + 1) % EXAMPLES.len(); None },
|
||||
Self::Previous =>
|
||||
{ state.0 = if state.0 > 0 { state.0 - 1 } else { EXAMPLES.len() - 1 }; None },
|
||||
});
|
||||
const EXAMPLES: &'static [&'static str] = &[
|
||||
include_str!("edn01.edn"),
|
||||
include_str!("edn02.edn"),
|
||||
include_str!("edn03.edn"),
|
||||
include_str!("edn04.edn"),
|
||||
include_str!("edn05.edn"),
|
||||
include_str!("edn06.edn"),
|
||||
include_str!("edn07.edn"),
|
||||
include_str!("edn08.edn"),
|
||||
include_str!("edn09.edn"),
|
||||
include_str!("edn10.edn"),
|
||||
include_str!("edn11.edn"),
|
||||
include_str!("edn12.edn"),
|
||||
include_str!("edn13.edn"),
|
||||
];
|
||||
view!(TuiOut: |self: Example|{
|
||||
let index = self.0 + 1;
|
||||
let wh = self.1.wh();
|
||||
let src = EXAMPLES[self.0];
|
||||
let heading = format!("Example {}/{} in {:?}", index, EXAMPLES.len(), &wh);
|
||||
let title = Tui::bg(Color::Rgb(60, 10, 10), Push::y(1, Align::n(heading)));
|
||||
let code = Tui::bg(Color::Rgb(10, 60, 10), Push::y(2, Align::n(format!("{}", src))));
|
||||
let content = Tui::bg(Color::Rgb(10, 10, 60), View(self, SourceIter::new(src)));
|
||||
self.1.of(Bsp::s(title, Bsp::n(""/*code*/, content)))
|
||||
}; {
|
||||
":title" => Tui::bg(Color::Rgb(60, 10, 10), Push::y(1, Align::n(format!("Example {}/{}:", self.0 + 1, EXAMPLES.len())))).boxed(),
|
||||
":code" => Tui::bg(Color::Rgb(10, 60, 10), Push::y(2, Align::n(format!("{}", EXAMPLES[self.0])))).boxed(),
|
||||
":hello" => Tui::bg(Color::Rgb(10, 100, 10), "Hello").boxed(),
|
||||
":world" => Tui::bg(Color::Rgb(100, 10, 10), "world").boxed(),
|
||||
":hello-world" => "Hello world!".boxed()
|
||||
});
|
||||
provide_bool!(bool: |self: Example| {});
|
||||
provide_num!(u16: |self: Example| {});
|
||||
provide_num!(usize: |self: Example| {});
|
||||
Loading…
Add table
Add a link
Reference in a new issue