Implemented contexts, optimizations
This commit is contained in:
		@@ -34,7 +34,7 @@ class LineRead
 | 
			
		||||
    {
 | 
			
		||||
        stream_set_blocking(STDIN, false);
 | 
			
		||||
        $this->sttyOld = trim(exec('stty -g'));
 | 
			
		||||
        exec('stty raw -echo'); // isig');
 | 
			
		||||
        exec('stty raw -echo opost onlret'); // isig');
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function __destruct()
 | 
			
		||||
@@ -63,11 +63,9 @@ class LineRead
 | 
			
		||||
        $buffer = $this->buffer;
 | 
			
		||||
        $cursor = strlen($this->prompt) + 1 + $this->posCursor - $this->posScroll;
 | 
			
		||||
        
 | 
			
		||||
        $promptStyle = $this->styleToAnsi($this->promptStyle);
 | 
			
		||||
        $commandStyle = $this->styleToAnsi($this->commandStyle);
 | 
			
		||||
        $endStyle = "\e[0m";
 | 
			
		||||
        
 | 
			
		||||
        fprintf(STDOUT, "\r\e[2K{$promptStyle}%s{$commandStyle}%s\e[%dG{$endStyle}", $prompt, $buffer, $cursor);
 | 
			
		||||
        fprintf(STDOUT, "\r\e[2K%s%s\e[%dG{$endStyle}", ($this->promptStyle)($prompt), ($this->commandStyle)($buffer), $cursor);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    protected function styleToAnsi($style)
 | 
			
		||||
@@ -160,12 +158,14 @@ class LineRead
 | 
			
		||||
        $this->commandStyle = $style;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setPrompt($prompt, $style=null)
 | 
			
		||||
    public function setPromptText($prompt)
 | 
			
		||||
    {
 | 
			
		||||
        $this->prompt = $prompt;
 | 
			
		||||
        if ($style) {
 | 
			
		||||
            $this->promptStyle = $style;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function setPromptStyle($style)
 | 
			
		||||
    {
 | 
			
		||||
        $this->promptStyle = $style;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user