Skip to content

On Linux if program exits when read_char() is blocking, the terminal will stay in raw mode #172

Open
@JasonWei512

Description

@JasonWei512

Problem

Run the following code on Linux with console v0.15.7:

use std::{thread, time::Duration};

fn main() {
    println!("(This program will exit in 5 seconds.)");
    println!("Press any key, and the program will echo the key you pressed.");

    thread::spawn(|| {
        let terminal = console::Term::stdout();
        loop {
            let key_pressed = terminal.read_char().unwrap();    // ← Blocking
            println!("You pressed: {}", key_pressed);
        }
    });

    thread::sleep(Duration::from_secs(5));
    panic!("After the program exits, the terminal will stay in raw mode.")
}

After the program exits, the terminal will stay in raw mode. Anything I type in shell does not display on screen.

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions