From 18a46fed12bba8ebfcc00f6d413f6b1563474531 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 13 Mar 2026 18:04:58 +0100 Subject: [PATCH 1/2] Improve rendering of admonitions --- CHANGELOG.md | 6 ++ src/Console/Style/TorrStyle.php | 114 +++++++++++++++++++++++++++++--- 2 files changed, 111 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf033df..c419401 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +1.4.0 +===== + +* (feature) Improve rendering of admonitions. + + 1.3.0 ===== diff --git a/src/Console/Style/TorrStyle.php b/src/Console/Style/TorrStyle.php index cc2dbc1..46969dc 100644 --- a/src/Console/Style/TorrStyle.php +++ b/src/Console/Style/TorrStyle.php @@ -127,18 +127,114 @@ public function createProgressBar ( } /** - * + * @param string[]|string $message */ #[\Override] public function info (array|string $message) : void { - $this->block( - $message, - "INFO", - 'fg=white;bg=blue', - ' ', - true, - ); + $this->renderAdmonition($message, "💡", "black", "blue"); + } + + /** + * @param string[]|string $message + */ + #[\Override] + public function warning (array|string $message) : void + { + $this->renderAdmonition($message, "🚨", "black", "yellow"); + } + + /** + * @param string[]|string $message + */ + #[\Override] + public function caution (array|string $message) : void + { + $this->renderAdmonition($message, "🚧", "black", "red"); + } + + /** + * @param string[]|string $message + */ + #[\Override] + public function error (array|string $message) : void + { + $this->renderAdmonition($message, "🔴", "black", "red"); + } + + /** + * @param string[]|string $message + */ + #[\Override] + public function note (array|string $message) : void + { + $this->renderAdmonition($message, "📝", "black", "cyan"); + } + + /** + * Renders a styled admonition box with rounded corners and solid background fill. + * + * Each line is wrapped in the style tag so the background color covers the full + * content width, producing a solid colored band with rounded corners: + * + * ╭──────────────────────────────────────────────╮ + * │ LABEL Message text padded to fill the line │ + * ╰──────────────────────────────────────────────╯ + * + * Line anatomy (total = lineLength): + * border: ╭ + {innerWidth + 2 dashes} + ╮ = innerWidth + 3 + * content: │ + space + {innerWidth chars} + space + │ = innerWidth + 4 + * Both are preceded by one leading space → innerWidth = lineLength - 5 + */ + private function renderAdmonition ( + array|string $message, + string $label, + string $foreground, + string $background, + ) : void + { + $messages = array_values(array_filter((array) $message)); + $lineLength = $this->getLineLength(); + + // Inner content area width that makes each line exactly lineLength chars. + // {paddingH} + {innerWidth} + {paddingH} = innerWidth + paddingH * 2 + $innerWidth = $lineLength - 6; + + // "LABEL " prefix on the first line; subsequent lines indented to match + $labelPrefix = $label . ' '; + $labelPrefixLen = mb_strwidth($labelPrefix); + $textWidth = max(1, $innerWidth - $labelPrefixLen); + $indent = str_repeat(' ', $labelPrefixLen); + + $contentLines = []; + + foreach ($messages as $i => $msg) + { + foreach (explode("\n", wordwrap($msg, $textWidth, "\n", true)) as $j => $line) + { + $contentLines[] = (0 === $i && 0 === $j ? $labelPrefix : $indent) . $line; + } + } + + // Each line is fully wrapped in the style tag so the background color fills + // every character cell — spaces become the solid fill. + // Width: {paddingH} + {innerWidth} + {paddingH} = innerWidth + paddingH * 2 = lineLength + $paddingH = 2; + $tag = "fg={$foreground};bg={$background}"; + $blank = \sprintf('<%s>%s', $tag, str_repeat(' ', $innerWidth + $paddingH * 2)); + + $this->newLine(); + $this->writeln($blank); + + foreach ($contentLines as $line) + { + $padding = str_repeat(' ', max(0, $innerWidth - mb_strwidth($line))); + $horizontalPad = str_repeat(' ', $paddingH); + $this->writeln(\sprintf('<%s>%s%s%s%s', $tag, $horizontalPad, $line, $padding, $horizontalPad)); + } + + $this->writeln($blank); + $this->newLine(); } /** @@ -146,7 +242,7 @@ public function info (array|string $message) : void */ public function done (string $message) : void { - $this->write(\sprintf( + $this->writeln(\sprintf( "✓ %s", $message, )); From 2c17608e8e5e7477275ef63af2e533679db1be84 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Fri, 13 Mar 2026 18:15:21 +0100 Subject: [PATCH 2/2] Improve styling of `comment()` and `done()` --- CHANGELOG.md | 1 + src/Console/Style/TorrStyle.php | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c419401..e7510c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ===== * (feature) Improve rendering of admonitions. +* (improvement) Improve styling of `comment()` and `done()`. 1.3.0 diff --git a/src/Console/Style/TorrStyle.php b/src/Console/Style/TorrStyle.php index 46969dc..659d80a 100644 --- a/src/Console/Style/TorrStyle.php +++ b/src/Console/Style/TorrStyle.php @@ -141,7 +141,7 @@ public function info (array|string $message) : void #[\Override] public function warning (array|string $message) : void { - $this->renderAdmonition($message, "🚨", "black", "yellow"); + $this->renderAdmonition($message, "🚨", "black", "#FFD700"); } /** @@ -150,7 +150,7 @@ public function warning (array|string $message) : void #[\Override] public function caution (array|string $message) : void { - $this->renderAdmonition($message, "🚧", "black", "red"); + $this->renderAdmonition($message, "🚧", "black", "#FF8700"); } /** @@ -168,7 +168,7 @@ public function error (array|string $message) : void #[\Override] public function note (array|string $message) : void { - $this->renderAdmonition($message, "📝", "black", "cyan"); + $this->renderAdmonition($message, "📝", "black", "#CCCCCC"); } /** @@ -237,15 +237,22 @@ private function renderAdmonition ( $this->newLine(); } + /** + */ + #[\Override] + public function comment (array|string $message) : void + { + $this->block($message, null, null, ' // ', false, false); + } + /** * A smaller way to mark something as done + * + * @param string[]|string $message */ - public function done (string $message) : void + public function done (array|string $message = "done") : void { - $this->writeln(\sprintf( - "✓ %s", - $message, - )); + $this->block($message, null, null, ' ✓ ', false, false); } /**