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:
if poll(Duration::from_millis(10))? {
let event = read()?;
match event {
Event::Key(KeyEvent {
code,
state: _,
kind,
modifiers: _,
}) => {
if kind == KeyEventKind::Press {
let mut tetromino = self.current_tetromino.clone();
match code {
KeyCode::Char('h') | KeyCode::Left => {
tetromino.move_left(self, stdout)?;
self.current_tetromino = tetromino;
}
Quan Tong