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

Enables applications to read piped data while maintaining interactive
keyboard input by redirecting stdin to /dev/tty when explicitly enabled.


Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Harri Pehkonen
2025-10-19 08:17:28 -07:00
committed by GitHub
parent a0ce9bf55d
commit 1d0913bfb9
7 changed files with 356 additions and 12 deletions

View File

@@ -43,10 +43,11 @@ class ScreenInteractive : public Screen {
static ScreenInteractive TerminalOutput();
// Destructor.
~ScreenInteractive();
~ScreenInteractive() override;
// 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();
@@ -100,6 +101,8 @@ class ScreenInteractive : public Screen {
void Draw(Component component);
void ResetCursorPosition();
void InstallPipedInputHandling();
void Signal(int signal);
void FetchTerminalEvents();
@@ -117,6 +120,7 @@ class ScreenInteractive : public Screen {
int dimx,
int dimy,
bool use_alternative_screen);
const Dimension dimension_;
const bool use_alternative_screen_;
@@ -141,6 +145,11 @@ class ScreenInteractive : public Screen {
bool force_handle_ctrl_c_ = true;
bool force_handle_ctrl_z_ = true;
// Piped input handling state (POSIX only)
bool handle_piped_input_ = true;
// File descriptor for /dev/tty, used for piped input handling.
int tty_fd_ = -1;
// The style of the cursor to restore on exit.
int cursor_reset_shape_ = 1;