Improved the cursor in LineRead when using history

This commit is contained in:
Christopher Vagnetoft 2016-11-19 15:46:13 +01:00
parent 43a6475192
commit bdec60717f
1 changed files with 14 additions and 3 deletions

View File

@ -161,22 +161,33 @@ class LineRead
if ($this->posHistory == 0) {
$this->stashedBuffer = $this->buffer;
}
if ($this->posCursor == strlen($this->buffer)) {
$this->posCursor = -1;
}
if ($this->posHistory < count($this->history)) {
$this->posHistory++;
$this->buffer = $this->history[$this->posHistory-1];
$this->redraw();
}
if ($this->posCursor == -1) {
$this->posCursor = strlen($this->buffer);
}
$this->redraw();
break;
case "\e[B": // down
if ($this->posCursor == strlen($this->buffer)) {
$this->posCursor = -1;
}
if ($this->posHistory > 1) {
$this->posHistory--;
$this->buffer = $this->history[$this->posHistory-1];
$this->redraw();
} elseif ($this->posHistory > 0) {
$this->posHistory--;
$this->buffer = $this->stashedBuffer;
$this->redraw();
}
if ($this->posCursor == -1) {
$this->posCursor = strlen($this->buffer);
}
$this->redraw();
break;
default:
fprintf(STDERR, "\n%s\n", substr($code,1));