console-rs / console-rs/console

Add Terminal Reset Helper

Open
#203 1 comment 1 reaction 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

This came out of the issue filed over at dialoguer: https://github.com/console-rs/dialoguer/issues/294

The TLDR is that when the application terminates in unexpected ways (or really just ctrl+c) it's pretty easy for the terminal to be left in an unfortunate state. While there might be ways in which APIs can be restructured to cause this less, this is generally quite unfortunate and too easy to cause.

It also will in most cases require either using raw inputs to ensure that ctrl+c is manually handled on all inputs to reset the terminal state locally or (more correctly) to handle cltr+c globally. The latter however requires the user to be involved here as there can really only be one handler via the ctrlc crate or similar.

As a strawman proposal I'm considering adding a helper that people can put into their own ctrlc handlers which resets the terminal back to the state it was in when the application was started.

fn main() {
    let state = console::capture_terminal_state();
    ctrlc::set_handler(move || {
        state.restore();
        // ...
    });
    // stuff happens here
}

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 reading the linked dialoguer issue and the terminal-state handling around the proposed capture_terminal_state entry point. Clarify how terminal state is captured and restored when a ctrlc handler invokes state.restore(); done should include a documented helper behavior and validation that it restores the startup state.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.