Improved the cursor in LineRead when using history
This commit is contained in:
parent
43a6475192
commit
bdec60717f
@ -161,22 +161,33 @@ class LineRead
|
|||||||
if ($this->posHistory == 0) {
|
if ($this->posHistory == 0) {
|
||||||
$this->stashedBuffer = $this->buffer;
|
$this->stashedBuffer = $this->buffer;
|
||||||
}
|
}
|
||||||
|
if ($this->posCursor == strlen($this->buffer)) {
|
||||||
|
$this->posCursor = -1;
|
||||||
|
}
|
||||||
if ($this->posHistory < count($this->history)) {
|
if ($this->posHistory < count($this->history)) {
|
||||||
$this->posHistory++;
|
$this->posHistory++;
|
||||||
$this->buffer = $this->history[$this->posHistory-1];
|
$this->buffer = $this->history[$this->posHistory-1];
|
||||||
$this->redraw();
|
|
||||||
}
|
}
|
||||||
|
if ($this->posCursor == -1) {
|
||||||
|
$this->posCursor = strlen($this->buffer);
|
||||||
|
}
|
||||||
|
$this->redraw();
|
||||||
break;
|
break;
|
||||||
case "\e[B": // down
|
case "\e[B": // down
|
||||||
|
if ($this->posCursor == strlen($this->buffer)) {
|
||||||
|
$this->posCursor = -1;
|
||||||
|
}
|
||||||
if ($this->posHistory > 1) {
|
if ($this->posHistory > 1) {
|
||||||
$this->posHistory--;
|
$this->posHistory--;
|
||||||
$this->buffer = $this->history[$this->posHistory-1];
|
$this->buffer = $this->history[$this->posHistory-1];
|
||||||
$this->redraw();
|
|
||||||
} elseif ($this->posHistory > 0) {
|
} elseif ($this->posHistory > 0) {
|
||||||
$this->posHistory--;
|
$this->posHistory--;
|
||||||
$this->buffer = $this->stashedBuffer;
|
$this->buffer = $this->stashedBuffer;
|
||||||
$this->redraw();
|
|
||||||
}
|
}
|
||||||
|
if ($this->posCursor == -1) {
|
||||||
|
$this->posCursor = strlen($this->buffer);
|
||||||
|
}
|
||||||
|
$this->redraw();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(STDERR, "\n%s\n", substr($code,1));
|
fprintf(STDERR, "\n%s\n", substr($code,1));
|
||||||
|
Loading…
Reference in New Issue
Block a user