blizz-ui 3.0.0-dev.11

Self-rendering terminal UI components for the blizz wizard
Documentation
#![allow(unexpected_cfgs)]

use std::io;
use std::io::Write;
use std::time::Duration;

use rand::rngs::ThreadRng;

pub mod decode;
pub mod input_buffer;
pub mod layout;
pub mod prompt;
pub mod select_option;
pub mod style;

pub mod components;

#[cfg(not(tarpaulin_include))]
mod wizard_composer;

#[cfg(not(tarpaulin_include))]
pub use wizard_composer::{WizardPromptRefs, render_wizard_prompt_layer};

pub use layout::Size;
pub use select_option::SelectOption;

/// Terminal dimensions and timing context shared across all components.
pub struct RenderContext {
  pub terminal_size: Size,
  pub elapsed: Duration,
}

/// A self-rendering UI element.
///
/// Each component owns its visual state (positions, reveal progress, etc.)
/// and knows how to draw itself into a terminal writer. The wizard loop
/// acts as a thin compositor, calling `render` on each component in
/// z-order.
pub trait Component {
  fn render<W: Write>(
    &self,
    writer: &mut W,
    ctx: &RenderContext,
    rng: &mut ThreadRng,
  ) -> io::Result<()>;
}