theme->classNameColor, format: ConsoleFormat::BOLD); // Top border $output[] = '╔' . str_repeat('═', $width - 2) . '╗'; // Title $titlePadded = str_pad($title, $width - 4); $output[] = '║ ' . $titleStyle->apply($titlePadded) . ' ║'; // Subtitle (if provided) if ($subtitle !== null) { $subtitleStyle = ConsoleStyle::create(color: $this->theme->metadataColor); $subtitlePadded = str_pad($subtitle, $width - 4); $output[] = '║ ' . $subtitleStyle->apply($subtitlePadded) . ' ║'; } // Bottom border $output[] = '╚' . str_repeat('═', $width - 2) . '╝'; return implode("\n", $output); } /** * Render a footer */ public function renderFooter(string $content, int $width = 80): string { $output = []; $footerStyle = ConsoleStyle::create(color: $this->theme->metadataColor); // Top border $output[] = '╔' . str_repeat('═', $width - 2) . '╗'; // Content $contentPadded = str_pad($content, $width - 4); $output[] = '║ ' . $footerStyle->apply($contentPadded) . ' ║'; // Bottom border $output[] = '╚' . str_repeat('═', $width - 2) . '╝'; return implode("\n", $output); } /** * Apply ANSI formatting to text */ public function applyStyle(string $text, ConsoleColor $color, ?ConsoleFormat $format = null): string { $style = ConsoleStyle::create(color: $color, format: $format); return $style->apply($text); } /** * Wrap text to fit width */ public function wrapText(string $text, int $width): array { $lines = explode("\n", $text); $wrapped = []; foreach ($lines as $line) { if (mb_strlen($line) <= $width) { $wrapped[] = $line; } else { $wrapped = array_merge($wrapped, $this->splitLine($line, $width)); } } return $wrapped; } private function splitLine(string $line, int $width): array { $words = explode(' ', $line); $currentLine = ''; $result = []; foreach ($words as $word) { $testLine = empty($currentLine) ? $word : $currentLine . ' ' . $word; if (mb_strlen($testLine) <= $width) { $currentLine = $testLine; } else { if (!empty($currentLine)) { $result[] = $currentLine; $currentLine = $word; } else { $result[] = mb_substr($word, 0, $width); $currentLine = mb_substr($word, $width); } } } if (!empty($currentLine)) { $result[] = $currentLine; } return $result ?: ['']; } }