From 482d8a54e5aa295a4ad39429f741a00ffdaec311 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Sat, 12 Nov 2016 16:37:51 +0100 Subject: [PATCH] Prompt can now be set before linereader is created --- lib/LineRead.php | 4 ++-- lib/Shell.php | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/LineRead.php b/lib/LineRead.php index 9e21609..9710387 100644 --- a/lib/LineRead.php +++ b/lib/LineRead.php @@ -68,11 +68,11 @@ class LineRead $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"; - 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) diff --git a/lib/Shell.php b/lib/Shell.php index 5b971f5..5833f76 100644 --- a/lib/Shell.php +++ b/lib/Shell.php @@ -19,6 +19,8 @@ class Shell protected $timers = []; + protected $prompt = ">"; + public function __construct() { $this->configure(); @@ -162,10 +164,11 @@ class Shell public function setPrompt($text) { - if (!$this->lineReader) { - return; + $this->prompt = $text; + + if ($this->lineReader) { + $this->lineReader->setPromptText($text); } - $this->lineReader->setPromptText($text); } /** @@ -314,7 +317,7 @@ class Shell { $this->lineReader = new LineRead(); - $this->lineReader->setPromptText("shell>"); + $this->lineReader->setPromptText($this->prompt); $this->lineReader->setPromptStyle(new Style(Style::BR_GREEN)); $this->lineReader->setCommandStyle(new Style(Style::GREEN));