diff --git a/lib/AutoComplete/Hinter.php b/lib/AutoComplete/Hinter.php deleted file mode 100644 index a1c4acd..0000000 --- a/lib/AutoComplete/Hinter.php +++ /dev/null @@ -1,14 +0,0 @@ -prompt; $buffer = $this->buffer; + + if ($this->posCursor > strlen($this->buffer)) { + $this->posCursor = strlen($this->buffer); + } + $cursor = strlen($this->prompt) + 1 + $this->posCursor - $this->posScroll; $endStyle = "\e[0m"; @@ -85,6 +92,10 @@ class LineRead $returnBuffer = null; while (strlen($keyBuffer)>0) { if ($keyBuffer[0] == "\e") { + if (strlen($keyBuffer)==1) { + $keyBuffer = ""; + return "\e"; + } if ($keyBuffer[1] == "[") { $ctrlChar = substr($keyBuffer, 0,3); $keyBuffer = substr($keyBuffer, 3); @@ -113,6 +124,7 @@ class LineRead } } elseif ($keyCode == 13) { $returnBuffer = $this->buffer; + array_unshift($this->history, $this->buffer); $this->buffer = null; $this->posCursor = 0; printf("\n\r"); @@ -146,7 +158,25 @@ class LineRead $this->redraw(); break; case "\e[A": // up + if ($this->posHistory == 0) { + $this->stashedBuffer = $this->buffer; + } + if ($this->posHistory < count($this->history)) { + $this->posHistory++; + $this->buffer = $this->history[$this->posHistory-1]; + $this->redraw(); + } + break; case "\e[B": // down + 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(); + } break; default: fprintf(STDERR, "\n%s\n", substr($code,1)); diff --git a/lib/Shell.php b/lib/Shell.php index dd4e787..7576da7 100644 --- a/lib/Shell.php +++ b/lib/Shell.php @@ -300,8 +300,14 @@ class Shell if (!($buffer = $this->lineReader->update())) { usleep(10000); } + // Escape is handy too... + if ($buffer == "\e") { + $this->dispatchEvent("shell.abort"); + continue; + } // we get a ^C on ^C, so deal with the ^C. if ($buffer == "\x03") { + $this->dispatchEvent("shell.stop"); $this->stop(); continue; }