From 37abaed498e1ca981c1cfb61086d9cac8bc51849 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 27 Feb 2026 14:34:23 +0100 Subject: [PATCH 1/2] Add styled info + createTable --- CHANGELOG.md | 7 +++++ src/Console/Style/TorrStyle.php | 50 ++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6612345..a261b49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +1.3.0 +===== + +* (feature) Also provide pre-formatted `createTable()`. +* (feature) Add styled `info()`. + + 1.2.4 ===== diff --git a/src/Console/Style/TorrStyle.php b/src/Console/Style/TorrStyle.php index 553550d..2cd4224 100644 --- a/src/Console/Style/TorrStyle.php +++ b/src/Console/Style/TorrStyle.php @@ -18,8 +18,8 @@ class TorrStyle extends SymfonyStyle private const HIGHLIGHT = "red"; /** - * @inheritDoc */ + #[\Override] public function title (string $message) : void { $length = Helper::width(Helper::removeDecoration($this->getFormatter(), $message)) + 4; @@ -32,8 +32,8 @@ public function title (string $message) : void } /** - * @inheritDoc */ + #[\Override] public function section (string $message) : void { $length = Helper::width(Helper::removeDecoration($this->getFormatter(), $message)); @@ -47,33 +47,40 @@ public function section (string $message) : void } /** - * @inheritDoc - * * @param string[] $headers * @param list|TableSeparator> $rows */ + #[\Override] public function table (array $headers, array $rows) : void { + $this->createTable() + ->setHeaders($headers) + ->setRows($rows) + ->render(); + $this->newLine(); + } + + /** + * + */ + #[\Override] + public function createTable () : Table + { + $table = parent::createTable(); + $style = (new TableStyle()) ->setHorizontalBorderChars('─') ->setVerticalBorderChars('│') ->setCrossingChars('┼', '╭', '┬', '╮', '┤', '╯', '┴', '╰', '├'); $style->setCellHeaderFormat('%s'); - $table = new Table($this); - $table->setHeaders($headers); - $table->setRows($rows); - $table->setStyle($style); - - $table->render(); - $this->newLine(); + return $table->setStyle($style); } /** - * @inheritDoc - * * @param string[] $elements */ + #[\Override] public function listing (array $elements) : void { $this->newLine(); @@ -87,8 +94,8 @@ public function listing (array $elements) : void } /** - * @inheritDoc */ + #[\Override] public function createProgressBar ( int $max = 0, string $format = " %current%/%max% [%bar%] %percent:3s%% %elapsed:6s% %message%", @@ -100,6 +107,21 @@ public function createProgressBar ( return $progressBar; } + /** + * + */ + #[\Override] + public function info (array|string $message) : void + { + $this->block( + $message, + "INFO", + 'fg=white;bg=blue', + ' ', + true, + ); + } + /** * A smaller way to mark something as done */ From bbdacd5ab956cd95deea045cb1cc39c27cba3907 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 27 Feb 2026 14:44:55 +0100 Subject: [PATCH 2/2] Add headline --- CHANGELOG.md | 1 + src/Console/Style/TorrStyle.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a261b49..bf033df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * (feature) Also provide pre-formatted `createTable()`. * (feature) Add styled `info()`. +* (feature) Add `headline()`. 1.2.4 diff --git a/src/Console/Style/TorrStyle.php b/src/Console/Style/TorrStyle.php index 2cd4224..cc2dbc1 100644 --- a/src/Console/Style/TorrStyle.php +++ b/src/Console/Style/TorrStyle.php @@ -9,6 +9,7 @@ use Symfony\Component\Console\Helper\TableSeparator; use Symfony\Component\Console\Helper\TableStyle; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Console\Terminal; /** * 21TORR-branded CLI style @@ -31,6 +32,24 @@ public function title (string $message) : void $this->newLine(); } + /** + * + */ + public function headline (string $message) : void + { + $length = Helper::width(Helper::removeDecoration($this->getFormatter(), $message)); + + $this->writeln([ + "", + \sprintf( + "──── %s %s", + $message, + "" . str_repeat("─", $this->getLineLength() - $length - 6) . "", + ), + "", + ]); + } + /** */ #[\Override] @@ -132,4 +151,16 @@ public function done (string $message) : void $message, )); } + + /** + * Calculates the line length (= width) of the CLI + */ + private function getLineLength ( + int $maxLineLength = 250, + ) : int + { + $width = new Terminal()->getWidth() ?: $maxLineLength; + + return min($width - (int) (\DIRECTORY_SEPARATOR === '\\'), $maxLineLength); + } }