example 00 compiles again
Some checks failed
/ build (push) Has been cancelled

and exits, weirdly. wonder what's up here
This commit is contained in:
i do not exist 2026-04-23 20:36:12 +03:00
parent b0fb9f013d
commit b44dc02f33
9 changed files with 110 additions and 80 deletions

View file

@ -16,7 +16,7 @@ use dizzle::*;
/// struct State {/*app-specific*/}
/// impl<'b> Namespace<'b, bool> for State {}
/// impl<'b> Namespace<'b, u16> for State {}
/// impl Understand<Target, ()> for State {}
/// impl Interpret<Target, ()> for State {}
///
/// # fn main () -> tengri::Usually<()> {
/// let state = State {};
@ -30,7 +30,7 @@ use dizzle::*;
#[cfg(feature = "dsl")] pub fn eval_view <'a, O: Screen + 'a, S> (
state: &S, output: &mut O, expr: &'a impl Expression
) -> Usually<bool> where
S: Understand<O, ()>
S: Interpret<O, ()>
+ for<'b>Namespace<'b, bool>
+ for<'b>Namespace<'b, O::Unit>
{
@ -52,18 +52,18 @@ use dizzle::*;
Some("when") => output.place(&when(
state.namespace(arg0?)?.unwrap(),
move|output: &mut O|state.understand(output, &arg1)
move|output: &mut O|state.interpret(output, &arg1)
)),
Some("either") => output.place(&either(
state.namespace(arg0?)?.unwrap(),
move|output: &mut O|state.understand(output, &arg1),
move|output: &mut O|state.understand(output, &arg2),
move|output: &mut O|state.interpret(output, &arg1),
move|output: &mut O|state.interpret(output, &arg2),
)),
Some("bsp") => output.place(&{
let a = move|output: &mut O|state.understand(output, &arg0);
let b = move|output: &mut O|state.understand(output, &arg1);
let a = move|output: &mut O|state.interpret(output, &arg0);
let b = move|output: &mut O|state.interpret(output, &arg1);
bsp(match frags.next() {
Some("n") => Alignment::N,
Some("s") => Alignment::S,
@ -76,7 +76,7 @@ use dizzle::*;
}),
Some("align") => output.place(&{
let a = move|output: &mut O|state.understand(output, &arg0).unwrap();
let a = move|output: &mut O|state.interpret(output, &arg0).unwrap();
align(match frags.next() {
Some("c") => Alignment::Center,
Some("n") => Alignment::N,
@ -90,7 +90,7 @@ use dizzle::*;
}),
Some("fill") => output.place(&{
let a = move|output: &mut O|state.understand(output, &arg0).unwrap();
let a = move|output: &mut O|state.interpret(output, &arg0).unwrap();
match frags.next() {
Some("xy") | None => fill_wh(a),
Some("x") => fill_w(a),
@ -102,7 +102,7 @@ use dizzle::*;
Some("exact") => output.place(&{
let axis = frags.next();
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("exact: unsupported axis {axis:?}") };
let cb = move|output: &mut O|state.understand(output, &arg).unwrap();
let cb = move|output: &mut O|state.interpret(output, &arg).unwrap();
match axis {
Some("xy") | None => exact_wh(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
Some("x") => exact_w(state.namespace(arg0?)?.unwrap(), cb),
@ -115,7 +115,7 @@ use dizzle::*;
Some("min") => output.place(&{
let axis = frags.next();
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("min: unsupported axis {axis:?}") };
let cb = move|output: &mut O|state.understand(output, &arg).unwrap();
let cb = move|output: &mut O|state.interpret(output, &arg).unwrap();
match axis {
Some("xy") | None => min_wh(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
Some("x") => min_w(state.namespace(arg0?)?.unwrap(), cb),
@ -127,7 +127,7 @@ use dizzle::*;
Some("max") => output.place(&{
let axis = frags.next();
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("max: unsupported axis {axis:?}") };
let cb = move|output: &mut O|state.understand(output, &arg).unwrap();
let cb = move|output: &mut O|state.interpret(output, &arg).unwrap();
match axis {
Some("xy") | None => max_wh(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
Some("x") => max_w(state.namespace(arg0?)?.unwrap(), cb),
@ -139,7 +139,7 @@ use dizzle::*;
Some("push") => output.place(&{
let axis = frags.next();
let arg = match axis { Some("x") | Some("y") => arg1, Some("xy") | None => arg2, _ => panic!("push: unsupported axis {axis:?}") };
let cb = move|output: &mut O|state.understand(output, &arg);
let cb = move|output: &mut O|state.interpret(output, &arg);
match axis {
Some("xy") | None => push_xy(state.namespace(arg0?)?.unwrap(), state.namespace(arg1?)?.unwrap(), cb),
Some("x") => push_x(state.namespace(arg0?)?.unwrap(), cb),
@ -157,13 +157,13 @@ use dizzle::*;
/// Interpret TUI-specific layout operation.
///
/// ```
/// use tengri::{Namespace, Understand, Tui, ratatui::prelude::Color};
/// use tengri::{Namespace, Interpret, Tui, ratatui::prelude::Color};
///
/// struct State;
/// impl<'b> Namespace<'b, bool> for State {}
/// impl<'b> Namespace<'b, u16> for State {}
/// impl<'b> Namespace<'b, Color> for State {}
/// impl Understand<Tui, ()> for State {}
/// impl Interpret<Tui, ()> for State {}
/// # fn main () -> tengri::Usually<()> {
/// let state = State;
/// let mut out = Tui::default();
@ -177,7 +177,7 @@ use dizzle::*;
pub fn eval_view_tui <'a, S> (
state: &S, output: &mut Tui, expr: impl Expression + 'a
) -> Usually<bool> where
S: Understand<Tui, ()>
S: Interpret<Tui, ()>
+ for<'b>Namespace<'b, bool>
+ for<'b>Namespace<'b, u16>
+ for<'b>Namespace<'b, Color>
@ -201,7 +201,7 @@ pub fn eval_view_tui <'a, S> (
let arg0 = arg0?.expect("fg: expected arg 0 (color)");
let color = Namespace::namespace(state, arg0)?.unwrap_or_else(||panic!("fg: {arg0:?}: not a color"));
output.place(&fg(color, thunk(move|output: &mut Tui|{
state.understand(output, &arg1)?;
state.interpret(output, &arg1)?;
// FIXME?: don't max out the used area?
Ok(output.area().into())
})))
@ -211,7 +211,7 @@ pub fn eval_view_tui <'a, S> (
let arg0 = arg0?.expect("bg: expected arg 0 (color)");
let color = Namespace::namespace(state, arg0)?.unwrap_or_else(||panic!("bg: {arg0:?}: not a color"));
output.place(&bg(color, thunk(move|output: &mut Tui|{
state.understand(output, &arg1)?;
state.interpret(output, &arg1)?;
// FIXME?: don't max out the used area?
Ok(output.area().into())
})))

View file

@ -34,7 +34,6 @@ pub(crate) use ::{
#[cfg(feature = "sing")] pub extern crate jack;
#[cfg(feature = "sing")] pub mod sing;
#[cfg(feature = "sing")] pub use ::jack::{*, contrib::{*, ClosureProcessHandler}};
#[cfg(feature = "draw")] pub mod draw;
#[cfg(feature = "draw")] pub mod space;

View file

@ -1,5 +1,5 @@
pub use ::jack::{*, contrib::{*, ClosureProcessHandler}};
use crate::{*, time::PerfModel};
use ::jack::*;
use JackState::*;
/// Trait for thing that has a JACK process callback.

View file

@ -136,6 +136,9 @@ impl Origin {
pub fn align <T: Screen> (origin: Origin, a: impl Draw<T>) -> impl Draw<T> {
thunk(move|to: &mut T| { todo!() })
}
pub fn align_n <T: Screen> (a: impl Draw<T>) -> impl Draw<T> {
align(Origin::N, a)
}
/// A numeric type that can be used as coordinate.
///

View file

@ -1,6 +1,6 @@
use crate::{*, lang::*, draw::*, space::{*, Split::*}, color::*, text::*, task::*};
use unicode_width::{UnicodeWidthStr, UnicodeWidthChar};
use rand::distributions::uniform::UniformSampler;
//use unicode_width::{UnicodeWidthStr, UnicodeWidthChar};
//use rand::distributions::uniform::UniformSampler;
use ::{
std::{
io::{stdout, Write},
@ -18,26 +18,72 @@ use ::{
crossterm::{
ExecutableCommand,
terminal::{EnterAlternateScreen, LeaveAlternateScreen, enable_raw_mode, disable_raw_mode},
event::{poll, read, Event, KeyEvent, KeyCode, KeyModifiers, KeyEventKind, KeyEventState},
//event::{poll, read, Event, KeyEvent, KeyCode, KeyModifiers, KeyEventKind, KeyEventState},
}
};
#[macro_export] macro_rules! tui_main {
($state:expr) => {
pub fn main () -> Usually<()> {
tengri::exit::Exit::run(|exit|{
let state = Arc::new(RwLock::new($state));
Ok((
::tengri::keys::tui_input(
exit.as_ref(), &state, std::time::Duration::from_millis(100)
)?,
::tengri::term::tui_output(
stdout(), exit.as_ref(), &state, std::time::Duration::from_millis(10)
)?
))
let input = ::tengri::keys::tui_input(
exit.as_ref(),
&state,
::std::time::Duration::from_millis(100)
)?;
let output = ::tengri::term::tui_output(
stdout(),
exit.as_ref(),
&state,
::std::time::Duration::from_millis(10)
)?;
Ok(())
})
}
}
}
#[macro_export] macro_rules! tui_keys {
(|$self:ident:$State:ty,$input:ident|$body:block) => {
impl Apply<TuiEvent, Usually<Self>> for $State {
fn apply (&mut $self, $input: &TuiEvent) -> Usually<Self> $body
}
};
}
#[macro_export] macro_rules! tui_view {
(|$self:ident: $State:ty|$body:block) => {
impl View<Tui> for $State {
fn view (&$self) -> impl Draw<Tui> $body
}
}
}
/// Spawn the TUI output thread which writes colored characters to the terminal.
pub fn tui_output <W: Write + Send + Sync + 'static, T: View<Tui> + Send + Sync + 'static> (
output: W,
exited: &Arc<AtomicBool>,
state: &Arc<RwLock<T>>,
sleep: Duration
) -> Usually<Task> {
let state = state.clone();
tui_setup()?;
let mut backend = CrosstermBackend::new(output);
let Size { width, height } = backend.size().expect("get size failed");
let mut buffer_a = Buffer::empty(Rect { x: 0, y: 0, width, height });
let mut buffer_b = Buffer::empty(Rect { x: 0, y: 0, width, height });
Ok(Task::new_sleep(exited.clone(), sleep, move |perf| {
let Size { width, height } = backend.size().expect("get size failed");
if let Ok(state) = state.try_read() {
tui_resize(&mut backend, &mut buffer_a, Rect { x: 0, y: 0, width, height });
tui_redraw(&mut backend, &mut buffer_a, &mut buffer_b);
}
let timer = format!("{:>3.3}ms", perf.used.load(Relaxed));
buffer_a.set_string(0, 0, &timer, Style::default());
})?)
}
pub struct Tui(pub Buffer, pub XYWH<u16>);
impl Screen for Tui { type Unit = u16; }
impl Deref for Tui { type Target = Buffer; fn deref (&self) -> &Buffer { &self.0 } }
@ -520,30 +566,6 @@ fn y_scroll () -> impl Draw<Tui> {
})
}
/// Spawn the TUI output thread which writes colored characters to the terminal.
pub fn tui_output <W: Write + Send + Sync + 'static, T: Draw<Tui> + Send + Sync + 'static> (
output: W,
exited: &Arc<AtomicBool>,
state: &Arc<RwLock<T>>,
sleep: Duration
) -> Usually<Task> {
let state = state.clone();
tui_setup()?;
let mut backend = CrosstermBackend::new(output);
let Size { width, height } = backend.size().expect("get size failed");
let mut buffer_a = Buffer::empty(Rect { x: 0, y: 0, width, height });
let mut buffer_b = Buffer::empty(Rect { x: 0, y: 0, width, height });
Ok(Task::new_sleep(exited.clone(), sleep, move |perf| {
let Size { width, height } = backend.size().expect("get size failed");
if let Ok(state) = state.try_read() {
tui_resize(&mut backend, &mut buffer_a, Rect { x: 0, y: 0, width, height });
tui_redraw(&mut backend, &mut buffer_a, &mut buffer_b);
}
let timer = format!("{:>3.3}ms", perf.used.load(Relaxed));
buffer_a.set_string(0, 0, &timer, Style::default());
})?)
}
pub fn tui_redraw <'b, W: Write> (
backend: &mut CrosstermBackend<W>,
mut prev_buffer: &'b mut Buffer,