Skip to content

feat: buffer stdin during TUI startup so early input is preserved#20934

Closed
JosXa wants to merge 1 commit into
anomalyco:devfrom
JosXa:feature/input-buffering
Closed

feat: buffer stdin during TUI startup so early input is preserved#20934
JosXa wants to merge 1 commit into
anomalyco:devfrom
JosXa:feature/input-buffering

Conversation

@JosXa

@JosXa JosXa commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #20933
Closes #14415

Type of change

  • Bug fix
  • New feature

What does this PR do?

Keystrokes typed while the TUI is booting were silently dropped. This PR adds a preload-phase stdin buffer that captures raw bytes from the moment the process starts, then replays them into the prompt once it mounts.

Replay splits at control/escape boundaries so each chunk gets a separate push/drain cycle in opentui's StdinParser, preserving cursor position for mid-input paste events. Bracketed paste is enabled early so startup pastes are properly tagged.

Theme detection (getTerminalBackgroundColor) queries OSC 11 via stdout and listens for the response on stdin. The buffer's patched emit forwards all events to existing listeners, so theme detection still receives the terminal response normally. The response bytes also land in the buffer, but opentui's StdinParser classifies them as inert "response" events that are silently ignored.

How did you verify your code works?

  • PTY-based automated test (keyboard-buffer.test.ts) sends input before the TUI renders and asserts it appears in the prompt
  • Manual testing with plain text, bracketed paste with image filepaths, and arrow keys during startup

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added contributor needs:compliance This means the issue will auto-close after 2 hours. labels Apr 3, 2026
@JosXa JosXa force-pushed the feature/input-buffering branch from cd15643 to 0faad97 Compare April 3, 2026 20:33
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 3, 2026
@JosXa JosXa force-pushed the feature/input-buffering branch from 0faad97 to 2dba8b5 Compare April 3, 2026 20:37
@github-actions

github-actions Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@TZubiri

TZubiri commented Apr 3, 2026

Copy link
Copy Markdown

While well meaning I don't think this is the way,

"This PR adds a preload-phase stdin buffer "

This is an additive solution, while there exist a subtractive solution. Temrinals naturally buffer input, there is something in the stack that is silently consuming the input buffer. In the issue I used a simple example in python that naturally buffers input, an even simpler example in C could be used to further the point.

There's something consuming the buffer and it needs to be removed, rather than adding another buffer.

@JosXa JosXa force-pushed the feature/input-buffering branch from 2dba8b5 to bf84d00 Compare April 4, 2026 17:52
@JosXa

JosXa commented Apr 5, 2026

Copy link
Copy Markdown
Contributor Author

While well meaning I don't think this is the way,

"This PR adds a preload-phase stdin buffer "

This is an additive solution, while there exist a subtractive solution. Temrinals naturally buffer input, there is something in the stack that is silently consuming the input buffer. In the issue I used a simple example in python that naturally buffers input, an even simpler example in C could be used to further the point.

There's something consuming the buffer and it needs to be removed, rather than adding another buffer.

Well, yes, it's the theme detection mechanism that this PR works around. Don't ask me what we even need it for, I'm in favor of getting rid of that

@rekram1-node

Copy link
Copy Markdown
Collaborator

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keystrokes typed during TUI startup are silently dropped Text written during startup is dropped.

3 participants