clue/stdio-react
ReactPHP-based STDIO stream wrapper for non-blocking access to STDIN/STDOUT/STDERR. Enables event-driven CLI apps with readable and writable streams, integrating terminal input/output into the ReactPHP loop for async command-line tools.
Start by installing via Composer: composer require clue/stdio-react. This package provides an InputStream and OutputStream that work asynchronously with ReactPHP’s event loop — ideal for building interactive CLI tools (e.g., REPLs, chat clients, progress bars, or TUIs). The first step is to bind input/output to the current process:
$loop = React\EventLoop\Factory::create();
$stdin = new Clue\React\Stdio\InputStream(STDIN, $loop);
$stdout = new Clue\React\Stdio\OutputStream(STDOUT, $loop);
$stdin->on('data', function ($chunk) use ($stdout) {
$stdout->write('You typed: ' . $chunk);
});
$loop->run();
Use the Terminal helper for advanced features like line editing and history (e.g., Terminal::createAutoDetect($loop)). Check the README’s "Examples" directory for minimal working demos (e.g., examples/readline.php).
InputStream with Terminal to build confirmation prompts (do you want to continue? (y/N)) with input validation and masking.OutputStream to stream ANSI-aware updates (e.g., Writing [=====> ] 50%) without overwriting previous output.Server component — handle client connections over TCP while allowing operator commands via stdin (e.g., reload config, toggle debug mode).proc_open() or streams — e.g., relay output from a subprocess to the terminal while accepting user input for interactive filtering.Terminal::enableRawMode() for full control over keystrokes (e.g., arrow keys, Ctrl+L for clear), enabling custom line editors.$terminal->disableRawMode() (or use finally blocks) before exit — otherwise, the terminal may remain in broken state after crashes.clue/terminal-react’s ANSI emulation. Test on target platforms.$terminal->enableUtf8() to ensure reliable multi-byte handling (e.g., emojis, accented chars).OutputStream is non-blocking and may drop data if the underlying stream can’t keep up — always listen for error events or check $stdout->isWritable().InputStream/OutputStream to add custom filters (e.g., logging all input to a file) or wrap with StreamDecorator for advanced transformations.php -d output_buffering=0 when testing — PHP’s output buffering can interfere with immediate terminal updates.How can I help you explore Laravel packages today?