-
Notifications
You must be signed in to change notification settings - Fork 0
/
tally.rs
40 lines (33 loc) · 955 Bytes
/
tally.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::io;
use ratatui::widgets::Paragraph;
use tundra::prelude::*;
struct Tally {
value: u32,
}
impl State for Tally {
type Result<T> = T;
type Out = u32;
type Global = ();
fn draw(&self, frame: &mut Frame) {
let widget = Paragraph::new(self.value.to_string());
frame.render_widget(widget, frame.size());
}
fn input(mut self, key: KeyEvent, ctx: &mut Context) -> Signal<Self> {
match key.code {
KeyCode::Up => self.value += 1,
KeyCode::Tab => self.value *= tally(ctx),
KeyCode::Enter => return Signal::Return(self.value),
_ => (),
}
Signal::Continue(self)
}
}
pub fn tally(ctx: &mut Context) -> u32 {
Tally{ value: 0 }.run(ctx)
}
fn main() -> io::Result<()> {
let ctx = &mut Context::new()?;
let value = tally(ctx);
dialog::info(format!("You entered {value}! Why?"), &(), ctx);
Ok(())
}