tui: update example

This commit is contained in:
🪞👃🪞 2025-09-08 17:48:56 +03:00
parent c5cdbf4f07
commit 8dfe20a58c
19 changed files with 160 additions and 155 deletions

View file

@ -1 +0,0 @@
:hello-world

View file

@ -1 +0,0 @@
(bsp/s :hello :world)

View file

@ -1 +0,0 @@
(fill/xy :hello-world)

View file

@ -1 +0,0 @@
(fixed/xy 20 10 :hello-world)

View file

@ -1 +0,0 @@
(bsp/s (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))

View file

@ -1 +0,0 @@
(bsp/e (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))

View file

@ -1 +0,0 @@
(bsp/n (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))

View file

@ -1 +0,0 @@
(bsp/w (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))

View file

@ -1 +0,0 @@
(bsp/a (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))

View file

@ -1 +0,0 @@
(bsp/b (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world))

View file

@ -1,11 +0,0 @@
(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))))))

View file

@ -1,11 +0,0 @@
(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))))))

View file

@ -1,11 +0,0 @@
(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)))))))

View file

@ -1 +0,0 @@
:map-e

View file

@ -1 +0,0 @@
(align/c :map-e)

View file

@ -1 +0,0 @@
:map-s

View file

@ -1 +0,0 @@
(align/c :map-s)

View file

@ -1,73 +0,0 @@
(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 Draw<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(())
//})))))
//}))
}

View file

@ -1,36 +1,102 @@
use tengri::{self, Usually, Perhaps, input::*, output::*, tui::*, dsl::*}; use tengri::{self, Usually, Perhaps, input::*, output::*, tui::*, dsl::*};
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
//use crossterm::event::{*, KeyCode::*};
use crate::ratatui::style::Color; use crate::ratatui::style::Color;
//use crossterm::event::{*, KeyCode::*};
fn main () -> Usually<()> { fn main () -> Usually<()> {
let state = Arc::new(RwLock::new(Example(10, Measure::new()))); let state = Example::new();
Tui::new().unwrap().run(&state)?; Tui::new().unwrap().run(&state)?;
Ok(()) Ok(())
} }
#[derive(Debug)] pub struct Example(usize, Measure<TuiOut>); #[derive(Debug)] pub struct Example(
usize,
Measure<TuiOut>
);
const KEYMAP: &str = "(@left prev) (@right next)"; impl Example {
const EXAMPLES: &'static [&'static str] = &[ fn new () -> Arc<RwLock<Self>> {
include_str!("edn/edn01.edn"), Arc::new(RwLock::new(Example(10, Measure::new())))
include_str!("edn/edn02.edn"), }
include_str!("edn/edn03.edn"), const BINDS: &'static str = stringify! {
include_str!("edn/edn04.edn"), (@left prev)
include_str!("edn/edn05.edn"), (@right next)
include_str!("edn/edn06.edn"), };
include_str!("edn/edn07.edn"), const VIEWS: &'static [&'static str] = &[
include_str!("edn/edn08.edn"), stringify! { :hello-world },
include_str!("edn/edn09.edn"), stringify! { (fill/xy :hello-world) },
include_str!("edn/edn10.edn"), stringify! { (bsp/s :hello :world) },
include_str!("edn/edn11.edn"), stringify! { (fixed/xy 20 10 :hello-world) },
include_str!("edn/edn12.edn"), stringify! { (bsp/s (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
//include_str!("edn/edn13.edn"), stringify! { (bsp/e (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
include_str!("edn/edn14.edn"), stringify! { (bsp/n (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
include_str!("edn/edn15.edn"), stringify! { (bsp/w (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
include_str!("edn/edn16.edn"), stringify! { (bsp/a (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
include_str!("edn/edn17.edn"), stringify! { (bsp/b (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)) },
]; stringify! {
(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))))))
},
stringify! {
(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))))))
},
stringify! {
(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)))))))
},
stringify! { :map-e },
stringify! { (align/c :map-e) },
stringify! { :map-s },
stringify! { (align/c :map-s) },
stringify! {
(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)))))))
},
];
}
tui_draw!(|self: Example, to|to.place(&self.content()));
content!(TuiOut: |self: Example|{
let index = self.0 + 1;
let wh = self.1.wh();
let src = EXAMPLES.get(self.0).unwrap_or(&"");
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, CstIter::new(src)));
self.1.of(Bsp::s(title, Bsp::n(""/*code*/, content)))
});
handle!(TuiIn: |self: Example, input|{ handle!(TuiIn: |self: Example, input|{
Ok(None)/*if let Some(command) = CstIter::new(KEYMAP).command::<_, ExampleCommand, _>(self, input) { Ok(None)/*if let Some(command) = CstIter::new(KEYMAP).command::<_, ExampleCommand, _>(self, input) {
@ -63,18 +129,6 @@ impl ExampleCommand {
} }
} }
tui_draw!(|self: Example, to|to.place(&self.content()));
content!(TuiOut: |self: Example|{
let index = self.0 + 1;
let wh = self.1.wh();
let src = EXAMPLES.get(self.0).unwrap_or(&"");
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, CstIter::new(src)));
self.1.of(Bsp::s(title, Bsp::n(""/*code*/, content)))
});
//#[tengri_proc::view(TuiOut)] //#[tengri_proc::view(TuiOut)]
//impl Example { //impl Example {
//pub fn title (&self) -> impl Draw<TuiOut> + use<'_> { //pub fn title (&self) -> impl Draw<TuiOut> + use<'_> {
@ -99,3 +153,74 @@ content!(TuiOut: |self: Example|{
//Map::south(5u16, ||0..5u16, |n, _i|format!("{n}")).boxed() //Map::south(5u16, ||0..5u16, |n, _i|format!("{n}")).boxed()
//} //}
//} //}
/*
fn content (&self) -> dyn Draw<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(())
//})))))
//}))
}
*/