3 Scripted input and event loops
Input comes from a script queue rather than the terminal. (char-input-push! spec ...) takes a deliberately ergonomic spec DSL, where modifiers are sticky and apply to the next key token:
"hello" —
type each character (UTF-8 ok); #\a / 'enter —
a character or named key; 'ctrl #\c, 'alt #\x, 'shift 'up, 'ctrl 'alt #\x —
modifier(s) + key; 'shift "abc" applies to a whole string; 'key key [mods] —
explicit key (mods merged with any sticky ones); 'paste "a\nb", 'resize 40 120, 'mouse 'press 'left 3 4, 'utf8 "你" —
paste / resize / mouse / utf8 events; an event? struct is queued as-is; the legacy (key mods) and (type data mods) forms still work.
(read-event) blocks by default (like the real terminal), so a loop does not spin when there is no input; (read-event-noblock) is the non-blocking variant. Call (char-input-close!) when the script ends; (read-event) then returns a null-event and (char-input-exhausted?) can be used as the stop condition. Both build-input and the loop-input* macros are provided with the same signatures as tui.