Skip to content

Commit 1967c05

Browse files
Merge pull request #99 from StartAutomating/EZ-Hyperlinks
EZOut 1.9.9
2 parents de5e11a + 7dc2897 commit 1967c05

File tree

10 files changed

+246
-73
lines changed

10 files changed

+246
-73
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 1.9.9:
2+
3+
* Format-RichText -Hyperlink/-Link/-HRef now works (Fixes #93)
4+
* Format-RichText now supports -Alignment and -LineLength (Fixes #45)
5+
* GitHub Action no longer output extra information (Fixes #98)
6+
7+
---
8+
19
## 1.9.8:
210

311
* Format-RichText now supports -Hyperlink (Fixes #93)

EZOut.GitHubAction.PSDevOps.ps1

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
#requires -Module PSDevOps
22
#requires -Module EZOut
33
Import-BuildStep -ModuleName EZOut
4-
New-GitHubAction -Name "UseEZOut" -Description 'Generate Formatting and Types .ps1xml for PowerShell Modules, using EZOut' -Action EZOutAction -Icon code -ActionOutput ([Ordered]@{
5-
EZOutScriptRuntime = [Ordered]@{
6-
description = "The time it took the .EZOutScript parameter to run"
7-
value = '${{steps.EZOutAction.outputs.EZOutScriptRuntime}}'
8-
}
9-
EZOutPS1Runtime = [Ordered]@{
10-
description = "The time it took all .EZOut.ps1 files to run"
11-
value = '${{steps.EZOutAction.outputs.EZOutPS1Runtime}}'
12-
}
13-
EZOutPS1Files = [Ordered]@{
14-
description = "The .EZOut.ps1 files that were run (separated by semicolons)"
15-
value = '${{steps.EZOutAction.outputs.EZOutPS1Files}}'
16-
}
17-
EZOutPS1Count = [Ordered]@{
18-
description = "The number of .EZOut.ps1 files that were run"
19-
value = '${{steps.EZOutAction.outputs.EZOutPS1Count}}'
20-
}
21-
}) |
22-
Set-Content .\action.yml -Encoding UTF8 -PassThru
4+
Push-Location $PSScriptRoot
5+
New-GitHubAction -Name "UseEZOut" -Description @'
6+
Generate Formatting and Types .ps1xml for PowerShell Modules, using EZOut
7+
'@ -Action EZOutAction -Icon code -OutputPath .\action.yml
8+
Pop-Location

EZOut.format.ps1xml

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-16"?>
2-
<!-- Generated with EZOut 1.9.8: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
2+
<!-- Generated with EZOut 1.9.9: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
33
<Configuration>
44
<SelectionSets>
55
<SelectionSet>
@@ -975,7 +975,7 @@ if ($Request -or $Host.UI.SupportsHTML) {
975975
.Notes
976976
Stylized Output works in two contexts at present:
977977
* Rich consoles (Windows Terminal, PowerShell.exe, Pwsh.exe) (when $host.UI.SupportsVirtualTerminal)
978-
* Web pages (Based off the presence of a $Request variable, or when $host.UI.SupportsHTML (you must add this property to $host.UI))
978+
* Web pages (Based off the presence of a $Request variable, or when $host.UI.SupportsHTML (you must add this property to $host.UI))
979979
#&gt;
980980
[Management.Automation.Cmdlet("Format","Object")]
981981
[ValidateScript({
@@ -1032,7 +1032,16 @@ if ($Request -or $Host.UI.SupportsHTML) {
10321032
$Link,
10331033

10341034
# If set, will not clear formatting
1035-
[switch]$NoClear
1035+
[switch]$NoClear,
1036+
1037+
# The alignment. Defaulting to Left.
1038+
# Setting an alignment will pad the remaining space on each line.
1039+
[ValidateSet('Left','Right','Center')]
1040+
[string]
1041+
$Alignment,
1042+
1043+
# The length of a line. By default, the buffer width
1044+
[int]$LineLength = $($host.UI.RawUI.BufferSize.Width)
10361045
)
10371046

10381047
begin {
@@ -1042,6 +1051,19 @@ if ($Request -or $Host.UI.SupportsHTML) {
10421051
Output='';Error='BrightRed';Warning='BrightYellow';
10431052
Verbose='BrightCyan';Debug='Yellow';Progress='Cyan';
10441053
Success='BrightGreen';Failure='Red';Default=''}
1054+
1055+
$ansiCode = [Regex]::new(@'
1056+
(?&lt;ANSI_Code&gt;
1057+
(?-i)\e # An Escape
1058+
\[ # Followed by a bracket
1059+
(?&lt;ParameterBytes&gt;[\d\:\;\&lt;\=\&gt;\?]{0,}) # Followed by zero or more parameter
1060+
bytes
1061+
(?&lt;IntermediateBytes&gt;[\s\!\"\#\$\%\&amp;\'\(\)\*\+\,\-\.\/]{0,}) # Followed by zero or more
1062+
intermediate bytes
1063+
(?&lt;FinalByte&gt;[\@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]\^_\`abcdefghijklmnopqrstuvwxyz\{\|\}\~]) # Followed by a final byte
1064+
1065+
)
1066+
'@)
10451067
$esc = [char]0x1b
10461068
$standardColors = 'Black', 'Red', 'Green', 'Yellow', 'Blue','Magenta', 'Cyan', 'White'
10471069
$brightColors = 'BrightBlack', 'BrightRed', 'BrightGreen', 'BrightYellow', 'BrightBlue','BrightMagenta', 'BrightCyan', 'BrightWhite'
@@ -1227,14 +1249,18 @@ if ($Request -or $Host.UI.SupportsHTML) {
12271249
elseif ($canUseANSI) {'' +$esc + "[21m" }
12281250
}
12291251

1230-
if ($Hyperlink) {
1252+
if ($Alignment -and $canUseHTML) {
1253+
"display:block;text-align:$($Alignment.ToLower())"
1254+
}
1255+
1256+
if ($Link) {
12311257
if ($canUseHTML) {
12321258
# Hyperlinks need to be a nested element
12331259
# so we will not add it to style attributes for HTML
12341260
}
12351261
elseif ($canUseANSI) {
12361262
# For ANSI,
1237-
'' + $esc + ']8m;;' + $Hyperlink + $esc + '\'
1263+
'' + $esc + ']8m;;' + $Link + $esc + '\'
12381264
}
12391265
}
12401266

@@ -1247,8 +1273,8 @@ if ($Request -or $Host.UI.SupportsHTML) {
12471273
)$(
12481274
if ($cssClasses) { " class='$($cssClasses -join ' ')'"}
12491275
)&gt;" + $(
1250-
if ($Hyperlink) {
1251-
"&lt;a href='$hyperLink'&gt;"
1276+
if ($Link) {
1277+
"&lt;a href='$link'&gt;"
12521278
}
12531279
)
12541280
} elseif ($canUseANSI) {
@@ -1257,21 +1283,47 @@ if ($Request -or $Host.UI.SupportsHTML) {
12571283
}
12581284

12591285
process {
1286+
$inputObjectAsString =
1287+
"$(if ($inputObject) { $inputObject | Out-String})".Trim()
1288+
1289+
$inputObjectAsString =
1290+
if ($Alignment -and -not $canUseHTML) {
1291+
(@(foreach ($inputObjectLine in ($inputObjectAsString -split '(?&gt;\r\n|\n)')) {
1292+
$inputObjectLength = $ansiCode.Replace($inputObjectLine, '').Length
1293+
if ($inputObjectLength -lt $LineLength) {
1294+
if ($Alignment -eq 'Left') {
1295+
$inputObjectLine
1296+
} elseif ($Alignment -eq 'Right') {
1297+
(' ' * ($LineLength - $inputObjectLength)) + $inputObjectLine
1298+
} else {
1299+
$half = ($LineLength - $inputObjectLength)/2
1300+
(' ' * [Math]::Floor($half)) + $inputObjectLine +
1301+
(' ' * [Math]::Ceiling($half))
1302+
}
1303+
}
1304+
else {
1305+
$inputObjectLine
1306+
}
1307+
}) -join [Environment]::NewLine) + [Environment]::newline
1308+
} else {
1309+
$inputObjectAsString
1310+
}
1311+
12601312
$allOutput +=
12611313
if ($header) {
1262-
"$header" + "$(if ($inputObject) { $inputObject | Out-String})".Trim()
1314+
"$header" + $inputObjectAsString
12631315
}
12641316
elseif ($inputObject) {
1265-
($inputObject | Out-String).Trim()
1266-
}
1317+
$inputObjectAsString
1318+
}
12671319
}
12681320

12691321
end {
12701322

12711323
if (-not $NoClear) {
12721324
$allOutput +=
12731325
if ($canUseHTML) {
1274-
if ($Hyperlink) {
1326+
if ($Link) {
12751327
"&lt;/a&gt;"
12761328
}
12771329
"&lt;/span&gt;"
@@ -1305,7 +1357,7 @@ if ($Request -or $Host.UI.SupportsHTML) {
13051357
"$esc[49m"
13061358
}
13071359

1308-
if ($Hyperlink) {
1360+
if ($Link) {
13091361
"$esc]8;;$esc\"
13101362
}
13111363

EZOut.psd1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
ModuleToProcess = 'EZOut.psm1'
3-
ModuleVersion = '1.9.8'
3+
ModuleVersion = '1.9.9'
44
GUID = 'cef786f0-8a0b-4a5d-a2c6-b433095354cd'
55
Author = 'James Brundage'
66
CompanyName = 'Start-Automating'
@@ -65,6 +65,14 @@
6565

6666
Tags = '.ps1xml', 'Format','Output','Types', 'Colorized'
6767
ReleaseNotes = @'
68+
## 1.9.9:
69+
70+
* Format-RichText -Hyperlink/-Link/-HRef now works (Fixes #93)
71+
* Format-RichText now supports -Alignment and -LineLength (Fixes #45)
72+
* GitHub Action no longer output extra information (Fixes #98)
73+
74+
---
75+
6876
## 1.9.8:
6977
7078
* Format-RichText now supports -Hyperlink (Fixes #93)

EZOut.tests.ps1

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,13 @@ describe "Write-FormatCustomView" {
438438
[PSCustomObject]@{PSTypeName=$tn;n=1} | Out-String | should -Belike '*This is true*'
439439
}
440440

441-
it "Will render an -Action that has only one token, which is a literal string, as <Text>" {
441+
it "Will render an -Action that has only one token, which is a literal string, as a Text element" {
442442
$fv = Write-formatCustomview -Action { "foobar" }
443443
$fvXml = [xml]$fv
444444
$fvXml.CustomControl.CustomEntries.CustomEntry.CustomItem.Text | should -Be foobar
445445
}
446446

447-
it "Will render an -Action that uses the mythical command Write-NewLine will become a <Newline/>" {
447+
it "Will render an -Action that uses the mythical command Write-NewLine will become a Newline element" {
448448
$fv = Write-FormatCustomView -Action { Write-NewLine }
449449
$fvXml = [xml]$fv
450450
if (-not $fvXml.CustomControl.CustomEntries.CustomEntry.CustomItem.ChildNodes[0].Name -eq 'Newline') {
@@ -470,7 +470,7 @@ describe "Write-FormatCustomView" {
470470
Add-FormatData
471471

472472

473-
[PSCustomObject]@{PSTypeName='HostAwareFormatter';N=1} | Out-String | should -Belike "*normal host*"
473+
[PSCustomObject]@{PSTypeName='HostAwareFormatter';N=1} | Out-String | should -Belike "*normal*host*"
474474
}
475475

476476
it 'Can use a -ViewCondition with a -ViewSelectionSet to match multiple typenames (piping is still required)' {
@@ -486,7 +486,7 @@ describe "Write-FormatCustomView" {
486486
Add-FormatData
487487

488488

489-
[PSCustomObject]@{PSTypeName='HostAwareFormatter';N=1} | Out-String | should -Belike "*normal host*"
489+
[PSCustomObject]@{PSTypeName='HostAwareFormatter';N=1} | Out-String | should -Belike "*normal*host*"
490490
}
491491

492492
it 'Can just run a command with no parameters in -Action' {
@@ -1022,7 +1022,7 @@ describe 'Add-FormatData' {
10221022
Out-FormatData |
10231023
Add-FormatData -PassThru |
10241024
Select-Object -ExpandProperty Name |
1025-
should match 'FormatModule\d+'
1025+
should -Match 'FormatModule\d+'
10261026
}
10271027
}
10281028
}
@@ -1203,4 +1203,34 @@ describe 'Format-Hashtable' {
12031203
it 'Can format a hashtable' {
12041204
Format-Hashtable -InputObject @{a='a'} | Should -Match "^\@\{\s+a\s=\s'a'\s+}"
12051205
}
1206+
}
1207+
1208+
describe 'Format-RichText' {
1209+
it 'Can format rich text' {
1210+
Format-RichText -ForegroundColor success -InputObject 'yay' | Should -Match '\e\[1;32'
1211+
}
1212+
1213+
it 'Can format any RGB color' {
1214+
$r, $g, $b = foreach ($n in 1..3) { Get-Random -Minimum 0 -Maximum 255 }
1215+
$rgb = "#{0:x2}{1:x2}{2:x2}" -f $r,$g,$b
1216+
Format-RichText -InputObject $rgb -ForegroundColor $rgb |
1217+
Should -Match "^\e\[38;2;$r;$g;$b"
1218+
}
1219+
1220+
it 'Can make a hyperlink' {
1221+
Format-RichText -Hyperlink https://github.com/StartAutomating/EZOut -InputObject EZOut |
1222+
Should -Match '^\e\]8m;;'
1223+
}
1224+
1225+
it 'Can make text bold' {
1226+
Format-RichText -InputObject "bold" -Bold | Should -Match '\e\[1'
1227+
}
1228+
1229+
it 'Can make text italic' {
1230+
Format-RichText -InputObject 'italic' -Italic | Should -Match '\e\[2'
1231+
}
1232+
1233+
it 'Can make text underlined' {
1234+
Format-RichText -InputObject 'underline' -Underline | Should -Match '\e\[4'
1235+
}
12061236
}

0 commit comments

Comments
 (0)