big flat; add midi/audio port handling

This commit is contained in:
facile pop culture reference 2026-07-26 21:49:32 +03:00
parent 66ac2bcbb6
commit c0d6d0174e
16 changed files with 1086 additions and 315 deletions

View file

@ -29,13 +29,13 @@
}
}
#[macro_export] macro_rules! tui_ns {
($self:ident: $State:ident, $to:pat, $pat:ident $body:expr) => {
impl Interpret<Tui, Option<XYWH<u16>>> for $State {
fn interpret_word <'a> (&'a $self, $to: &mut Tui, $pat: &'a impl Symbol) -> Drawn<u16> {
$body
#[macro_export] macro_rules! tui_interpret {
($self:ident: $State:ident, $to:pat, $pat:ident -> $Result:ty { $($body:tt)+ }) => {
impl Interpret<Tui, $Result> for $State {
fn interpret_word <'a> (&'a $self, $to: &mut Tui, $pat: &'a impl Symbol) -> Usually<$Result> {
$($body)+
}
fn interpret_expr <'a> (&'a self, to: &mut Tui, src: &'a impl Expression) -> Drawn<u16> {
fn interpret_expr <'a> (&'a self, to: &mut Tui, src: &'a impl Expression) -> Usually<$Result> {
Ok(Some(if let Some(area) = eval_view(self, to, src)? {
area
} else if let Some(area) = eval_view_tui(self, to, src)? {
@ -50,9 +50,9 @@
/// Enable TUI keyboard input for main state struct.
#[macro_export] macro_rules! tui_keys {
($self:ident:$State:ty,$input:ident $body:block) => {
($self:ident:$State:ty,$input:ident $($body:tt)+) => {
impl Apply<TuiEvent, Usually<()>> for $State {
fn apply (&mut $self, $input: &TuiEvent) -> Usually<()> $body
fn apply (&mut $self, $input: &TuiEvent) -> Usually<()> $($body)+
}
};
}
@ -154,23 +154,10 @@ impl Tui {
let state = state.clone();
Task::new_poll(exited.clone(), poll, move |_| {
let event = read().unwrap();
match event {
// Hardcoded exit.
Event::Key(KeyEvent {
modifiers: KeyModifiers::CONTROL,
code: KeyCode::Char('c'),
kind: KeyEventKind::Press,
state: KeyEventState::NONE
}) => { exited.store(true, Relaxed); },
// Handle all other events by the state:
event => {
if let Err(e) = state.write().unwrap().apply(&TuiEvent(event)) {
panic!("{e}")
}
},
if Exit::is(&event) {
exited.store(true, Relaxed);
} else if let Err(e) = state.write().unwrap().apply(&TuiEvent(event)) {
panic!("{e}")
}
})
}