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