Skip to main content

blizz_ui/
lib.rs

1#![allow(unexpected_cfgs)]
2
3use std::io;
4use std::io::Write;
5use std::time::Duration;
6
7use rand::rngs::ThreadRng;
8
9pub mod decode;
10pub mod input_buffer;
11pub mod layout;
12pub mod prompt;
13pub mod style;
14
15pub mod components;
16
17pub use layout::Size;
18
19/// Terminal dimensions and timing context shared across all components.
20pub struct RenderContext {
21  pub terminal_size: Size,
22  pub elapsed: Duration,
23}
24
25/// A self-rendering UI element.
26///
27/// Each component owns its visual state (positions, reveal progress, etc.)
28/// and knows how to draw itself into a terminal writer. The wizard loop
29/// acts as a thin compositor, calling `render` on each component in
30/// z-order.
31pub trait Component {
32  fn render<W: Write>(
33    &self,
34    writer: &mut W,
35    ctx: &RenderContext,
36    rng: &mut ThreadRng,
37  ) -> io::Result<()>;
38}