mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-08-07 14:16:56 +02:00
This commit is contained in:
parent
859b173a1e
commit
94c26f06cc
5 changed files with 347 additions and 250 deletions
8
Justfile
8
Justfile
|
|
@ -29,11 +29,9 @@ doc:
|
||||||
CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' RUSTDOCFLAGS='-Cinstrument-coverage' \
|
CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' RUSTDOCFLAGS='-Cinstrument-coverage' \
|
||||||
cargo doc
|
cargo doc
|
||||||
|
|
||||||
example-tui-00:
|
mode-00:
|
||||||
cargo run --example mode_00
|
cargo run --example mode_00
|
||||||
|
mode-01:
|
||||||
example-tui-01:
|
|
||||||
cargo run --example mode_01
|
cargo run --example mode_01
|
||||||
|
mode-02:
|
||||||
example-tui-02:
|
|
||||||
cargo run --example mode_02
|
cargo run --example mode_02
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,37 @@
|
||||||
//! Mode 0: Direct draw
|
//! Mode 00: Direct draw, direct control
|
||||||
use ::{std::sync::{Arc, RwLock}, ratatui::style::Color, tengri::*};
|
|
||||||
fn main () {}
|
use ::std::sync::{Arc, RwLock};
|
||||||
|
use ::crossterm::event::{Event::*, KeyEvent, KeyCode::*};
|
||||||
|
use ::ratatui::style::Color;
|
||||||
|
use ::tengri::{*, lang::*};
|
||||||
|
|
||||||
|
tui_app!(State {
|
||||||
|
/** User-controllable value. */
|
||||||
|
cursor: usize,
|
||||||
|
});
|
||||||
|
|
||||||
|
tui_view!(self: State {
|
||||||
|
thunk(|to: &mut Tui|{
|
||||||
|
let cursor = format!("Cursor: {}", self.cursor);
|
||||||
|
let _ = "DEMO [MODE 00]".align_sw().draw(to);
|
||||||
|
let _ = ShowSize.align_se().draw(to);
|
||||||
|
let _ = format!("Cursor: {}", self.cursor).align_c().draw(to);
|
||||||
|
Ok(Some(to.area()))
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
tui_keys!(self: State, input {
|
||||||
|
Ok(if let Key(KeyEvent { code, .. }) = input.0 {
|
||||||
|
match code {
|
||||||
|
Up | Right => {
|
||||||
|
self.cursor = (self.cursor + 1) % 10;
|
||||||
|
()
|
||||||
|
},
|
||||||
|
Down | Left => {
|
||||||
|
self.cursor = if self.cursor > 0 { self.cursor - 1 } else { 10 - 1 };
|
||||||
|
()
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,161 +1,63 @@
|
||||||
//! Mode 01
|
//! Mode 01: Direct view, actions with history
|
||||||
|
|
||||||
use ::std::sync::{Arc, RwLock};
|
use ::std::sync::{Arc, RwLock};
|
||||||
use ::crossterm::event::{Event::*, KeyEvent, KeyCode::*};
|
use ::crossterm::event::{Event::*, KeyEvent, KeyCode::*};
|
||||||
use ::ratatui::style::Color;
|
use ::ratatui::style::Color;
|
||||||
use ::tengri::{*, lang::*};
|
use ::tengri::{*, lang::*};
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
tui_app!(State {
|
tui_app!(State {
|
||||||
/** Command history (undo/redo). */
|
/** Command history (undo/redo). */
|
||||||
history: Vec<Action>,
|
history: Vec<Action>,
|
||||||
/** User-controllable value. */
|
/** User-controllable value. */
|
||||||
cursor: usize,
|
cursor: usize,
|
||||||
/** Rendered window size. */
|
|
||||||
size: Sizer,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tui_keys!(self: State, input {
|
tui_keys!(self: State, input {
|
||||||
Ok(if let Key(KeyEvent { code, .. }) = input.0 {
|
Ok(if let Key(KeyEvent { code, .. }) = input.0 {
|
||||||
match code {
|
match code {
|
||||||
Up | Right => { self.next()?.map(|x|self.history.push(x)); },
|
Down | Right => Action::Next,
|
||||||
Down | Left => { self.prev()?.map(|x|self.history.push(x)); },
|
Up | Left => Action::Prev,
|
||||||
_ => {}
|
_ => { return Ok(()) }
|
||||||
}
|
}
|
||||||
|
.apply(self)?
|
||||||
|
.map(|x|self.history.push(x));
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
tui_view!(self: State {
|
tui_view!(self: State {
|
||||||
let index = self.cursor + 1;
|
let title = "Demo Mode 00";
|
||||||
let wh = (self.size.w(), self.size.h());
|
let items = self.history.iter().take(10).map(|x|format!("{x:?}")).join("\n");
|
||||||
let src = VIEWS.get(self.cursor).unwrap_or(&"");
|
let history = format!("History: {}\n{items}", self.history.len());
|
||||||
let heading = format!("State {}/{} in {:?}", index, VIEWS.len(), &wh);
|
let cursor = format!("Cursor: {}", self.cursor);
|
||||||
let title = bg(Color::Rgb(60, 10, 10), heading.align_n().push_y(1));
|
north(
|
||||||
let code = bg(Color::Rgb(10, 60, 10), format!("{}", src).align_n().push_y(2));
|
east(title.align_sw(), ShowSize.align_se()),
|
||||||
let widget = thunk(move|to: &mut Tui|self.interpret(to, &src));
|
east(history.align_c(), cursor.align_c()),
|
||||||
self.size.of(south(title, north(code, widget)))
|
)
|
||||||
});
|
});
|
||||||
impl Interpret<Tui, Color> for State {
|
|
||||||
fn interpret_expr (&self, to: &mut Tui, expr: &impl Language) -> Usually<Color> {
|
#[derive(Debug)] enum Action {
|
||||||
let expr = expr.expr()?;
|
|
||||||
match expr.head()? {
|
|
||||||
Some("g") if let Some(tail) = expr.tail()? => {
|
|
||||||
Color::new_g(tail.head()?, try_to_u8)
|
|
||||||
},
|
|
||||||
Some("rgb") if let Some(tail) = expr.tail()? => {
|
|
||||||
Color::new_rgb(tail.head()?, try_to_u8)
|
|
||||||
},
|
|
||||||
_ => Err(format!("not a color").into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn try_to_u8 (src: Perhaps<&str>) -> Perhaps<u8> {
|
|
||||||
use std::str::FromStr;
|
|
||||||
if let Some(src) = src? {
|
|
||||||
Ok(Some(u8::from_str(src)?))
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Interpret<Tui, Option<XYWH<u16>>> for State {
|
|
||||||
fn interpret_word (&self, to: &mut Tui, sym: &impl Language) -> Perhaps<XYWH<u16>> {
|
|
||||||
match sym.src()? {
|
|
||||||
Some(":foo") => "foo".draw(to),
|
|
||||||
Some(":bar") => "bar".draw(to),
|
|
||||||
Some(":foobar") => "FOOBAR".draw(to),
|
|
||||||
_ => todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn interpret_expr (&self, to: &mut Tui, src: &impl Expression) -> Perhaps<XYWH<u16>> {
|
|
||||||
Ok(Some(if let Some(area) = eval_view(self, to, src)? {
|
|
||||||
area
|
|
||||||
} else if let Some(area) = eval_view_tui(self, to, src)? {
|
|
||||||
area
|
|
||||||
} else {
|
|
||||||
return Err(format!("App::interpret_expr: unexpected: {src:?}").into())
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl State {
|
|
||||||
fn next (&mut self) -> Perhaps<Action> {
|
|
||||||
self.cursor = (self.cursor + 1) % VIEWS.len();
|
|
||||||
Ok(Some(Action::Prev))
|
|
||||||
}
|
|
||||||
fn prev (&mut self) -> Perhaps<Action> {
|
|
||||||
self.cursor = if self.cursor > 0 { self.cursor - 1 } else { VIEWS.len() - 1 };
|
|
||||||
Ok(Some(Action::Next))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[derive(Debug)]
|
|
||||||
enum Action {
|
|
||||||
/** Increment cursor */ Next,
|
/** Increment cursor */ Next,
|
||||||
/** Decrement cursor */ Prev,
|
/** Decrement cursor */ Prev,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action {
|
impl Action {
|
||||||
fn eval (&self, state: &mut State) -> Perhaps<Self> {
|
fn apply (&self, state: &mut State) -> Perhaps<Self> {
|
||||||
use Action::*;
|
use Action::*;
|
||||||
match self { Next => state.next(), Prev => state.prev(), }
|
match self {
|
||||||
|
Next => state.next(),
|
||||||
|
Prev => state.prev(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl State {
|
||||||
|
fn next (&mut self) -> Perhaps<Action> {
|
||||||
|
self.cursor = (self.cursor + 1) % 10;
|
||||||
|
Ok(Some(Action::Prev))
|
||||||
|
}
|
||||||
|
fn prev (&mut self) -> Perhaps<Action> {
|
||||||
|
self.cursor = if self.cursor > 0 { self.cursor - 1 } else { 10 - 1 };
|
||||||
|
Ok(Some(Action::Next))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const VIEWS: &'static [&'static str] = &[
|
|
||||||
stringify! { :foobar },
|
|
||||||
stringify! { (bg (g 8) :foobar) },
|
|
||||||
stringify! { (fill/xy :foobar) },
|
|
||||||
stringify! { (bsp/s :foo :bar) },
|
|
||||||
stringify! { (fixed/xy 20 10 :foobar) },
|
|
||||||
stringify! { (bsp/s (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
|
||||||
stringify! { (bsp/e (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
|
||||||
stringify! { (bsp/n (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
|
||||||
stringify! { (bsp/w (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
|
||||||
stringify! { (bsp/a (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
|
||||||
stringify! { (bsp/b (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
|
||||||
stringify! {
|
|
||||||
(bsp/s
|
|
||||||
(bsp/e (align/nw (fixed/xy 5 3 :foo))
|
|
||||||
(bsp/e (align/n (fixed/xy 5 3 :foo))
|
|
||||||
(align/ne (fixed/xy 5 3 :foo))))
|
|
||||||
(bsp/s
|
|
||||||
(bsp/e (align/w (fixed/xy 5 3 :foo))
|
|
||||||
(bsp/e (align/c (fixed/xy 5 3 :foo))
|
|
||||||
(align/e (fixed/xy 5 3 :foo))))
|
|
||||||
(bsp/e (align/sw (fixed/xy 5 3 :foo))
|
|
||||||
(bsp/e (align/s (fixed/xy 5 3 :foo))
|
|
||||||
(align/se (fixed/xy 5 3 :foo))))))
|
|
||||||
},
|
|
||||||
stringify! {
|
|
||||||
(bsp/s
|
|
||||||
(bsp/e (fixed/xy 8 5 (align/nw :foo))
|
|
||||||
(bsp/e (fixed/xy 8 5 (align/n :foo))
|
|
||||||
(fixed/xy 8 5 (align/ne :foo))))
|
|
||||||
(bsp/s
|
|
||||||
(bsp/e (fixed/xy 8 5 (align/w :foo))
|
|
||||||
(bsp/e (fixed/xy 8 5 (align/c :foo))
|
|
||||||
(fixed/xy 8 5 (align/e :foo))))
|
|
||||||
(bsp/e (fixed/xy 8 5 (align/sw :foo))
|
|
||||||
(bsp/e (fixed/xy 8 5 (align/s :foo))
|
|
||||||
(fixed/xy 8 5 (align/se :foo))))))
|
|
||||||
},
|
|
||||||
stringify! {
|
|
||||||
(bsp/s
|
|
||||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/nw :foo)))
|
|
||||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/n :foo)))
|
|
||||||
(grow/xy 1 1 (fixed/xy 8 5 (align/ne :foo)))))
|
|
||||||
(bsp/s
|
|
||||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/w :foo)))
|
|
||||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/c :foo)))
|
|
||||||
(grow/xy 1 1 (fixed/xy 8 5 (align/e :foo)))))
|
|
||||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/sw :foo)))
|
|
||||||
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/s :foo)))
|
|
||||||
(grow/xy 1 1 (fixed/xy 8 5 (align/se :foo)))))))
|
|
||||||
},
|
|
||||||
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)))))))
|
|
||||||
},
|
|
||||||
];
|
|
||||||
//handle!(TuiIn: |self: State, input|Action::from(input).eval(self).map(|_|None));
|
|
||||||
//view!(State: Tui: [ evaluate_output_expression, evaluate_output_expression_tui ]);
|
|
||||||
//draw!(State: Tui: [ draw_example ]);
|
|
||||||
//impl_from!(Action: |input: &TuiIn| todo!());
|
|
||||||
//fn draw_example (state: &State, to: &mut Tui) {}
|
|
||||||
|
|
|
||||||
|
|
@ -1,107 +1,162 @@
|
||||||
//! Mode 02
|
//! Mode 02: Inline Dizzle config
|
||||||
use ::{std::sync::{Arc, RwLock}, ratatui::style::Color, tengri::*};
|
|
||||||
fn main () {}
|
|
||||||
|
|
||||||
//#[tengri_proc::expose]
|
use ::std::sync::{Arc, RwLock};
|
||||||
//impl Example {
|
use ::crossterm::event::{Event::*, KeyEvent, KeyCode::*};
|
||||||
//fn _todo_u16_stub (&self) -> u16 { todo!() }
|
use ::ratatui::style::Color;
|
||||||
//fn _todo_bool_stub (&self) -> bool { todo!() }
|
use ::tengri::{*, lang::*};
|
||||||
//fn _todo_usize_stub (&self) -> usize { todo!() }
|
tui_app!(State {
|
||||||
////[bool] => {}
|
/** Command history (undo/redo). */
|
||||||
////[u16] => {}
|
history: Vec<Action>,
|
||||||
////[usize] => {}
|
/** User-controllable value. */
|
||||||
//}
|
cursor: usize,
|
||||||
|
/** Rendered window size. */
|
||||||
//#[tengri_proc::view(TuiOut)]
|
size: Sizer,
|
||||||
//impl Example {
|
});
|
||||||
//pub fn title (&self) -> impl Content<TuiOut> + use<'_> {
|
tui_keys!(self: State, input {
|
||||||
//Tui::bg(Color::Rgb(60, 10, 10), Push::y(1, Align::n(format!("Example {}/{}:", self.0 + 1, VIEWS.len())))).boxed()
|
Ok(if let Key(KeyEvent { code, .. }) = input.0 {
|
||||||
//}
|
match code {
|
||||||
//pub fn code (&self) -> impl Content<TuiOut> + use<'_> {
|
Up | Right => { self.next()?.map(|x|self.history.push(x)); },
|
||||||
//Tui::bg(Color::Rgb(10, 60, 10), Push::y(2, Align::n(format!("{}", VIEWS[self.0])))).boxed()
|
Down | Left => { self.prev()?.map(|x|self.history.push(x)); },
|
||||||
//}
|
_ => {}
|
||||||
//pub fn hello (&self) -> impl Content<TuiOut> + use<'_> {
|
}
|
||||||
//Tui::bg(Color::Rgb(10, 100, 10), "Hello").boxed()
|
})
|
||||||
//}
|
});
|
||||||
//pub fn world (&self) -> impl Content<TuiOut> + use<'_> {
|
tui_view!(self: State {
|
||||||
//Tui::bg(Color::Rgb(100, 10, 10), "world").boxed()
|
let index = self.cursor + 1;
|
||||||
//}
|
let wh = (self.size.w(), self.size.h());
|
||||||
//pub fn hello_world (&self) -> impl Content<TuiOut> + use<'_> {
|
let src = VIEWS.get(self.cursor).unwrap_or(&"");
|
||||||
//"Hello world!".boxed()
|
let heading = format!("State {}/{} in {:?}", index, VIEWS.len(), &wh);
|
||||||
//}
|
let title = bg(Color::Rgb(60, 10, 10), heading.align_n().push_y(1));
|
||||||
//pub fn map_e (&self) -> impl Content<TuiOut> + use<'_> {
|
let code = bg(Color::Rgb(10, 60, 10), format!("{}", src).align_n().push_y(2));
|
||||||
//Map::east(5u16, ||0..5u16, |n, _i|format!("{n}")).boxed()
|
let widget = thunk(move|to: &mut Tui|self.interpret(to, &src));
|
||||||
//}
|
self.size.of(south(title, north(code, widget)))
|
||||||
//pub fn map_s (&self) -> impl Content<TuiOut> + use<'_> {
|
});
|
||||||
//Map::south(5u16, ||0..5u16, |n, _i|format!("{n}")).boxed()
|
impl Interpret<Tui, Color> for State {
|
||||||
//}
|
fn interpret_expr (&self, to: &mut Tui, expr: &impl Language) -> Usually<Color> {
|
||||||
//}
|
let expr = expr.expr()?;
|
||||||
|
match expr.head()? {
|
||||||
//fn content (&self) -> dyn Draw<Engine = Tui> {
|
Some("g") if let Some(tail) = expr.tail()? => {
|
||||||
//let border_style = Style::default().fg(Color::Rgb(0,0,0));
|
Color::new_g(tail.head()?, try_to_u8)
|
||||||
//Align::Center(Layers::new(move|add|{
|
},
|
||||||
|
Some("rgb") if let Some(tail) = expr.tail()? => {
|
||||||
//add(&Background(Color::Rgb(0,128,128)))?;
|
Color::new_rgb(tail.head()?, try_to_u8)
|
||||||
|
},
|
||||||
//add(&Margin::XY(1, 1, Stack::down(|add|{
|
_ => Err(format!("not a color").into())
|
||||||
|
}
|
||||||
//add(&Layers::new(|add|{
|
}
|
||||||
//add(&Background(Color::Rgb(128,96,0)))?;
|
}
|
||||||
//add(&Border(Square(border_style)))?;
|
fn try_to_u8 (src: Perhaps<&str>) -> Perhaps<u8> {
|
||||||
//add(&Margin::XY(2, 1, "..."))?;
|
use std::str::FromStr;
|
||||||
//Ok(())
|
if let Some(src) = src? {
|
||||||
//}).debug())?;
|
Ok(Some(u8::from_str(src)?))
|
||||||
|
} else {
|
||||||
//add(&Layers::new(|add|{
|
Ok(None)
|
||||||
//add(&Background(Color::Rgb(128,64,0)))?;
|
}
|
||||||
//add(&Border(Lozenge(border_style)))?;
|
}
|
||||||
//add(&Margin::XY(4, 2, "---"))?;
|
impl Interpret<Tui, Option<XYWH<u16>>> for State {
|
||||||
//Ok(())
|
fn interpret_word (&self, to: &mut Tui, sym: &impl Language) -> Perhaps<XYWH<u16>> {
|
||||||
//}).debug())?;
|
match sym.src()? {
|
||||||
|
Some(":foo") => "foo".draw(to),
|
||||||
//add(&Layers::new(|add|{
|
Some(":bar") => "bar".draw(to),
|
||||||
//add(&Background(Color::Rgb(96,64,0)))?;
|
Some(":foobar") => "FOOBAR".draw(to),
|
||||||
//add(&Border(SquareBold(border_style)))?;
|
_ => todo!()
|
||||||
//add(&Margin::XY(6, 3, "~~~"))?;
|
}
|
||||||
//Ok(())
|
}
|
||||||
//}).debug())?;
|
fn interpret_expr (&self, to: &mut Tui, src: &impl Expression) -> Perhaps<XYWH<u16>> {
|
||||||
|
Ok(Some(if let Some(area) = eval_view(self, to, src)? {
|
||||||
//Ok(())
|
area
|
||||||
//})).debug())?;
|
} else if let Some(area) = eval_view_tui(self, to, src)? {
|
||||||
|
area
|
||||||
//Ok(())
|
} else {
|
||||||
|
return Err(format!("App::interpret_expr: unexpected: {src:?}").into())
|
||||||
//}))
|
}))
|
||||||
////Align::Center(Margin::X(1, Layers::new(|add|{
|
}
|
||||||
////add(&Background(Color::Rgb(128,0,0)))?;
|
}
|
||||||
////add(&Stack::down(|add|{
|
impl State {
|
||||||
////add(&Margin::Y(1, Layers::new(|add|{
|
fn next (&mut self) -> Perhaps<Action> {
|
||||||
////add(&Background(Color::Rgb(0,128,0)))?;
|
self.cursor = (self.cursor + 1) % VIEWS.len();
|
||||||
////add(&Align::Center("12345"))?;
|
Ok(Some(Action::Prev))
|
||||||
////add(&Align::Center("FOO"))
|
}
|
||||||
////})))?;
|
fn prev (&mut self) -> Perhaps<Action> {
|
||||||
////add(&Margin::XY(1, 1, Layers::new(|add|{
|
self.cursor = if self.cursor > 0 { self.cursor - 1 } else { VIEWS.len() - 1 };
|
||||||
////add(&Align::Center("1234567"))?;
|
Ok(Some(Action::Next))
|
||||||
////add(&Align::Center("BAR"))?;
|
}
|
||||||
////add(&Background(Color::Rgb(0,0,128)))
|
}
|
||||||
////})))
|
#[derive(Debug)]
|
||||||
////}))
|
enum Action {
|
||||||
////})))
|
/** Increment cursor */ Next,
|
||||||
|
/** Decrement cursor */ Prev,
|
||||||
////Align::Y(Layers::new(|add|{
|
}
|
||||||
////add(&Background(Color::Rgb(128,0,0)))?;
|
impl Action {
|
||||||
////add(&Margin::X(1, Align::Center(Stack::down(|add|{
|
fn eval (&self, state: &mut State) -> Perhaps<Self> {
|
||||||
////add(&Align::X(Margin::Y(1, Layers::new(|add|{
|
use Action::*;
|
||||||
////add(&Background(Color::Rgb(0,128,0)))?;
|
match self { Next => state.next(), Prev => state.prev(), }
|
||||||
////add(&Align::Center("12345"))?;
|
}
|
||||||
////add(&Align::Center("FOO"))
|
}
|
||||||
////})))?;
|
const VIEWS: &'static [&'static str] = &[
|
||||||
////add(&Margin::XY(1, 1, Layers::new(|add|{
|
stringify! { :foobar },
|
||||||
////add(&Align::Center("1234567"))?;
|
stringify! { (bg (g 8) :foobar) },
|
||||||
////add(&Align::Center("BAR"))?;
|
stringify! { (fill/xy :foobar) },
|
||||||
////add(&Background(Color::Rgb(0,0,128)))
|
stringify! { (bsp/s :foo :bar) },
|
||||||
////})))?;
|
stringify! { (fixed/xy 20 10 :foobar) },
|
||||||
////Ok(())
|
stringify! { (bsp/s (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
||||||
////})))))
|
stringify! { (bsp/e (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
||||||
////}))
|
stringify! { (bsp/n (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
||||||
//}
|
stringify! { (bsp/w (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
||||||
|
stringify! { (bsp/a (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
||||||
|
stringify! { (bsp/b (fixed/xy 5 6 :foo) (fixed/xy 7 8 :bar)) },
|
||||||
|
stringify! {
|
||||||
|
(bsp/s
|
||||||
|
(bsp/e (align/nw (fixed/xy 5 3 :foo))
|
||||||
|
(bsp/e (align/n (fixed/xy 5 3 :foo))
|
||||||
|
(align/ne (fixed/xy 5 3 :foo))))
|
||||||
|
(bsp/s
|
||||||
|
(bsp/e (align/w (fixed/xy 5 3 :foo))
|
||||||
|
(bsp/e (align/c (fixed/xy 5 3 :foo))
|
||||||
|
(align/e (fixed/xy 5 3 :foo))))
|
||||||
|
(bsp/e (align/sw (fixed/xy 5 3 :foo))
|
||||||
|
(bsp/e (align/s (fixed/xy 5 3 :foo))
|
||||||
|
(align/se (fixed/xy 5 3 :foo))))))
|
||||||
|
},
|
||||||
|
stringify! {
|
||||||
|
(bsp/s
|
||||||
|
(bsp/e (fixed/xy 8 5 (align/nw :foo))
|
||||||
|
(bsp/e (fixed/xy 8 5 (align/n :foo))
|
||||||
|
(fixed/xy 8 5 (align/ne :foo))))
|
||||||
|
(bsp/s
|
||||||
|
(bsp/e (fixed/xy 8 5 (align/w :foo))
|
||||||
|
(bsp/e (fixed/xy 8 5 (align/c :foo))
|
||||||
|
(fixed/xy 8 5 (align/e :foo))))
|
||||||
|
(bsp/e (fixed/xy 8 5 (align/sw :foo))
|
||||||
|
(bsp/e (fixed/xy 8 5 (align/s :foo))
|
||||||
|
(fixed/xy 8 5 (align/se :foo))))))
|
||||||
|
},
|
||||||
|
stringify! {
|
||||||
|
(bsp/s
|
||||||
|
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/nw :foo)))
|
||||||
|
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/n :foo)))
|
||||||
|
(grow/xy 1 1 (fixed/xy 8 5 (align/ne :foo)))))
|
||||||
|
(bsp/s
|
||||||
|
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/w :foo)))
|
||||||
|
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/c :foo)))
|
||||||
|
(grow/xy 1 1 (fixed/xy 8 5 (align/e :foo)))))
|
||||||
|
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/sw :foo)))
|
||||||
|
(bsp/e (grow/xy 1 1 (fixed/xy 8 5 (align/s :foo)))
|
||||||
|
(grow/xy 1 1 (fixed/xy 8 5 (align/se :foo)))))))
|
||||||
|
},
|
||||||
|
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)))))))
|
||||||
|
},
|
||||||
|
];
|
||||||
|
//handle!(TuiIn: |self: State, input|Action::from(input).eval(self).map(|_|None));
|
||||||
|
//view!(State: Tui: [ evaluate_output_expression, evaluate_output_expression_tui ]);
|
||||||
|
//draw!(State: Tui: [ draw_example ]);
|
||||||
|
//impl_from!(Action: |input: &TuiIn| todo!());
|
||||||
|
//fn draw_example (state: &State, to: &mut Tui) {}
|
||||||
|
|
|
||||||
108
examples/mode_03.rs
Normal file
108
examples/mode_03.rs
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
//! Mode 03: Hot reloaded Dizzle config
|
||||||
|
|
||||||
|
use ::{std::sync::{Arc, RwLock}, ratatui::style::Color, tengri::*};
|
||||||
|
fn main () {}
|
||||||
|
|
||||||
|
//#[tengri_proc::expose]
|
||||||
|
//impl Example {
|
||||||
|
//fn _todo_u16_stub (&self) -> u16 { todo!() }
|
||||||
|
//fn _todo_bool_stub (&self) -> bool { todo!() }
|
||||||
|
//fn _todo_usize_stub (&self) -> usize { todo!() }
|
||||||
|
////[bool] => {}
|
||||||
|
////[u16] => {}
|
||||||
|
////[usize] => {}
|
||||||
|
//}
|
||||||
|
|
||||||
|
//#[tengri_proc::view(TuiOut)]
|
||||||
|
//impl Example {
|
||||||
|
//pub fn title (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//Tui::bg(Color::Rgb(60, 10, 10), Push::y(1, Align::n(format!("Example {}/{}:", self.0 + 1, VIEWS.len())))).boxed()
|
||||||
|
//}
|
||||||
|
//pub fn code (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//Tui::bg(Color::Rgb(10, 60, 10), Push::y(2, Align::n(format!("{}", VIEWS[self.0])))).boxed()
|
||||||
|
//}
|
||||||
|
//pub fn hello (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//Tui::bg(Color::Rgb(10, 100, 10), "Hello").boxed()
|
||||||
|
//}
|
||||||
|
//pub fn world (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//Tui::bg(Color::Rgb(100, 10, 10), "world").boxed()
|
||||||
|
//}
|
||||||
|
//pub fn hello_world (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//"Hello world!".boxed()
|
||||||
|
//}
|
||||||
|
//pub fn map_e (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//Map::east(5u16, ||0..5u16, |n, _i|format!("{n}")).boxed()
|
||||||
|
//}
|
||||||
|
//pub fn map_s (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
|
//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(())
|
||||||
|
////})))))
|
||||||
|
////}))
|
||||||
|
//}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue