From 725c594fa159f23007a5dbd3bfd3db271cf9ad31 Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 28 Jul 2023 23:20:43 +0100 Subject: [PATCH 1/2] Check for and require tput command to be available The tput command isn't available by default in the Alpine Linux official PHP docker images and this throws an InvalidArgumentException for truncation length. This commit replaces tput in favour of using the Symfony `Terminal` class from Console, which is already part of the package. --- src/Terminal.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Terminal.php b/src/Terminal.php index b74c302f..62bc5e99 100644 --- a/src/Terminal.php +++ b/src/Terminal.php @@ -2,6 +2,8 @@ namespace Laravel\Prompts; +use Symfony\Component\Console\Terminal as Term; + class Terminal { /** @@ -62,7 +64,7 @@ public function restoreTty(): void */ public function cols(): int { - return $this->cols ??= (int) shell_exec('tput cols 2>/dev/null'); + return $this->cols ??= (new Term())->getWidth(); } /** @@ -70,7 +72,7 @@ public function cols(): int */ public function lines(): int { - return $this->lines ??= (int) shell_exec('tput lines 2>/dev/null'); + return $this->lines ??= (new Term())->getHeight(); } /** From f80238bfaf409df720b779de64ae866c7ca6da73 Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Sun, 30 Jul 2023 09:39:30 +1000 Subject: [PATCH 2/2] Formatting --- src/Terminal.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Terminal.php b/src/Terminal.php index 62bc5e99..8d304e67 100644 --- a/src/Terminal.php +++ b/src/Terminal.php @@ -2,7 +2,7 @@ namespace Laravel\Prompts; -use Symfony\Component\Console\Terminal as Term; +use Symfony\Component\Console\Terminal as SymfonyTerminal; class Terminal { @@ -64,7 +64,7 @@ public function restoreTty(): void */ public function cols(): int { - return $this->cols ??= (new Term())->getWidth(); + return $this->cols ??= (new SymfonyTerminal())->getWidth(); } /** @@ -72,7 +72,7 @@ public function cols(): int */ public function lines(): int { - return $this->lines ??= (new Term())->getHeight(); + return $this->lines ??= (new SymfonyTerminal())->getHeight(); } /**