diff --git a/lib/LineRead.php b/lib/LineRead.php index 9710387..cf80e5f 100644 --- a/lib/LineRead.php +++ b/lib/LineRead.php @@ -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));