re-add tui_main, fixing examples

This commit is contained in:
i do not exist 2026-04-15 11:11:36 +03:00
parent a93fe92a59
commit 6c382e2627
7 changed files with 89 additions and 44 deletions

View file

@ -1,31 +1,57 @@
use ::{std::{io::stdout, sync::{Arc, RwLock}}, ratatui::style::Color, tengri::*};
tui_main!(State { cursor: 10, ..Default::default() });
namespace!(State: bool {});
namespace!(State: u16 {});
namespace!(State: Color {});
handle!(TuiIn: |self: State, input|Action::from(input).eval(self).map(|_|None));
view!(State: TuiOut: [ evaluate_output_expression, evaluate_output_expression_tui ]);
draw!(State: TuiOut: [ draw_example ]);
use ::{
std::{io::stdout, sync::{Arc, RwLock}},
tengri::{*, term::*, lang::*, keys::*, draw::*, space::*},
ratatui::style::Color,
};
tui_main!(State { cursor: 10, ..Default::default() });
//namespace!(State: bool {});
//namespace!(State: u16 {});
//namespace!(State: Color {});
//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 Apply<TuiEvent, Usually<Self>> for State {
fn apply (&mut self, input: &TuiEvent) -> Usually<Self> {
todo!()
}
}
impl View<Tui> for State {
fn view (&self) -> impl Draw<Tui> {
let index = self.cursor + 1;
let wh = (self.size.w(), self.size.h());
let src = VIEWS.get(self.cursor).unwrap_or(&"");
let heading = format!("State {}/{} in {:?}", index, VIEWS.len(), &wh);
let title = bg(Color::Rgb(60, 10, 10), push_y(1, align_n(heading)));
let code = bg(Color::Rgb(10, 60, 10), push_y(2, align_n(format!("{}", src))));
//let content = ;//();//bg(Color::Rgb(10, 10, 60), View(self, CstIter::new(src)));
self.size.of(bsp_s(title, bsp_n(code, self.understand(to, &src).unwrap())))
}
}
#[derive(Debug, Default)] struct State {
/** Rendered window size */ size: Measure<TuiOut>,
/** Command history (undo/redo) */ history: Vec<Action>,
/** User-controllable value */ cursor: usize,
/** Command history (undo/redo). */
history: Vec<Action>,
/** User-controllable value. */
cursor: usize,
/** Rendered window size. */
size: crate::space::Size,
}
impl_from!(Action: |input: &TuiIn| todo!());
//impl_from!(Action: |input: &TuiIn| todo!());
#[derive(Debug)] enum Action {
/** Increment cursor */ Next,
/** Decrement cursor */ Prev
/** Increment cursor */
Next,
/** Decrement cursor */
Prev
}
fn draw_example (state: &State, to: &mut TuiOut) {
let index = state.cursor + 1;
let wh = state.size.wh();
let src = VIEWS.get(state.cursor).unwrap_or(&"");
let heading = format!("State {}/{} in {:?}", index, VIEWS.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(state, CstIter::new(src)));
state.size.of(Bsp::s(title, Bsp::n(code, state.understand(to, &src).unwrap()))).draw(to)
fn draw_example (state: &State, to: &mut Tui) {
}
impl Action {
const BINDS: &'static str = stringify! { (@left prev) (@right next) };
fn eval (&self, state: &mut State) -> Perhaps<Self> {
@ -41,6 +67,7 @@ impl Action {
Ok(Some(Self::Next))
}
}
const VIEWS: &'static [&'static str] = &[
stringify! { :hello-world },