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