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