Skip to main content

sim_view_tty/
lib.rs

1//! Loadable terminal (CLI/TUI) view/edit surface for SIM.
2//!
3//! The thesis: a terminal is one *surface*, not a baked subcommand. The `sim`
4//! binary stays a bootloader; this crate is a library loaded at runtime that
5//! projects a [`Scene`](sim_lib_scene) to text and reduces terminal key input to
6//! [`Intent`](sim_lib_intent) values. Nothing here parses argv or owns the
7//! process. Both directions are pure and deterministic, so the whole surface is
8//! testable without a tty:
9//!
10//! - [`render_scene`] fits a scene to a `SurfaceCaps` (via the view crate's
11//!   density projection) and walks it to stable ASCII.
12//! - [`intent_from_key`] turns a normalized [`KeyInput`] into a validated Intent.
13//!
14//! The CLI and TUI presets differ only in advertised capabilities -- a `cli`
15//! surface is keyboard-only ANSI, a `tui` surface adds pointer input and a
16//! richer palette -- which the projection ranker reads. Build them with
17//! [`cli_caps`] and [`tui_caps`].
18//!
19//! # Example
20//!
21//! ```
22//! use sim_view_tty::{cli_caps, render_scene};
23//!
24//! let scene = sim_lib_scene::build::text_node("ready");
25//! let text = render_scene(&scene, &cli_caps("tty.local.1"));
26//! assert_eq!(text, "ready");
27//! ```
28
29#![forbid(unsafe_code)]
30#![deny(missing_docs)]
31
32mod caps;
33mod input;
34mod render;
35
36pub use caps::{cli_caps, tui_caps};
37pub use input::{KeyInput, intent_from_key, palette_intent_from_colon};
38pub use render::{render_palette, render_scene};
39
40#[cfg(test)]
41mod tests;