Skip to content

Adds opt-in support for applications that need to read piped data from stdin while still receiving interactive keyboard input #1094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

HarryPehkonen
Copy link

Summary

Adds opt-in support for applications that need to read piped data from stdin while still receiving interactive keyboard input.

Changes

  • Add HandlePipedInput(bool enable) method to ScreenInteractive
  • Detects piped input and redirects stdin to /dev/tty when enabled
  • POSIX-only feature with Windows/WASM stubs for compatibility
  • Comprehensive test coverage
  • Documentation in README

Usage

auto screen = ScreenInteractive::Fullscreen();
screen.HandlePipedInput(true);  // Enable before Loop()
screen.Loop(component);

Allows commands like cat data.txt | your_app to work with full keyboard interaction.

Backward Compatibility

- Feature is disabled by default - zero breaking changes
- Existing applications work exactly as before
- Cross-platform safe with appropriate guards

Testing

- Unit tests cover normal operation, edge cases, and failure modes
- Only runs on POSIX systems where feature is available

@ArthurSonzogni
Copy link
Owner

Thanks! I like having this builtin.
Nice description.

I will merge it as soon as I can 😉

@ArthurSonzogni
Copy link
Owner

Question

Would it make sense to enable this unconditionnally? I don't think anyone would ever need to opt-out of this.

HarryPehkonen and others added 3 commits August 17, 2025 19:24
Enables applications to read piped data while maintaining interactive
keyboard input by redirecting stdin to /dev/tty when explicitly enabled.
Added an entry for the POSIX Piped Input Handling feature, including
details about its functionality, default state, and how to disable it.
Also attributed @HarryPehkonen for their contribution in PR ArthurSonzogni#1094.
Refactored the POSIX piped input handling to avoid redirecting stdin.
Instead, it now directly opens and reads from /dev/tty for keyboard input
when stdin is piped, allowing applications to process piped data while
still receiving interactive keyboard events.

This addresses the TODO comment in ScreenInteractive::InstallPipedInputHandling().
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