Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

termgame panicing during on_tick leaves mouse inputs enabled in the terminal #3

Open
Nilaos opened this issue Oct 17, 2022 · 2 comments

Comments

@Nilaos
Copy link

Nilaos commented Oct 17, 2022

I noticed during some testing that if a panic (via panic!, todo!, etc) occurred, inside a running Controller, then mouse inputs are being read by the terminal after the controller exits. While a panic is obviously not expected behaviour, having a side effect that renders a terminal unusable on most/all modern computers is undesirable.

MVE:

use termgame::{SimpleEvent, Controller, Game, GameEvent, GameSettings, StyledCharacter, run_game, KeyCode};
use std::error::Error;
use std::time::Duration;

struct MyGame {}

impl Controller for MyGame {
    fn on_start(&mut self, game: &mut Game) {
    }

    fn on_event(&mut self, game: &mut Game, event: GameEvent) {
        match event.into() {
            SimpleEvent::Just(KeyCode::Char(ch)) => {
                game.set_screen_char(1, 1, Some(StyledCharacter::new(ch)))
            },
            _ => {}
        }

    }

    fn on_tick(&mut self, _game: &mut Game) { panic!("This shouldn't break terminals!") }
}

fn main() -> Result<(), Box<dyn Error>> {
    let mut controller = MyGame {};

    run_game(
        &mut controller,
        GameSettings::new()
            // The below are the defaults, but shown so you can edit them.
            .tick_duration(Duration::from_millis(50))
            .quit_event(Some(SimpleEvent::WithControl(KeyCode::Char('c')).into()))
    )?;

    println!("Game Ended!");

    Ok(())
}
@tfpk
Copy link
Contributor

tfpk commented Oct 22, 2022

Hiya! If we were to fix this I think we'd just need something like a panic_unwind to fix the terminal.

I'll look into it, but I'm not going to fix it before we're done using termgame for the term.

Thanks for the bug report!

@insou22
Copy link
Member

insou22 commented Oct 23, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants