From 2fb8b9254906338540ecb67aaf61ff5ddcf81642 Mon Sep 17 00:00:00 2001 From: Pavex Date: Mon, 28 Aug 2023 19:31:12 +0200 Subject: [PATCH] Inserts any text before the menu serving as a header. For example, you can display the application status, name, version, etc. --- src/Builder/CliMenuBuilder.php | 7 +++++++ src/CliMenu.php | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Builder/CliMenuBuilder.php b/src/Builder/CliMenuBuilder.php index 67e3cab..fcacbc6 100644 --- a/src/Builder/CliMenuBuilder.php +++ b/src/Builder/CliMenuBuilder.php @@ -108,6 +108,13 @@ public static function newSubMenu(Terminal $terminal) : self return $instance; } + public function setHeader(string $header) : self + { + $this->menu->setHeader($header); + + return $this; + } + public function setTitle(string $title) : self { $this->menu->setTitle($title); diff --git a/src/CliMenu.php b/src/CliMenu.php index f3f9de7..cda4cf4 100644 --- a/src/CliMenu.php +++ b/src/CliMenu.php @@ -47,6 +47,11 @@ class CliMenu */ private $itemStyleLocator; + /** + * @var ?string + */ + protected $header; + /** * @var ?string */ @@ -143,6 +148,11 @@ private function assertTerminalIsValidTTY() : void } } + public function setHedader(string $header) : void + { + $this->header = $header; + } + public function setTitle(string $title) : void { $this->title = $title; @@ -493,7 +503,12 @@ protected function draw() : void { $frame = new Frame; - $frame->newLine(2); + if ($this->header) { + $frame -> addRow($this->header); + } + else { + $frame->newLine(2); + } if ($this->style->getBorderTopWidth() > 0) { $frame->addRows($this->style->getBorderTopRows());