Skip to main content

Crate mural

Crate mural 

Source
Expand description

Conversational terminal rendering for command-line applications.

Mural manages a small live conversation surface in the terminal’s normal buffer. Applications add transcript-like live blocks first and optional pinned blocks after them for status lines, progress, or ephemeral UI. Nothing is drawn until Terminal::render is called, so callers can batch several mutations before one terminal update. Calling Terminal::finish removes pinned UI, leaves the rendered live transcript behind, restores the cursor, and flushes the backend.

Mural intentionally does not own an alternate screen, stdin, raw mode, signal handling, or the event loop. Resize handling is caller-driven through Terminal::resize. If another component writes to the terminal, use the backend escape hatch and then call Terminal::force_full_redraw before the next render so Mural can recover its cached screen snapshot with a full rewrite.

The public API is organized around:

  • terminal for the renderer lifecycle and live/pinned block management.
  • text for validated plain, raw, ANSI, styled, and wrapped text.
  • backend for stdout integration, fake backends, and custom terminal I/O.
  • blocks for pre-built renderable blocks such as Hr, ListItem, Spinner, Textarea, and Padding.
  • error for typed lifecycle and identified-block errors.

See examples/conversation.rs for a runnable end-to-end conversation model.

let mut terminal = Terminal::new(FakeBackend::new(Size::new(80, 24)))?;

terminal.push_live(Text::from_plain("user: hello")?)?;
terminal.insert_live("assistant", Text::from_plain("assistant: …")?)?;
terminal.insert_pinned("status", Text::from_plain("status: streaming")?)?;
terminal.render()?;

*terminal.live_block_mut::<Text>("assistant")? =
    Text::from_plain("assistant: hello back")?;
terminal.resize(Size::new(60, 20))?;
terminal.force_full_redraw()?;
terminal.render()?;

terminal.finish()?;

Re-exports§

pub use backend::Backend;
pub use backend::FakeBackend;
pub use backend::Operation;
pub use backend::StdoutBackend;
pub use blocks::Hr;
pub use blocks::ListItem;
pub use blocks::Padding;
pub use blocks::Spinner;
pub use blocks::Textarea;
pub use blocks::hr;
pub use blocks::list_item;
pub use blocks::padding;
pub use blocks::spinner;
pub use blocks::textarea;
pub use error::TerminalError;
pub use size::Size;
pub use terminal::Terminal;
pub use text::Color;
pub use text::Line;
pub use text::Modifiers;
pub use text::Span;
pub use text::Style;
pub use text::Text;
pub use text::TextError;

Modules§

backend
Terminal I/O backends used by Terminal.
blocks
Pre-built renderable terminal blocks.
error
Error types produced by terminal block management APIs.
size
Terminal size value used by backends and resize notifications.
terminal
High-level renderer lifecycle and block management.
text
Text, styling, ANSI parsing, and Unicode-aware wrapping.

Traits§

Render
A value that can render itself into terminal text for a printable width.