diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index dbb8d3a2085..d881f551b31 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -2039,6 +2039,8 @@ private static IEnumerable ViewsOf_System_Management_Autom .AddItemScriptBlock(@"""$($_.Italic)$($_.Italic.Replace(""""`e"""",'`e'))$($_.Reset)""", label: "Italic") .AddItemScriptBlock(@"""$($_.UnderlineOff)$($_.UnderlineOff.Replace(""""`e"""",'`e'))$($_.Reset)""", label: "UnderlineOff") .AddItemScriptBlock(@"""$($_.Underline)$($_.Underline.Replace(""""`e"""",'`e'))$($_.Reset)""", label: "Underline") + .AddItemScriptBlock(@"""$($_.StrikethroughOff)$($_.StrikethroughOff.Replace(""""`e"""",'`e'))$($_.Reset)""", label: "StrikethroughOff") + .AddItemScriptBlock(@"""$($_.Strikethrough)$($_.Strikethrough.Replace(""""`e"""",'`e'))$($_.Reset)""", label: "Strikethrough") .AddItemProperty(@"OutputRendering") .AddItemScriptBlock(@"""$($_.Formatting.FormatAccent)$($_.Formatting.FormatAccent.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Formatting.FormatAccent") .AddItemScriptBlock(@"""$($_.Formatting.ErrorAccent)$($_.Formatting.ErrorAccent.Replace(""""`e"""",'`e'))$($PSStyle.Reset)""", label: "Formatting.ErrorAccent") diff --git a/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs b/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs index f27a5b89da9..e45899c7f7d 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs @@ -365,6 +365,27 @@ public class FormattingData /// public string Underline { get; } = "\x1b[4m"; + /// + /// Gets value to turn off strikethrough. + /// + public string StrikethroughOff { get; } = "\x1b[29m"; + + /// + /// Gets value to turn on strikethrough. + /// + public string Strikethrough { get; } = "\x1b[9m"; + + /// + /// Gets ANSI representation of a hyperlink. + /// + /// Text describing the link. + /// A valid hyperlink. + /// String representing ANSI code for the hyperlink. + public string FormatHyperlink(string text, Uri link) + { + return $"\x1b]8;;{link}\x1b\\{text}\x1b]8;;\x1b\\"; + } + /// /// Gets the formatting rendering settings. /// diff --git a/test/powershell/engine/Formatting/PSStyle.Tests.ps1 b/test/powershell/engine/Formatting/PSStyle.Tests.ps1 index 5e02e2e231c..a55c2392a8d 100644 --- a/test/powershell/engine/Formatting/PSStyle.Tests.ps1 +++ b/test/powershell/engine/Formatting/PSStyle.Tests.ps1 @@ -18,6 +18,8 @@ Describe 'Tests for $PSStyle automatic variable' { Italic = "`e[3m" UnderlineOff = "`e[24m" Underline = "`e[4m" + StrikethroughOff = "`e[29m" + Strikethrough = "`e[9m" } $formattingDefaults = @{ @@ -111,4 +113,29 @@ Describe 'Tests for $PSStyle automatic variable' { $PSStyle.Background.$key | Should -BeExactly $value } + + It '$PSStyle.Foreground.FromRGB(r, g, b) works' { + $o = $PSStyle.Foreground.FromRGB(11,22,33) + $o | Should -BeExactly "`e[38;2;11;22;33m" -Because ($o | Format-Hex | Out-String) + } + + It '$PSStyle.Foreground.FromRGB(rgb) works' { + $o = $PSStyle.Foreground.FromRGB(0x223344) + $o | Should -BeExactly "`e[38;2;34;51;68m" -Because ($o | Format-Hex | Out-String) + } + + It '$PSStyle.Background.FromRGB(r, g, b) works' { + $o = $PSStyle.Background.FromRGB(33,44,55) + $o | Should -BeExactly "`e[48;2;33;44;55m" -Because ($o | Format-Hex | Out-String) + } + + It '$PSStyle.Background.FromRGB(rgb) works' { + $o = $PSStyle.Background.FromRGB(0x445566) + $o | Should -BeExactly "`e[48;2;68;85;102m" -Because ($o | Format-Hex | Out-String) + } + + It '$PSStyle.FormatHyperlink() works' { + $o = $PSStyle.FormatHyperlink('PSBlog','https://aka.ms/psblog') + $o | Should -BeExactly "`e]8;;https://aka.ms/psblog`e\PSBlog`e]8;;`e\" -Because ($o | Format-Hex | Out-String) + } }