Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Stdio React Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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).

Implementation Patterns

  • Interactive Prompts: Combine InputStream with Terminal to build confirmation prompts (do you want to continue? (y/N)) with input validation and masking.
  • Real-time Progress Bars: Use OutputStream to stream ANSI-aware updates (e.g., Writing [=====> ] 50%) without overwriting previous output.
  • Command-Line Servers: Integrate with ReactPHP’s Server component — handle client connections over TCP while allowing operator commands via stdin (e.g., reload config, toggle debug mode).
  • Pipe Support: Works seamlessly with proc_open() or streams — e.g., relay output from a subprocess to the terminal while accepting user input for interactive filtering.
  • Multiline Editing: Leverage Terminal::enableRawMode() for full control over keystrokes (e.g., arrow keys, Ctrl+L for clear), enabling custom line editors.

Gotchas and Tips

  • Raw Mode Cleanup: Always call $terminal->disableRawMode() (or use finally blocks) before exit — otherwise, the terminal may remain in broken state after crashes.
  • Windows Compatibility: Raw mode and advanced ANSI features (like color) require modern Windows 10+ or clue/terminal-react’s ANSI emulation. Test on target platforms.
  • Chunk Boundaries: Input events may emit partial UTF-8 characters — use $terminal->enableUtf8() to ensure reliable multi-byte handling (e.g., emojis, accented chars).
  • Buffering Gotchas: 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().
  • Extensibility: Extend InputStream/OutputStream to add custom filters (e.g., logging all input to a file) or wrap with StreamDecorator for advanced transformations.
  • Debugging Tip: Use php -d output_buffering=0 when testing — PHP’s output buffering can interfere with immediate terminal updates.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport