Skip to content

Commit 2d38585

Browse files
committed
Simplify Ascii banner
- Simplify Ascii banner so that it displays correctly for all languages
1 parent 7fa7c9f commit 2d38585

File tree

2 files changed

+30
-83
lines changed

2 files changed

+30
-83
lines changed

Src/Private/Draw-AsciiBanner.ps1

Lines changed: 25 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,50 @@
11
function Draw-AsciiBanner {
22
<#
33
.SYNOPSIS
4-
Draws a decorative ASCII banner box around text for console output.
4+
Draws a decorative banner with text for console output.
55
.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.
109
.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.
1211
.PARAMETER TextColor
1312
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.
1917
.EXAMPLE
20-
Draw-AsciiBanner -Lines @("Welcome", "AsBuiltReport") -TextColor 'Cyan' -BorderColor 'Cyan'
18+
Draw-AsciiBanner -Lines @("Welcome", "AsBuiltReport") -TextColor 'Cyan' -SeparatorColor 'Cyan'
2119
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.
2321
.EXAMPLE
24-
Draw-AsciiBanner -Lines @("Configuration") -TextColor 'Green' -BorderColor 'Yellow' -ExtraPadding 5
22+
Draw-AsciiBanner -Lines @("Configuration") -TextColor 'Green' -SeparatorColor 'Yellow'
2523
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.
2725
.NOTES
2826
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.
3128
#>
3229
param(
3330
[string[]]$Lines,
3431
[string]$TextColor,
35-
[string]$BorderColor,
36-
[int]$ExtraPadding = 2
32+
[string]$SeparatorColor,
33+
[int]$SeparatorLength = 60
3734
)
3835

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
4339

44-
$width = 0
45-
foreach ($char in $Text.ToCharArray()) {
46-
$codePoint = [int][char]$char
40+
# Draw top separator
41+
Write-Host $separatorLine -ForegroundColor $SeparatorColor
4742

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
7144
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
7646
}
7747

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
10350
}

Src/Public/New-AsBuiltConfig.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function New-AsBuiltConfig {
4141
Clear-Host
4242
#region Report configuration
4343
# Show As Built Report configuration banner
44-
Draw-AsciiBanner -Lines @($translate.ReportInfo.BannerTitle) -ExtraPadding 4 -TextColor 'Cyan' -BorderColor 'Cyan'
44+
Draw-AsciiBanner -Lines @($translate.ReportInfo.BannerTitle) -TextColor 'Cyan' -SeparatorColor 'Cyan'
4545

4646
$ReportAuthor = Read-Host -Prompt ($translate.ReportInfo.ReportAuthor -f [System.Environment]::Username)
4747
if (($null -eq $ReportAuthor) -or ($ReportAuthor -eq "")) {
@@ -56,7 +56,7 @@ function New-AsBuiltConfig {
5656
#region Company configuration
5757
Clear-Host
5858
# Show Company configuration banner
59-
Draw-AsciiBanner -Lines @($translate.CompanyConfig.BannerTitle) -ExtraPadding 4 -TextColor 'Cyan' -BorderColor 'Cyan'
59+
Draw-AsciiBanner -Lines @($translate.CompanyConfig.BannerTitle) -TextColor 'Cyan' -SeparatorColor 'Cyan'
6060

6161
$CompanyInfo = Read-Host -Prompt $translate.CompanyConfig.CompanyInfo
6262
if (($null -eq $CompanyInfo) -or ($CompanyInfo -eq "")) {
@@ -107,7 +107,7 @@ function New-AsBuiltConfig {
107107
#region Email configuration
108108
Clear-Host
109109
# Show Email configuration banner
110-
Draw-AsciiBanner -Lines @($translate.EmailConfig.BannerTitle) -ExtraPadding 4 -TextColor 'Cyan' -BorderColor 'Cyan'
110+
Draw-AsciiBanner -Lines @($translate.EmailConfig.BannerTitle) -TextColor 'Cyan' -SeparatorColor 'Cyan'
111111
if (-not ($SendEmail)) {
112112
$ConfigureMailSettings = Read-Host -Prompt $translate.EmailConfig.ConfigureMailSettings
113113
if (($null -eq $ConfigureMailSettings) -or ($ConfigureMailSettings -eq "")) {
@@ -306,7 +306,7 @@ function New-AsBuiltConfig {
306306
if ($Report -and (-not $ReportConfigFilePath)) {
307307
Clear-Host
308308
# Show Rerport configuration banner
309-
Draw-AsciiBanner -Lines @($translate.ReportConfig.BannerTitle) -ExtraPadding 4 -TextColor 'Cyan' -BorderColor 'Cyan'
309+
Draw-AsciiBanner -Lines @($translate.ReportConfig.BannerTitle) -TextColor 'Cyan' -SeparatorColor 'Cyan'
310310
$DefaultConfigFolder = Join-Path -Path $Home -ChildPath "AsBuiltReport"
311311
$ReportConfigFolder = Read-Host -Prompt ($translate.ReportConfig.ReportConfigFolder -f $DefaultConfigFolder)
312312
if (($null -eq $ReportConfigFolder) -or ($ReportConfigFolder -eq "")) {
@@ -373,7 +373,7 @@ function New-AsBuiltConfig {
373373

374374
#region Save configuration
375375
Clear-Host
376-
Draw-AsciiBanner -Lines @($translate.ReportConfig.BannerTitle) -ExtraPadding 4 -TextColor 'Cyan' -BorderColor 'Cyan'
376+
Draw-AsciiBanner -Lines @($translate.ReportConfig.BannerTitle) -TextColor 'Cyan' -SeparatorColor 'Cyan'
377377
$SaveAsBuiltConfig = Read-Host -Prompt $translate.ReportConfig.SaveAsBuiltConfig
378378
if (($null -eq $SaveAsBuiltConfig) -or ($SaveAsBuiltConfig -eq "")) {
379379
$SaveAsBuiltConfig = "y"

0 commit comments

Comments
 (0)