Improvements
This commit is contained in:
		@@ -29,13 +29,13 @@ class LineRead
 | 
			
		||||
    public function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        stream_set_blocking(STDIN, false);
 | 
			
		||||
        $this->sttyOld = exec('stty -g');
 | 
			
		||||
        exec('stty raw -echo isig');
 | 
			
		||||
        $this->sttyOld = trim(exec('stty -g'));
 | 
			
		||||
        exec('stty raw -echo'); // isig');
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function __destruct()
 | 
			
		||||
    {
 | 
			
		||||
        exec('stty {$this->sttyOld}');
 | 
			
		||||
        exec('stty '.$this->sttyOld);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function update()
 | 
			
		||||
@@ -57,8 +57,8 @@ class LineRead
 | 
			
		||||
    {
 | 
			
		||||
        $prompt = $this->prompt;
 | 
			
		||||
        $buffer = $this->buffer;
 | 
			
		||||
        $cursor = strlen($this->prompt) + 2 + $this->posCursor - $this->posScroll;
 | 
			
		||||
        fprintf(STDOUT, "\r\e[2K\e[36;1;4m%s\e[37;24m %s\e[%dG\e[0m", $prompt, $buffer, $cursor);
 | 
			
		||||
        $cursor = strlen($this->prompt) + 1 + $this->posCursor - $this->posScroll;
 | 
			
		||||
        fprintf(STDOUT, "\r\e[2K\e[32;1m%s\e[37m%s\e[%dG\e[0m", $prompt, $buffer, $cursor);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    protected function handleInput()
 | 
			
		||||
@@ -75,6 +75,11 @@ class LineRead
 | 
			
		||||
                    $keyBuffer = substr($keyBuffer, 3);
 | 
			
		||||
                    $this->parseControlCode($ctrlChar);
 | 
			
		||||
                }
 | 
			
		||||
            } elseif ($keyBuffer[0]=="\x03") {
 | 
			
		||||
                $this->posCursor = 0;
 | 
			
		||||
                $this->buffer = null;
 | 
			
		||||
                fprintf(STDOUT, "\r\n");
 | 
			
		||||
                return $keyBuffer[0];
 | 
			
		||||
            } else {
 | 
			
		||||
                $keyChar = $keyBuffer[0];
 | 
			
		||||
                $keyCode = ord($keyChar);
 | 
			
		||||
@@ -95,7 +100,7 @@ class LineRead
 | 
			
		||||
                    $returnBuffer = $this->buffer;
 | 
			
		||||
                    $this->buffer = null;
 | 
			
		||||
                    $this->posCursor = 0;
 | 
			
		||||
                    printf("\n");
 | 
			
		||||
                    printf("\n\r");
 | 
			
		||||
                    $this->state = self::STATE_IDLE;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@@ -133,4 +138,9 @@ class LineRead
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setPrompt($prompt)
 | 
			
		||||
    {
 | 
			
		||||
        $this->prompt = $prompt;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user