|
1 | 1 | function Draw-AsciiBanner { |
2 | 2 | <# |
3 | 3 | .SYNOPSIS |
4 | | - Draws a decorative ASCII banner box around text for console output. |
| 4 | + Draws a decorative banner with text for console output. |
5 | 5 | .DESCRIPTION |
6 | | - Draws a decorative ASCII banner box with rounded corners around one or more lines of text. |
7 | | - Uses Unicode box-drawing characters for a clean, modern appearance in the console. |
8 | | - Supports customizable text and border colors, and adjustable padding. |
9 | | - Properly handles double-width characters (CJK, emoji, etc.) for correct alignment. |
| 6 | + Draws a simple banner with horizontal line separators above and below text. |
| 7 | + Uses Unicode characters for a clean appearance that works reliably across all |
| 8 | + languages, scripts, and terminal types. |
10 | 9 | .PARAMETER Lines |
11 | | - An array of strings to display inside the banner. Each string will be centered on its own line. |
| 10 | + An array of strings to display in the banner. Each string will be displayed on its own line. |
12 | 11 | .PARAMETER TextColor |
13 | 12 | The color to use for the text content. Accepts standard PowerShell console colors. |
14 | | - .PARAMETER BorderColor |
15 | | - The color to use for the border characters. Accepts standard PowerShell console colors. |
16 | | - .PARAMETER ExtraPadding |
17 | | - The number of additional spaces to add on each side of the content for padding. |
18 | | - Default is 2 spaces. |
| 13 | + .PARAMETER SeparatorColor |
| 14 | + The color to use for the separator lines. Accepts standard PowerShell console colors. |
| 15 | + .PARAMETER SeparatorLength |
| 16 | + The length of the separator lines. Default is 60 characters. |
19 | 17 | .EXAMPLE |
20 | | - Draw-AsciiBanner -Lines @("Welcome", "AsBuiltReport") -TextColor 'Cyan' -BorderColor 'Cyan' |
| 18 | + Draw-AsciiBanner -Lines @("Welcome", "AsBuiltReport") -TextColor 'Cyan' -SeparatorColor 'Cyan' |
21 | 19 |
|
22 | | - Displays a cyan-colored banner with "Welcome" and "AsBuiltReport" centered on separate lines. |
| 20 | + Displays a cyan-colored banner with "Welcome" and "AsBuiltReport" on separate lines. |
23 | 21 | .EXAMPLE |
24 | | - Draw-AsciiBanner -Lines @("Configuration") -TextColor 'Green' -BorderColor 'Yellow' -ExtraPadding 5 |
| 22 | + Draw-AsciiBanner -Lines @("Configuration") -TextColor 'Green' -SeparatorColor 'Yellow' |
25 | 23 |
|
26 | | - Displays a banner with green text and yellow border, with extra padding of 5 spaces on each side. |
| 24 | + Displays a banner with green text and yellow separator lines. |
27 | 25 | .NOTES |
28 | 26 | This is a private function used internally by the AsBuiltReport.Core module. |
29 | | - Uses Unicode box-drawing characters (U+256D, U+256E, U+2570, U+256F, U+2500, U+2502) for PS 5.1 compatibility. |
30 | | - Calculates display width accounting for double-width characters (CJK ideographs, full-width forms, etc.). |
| 27 | + Uses a simple horizontal line format that works reliably with all character sets. |
31 | 28 | #> |
32 | 29 | param( |
33 | 30 | [string[]]$Lines, |
34 | 31 | [string]$TextColor, |
35 | | - [string]$BorderColor, |
36 | | - [int]$ExtraPadding = 2 |
| 32 | + [string]$SeparatorColor, |
| 33 | + [int]$SeparatorLength = 60 |
37 | 34 | ) |
38 | 35 |
|
39 | | - # Helper function to calculate display width of a string |
40 | | - # Accounts for double-width characters (CJK, emoji, etc.) |
41 | | - function Get-DisplayWidth { |
42 | | - param([string]$Text) |
| 36 | + # Use heavy horizontal line character for visual separation |
| 37 | + $separator = [char]0x2500 # ─ |
| 38 | + $separatorLine = $separator.ToString() * $SeparatorLength |
43 | 39 |
|
44 | | - $width = 0 |
45 | | - foreach ($char in $Text.ToCharArray()) { |
46 | | - $codePoint = [int][char]$char |
| 40 | + # Draw top separator |
| 41 | + Write-Host $separatorLine -ForegroundColor $SeparatorColor |
47 | 42 |
|
48 | | - # Check if character is double-width |
49 | | - # CJK Unified Ideographs: U+4E00-U+9FFF |
50 | | - # CJK Extension A: U+3400-U+4DBF |
51 | | - # Hangul Syllables: U+AC00-U+D7AF |
52 | | - # Hiragana/Katakana: U+3040-U+30FF |
53 | | - # Full-width Forms: U+FF00-U+FFEF |
54 | | - # CJK Symbols and Punctuation: U+3000-U+303F |
55 | | - if (($codePoint -ge 0x4E00 -and $codePoint -le 0x9FFF) -or |
56 | | - ($codePoint -ge 0x3400 -and $codePoint -le 0x4DBF) -or |
57 | | - ($codePoint -ge 0xAC00 -and $codePoint -le 0xD7AF) -or |
58 | | - ($codePoint -ge 0x3040 -and $codePoint -le 0x30FF) -or |
59 | | - ($codePoint -ge 0xFF00 -and $codePoint -le 0xFFEF) -or |
60 | | - ($codePoint -ge 0x3000 -and $codePoint -le 0x303F)) { |
61 | | - $width += 2 |
62 | | - } else { |
63 | | - $width += 1 |
64 | | - } |
65 | | - } |
66 | | - return $width |
67 | | - } |
68 | | - |
69 | | - # Calculate max display width across all lines |
70 | | - $maxDisplayWidth = 0 |
| 43 | + # Draw each line of text with padding |
71 | 44 | foreach ($line in $Lines) { |
72 | | - $displayWidth = Get-DisplayWidth -Text $line |
73 | | - if ($displayWidth -gt $maxDisplayWidth) { |
74 | | - $maxDisplayWidth = $displayWidth |
75 | | - } |
| 45 | + Write-Host " $line" -ForegroundColor $TextColor |
76 | 46 | } |
77 | 47 |
|
78 | | - $contentWidth = $maxDisplayWidth + ($ExtraPadding * 2) |
79 | | - |
80 | | - # Top and bottom borders - use Unicode code points for PS 5.1 compatibility |
81 | | - $topLeft = [char]0x256D # ╭ |
82 | | - $topRight = [char]0x256E # ╮ |
83 | | - $bottomLeft = [char]0x2570 # ╰ |
84 | | - $bottomRight = [char]0x256F # ╯ |
85 | | - $horizontal = [char]0x2500 # ─ |
86 | | - $vertical = [char]0x2502 # │ |
87 | | - |
88 | | - $top = $topLeft + ($horizontal.ToString() * ($contentWidth + 2)) + $topRight |
89 | | - $bottom = $bottomLeft + ($horizontal.ToString() * ($contentWidth + 2)) + $bottomRight |
90 | | - |
91 | | - Write-Host $top -ForegroundColor $BorderColor |
92 | | - foreach ($line in $Lines) { |
93 | | - $lineDisplayWidth = Get-DisplayWidth -Text $line |
94 | | - $totalPadding = $contentWidth - $lineDisplayWidth |
95 | | - $leftPad = [math]::Floor($totalPadding / 2) |
96 | | - $rightPad = $totalPadding - $leftPad |
97 | | - $padded = (' ' * $leftPad) + $line + (' ' * $rightPad) |
98 | | - Write-Host "$vertical " -NoNewline -ForegroundColor $BorderColor |
99 | | - Write-Host $padded -NoNewline -ForegroundColor $TextColor |
100 | | - Write-Host " $vertical" -ForegroundColor $BorderColor |
101 | | - } |
102 | | - Write-Host $bottom -ForegroundColor $BorderColor |
| 48 | + # Draw bottom separator |
| 49 | + Write-Host $separatorLine -ForegroundColor $SeparatorColor |
103 | 50 | } |
0 commit comments