diff --git a/Cargo.lock b/Cargo.lock index 877cb78..ac7fc49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -524,11 +524,21 @@ name = "dizzle" version = "0.1.0" dependencies = [ "const_panic", + "dizzle_proc", "itertools 0.14.0", "konst", "thiserror 2.0.18", ] +[[package]] +name = "dizzle_proc" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "dlib" version = "0.5.2" @@ -1573,9 +1583,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.44" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" dependencies = [ "proc-macro2", ] @@ -2001,9 +2011,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.116" +version = "2.0.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df424c70518695237746f84cede799c9c58fcb37450d7b23716568cc8bc69cb" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" dependencies = [ "proc-macro2", "quote", diff --git a/dizzle b/dizzle index 0050385..060c517 160000 --- a/dizzle +++ b/dizzle @@ -1 +1 @@ -Subproject commit 0050385e63ea5d3ab9be7c495dae5fc635396cf0 +Subproject commit 060c51757ccce141f751a79d8b9b2d5af3955f66 diff --git a/examples/tui_00.rs b/examples/tui_00.rs index 8aedd9f..3c5f3d9 100644 --- a/examples/tui_00.rs +++ b/examples/tui_00.rs @@ -5,7 +5,7 @@ use ::{ }; tui_main!(State { - cursor: 10, + cursor: 0, ..Default::default() }); @@ -20,11 +20,14 @@ tui_view!(|self: State| { let heading = format!("State {}/{} in {:?}", index, VIEWS.len(), &wh); let title = bg(Color::Rgb(60, 10, 10), heading.align_n().push_y(1)); let code = bg(Color::Rgb(10, 60, 10), format!("{}", src).align_n().push_y(2)); - //let content = ;//();//bg(Color::Rgb(10, 10, 60), View(self, CstIter::new(src))); - let widget = thunk(move|to: &mut Tui|self.interpret(to, &src).map(Some)); + let widget = thunk(move|to: &mut Tui|self.interpret(to, &src)); self.size.of(south(title, north(code, widget))) }); +#[dizzle::namespace(bool)] +#[dizzle::namespace(u16)] +#[dizzle::namespace(Option)] +#[dizzle::namespace(Color)] #[derive(Debug, Default)] struct State { /** Command history (undo/redo). */ @@ -35,7 +38,16 @@ struct State { size: Sizer, } -impl Interpret> for State { +impl Interpret>> for State { + fn interpret_expr <'a> (&'a self, to: &mut Tui, lang: &'a impl Expression) -> Drawn { + Ok(Some(if let Some(area) = eval_view(self, to, lang)? { + area + } else if let Some(area) = eval_view_tui(self, to, lang)? { + area + } else { + return Err(format!("App::interpret_expr: unexpected: {lang:?}").into()) + })) + } } #[derive(Debug)] enum Action { @@ -45,11 +57,6 @@ impl Interpret> for State { Prev } -//impl_from!(Action: |input: &TuiIn| todo!()); - -fn draw_example (state: &State, to: &mut Tui) { -} - impl Action { const BINDS: &'static str = stringify! { @@ -155,9 +162,11 @@ const VIEWS: &'static [&'static str] = &[ ]; -//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_from!(Action: |input: &TuiIn| todo!()); + +//fn draw_example (state: &State, to: &mut Tui) { +//} diff --git a/proc/src/lib.rs b/proc/src/lib.rs index 7ae7699..1c31c78 100644 --- a/proc/src/lib.rs +++ b/proc/src/lib.rs @@ -50,26 +50,6 @@ pub fn view (meta: TokenStream, item: TokenStream) -> TokenStream { )) } -pub(crate) fn write (t: T) -> TokenStream { - let mut out = TokenStream2::new(); - t.to_tokens(&mut out); - out.into() -} - -pub(crate) fn write_quote (quote: TokenStream2) -> TokenStream2 { - let mut out = TokenStream2::new(); - for token in quote { - out.append(token); - } - out -} - -pub(crate) fn write_quote_to (out: &mut TokenStream2, quote: TokenStream2) { - for token in quote { - out.append(token); - } -} - #[cfg(test)] #[test] fn test_proc_view () { let x: crate::proc_view::ViewMeta = pq! { SomeOut }; let output: Ident = pq! { SomeOut }; diff --git a/shell.nix b/shell.nix index 6f44581..f3e43dc 100644 --- a/shell.nix +++ b/shell.nix @@ -1,13 +1,14 @@ #!/usr/bin/env nix-shell {pkgs?import{}}:let - name = "tengri"; - stdenv = pkgs.clang19Stdenv; - LIBCLANG_PATH = "${pkgs.libclang.lib.outPath}/lib"; - LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath []; + name = "tengri"; + stdenv = pkgs.clang19Stdenv; in pkgs.mkShell.override { inherit stdenv; } { - inherit name LIBCLANG_PATH LD_LIBRARY_PATH; + LIBCLANG_PATH = "${pkgs.libclang.lib.outPath}/lib"; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ + pkgs.pipewire.jack + ]; buildInputs = [ pkgs.libclang pkgs.jack2 diff --git a/src/eval.rs b/src/eval.rs index 67f565e..168a5ce 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -146,7 +146,9 @@ pub fn eval_view <'a, O: Screen + 'a, S> ( Some("align") => thunk(move|output: &mut O|{ state.interpret(output, &arg0) }).align(eval_enum!("align", output, state, frags.next(), arg0, Azimuth { - "c" => C, "n" => N, "s" => S, "e" => E, "w" => W, "x" => X, "y" => Y + "c" => C, "x" => X, "y" => Y, + "n" => N, "s" => S, "e" => E, "w" => W, + "nw" => NW, "sw" => SW, "ne" => NE, "se" => SE, })).draw(output), Some("exact") => eval_xy!( "exact" => expr, head, output, state, frags.next(), exact_wh, exact_w, exact_h, arg0, arg1, arg2, @@ -176,27 +178,14 @@ pub fn eval_view <'a, O: Screen + 'a, S> ( /// ``` /// use tengri::{*, lang::*, ratatui::prelude::Color}; /// -/// #[namespace(bool {})] -/// #[namespace(u8: try_to_u8)] -/// #[namespace(u16: try_to_u16)] -/// #[namespace(Color: try_to_color)] +/// #[namespace(bool)] +/// #[namespace(u8 try_to_u8)] +/// #[namespace(u16 try_to_u16)] +/// #[namespace(Color try_to_color)] /// #[interpret(Tui -> Option>: try_eval_tui)] /// struct State; /// tengri::lang::primitive!(u8: try_to_u8); /// tengri::lang::primitive!(u16: try_to_u16); -/// tengri::lang::namespace!(State: bool { -/// }); -/// tengri::lang::namespace!(State: u8 { -/// literal = |x|try_to_u8(x); -/// }); -/// tengri::lang::namespace!(State: u16 { -/// literal = |x|try_to_u16(x); -/// }); -/// tengri::lang::namespace!(State: Color { -/// expression = |_state| { -/// "g" (x: u8) => { ItemTheme::G[x as usize].base.term } -/// }; -/// }); /// tengri::lang::interpret!(|self: State, context: Tui, lang|->Option>{ /// expression = { /// "text" (...rest) => { todo!() } diff --git a/src/term.rs b/src/term.rs index a289e66..24364b7 100644 --- a/src/term.rs +++ b/src/term.rs @@ -103,7 +103,10 @@ impl Tui { /// Implement standard [main] entrypoint for TUI apps. #[macro_export] macro_rules! tui_main { ($state:expr) => { - pub fn main () -> Usually<()> { tui_run_main(Arc::new(RwLock::new($state))) } + pub fn main () -> Usually<()> { + tui_setup_panic(); + tui_run_main(Arc::new(RwLock::new($state))) + } } }