Skip to content

Commit f5d6ae2

Browse files
StartAutomatingStartAutomating
authored andcommitted
Updating manifest (fixing exports). Adding FileTypes to PrivateData.
1 parent 6ad2e35 commit f5d6ae2

File tree

1 file changed

+134
-46
lines changed

1 file changed

+134
-46
lines changed

PipeScript.format.ps1xml

Lines changed: 134 additions & 46 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.7: 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
<Controls>
55
<Control>
@@ -156,7 +156,7 @@
156156
.Notes
157157
Stylized Output works in two contexts at present:
158158
* Rich consoles (Windows Terminal, PowerShell.exe, Pwsh.exe) (when $host.UI.SupportsVirtualTerminal)
159-
* Web pages (Based off the presence of a $Request variable, or when $host.UI.SupportsHTML (you must add this property to $host.UI))
159+
* Web pages (Based off the presence of a $Request variable, or when $host.UI.SupportsHTML (you must add this property to $host.UI))
160160
#&gt;
161161
[Management.Automation.Cmdlet("Format","Object")]
162162
[ValidateScript({
@@ -165,12 +165,13 @@
165165
if (-not ($canUseANSI -or $canUseHTML)) { return $false}
166166
return $true
167167
})]
168+
[OutputType([string])]
168169
param(
169170
# The input object
170171
[Parameter(ValueFromPipeline)]
171172
[PSObject]
172173
$InputObject,
173-
174+
174175
# The foreground color
175176
[string]$ForegroundColor,
176177

@@ -205,8 +206,23 @@
205206

206207
# If set, will invert text
207208
[switch]$Invert,
209+
210+
# If provided, will create a hyperlink to a given uri
211+
[Alias('Hyperlink', 'Href')]
212+
[uri]
213+
$Link,
214+
208215
# If set, will not clear formatting
209-
[switch]$NoClear
216+
[switch]$NoClear,
217+
218+
# The alignment. Defaulting to Left.
219+
# Setting an alignment will pad the remaining space on each line.
220+
[ValidateSet('Left','Right','Center')]
221+
[string]
222+
$Alignment,
223+
224+
# The length of a line. By default, the buffer width
225+
[int]$LineLength = $($host.UI.RawUI.BufferSize.Width)
210226
)
211227

212228
begin {
@@ -216,12 +232,27 @@
216232
Output='';Error='BrightRed';Warning='BrightYellow';
217233
Verbose='BrightCyan';Debug='Yellow';Progress='Cyan';
218234
Success='BrightGreen';Failure='Red';Default=''}
235+
236+
$ansiCode = [Regex]::new(@'
237+
(?&lt;ANSI_Code&gt;
238+
(?-i)\e # An Escape
239+
\[ # Followed by a bracket
240+
(?&lt;ParameterBytes&gt;[\d\:\;\&lt;\=\&gt;\?]{0,}) # Followed by zero or more parameter
241+
bytes
242+
(?&lt;IntermediateBytes&gt;[\s\!\"\#\$\%\&amp;\'\(\)\*\+\,\-\.\/]{0,}) # Followed by zero or more
243+
intermediate bytes
244+
(?&lt;FinalByte&gt;[\@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]\^_\`abcdefghijklmnopqrstuvwxyz\{\|\}\~]) # Followed by a final byte
245+
246+
)
247+
'@)
219248
$esc = [char]0x1b
220249
$standardColors = 'Black', 'Red', 'Green', 'Yellow', 'Blue','Magenta', 'Cyan', 'White'
221250
$brightColors = 'BrightBlack', 'BrightRed', 'BrightGreen', 'BrightYellow', 'BrightBlue','BrightMagenta', 'BrightCyan', 'BrightWhite'
222251

252+
$allOutput = @()
253+
223254
$n =0
224-
$cssClasses = @()
255+
$cssClasses = @()
225256
$colorAttributes =
226257
@(:nextColor foreach ($hc in $ForegroundColor,$BackgroundColor) {
227258
$n++
@@ -398,6 +429,21 @@
398429
if ($canUseHTML) { "border-bottom: 3px double;"}
399430
elseif ($canUseANSI) {'' +$esc + "[21m" }
400431
}
432+
433+
if ($Alignment -and $canUseHTML) {
434+
"display:block;text-align:$($Alignment.ToLower())"
435+
}
436+
437+
if ($Link) {
438+
if ($canUseHTML) {
439+
# Hyperlinks need to be a nested element
440+
# so we will not add it to style attributes for HTML
441+
}
442+
elseif ($canUseANSI) {
443+
# For ANSI,
444+
'' + $esc + ']8m;;' + $Link + $esc + '\'
445+
}
446+
}
401447

402448
)
403449

@@ -407,61 +453,102 @@
407453
if ($styleAttributes) { " style='$($styleAttributes -join ';')'"}
408454
)$(
409455
if ($cssClasses) { " class='$($cssClasses -join ' ')'"}
410-
)&gt;"
456+
)&gt;" + $(
457+
if ($Link) {
458+
"&lt;a href='$link'&gt;"
459+
}
460+
)
411461
} elseif ($canUseANSI) {
412462
$styleAttributes -join ''
413463
}
414464
}
415465

416466
process {
417-
if ($header) {
418-
"$header" + "$(if ($inputObject) { $inputObject | Out-String})".Trim()
419-
}
420-
elseif ($inputObject) {
421-
($inputObject | Out-String).Trim()
422-
}
467+
$inputObjectAsString =
468+
"$(if ($inputObject) { $inputObject | Out-String})".Trim()
469+
470+
$inputObjectAsString =
471+
if ($Alignment -and -not $canUseHTML) {
472+
(@(foreach ($inputObjectLine in ($inputObjectAsString -split '(?&gt;\r\n|\n)')) {
473+
$inputObjectLength = $ansiCode.Replace($inputObjectLine, '').Length
474+
if ($inputObjectLength -lt $LineLength) {
475+
if ($Alignment -eq 'Left') {
476+
$inputObjectLine
477+
} elseif ($Alignment -eq 'Right') {
478+
(' ' * ($LineLength - $inputObjectLength)) + $inputObjectLine
479+
} else {
480+
$half = ($LineLength - $inputObjectLength)/2
481+
(' ' * [Math]::Floor($half)) + $inputObjectLine +
482+
(' ' * [Math]::Ceiling($half))
483+
}
484+
}
485+
else {
486+
$inputObjectLine
487+
}
488+
}) -join [Environment]::NewLine) + [Environment]::newline
489+
} else {
490+
$inputObjectAsString
491+
}
492+
493+
$allOutput +=
494+
if ($header) {
495+
"$header" + $inputObjectAsString
496+
}
497+
elseif ($inputObject) {
498+
$inputObjectAsString
499+
}
423500
}
424501

425502
end {
426503

427504
if (-not $NoClear) {
428-
if ($canUseHTML) {
429-
"&lt;/span&gt;"
430-
}
431-
elseif ($canUseANSI) {
432-
if ($Bold -or $Faint -or $colorAttributes -match '\[1;') {
433-
"$esc[22m"
434-
}
435-
if ($Italic) {
436-
"$esc[23m"
437-
}
438-
if ($Underline -or $doubleUnderline) {
439-
"$esc[24m"
440-
}
441-
if ($Blink) {
442-
"$esc[25m"
443-
}
444-
if ($Invert) {
445-
"$esc[27m"
446-
}
447-
if ($hide) {
448-
"$esc[28m"
449-
}
450-
if ($Strikethru) {
451-
"$esc[29m"
452-
}
453-
if ($ForegroundColor) {
454-
"$esc[39m"
455-
}
456-
if ($BackgroundColor) {
457-
"$esc[49m"
505+
$allOutput +=
506+
if ($canUseHTML) {
507+
if ($Link) {
508+
"&lt;/a&gt;"
509+
}
510+
"&lt;/span&gt;"
458511
}
459-
460-
if (-not ($Underline -or $Bold -or $Invert -or $ForegroundColor -or $BackgroundColor)) {
461-
'' + $esc + '[0m'
512+
elseif ($canUseANSI) {
513+
if ($Bold -or $Faint -or $colorAttributes -match '\[1;') {
514+
"$esc[22m"
515+
}
516+
if ($Italic) {
517+
"$esc[23m"
518+
}
519+
if ($Underline -or $doubleUnderline) {
520+
"$esc[24m"
521+
}
522+
if ($Blink) {
523+
"$esc[25m"
524+
}
525+
if ($Invert) {
526+
"$esc[27m"
527+
}
528+
if ($hide) {
529+
"$esc[28m"
530+
}
531+
if ($Strikethru) {
532+
"$esc[29m"
533+
}
534+
if ($ForegroundColor) {
535+
"$esc[39m"
536+
}
537+
if ($BackgroundColor) {
538+
"$esc[49m"
539+
}
540+
541+
if ($Link) {
542+
"$esc]8;;$esc\"
543+
}
544+
545+
if (-not ($Underline -or $Bold -or $Invert -or $ForegroundColor -or $BackgroundColor)) {
546+
'' + $esc + '[0m'
547+
}
462548
}
463-
}
464549
}
550+
551+
$allOutput -join ''
465552
}
466553
</ScriptBlock>
467554
</ExpressionBinding>
@@ -813,6 +900,7 @@
813900

814901
# If set, will create a link. The -InputObject will be used as the link content
815902
[Parameter(ValueFromPipelineByPropertyName)]
903+
[Alias('Hyperlink', 'Href')]
816904
[string]
817905
$Link,
818906

0 commit comments

Comments
 (0)