Improved the cursor in LineRead when using history
This commit is contained in:
		@@ -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));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user