use epkard::*;
#[derive(Clone)]
enum MyNode {
Small,
Large,
}
struct State {
count: usize,
}
impl Node for MyNode {
type State = State;
fn next<F>(self, rt: &mut Runtime<Self, F>) -> Control<Self>
where
F: Frontend,
{
rt.clear();
rt.println(format!("count: {}\n", rt.count));
match self {
MyNode::Small => {
match rt
.multiple_choice("How many do you want to add?", &["1", "2", "3", "more"])?
{
n if n <= 2 => rt.count += n + 1,
_ => return next(MyNode::Large),
}
}
MyNode::Large => {
let input = rt.prompt("Enter a number to add")?;
match input.parse::<usize>() {
Ok(i) => rt.count += i,
Err(_) => rt.println("Invalid number"),
}
}
}
next(MyNode::Small)
}
}
fn main() {
run(
MyNode::Small,
&mut State { count: 0 },
&mut CliFrontend::new(),
);
}