use std::collections::HashMap;
pub enum WizardStepKind {
Leaf,
Optional,
Select(&'static [&'static str]),
Section(&'static [WizardStep]),
Array(&'static [WizardStep]),
Buttons(&'static [&'static str]),
}
pub struct WizardStep {
pub label: &'static str,
pub kind: WizardStepKind,
}
impl WizardStep {
pub const fn leaf(label: &'static str) -> Self {
Self { label, kind: WizardStepKind::Leaf }
}
pub const fn optional(label: &'static str) -> Self {
Self { label, kind: WizardStepKind::Optional }
}
pub const fn select(label: &'static str, opts: &'static [&'static str]) -> Self {
Self { label, kind: WizardStepKind::Select(opts) }
}
pub const fn section(label: &'static str, children: &'static [WizardStep]) -> Self {
Self { label, kind: WizardStepKind::Section(children) }
}
pub const fn array(label: &'static str, sub_steps: &'static [WizardStep]) -> Self {
Self { label, kind: WizardStepKind::Array(sub_steps) }
}
pub const fn buttons(labels: &'static [&'static str]) -> Self {
Self { label: "", kind: WizardStepKind::Buttons(labels) }
}
pub fn is_section(&self) -> bool { matches!(self.kind, WizardStepKind::Section(_)) }
pub fn is_array(&self) -> bool { matches!(self.kind, WizardStepKind::Array(_)) }
pub fn children(&self) -> &'static [WizardStep] {
match &self.kind {
WizardStepKind::Section(c) | WizardStepKind::Array(c) => c,
_ => &[],
}
}
}
pub struct ArrayEditSession {
pub item_idx: usize,
pub sub_step: usize,
pub is_new: bool,
pub original_values: Vec<String>,
pub buffer: String,
pub buf_cursor: usize,
pub select_idx: usize,
}
pub struct ArrayState {
pub items: Vec<Vec<String>>,
pub selected: usize,
pub editing: Option<ArrayEditSession>,
pub expanded: bool,
pub header_sel: usize,
pub item_btn_sel: usize,
}
impl ArrayState {
pub fn new() -> Self {
Self {
items: vec![],
selected: 0,
editing: None,
expanded: false,
header_sel: 0,
item_btn_sel: 0,
}
}
}
pub struct WizardState {
pub steps: &'static [WizardStep],
pub input_count: usize,
pub current: usize,
pub values: Vec<String>,
pub buffer: String,
pub cursor: usize,
pub array_states: HashMap<usize, ArrayState>,
pub button_selected: usize,
}
#[derive(Debug)]
pub enum WizardEvent {
None,
StepCompleted { index: usize, value: String },
Done(Vec<String>),
Cancelled,
ArrayItemAdded { array_step_idx: usize, item_idx: usize },
ArrayItemDeleted { array_step_idx: usize, item_idx: usize },
ArrayItemCompleted { array_step_idx: usize, item_idx: usize, values: Vec<String> },
}
#[derive(Clone, Copy)]
pub(super) enum StepKindRef {
Leaf,
Optional,
Select(&'static [&'static str]),
Array(&'static [WizardStep]),
Buttons(&'static [&'static str]),
}