Skip to content

fix: use cancellation signal in InteractiveContinuePrinter for proper Ctrl+C cleanup - #775

Merged
MarvinJWendt merged 1 commit into
pterm:masterfrom
Yanhu007:fix/continue-printer-ctrl-c-cleanup
Apr 30, 2026
Merged

MarvinJWendt merged 1 commit into
pterm:masterfrom
Yanhu007:fix/continue-printer-ctrl-c-cleanup

Conversation

@Yanhu007

Copy link
Copy Markdown
Contributor

Fixes #758

Problem

InteractiveContinuePrinter.Show() calls internal.Exit(1) directly on Ctrl+C, which:

  • Skips all deferred cleanup (keyboard listener stopListener() / con.Reset())
  • Leaves the terminal in raw mode
  • Results in a broken prompt that requires reset to fix

All other interactive printers (InteractiveSelectPrinter, InteractiveMultiselectPrinter, InteractiveTextInputPrinter) were fixed in #383 to use NewCancelationSignal, but InteractiveContinuePrinter was missed.

Fix

Apply the same cancellation signal pattern used by the other printers:

  1. Add OnInterruptFunc field for custom interrupt handling (consistent API)
  2. Replace internal.Exit(1) with cancel()
  3. Defer exit() to ensure keyboard listener cleanup runs before exit

This ensures the terminal is properly restored to cooked mode before the process exits.

… Ctrl+C cleanup

InteractiveContinuePrinter calls internal.Exit(1) directly on
Ctrl+C, which skips deferred cleanup and leaves the terminal in
raw mode (broken prompt, invisible cursor).

All other interactive printers (Select, Multiselect, TextInput)
were fixed in pterm#383 to use NewCancelationSignal, but
InteractiveContinuePrinter was missed.

Apply the same cancellation signal pattern:
- Add OnInterruptFunc field for custom interrupt handling
- Replace internal.Exit(1) with cancel()
- Defer exit() to ensure keyboard listener cleanup runs first

Fixes pterm#758
@Yanhu007
Yanhu007 requested a review from MarvinJWendt as a code owner April 12, 2026 20:37
@github-actions github-actions Bot added the fix label Apr 12, 2026

@MarvinJWendt MarvinJWendt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for contributing 🚀

@MarvinJWendt
MarvinJWendt merged commit 32e5000 into pterm:master Apr 30, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InteractiveContinuePrinter doesn't cleanup on Ctrl+C, leaving terminal in raw mode

2 participants