react-shell/examples/timers.php

27 lines
810 B
PHP

<?php
use React\EventLoop\Loop;
require_once __DIR__."/../vendor/autoload.php";
$shell = new NoccyLabs\React\Shell\Shell();
// The prompt event is invoked before every full redraw. Call redrawPrompt()
// to trigger it manually. Set the prompt or the style here.
$shell->on('prompt', function ($shell) {
$shell->setPrompt(date("H:i:s> "));
});
// Input handler, parse the commands.
$shell->on('input', function (array $input) use ($shell) {
$shell->write("You entered: ".join(" ", $input)."\n");
});
// The shell is an OutputStream, and writing to it will handle hiding the prompt
// and redrawing it afterwards!
$shell->write("Hello World!\n\n");
// So output can be writen while you are typing!
Loop::addPeriodicTimer(5, function () use ($shell) {
$shell->write(date(DATE_ATOM)."\n");
});