An interactive shell library for ReactPHP
Go to file
Chris 266c538f01 Bugfixed history logic, example tweaks 2024-03-02 02:17:32 +01:00
examples Bugfixed history logic, example tweaks 2024-03-02 02:17:32 +01:00
src Bugfixed history logic, example tweaks 2024-03-02 02:17:32 +01:00
.gitignore Initial commit 2024-02-27 02:08:29 +01:00
LICENSE Initial commit 2024-02-27 02:08:29 +01:00 Updated readme and examples 2024-02-28 12:44:09 +01:00
composer.json Initial commit 2024-02-27 02:08:29 +01:00
phpstan.neon Initial commit 2024-02-27 02:08:29 +01:00

An interactive Unicode-aware shell for ReactPHP


$ composer require noccylabs/react-shell:@dev


  • Interactive line-editing including arrow keys, home, end, delete and all the commodities you are used to.
  • Automatic scrollback history, to avoid having to retype commands.
  • Input is edited on a single scrolling line.
  • Mostly Unicode-aware, meaning it will not have a nervous breakdown if you try to enter (single-width LTR) unicode characters.


$shell = new NoccyLabs\React\Shell\Shell();

// Emitted whenever the prompt is fully redrawn, or redrawPrompt() is manually
// invoked. This is a good place to update a live prompt.
$shell->on('prompt', function () use ($shell) { 
    $shell->setPrompt(date("H:i:s> ")); 
// Emitted whenever a line is entered. The input is already parsed into tokens
// using str_getcsv, respecting double quotes and escape sequeneces.
$shell->on('input', function (array $input) use ($shell) {
    $shell->write("You entered: ".join(" ", $input)."\n");

// The shell is an OutputStream, so you can write to it! Doing so will hide the
// prompt, write the output, and then redraw the prompt. This means you don't
// have to care whether the prompt is visible as long as your output is written
// to the shell!
$shell->write("Hello World!\n\n");

// So, this works:
React\EventLoop\Loop::addPeriodicTimer(5, function () use ($shell) {