react-shell/examples/timers.php

27 lines
810 B
PHP
Raw Permalink Normal View History

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