//! `tui` — simple terminal interactivity for scripts. //! //! The module has two halves, each in its own submodule: //! //! - **Prompts** ([`prompts`]): interactive one-liners backed by the //! `inquire` crate — `tui.confirm`, `tui.promptText`, `tui.promptSelect`, //! …. Shared shape `(text, default, opts)`; Esc returns `nil`, Ctrl-C //! raises `"tui.: interrupted"`, no terminal raises `"not a terminal"`. //! - **Output** ([`output`]): `tui.styled` markup (engine in [`markup`]), //! `tui.addPreset`, SymfonyStyle-like message blocks (`tui.success` & co., //! rendering in [`blocks`]), and the `tui.raw` / `tui.screenInfo` //! building blocks. //! //! A third piece, **terminal control** ([`term`]), exposes the raw escape //! sequences behind rich TUIs — cursor movement, clearing, the alternate //! screen, scroll regions, title/clipboard — as `tui.moveTo`, `tui.altScreen` //! and friends, with [`cleanup`] restoring the terminal on every exit path. //! //! Shared argument parsing (the validated opts table, positional-arg //! helpers) lives in [`opts`]. mod blocks; mod markup; mod opts; mod output; mod prompts; mod term; // The fs module's permission prompt shares the terminal with tui's prompts // and must take the same lock. (In test builds fs never opens a real prompt, // leaving this re-export unused.) #[cfg_attr(test, allow(unused_imports))] pub(crate) use prompts::PROMPT_LOCK; pub(crate) use term::cleanup; use mlua::prelude::LuaResult; use mlua::Lua; /// `mlua::Error::external(format!(...))` — every Lua-facing error in this /// module goes through this, prefixed `tui.: …`. macro_rules! ext_err { ($($arg:tt)*) => { mlua::Error::external(format!($($arg)*)) }; } use ext_err; pub(super) fn install(lua: &Lua) -> LuaResult<()> { // Registry for tui.addPreset, read by tui.styled and the block `style` // option; per Lua state, so scripts and tests don't leak into each other. lua.set_app_data(markup::Presets::default()); let tui = lua.create_table()?; prompts::install(lua, &tui)?; output::install(lua, &tui)?; term::install(lua, &tui)?; lua.globals().raw_set("tui", tui)?; Ok(()) }