on('prompt', function ($shell) { $shell->setPrompt(">> "); }); // Input handler, parse the commands. $shell->on('input', function ($args, $shell) use ($operation){ switch ($args[0]) { case 'start': $operation->active = true; $shell->write("Operation started... Press Ctrl-C to abort\n"); break; default: $shell->write("Type start to start the imaginary operation, then ctrl-c to abort it. Press ctrl-c again to exit.\n"); } }); // The abort event lets you keep going if a specific operation is the main // context. For example, if you are copying a file ^C could stop the copy // operation. $shell->on('abort', function ($shell) use ($operation) { if ($operation->active == true) { $shell->write("Aborting operation\n"); $operation->active = false; } else { $shell->write("Exiting\n"); $shell->close(); } });