[PR #421] [CLOSED] fix(windows): handle Ctrl+C gracefully with ConPTY terminal restoration #523

Closed
opened 2026-03-02 23:46:54 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/421
Author: @Hona
Created: 12/16/2025
Status: Closed

Base: mainHead: fix/winterm-ctrl+c-rawmode


📝 Commits (3)

  • 96d7bba fix(windows): handle Ctrl+C gracefully with ConPTY terminal restoration
  • e83d79a Update lib.zig
  • ec7db10 Update lib.zig

📊 Changes

1 file changed (+140 additions, -0 deletions)

View changed files

📝 packages/core/src/zig/lib.zig (+140 -0)

📄 Description

On Windows with ConPTY (Windows Terminal), Ctrl+C triggers CTRL_C_EVENT at the Windows API level, but ConPTY does not pass the 0x03 byte through to stdin. This caused immediate process termination without giving the TUI a chance to restore terminal state (exit alternate screen, disable raw mode, etc.).
Add SetConsoleCtrlHandler to intercept CTRL_C_EVENT and inject 0x03 into stdin via WriteConsoleInputW, allowing the existing graceful shutdown code path to execute.

  • installCtrlCHandler(): registers the handler (no-op on non-Windows)
  • removeCtrlCHandler(): unregisters the handler (no-op on non-Windows)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opentui/pull/421 **Author:** [@Hona](https://github.com/Hona) **Created:** 12/16/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/winterm-ctrl+c-rawmode` --- ### 📝 Commits (3) - [`96d7bba`](https://github.com/anomalyco/opentui/commit/96d7bbaef8d67db29d25f0342afbe5ada467cbd1) fix(windows): handle Ctrl+C gracefully with ConPTY terminal restoration - [`e83d79a`](https://github.com/anomalyco/opentui/commit/e83d79af2ce863f7e3aa8999f3591783d6871f7e) Update lib.zig - [`ec7db10`](https://github.com/anomalyco/opentui/commit/ec7db10b497a728ea4afd6bfd37e50275cbdd381) Update lib.zig ### 📊 Changes **1 file changed** (+140 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/zig/lib.zig` (+140 -0) </details> ### 📄 Description On Windows with ConPTY (Windows Terminal), Ctrl+C triggers CTRL_C_EVENT at the Windows API level, but ConPTY does not pass the 0x03 byte through to stdin. This caused immediate process termination without giving the TUI a chance to restore terminal state (exit alternate screen, disable raw mode, etc.). Add SetConsoleCtrlHandler to intercept CTRL_C_EVENT and inject 0x03 into stdin via WriteConsoleInputW, allowing the existing graceful shutdown code path to execute. - installCtrlCHandler(): registers the handler (no-op on non-Windows) - removeCtrlCHandler(): unregisters the handler (no-op on non-Windows) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 23:46:54 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/opentui#523
No description provided.