Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,8 @@ private static IEnumerable<FormatViewDefinition> 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")
Expand Down
21 changes: 21 additions & 0 deletions src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,27 @@ public class FormattingData
/// </summary>
public string Underline { get; } = "\x1b[4m";

/// <summary>
/// Gets value to turn off strikethrough.
/// </summary>
public string StrikethroughOff { get; } = "\x1b[29m";

/// <summary>
/// Gets value to turn on strikethrough.
/// </summary>
public string Strikethrough { get; } = "\x1b[9m";

/// <summary>
/// Gets ANSI representation of a hyperlink.
/// </summary>
/// <param name="text">Text describing the link.</param>
/// <param name="link">A valid hyperlink.</param>
/// <returns>String representing ANSI code for the hyperlink.</returns>
public string FormatHyperlink(string text, Uri link)
{
return $"\x1b]8;;{link}\x1b\\{text}\x1b]8;;\x1b\\";
}

/// <summary>
/// Gets the formatting rendering settings.
/// </summary>
Expand Down
27 changes: 27 additions & 0 deletions test/powershell/engine/Formatting/PSStyle.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{
Expand Down Expand Up @@ -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)
}
}