Prompt can now be set before linereader is created
This commit is contained in:
parent
b2a23f992d
commit
482d8a54e5
@ -68,11 +68,11 @@ class LineRead
|
|||||||
$this->posCursor = strlen($this->buffer);
|
$this->posCursor = strlen($this->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cursor = strlen($this->prompt) + 1 + $this->posCursor - $this->posScroll;
|
$cursor = strlen($this->prompt) + 2 + $this->posCursor - $this->posScroll;
|
||||||
|
|
||||||
$endStyle = "\e[0m";
|
$endStyle = "\e[0m";
|
||||||
|
|
||||||
fprintf(STDOUT, "\r\e[2K%s%s\e[%dG{$endStyle}", ($this->promptStyle)($prompt), ($this->commandStyle)($buffer), $cursor);
|
fprintf(STDOUT, "\r\e[2K%s %s\e[%dG{$endStyle}", ($this->promptStyle)($prompt), ($this->commandStyle)($buffer), $cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function styleToAnsi($style)
|
protected function styleToAnsi($style)
|
||||||
|
@ -19,6 +19,8 @@ class Shell
|
|||||||
|
|
||||||
protected $timers = [];
|
protected $timers = [];
|
||||||
|
|
||||||
|
protected $prompt = ">";
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->configure();
|
$this->configure();
|
||||||
@ -162,11 +164,12 @@ class Shell
|
|||||||
|
|
||||||
public function setPrompt($text)
|
public function setPrompt($text)
|
||||||
{
|
{
|
||||||
if (!$this->lineReader) {
|
$this->prompt = $text;
|
||||||
return;
|
|
||||||
}
|
if ($this->lineReader) {
|
||||||
$this->lineReader->setPromptText($text);
|
$this->lineReader->setPromptText($text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a command and return a closure.
|
* Find a command and return a closure.
|
||||||
@ -314,7 +317,7 @@ class Shell
|
|||||||
{
|
{
|
||||||
$this->lineReader = new LineRead();
|
$this->lineReader = new LineRead();
|
||||||
|
|
||||||
$this->lineReader->setPromptText("shell>");
|
$this->lineReader->setPromptText($this->prompt);
|
||||||
$this->lineReader->setPromptStyle(new Style(Style::BR_GREEN));
|
$this->lineReader->setPromptStyle(new Style(Style::BR_GREEN));
|
||||||
$this->lineReader->setCommandStyle(new Style(Style::GREEN));
|
$this->lineReader->setCommandStyle(new Style(Style::GREEN));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user