"Life is all about sharing. If we are good at something, pass it on." - Mary Berry

Integration testing TUI applications in Rust

2024-01-21

In building games with any language, there will be a loop to handle the key events. In case of crossterm, it’s event::read:

 1if poll(Duration::from_millis(10))? {
 2    let event = read()?;
 3    match event {
 4        Event::Key(KeyEvent {
 5            code,
 6            state: _,
 7            kind,
 8            modifiers: _,
 9        }) => {
10            if kind == KeyEventKind::Press {
11                let mut tetromino = self.current_tetromino.clone();
12                match code {
13                    KeyCode::Char('h') | KeyCode::Left => {
14                        tetromino.move_left(self, stdout)?;
15                        self.current_tetromino = tetromino;
16                    }

Read More...