1+ function New-PSMDHeader
2+ {
3+ <#
4+ . SYNOPSIS
5+ Generates a header wrapping around text.
6+
7+ . DESCRIPTION
8+ Generates a header wrapping around text.
9+ The output is an object that contains the configuration options to generate a header.
10+ Use its ToString() method (or cast it to string) to generate the header.
11+
12+ . PARAMETER Text
13+ The text to wrap into a header.
14+ Can handle multiline text.
15+ When passing a list of strings, each string will be wrapped into its own header.
16+
17+ . PARAMETER BorderBottom
18+ The border used for the bottom of the frame. Use a single letter, such as "-"
19+
20+ . PARAMETER BorderLeft
21+ The border used for the left side of the frame.
22+
23+ . PARAMETER BorderRight
24+ The border used for the right side of the frame.
25+
26+ . PARAMETER BorderTop
27+ The border used for the top of the frame. Use a single letter, such as "-"
28+
29+ . PARAMETER CornerLB
30+ The symbol used for the left-bottom corner of the frame
31+
32+ . PARAMETER CornerLT
33+ The symbol used for the left-top corner of the frame
34+
35+ . PARAMETER CornerRB
36+ The symbol used for the right-bottom corner of the frame
37+
38+ . PARAMETER CornerRT
39+ The symbol used for the right-top corner of the frame
40+
41+ . PARAMETER MaxWidth
42+ Whether to align the frame's total width to the window width.
43+
44+ . PARAMETER Padding
45+ Whether the text should be padded.
46+ Only applies to left/right aligned text.
47+
48+ . PARAMETER TextAlignment
49+ Default: Center
50+ Whether the text should be aligned left, center or right.
51+
52+ . PARAMETER Width
53+ Total width of the header.
54+ Defaults to entire screen.
55+
56+ . EXAMPLE
57+ PS C:\> New-PSMDHeader -Text 'Example'
58+
59+ Will create a header labeled 'Example' that spans the entire screen.
60+
61+ . EXAMPLE
62+ PS C:\> New-PSMDHeader -Text 'Example' -Width 80
63+
64+ Will create a header labeled 'Example' with a total width of 80:
65+ #----------------------------------------------------------------------------#
66+ # Example #
67+ #----------------------------------------------------------------------------#
68+
69+ . EXAMPLE
70+ PS C:\> New-PSMDHeader -Text 'Example' -Width 80 -BorderLeft " |" -BorderRight "| " -CornerLB " \" -CornerLT " /" -CornerRB "/" -CornerRT "\"
71+
72+ Will create a header labeled "Example with a total width of 80 and some custom border lines:
73+ /----------------------------------------------------------------------------\
74+ | Example |
75+ \----------------------------------------------------------------------------/
76+ #>
77+ [CmdletBinding ()]
78+ Param (
79+ [Parameter (Mandatory = $true , Position = 0 , ValueFromPipeline = $true )]
80+ [string []]
81+ $Text ,
82+
83+ [string ]
84+ $BorderBottom = " -" ,
85+
86+ [string ]
87+ $BorderLeft = " #" ,
88+
89+ [string ]
90+ $BorderRight = " # " ,
91+
92+ [string ]
93+ $BorderTop = " -" ,
94+
95+ [string ]
96+ $CornerLB = " #" ,
97+
98+ [string ]
99+ $CornerLT = " #" ,
100+
101+ [string ]
102+ $CornerRB = " # " ,
103+
104+ [string ]
105+ $CornerRT = " # " ,
106+
107+ [switch ]
108+ $MaxWidth ,
109+
110+ [int ]
111+ $Padding = 0 ,
112+
113+ [PSModuleDevelopment.Utility.TextAlignment ]
114+ $TextAlignment = " Center" ,
115+
116+ [int ]
117+ $Width = $Host.UI.RawUI.WindowSize.Width
118+ )
119+
120+ process
121+ {
122+ foreach ($line in $Text )
123+ {
124+ $header = New-Object PSModuleDevelopment.Utility.TextHeader($line )
125+
126+ $header.BorderBottom = $BorderBottom
127+ $header.BorderLeft = $BorderLeft
128+ $header.BorderRight = $BorderRight
129+ $header.BorderTop = $BorderTop
130+ $header.CornerLB = $CornerLB
131+ $header.CornerLT = $CornerLT
132+ $header.CornerRB = $CornerRB
133+ $header.CornerRT = $CornerRT
134+ $header.Padding = $Padding
135+ $header.TextAlignment = $TextAlignment
136+
137+ if ((Test-PSFParameterBinding - ParameterName Width) -and (Test-PSFParameterBinding - ParameterName MaxWidth -Not ))
138+ {
139+ $header.MaxWidth = $false
140+ $header.Width = $Width
141+ }
142+ else
143+ {
144+ $header.MaxWidth = $MaxWidth
145+ $header.Width = $Width
146+ }
147+
148+ $header
149+ }
150+ }
151+ }
0 commit comments