Skip to content

Commit 946ad01

Browse files
author
FriedrichWeinmann
committed
Added header generating function
1 parent 88b752f commit 946ad01

3 files changed

Lines changed: 164 additions & 2 deletions

File tree

PSModuleDevelopment/PSModuleDevelopment.psproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Synchronized="True" SyncFilter="*.ps1;*.psm1;*.psd1;*.psxml;*.psf;*.pss;*.xml; *.txt">
1+
<Project Synchronized="True" SyncFilter="*.ps1;*.psm1;*.psd1;*.psxml;*.psf;*.pss;*.xml; *.txt;*.dll">
22
<Version>2.0</Version>
33
<FileID>37dd5fce-e7b5-4d57-ac37-832055ce49d6</FileID>
44
<ProjectType>1</ProjectType>
@@ -17,6 +17,9 @@
1717
<Folder>functions\format</Folder>
1818
<Folder>functions\refactor</Folder>
1919
<Folder>functions\assembly</Folder>
20+
<Folder>bin</Folder>
21+
<Folder>xml</Folder>
22+
<Folder>internal\scripts\NewFolder1</Folder>
2023
</Folders>
2124
<Files>
2225
<File Build="2">PSModuleDevelopment.psd1</File>
@@ -44,6 +47,11 @@
4447
<File Build="2" Shared="True" ReferenceFunction="Invoke-Rename-PSMDParameter_ps1">functions\refactor\Rename-PSMDParameter.ps1</File>
4548
<File Build="2" Shared="True" ReferenceFunction="Invoke-Expand-PSMDTypeName_ps1">functions\assembly\Expand-PSMDTypeName.ps1</File>
4649
<File Build="2" Shared="True" ReferenceFunction="Invoke-Set-PSMDParameterHelp_ps1">functions\refactor\Set-PSMDParameterHelp.ps1</File>
50+
<File Build="2">bin\PSModuleDevelopment.xml</File>
51+
<File Build="2" Shared="True" ReferenceFunction="Invoke-Set-PSMDCmdletBinding_ps1">functions\refactor\Set-PSMDCmdletBinding.ps1</File>
52+
<File Build="2" Shared="True" ReferenceFunction="Invoke-Split-PSMDScriptFile_ps1">functions\refactor\Split-PSMDScriptFile.ps1</File>
53+
<File Build="2">bin\PSModuleDevelopment.dll</File>
54+
<File Build="2" Shared="True" ReferenceFunction="Invoke-New-PSMDHeader_ps1">functions\utility\New-PSMDHeader.ps1</File>
4755
</Files>
4856
<StartupScript>F:\Synchronized Data\Scripte\Powershell Studio\Projects\PSModuleDevelopment\Test-Module.ps1</StartupScript>
4957
</Project>
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
}

PSModuleDevelopment/internal/scripts/preload.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ if (-not (Test-Path $root)) { New-Item $root -ItemType Directory -Force | Out-Nu
2727
# If the config file doesn't exist yet, create it
2828
if (-not (Test-Path $PSModuleDevelopment_ModuleConfigPath)) { Export-Clixml -InputObject @() -Path $PSModuleDevelopment_ModuleConfigPath}
2929

30-
#endregion Ensure Config path exists
30+
#endregion Ensure Config path exists
31+
32+
# Pass on the host UI to the library
33+
[PSModuleDevelopment.Utility.UtilityHost]::RawUI = $host.UI.RawUI

0 commit comments

Comments
 (0)