console-rs / console-rs/console

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

Open
#172 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.2k
Forks
144
Avg merge
8h 24m
Merged PRs (30d)
4

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Linux reproduction with console v0.15.7 and observe the terminal after the process exits while read_char() is blocked. Read related issues 36 and 136, then trace the terminal raw-mode handling; done means the shell displays typed input normally after the program exits.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.