[PR #331] [MERGED] fix: stdin handling on suspend/resume #1241

Closed
opened 2026-03-14 09:25:55 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opentui/pull/331
Author: @veracioux
Created: 11/21/2025
Status: Merged
Merged: 11/22/2025
Merged by: @kommander

Base: mainHead: fix/suspend-resume-stdin


📝 Commits (5)

  • af3e768 fix: stdin handling on suspend/resume
  • cd8a76b fix: Prevent consuming first keystroke after resume
  • 14576ca test: Fix tests
  • 9820514 style: Fix formatting
  • 78d67e3 test: Fix palette tests

📊 Changes

3 files changed (+21 additions, -10 deletions)

View changed files

📝 packages/core/src/renderer.ts (+9 -3)
📝 packages/core/src/tests/renderer.control.test.ts (+5 -2)
📝 packages/core/src/tests/renderer.palette.test.ts (+7 -5)

📄 Description

Fixes https://github.com/sst/opencode/issues/4586.
Fixes https://github.com/sst/opencode/issues/4209.

Cause

When the editor is running in opencode, both it and opencode are reading from stdin, because stdin.pause() was removed from renderer.suspend. This means that the editor and opencode compete to receive keystrokes.

Fix

Do stdin.pause() like before, but to prevent buffered input on resume, consume everything synchronously before reattaching renderer's stdin listener. I believe this is a universal and foolproof fix.

Testing

I tested this change in opencode, using this development version of opentui.

Scenario 1

Open the editor using /editor or keybind and it should work as expected, receiving all input

Scenario 2

Replace the logic in opencode that opens the editor with an `await new Promise(r => setTimeout(r, 2000)). While the renderer is suspended, type characters into the terminal - they should be printed. When the renderer resumes, those characters should not be added to the prompt.


🔄 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/331 **Author:** [@veracioux](https://github.com/veracioux) **Created:** 11/21/2025 **Status:** ✅ Merged **Merged:** 11/22/2025 **Merged by:** [@kommander](https://github.com/kommander) **Base:** `main` ← **Head:** `fix/suspend-resume-stdin` --- ### 📝 Commits (5) - [`af3e768`](https://github.com/anomalyco/opentui/commit/af3e76871ebd96f83e0e682b3c9bf4573d3c0a4c) fix: stdin handling on suspend/resume - [`cd8a76b`](https://github.com/anomalyco/opentui/commit/cd8a76b002fe5d6c39cdf796bf9393ed273793c7) fix: Prevent consuming first keystroke after resume - [`14576ca`](https://github.com/anomalyco/opentui/commit/14576ca2c13d5d9918a777c9a34aa059400cef03) test: Fix tests - [`9820514`](https://github.com/anomalyco/opentui/commit/98205140f3db6b31bebe608ac9ff43f478af7883) style: Fix formatting - [`78d67e3`](https://github.com/anomalyco/opentui/commit/78d67e330da7c7f10f9b4ae414b9fd11bc7e87d5) test: Fix palette tests ### 📊 Changes **3 files changed** (+21 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `packages/core/src/renderer.ts` (+9 -3) 📝 `packages/core/src/tests/renderer.control.test.ts` (+5 -2) 📝 `packages/core/src/tests/renderer.palette.test.ts` (+7 -5) </details> ### 📄 Description Fixes https://github.com/sst/opencode/issues/4586. Fixes https://github.com/sst/opencode/issues/4209. ## Cause When the editor is running in opencode, both it and opencode are reading from stdin, because stdin.pause() was removed from renderer.suspend. This means that the editor and opencode compete to receive keystrokes. ## Fix Do stdin.pause() like before, but to prevent buffered input on resume, consume everything synchronously before reattaching renderer's stdin listener. I believe this is a universal and foolproof fix. ## Testing I tested this change in opencode, using this development version of opentui. ### Scenario 1 Open the editor using `/editor` or keybind and it should work as expected, receiving all input ### Scenario 2 Replace the logic in opencode that opens the editor with an `await new Promise(r => setTimeout(r, 2000)). While the renderer is suspended, type characters into the terminal - they should be printed. When the renderer resumes, those characters should not be added to the prompt. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-14 09:25:55 +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#1241
No description provided.