Add opt-in piped input support for POSIX systems

Enables applications to read piped data while maintaining interactive
keyboard input by redirecting stdin to /dev/tty when explicitly enabled.
This commit is contained in:
Harri Pehkonen
2025-08-09 20:26:37 -07:00
committed by ArthurSonzogni
parent 40e1fac3d4
commit 143b24c6a5
4 changed files with 294 additions and 0 deletions

View File

@@ -47,6 +47,7 @@ class ScreenInteractive : public Screen {
// Options. Must be called before Loop().
void TrackMouse(bool enable = true);
void HandlePipedInput(bool enable = true);
// Return the currently active screen, nullptr if none.
static ScreenInteractive* Active();
@@ -141,6 +142,13 @@ class ScreenInteractive : public Screen {
bool force_handle_ctrl_c_ = true;
bool force_handle_ctrl_z_ = true;
#if !defined(_WIN32) && !defined(__EMSCRIPTEN__)
// Piped input handling state (POSIX only)
bool handle_piped_input_ = false;
bool stdin_was_redirected_ = false;
int original_stdin_fd_ = -1;
#endif
// The style of the cursor to restore on exit.
int cursor_reset_shape_ = 1;