Command and prompt style can be modified
This commit is contained in:
@ -26,6 +26,10 @@ class LineRead
|
||||
|
||||
protected $sttyOld;
|
||||
|
||||
protected $commandStyle;
|
||||
|
||||
protected $promptStyle;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
stream_set_blocking(STDIN, false);
|
||||
@ -58,7 +62,20 @@ class LineRead
|
||||
$prompt = $this->prompt;
|
||||
$buffer = $this->buffer;
|
||||
$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);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
protected function styleToAnsi($style)
|
||||
{
|
||||
if (!$style) {
|
||||
return;
|
||||
}
|
||||
return "\e[0;".$style."m";
|
||||
}
|
||||
|
||||
protected function handleInput()
|
||||
@ -137,10 +154,18 @@ class LineRead
|
||||
fprintf(STDERR, "\n%s\n", substr($code,1));
|
||||
}
|
||||
}
|
||||
|
||||
public function setCommandStyle($style)
|
||||
{
|
||||
$this->commandStyle = $style;
|
||||
}
|
||||
|
||||
public function setPrompt($prompt)
|
||||
public function setPrompt($prompt, $style=null)
|
||||
{
|
||||
$this->prompt = $prompt;
|
||||
if ($style) {
|
||||
$this->promptStyle = $style;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user