Basic command handler, bugfixes

This commit is contained in:
2024-02-27 02:22:49 +01:00
parent c92c40b45a
commit baff64be7a
4 changed files with 70 additions and 5 deletions

View File

@ -68,11 +68,16 @@ class Shell implements WritableStreamInterface, EventEmitterInterface
exit(0);
case "\n":
$buffer = str_getcsv($this->buffer, " ");
$buffer = str_getcsv(trim($this->buffer), " ");
$this->buffer = '';
$this->cursorPos = 0;
$this->scrollOffset = 0;
$this->emit('input', [ $buffer ]);
$this->ostream->write("\n");
if ($buffer[0] !== NULL) {
$this->emit('input', [ $buffer, $this ]);
} else {
$this->redrawPrompt();
}
break;
case "\x7F": // backspace
@ -156,7 +161,7 @@ class Shell implements WritableStreamInterface, EventEmitterInterface
public function redrawPrompt(): void
{
$prompt = $this->emit("prompt");
$this->emit("prompt", [ $this ]);
$this->termWidth = intval(exec("tput cols"));
$this->isPrompting = true;