Skip to content

Restore terminal state on exit by properly closing TTY#4

Open
rafabmr wants to merge 2 commits intoyarlson:mainfrom
rafabmr:work/terminal
Open

Restore terminal state on exit by properly closing TTY#4
rafabmr wants to merge 2 commits intoyarlson:mainfrom
rafabmr:work/terminal

Conversation

@rafabmr
Copy link
Copy Markdown

@rafabmr rafabmr commented Dec 30, 2025

Description:
Once the program finishes running, the terminal doesn’t return to its normal behavior. Although keystrokes are still being captured internally, nothing is shown on screen. The cursor keeps blinking, but the characters the user types are invisible, making it feel like the terminal is “broken”.

Root Cause:
The terminal is opened in raw mode by go-tty but is never properly closed, leaving the terminal with echo disabled.

Expected Behavior:
Terminal state should be restored to normal after the program exits, allowing users to see their input.

Solution:

  • Add a Close() method to the Terminal struct that properly closes the TTY connection.
  • Make sure Close() is always executed by calling it with defer inside runWithTerminal(), ensuring the terminal is cleaned up even if the program exits early.

Description:
syscall.SIGWINCH is not available on Windows, causing build/runtime failures when compiling for the Windows platform.

Solution:
Add platform-specific handling or conditional compilation to avoid using syscall.SIGWINCH on Windows.

Fixes an issue where the terminal remained in raw mode after program exit, leaving input invisible. The TTY was not being properly closed, so echo stayed disabled. This change adds a Close() method to the Terminal struct and ensures it is always called with defer to correctly restore the terminal state.
@jmillerv
Copy link
Copy Markdown

I think I am running into this issue as well on arch Linux. When I ctrl+c out of the program, my terminal doesn't behave as expected after the fact and I find myself having to create an entirely new terminal session.

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

Successfully merging this pull request may close these issues.

2 participants