Implemented update event
This commit is contained in:
parent
de7f12b7d5
commit
612e8d06c0
@ -26,22 +26,21 @@ class MyShell extends Shell
|
|||||||
});
|
});
|
||||||
$context->addCommand("mycommand", new MyCommand());
|
$context->addCommand("mycommand", new MyCommand());
|
||||||
$this->updatePrompt();
|
$this->updatePrompt();
|
||||||
|
|
||||||
|
$this->addListener("update", function() {
|
||||||
|
static $lt;
|
||||||
|
$t = floor(microtime(true));
|
||||||
|
if ($t > $lt) {
|
||||||
|
$lt = $t + 5;
|
||||||
|
echo date("Y-m-d h:i:s")."\n";
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updatePrompt()
|
protected function updatePrompt()
|
||||||
{
|
{
|
||||||
$this->setPrompt("test[{$this->seq}]: ");
|
$this->setPrompt("test[{$this->seq}]: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function onUpdate()
|
|
||||||
{
|
|
||||||
static $lt;
|
|
||||||
$t = floor(microtime(true));
|
|
||||||
if ($t > $lt) {
|
|
||||||
$lt = $t + 5;
|
|
||||||
echo date("Y-m-d h:i:s")."\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function onCommand($buffer)
|
protected function onCommand($buffer)
|
||||||
{
|
{
|
||||||
|
@ -261,7 +261,6 @@ class Shell
|
|||||||
// Update the input stuff, sleep if nothing to do.
|
// Update the input stuff, sleep if nothing to do.
|
||||||
if (!($buffer = $this->lineReader->update())) {
|
if (!($buffer = $this->lineReader->update())) {
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
// we get a ^C on ^C, so deal with the ^C.
|
// we get a ^C on ^C, so deal with the ^C.
|
||||||
if ($buffer == "\x03") {
|
if ($buffer == "\x03") {
|
||||||
@ -270,7 +269,10 @@ class Shell
|
|||||||
}
|
}
|
||||||
// Execute the buffer
|
// Execute the buffer
|
||||||
ob_start();
|
ob_start();
|
||||||
$this->executeBuffer($buffer);
|
$this->dispatchEvent("update");
|
||||||
|
if ($buffer) {
|
||||||
|
$this->executeBuffer($buffer);
|
||||||
|
}
|
||||||
$output = ob_get_contents();
|
$output = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
|
||||||
@ -284,7 +286,9 @@ class Shell
|
|||||||
$this->stop();
|
$this->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->dispatchEvent("prompt", [ "context"=>$this->context ]);
|
if ($buffer) {
|
||||||
|
$this->dispatchEvent("prompt", [ "context"=>$this->context ]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->lineReader = null;
|
$this->lineReader = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user