Change default to OutputRendering.Host
and remove OutputRendering.Automatic
(#15882)
This commit is contained in:
parent
b3a12b4faa
commit
a162856af5
|
@ -13,17 +13,14 @@ namespace System.Management.Automation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum OutputRendering
|
public enum OutputRendering
|
||||||
{
|
{
|
||||||
/// <summary>Automatic by PowerShell.</summary>
|
/// <summary>Render ANSI only to host.</summary>
|
||||||
Automatic = 0,
|
Host = 0,
|
||||||
|
|
||||||
/// <summary>Render as plaintext.</summary>
|
/// <summary>Render as plaintext.</summary>
|
||||||
PlainText = 1,
|
PlainText = 1,
|
||||||
|
|
||||||
/// <summary>Render as ANSI.</summary>
|
/// <summary>Render as ANSI.</summary>
|
||||||
Ansi = 2,
|
Ansi = 2,
|
||||||
|
|
||||||
/// <summary>Render ANSI only to host.</summary>
|
|
||||||
Host = 3,
|
|
||||||
}
|
}
|
||||||
#endregion OutputRendering
|
#endregion OutputRendering
|
||||||
|
|
||||||
|
@ -565,7 +562,7 @@ namespace System.Management.Automation
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the rendering mode for output.
|
/// Gets or sets the rendering mode for output.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public OutputRendering OutputRendering { get; set; } = OutputRendering.Automatic;
|
public OutputRendering OutputRendering { get; set; } = OutputRendering.Host;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets value to turn off all attributes.
|
/// Gets value to turn off all attributes.
|
||||||
|
|
|
@ -55,7 +55,10 @@ namespace System.Management.Automation.Internal
|
||||||
/// Render the decorarted string using automatic output rendering.
|
/// Render the decorarted string using automatic output rendering.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Rendered string based on automatic output rendering.</returns>
|
/// <returns>Rendered string based on automatic output rendering.</returns>
|
||||||
public override string ToString() => _isDecorated ? ToString(OutputRendering.Automatic) : _text;
|
public override string ToString() => ToString(
|
||||||
|
PSStyle.Instance.OutputRendering == OutputRendering.PlainText
|
||||||
|
? OutputRendering.PlainText
|
||||||
|
: OutputRendering.Ansi);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return string representation of content depending on output rendering mode.
|
/// Return string representation of content depending on output rendering mode.
|
||||||
|
@ -64,28 +67,17 @@ namespace System.Management.Automation.Internal
|
||||||
/// <returns>Rendered string based on outputRendering.</returns>
|
/// <returns>Rendered string based on outputRendering.</returns>
|
||||||
public string ToString(OutputRendering outputRendering)
|
public string ToString(OutputRendering outputRendering)
|
||||||
{
|
{
|
||||||
|
if (outputRendering == OutputRendering.Host)
|
||||||
|
{
|
||||||
|
throw new ArgumentException(StringDecoratedStrings.RequireExplicitRendering);
|
||||||
|
}
|
||||||
|
|
||||||
if (!_isDecorated)
|
if (!_isDecorated)
|
||||||
{
|
{
|
||||||
return _text;
|
return _text;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputRendering == OutputRendering.Automatic)
|
return outputRendering == OutputRendering.PlainText ? PlainText : _text;
|
||||||
{
|
|
||||||
outputRendering = OutputRendering.Ansi;
|
|
||||||
if (PSStyle.Instance.OutputRendering == OutputRendering.PlainText)
|
|
||||||
{
|
|
||||||
outputRendering = OutputRendering.PlainText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outputRendering == OutputRendering.PlainText)
|
|
||||||
{
|
|
||||||
return PlainText;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return _text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +131,10 @@ namespace System.Management.Automation.Internal
|
||||||
/// Render the decorarted string using automatic output rendering.
|
/// Render the decorarted string using automatic output rendering.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Rendered string based on automatic output rendering.</returns>
|
/// <returns>Rendered string based on automatic output rendering.</returns>
|
||||||
public override string ToString() => _isDecorated ? ToString(OutputRendering.Automatic) : _text;
|
public override string ToString() => ToString(
|
||||||
|
PSStyle.Instance.OutputRendering == OutputRendering.PlainText
|
||||||
|
? OutputRendering.PlainText
|
||||||
|
: OutputRendering.Ansi);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return string representation of content depending on output rendering mode.
|
/// Return string representation of content depending on output rendering mode.
|
||||||
|
@ -148,28 +143,17 @@ namespace System.Management.Automation.Internal
|
||||||
/// <returns>Rendered string based on outputRendering.</returns>
|
/// <returns>Rendered string based on outputRendering.</returns>
|
||||||
public string ToString(OutputRendering outputRendering)
|
public string ToString(OutputRendering outputRendering)
|
||||||
{
|
{
|
||||||
|
if (outputRendering == OutputRendering.Host)
|
||||||
|
{
|
||||||
|
throw new ArgumentException(StringDecoratedStrings.RequireExplicitRendering);
|
||||||
|
}
|
||||||
|
|
||||||
if (!_isDecorated)
|
if (!_isDecorated)
|
||||||
{
|
{
|
||||||
return _text;
|
return _text;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputRendering == OutputRendering.Automatic)
|
return outputRendering == OutputRendering.PlainText ? PlainText : _text;
|
||||||
{
|
|
||||||
outputRendering = OutputRendering.Ansi;
|
|
||||||
if (PSStyle.Instance.OutputRendering == OutputRendering.PlainText)
|
|
||||||
{
|
|
||||||
outputRendering = OutputRendering.PlainText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outputRendering == OutputRendering.PlainText)
|
|
||||||
{
|
|
||||||
return PlainText;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return _text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1570,9 +1570,6 @@ namespace System.Management.Automation
|
||||||
{
|
{
|
||||||
switch (PSStyle.Instance.OutputRendering)
|
switch (PSStyle.Instance.OutputRendering)
|
||||||
{
|
{
|
||||||
case OutputRendering.Automatic:
|
|
||||||
outputRendering = OutputRendering.Ansi;
|
|
||||||
break;
|
|
||||||
case OutputRendering.Host:
|
case OutputRendering.Host:
|
||||||
outputRendering = isHost ? OutputRendering.Ansi : OutputRendering.PlainText;
|
outputRendering = isHost ? OutputRendering.Ansi : OutputRendering.PlainText;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="https://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<data name="RequireExplicitRendering" xml:space="preserve">
|
||||||
|
<value>Only 'ANSI' or 'PlainText' is supported for this method.</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
|
@ -4,10 +4,13 @@
|
||||||
Describe '$env:__SuppressAnsiEscapeSequences tests' -Tag CI {
|
Describe '$env:__SuppressAnsiEscapeSequences tests' -Tag CI {
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
$originalSuppressPref = $env:__SuppressAnsiEscapeSequences
|
$originalSuppressPref = $env:__SuppressAnsiEscapeSequences
|
||||||
|
$originalRendering = $PSStyle.OutputRendering
|
||||||
|
$PSStyle.OutputRendering = 'Ansi'
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterAll {
|
AfterAll {
|
||||||
$env:__SuppressAnsiEscapeSequences = $originalSuppressPref
|
$env:__SuppressAnsiEscapeSequences = $originalSuppressPref
|
||||||
|
$PSStyle.OutputRendering = $originalRendering
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -213,10 +213,13 @@ dbda : KM
|
||||||
|
|
||||||
Describe 'Format-List color tests' {
|
Describe 'Format-List color tests' {
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
|
$originalRendering = $PSStyle.OutputRendering
|
||||||
|
$PSStyle.OutputRendering = 'Ansi'
|
||||||
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('ForceFormatListFixedLabelWidth', $true)
|
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('ForceFormatListFixedLabelWidth', $true)
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterAll {
|
AfterAll {
|
||||||
|
$PSStyle.OutputRendering = $originalRendering
|
||||||
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('ForceFormatListFixedLabelWidth', $false)
|
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('ForceFormatListFixedLabelWidth', $false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -848,6 +848,15 @@ A Name B
|
||||||
}
|
}
|
||||||
|
|
||||||
Describe 'Table color tests' {
|
Describe 'Table color tests' {
|
||||||
|
BeforeAll {
|
||||||
|
$originalRendering = $PSStyle.OutputRendering
|
||||||
|
$PSStyle.OutputRendering = 'Ansi'
|
||||||
|
}
|
||||||
|
|
||||||
|
AfterAll {
|
||||||
|
$PSStyle.OutputRendering = $originalRendering
|
||||||
|
}
|
||||||
|
|
||||||
It 'Table header should use FormatAccent' {
|
It 'Table header should use FormatAccent' {
|
||||||
([pscustomobject]@{foo = 1} | Format-Table | Out-String).Trim() | Should -BeExactly @"
|
([pscustomobject]@{foo = 1} | Format-Table | Out-String).Trim() | Should -BeExactly @"
|
||||||
$($PSStyle.Formatting.FormatAccent)foo$($PSStyle.Reset)
|
$($PSStyle.Formatting.FormatAccent)foo$($PSStyle.Reset)
|
||||||
|
|
|
@ -134,6 +134,8 @@ Describe 'Get-Error tests' -Tag CI {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$originalRendering = $PSStyle.OutputRendering
|
||||||
|
$PSStyle.OutputRendering = 'Ansi'
|
||||||
$out = pwsh -noprofile -command '$PSStyle.OutputRendering = "ANSI"; [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook("BypassOutputRedirectionCheck", $true); try { 1/0 } catch { }; Get-Error' | Out-String
|
$out = pwsh -noprofile -command '$PSStyle.OutputRendering = "ANSI"; [System.Management.Automation.Internal.InternalTestHooks]::SetTestHook("BypassOutputRedirectionCheck", $true); try { 1/0 } catch { }; Get-Error' | Out-String
|
||||||
|
|
||||||
# need to escape the open square bracket so the regex works
|
# need to escape the open square bracket so the regex works
|
||||||
|
@ -145,6 +147,7 @@ Describe 'Get-Error tests' -Tag CI {
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
$PSStyle.OutputRendering = $originalRendering
|
||||||
if ($suppressVT) {
|
if ($suppressVT) {
|
||||||
$env:__SuppressAnsiEscapeSequences = 1
|
$env:__SuppressAnsiEscapeSequences = 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,12 @@ Describe "Select-String" -Tags "CI" {
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
$nl = [Environment]::NewLine
|
$nl = [Environment]::NewLine
|
||||||
$currentDirectory = $PWD.Path
|
$currentDirectory = $PWD.Path
|
||||||
|
$originalRendering = $PSStyle.OutputRendering
|
||||||
|
$PSStyle.OutputRendering = 'Ansi'
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterAll {
|
AfterAll {
|
||||||
|
$PSStyle.OutputRendering = $originalRendering
|
||||||
Push-Location $currentDirectory
|
Push-Location $currentDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ Describe 'OutputRendering tests' {
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'OutputRendering works for "<outputRendering>" to the host' -TestCases @(
|
It 'OutputRendering works for "<outputRendering>" to the host' -TestCases @(
|
||||||
@{ outputRendering = 'automatic'; ansi = $true }
|
|
||||||
@{ outputRendering = 'host' ; ansi = $true }
|
@{ outputRendering = 'host' ; ansi = $true }
|
||||||
@{ outputRendering = 'ansi' ; ansi = $true }
|
@{ outputRendering = 'ansi' ; ansi = $true }
|
||||||
@{ outputRendering = 'plaintext'; ansi = $false }
|
@{ outputRendering = 'plaintext'; ansi = $false }
|
||||||
|
@ -43,7 +42,6 @@ Describe 'OutputRendering tests' {
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'OutputRendering works for "<outputRendering>" to the pipeline' -TestCases @(
|
It 'OutputRendering works for "<outputRendering>" to the pipeline' -TestCases @(
|
||||||
@{ outputRendering = 'automatic'; ansi = $true }
|
|
||||||
@{ outputRendering = 'host' ; ansi = $false }
|
@{ outputRendering = 'host' ; ansi = $false }
|
||||||
@{ outputRendering = 'ansi' ; ansi = $true }
|
@{ outputRendering = 'ansi' ; ansi = $true }
|
||||||
@{ outputRendering = 'plaintext'; ansi = $false }
|
@{ outputRendering = 'plaintext'; ansi = $false }
|
||||||
|
@ -79,4 +77,13 @@ Describe 'OutputRendering tests' {
|
||||||
$out[0] | Should -BeExactly "$($PSStyle.Formatting.$stream)$($stream.ToUpper()): hello$($PSStyle.Reset)" -Because ($out[0] | Out-String | Format-hex)
|
$out[0] | Should -BeExactly "$($PSStyle.Formatting.$stream)$($stream.ToUpper()): hello$($PSStyle.Reset)" -Because ($out[0] | Out-String | Format-hex)
|
||||||
$out[1] | Should -BeExactly "bye"
|
$out[1] | Should -BeExactly "bye"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It 'ToString(OutputRendering) works correctly' {
|
||||||
|
$s = [System.Management.Automation.Internal.StringDecorated]::new($PSStyle.Foreground.Red + 'Hello')
|
||||||
|
$s.IsDecorated | Should -BeTrue
|
||||||
|
$s.ToString() | Should -BeExactly "$($PSStyle.Foreground.Red)Hello"
|
||||||
|
$s.ToString([System.Management.Automation.OutputRendering]::ANSI) | Should -BeExactly "$($PSStyle.Foreground.Red)Hello"
|
||||||
|
$s.ToString([System.Management.Automation.OutputRendering]::PlainText) | Should -BeExactly 'Hello'
|
||||||
|
{ $s.ToString([System.Management.Automation.OutputRendering]::Host) } | Should -Throw -ErrorId 'ArgumentException'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ Describe 'Tests for $PSStyle automatic variable' {
|
||||||
|
|
||||||
It '$PSStyle has correct default for OutputRendering' {
|
It '$PSStyle has correct default for OutputRendering' {
|
||||||
$PSStyle | Should -Not -BeNullOrEmpty
|
$PSStyle | Should -Not -BeNullOrEmpty
|
||||||
$PSStyle.OutputRendering | Should -BeExactly 'Automatic'
|
$PSStyle.OutputRendering | Should -BeExactly 'Host'
|
||||||
}
|
}
|
||||||
|
|
||||||
It '$PSStyle has correct defaults for style <key>' -TestCases (Get-TestCases $styleDefaults) {
|
It '$PSStyle has correct defaults for style <key>' -TestCases (Get-TestCases $styleDefaults) {
|
||||||
|
@ -137,26 +137,32 @@ Describe 'Tests for $PSStyle automatic variable' {
|
||||||
|
|
||||||
It '$PSStyle.Formatting.FormatAccent is applied to Format-List' {
|
It '$PSStyle.Formatting.FormatAccent is applied to Format-List' {
|
||||||
$old = $PSStyle.Formatting.FormatAccent
|
$old = $PSStyle.Formatting.FormatAccent
|
||||||
|
$oldRender = $PSStyle.OutputRendering
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$PSStyle.OutputRendering = 'Ansi'
|
||||||
$PSStyle.Formatting.FormatAccent = $PSStyle.Foreground.Yellow + $PSStyle.Background.Red + $PSStyle.Italic
|
$PSStyle.Formatting.FormatAccent = $PSStyle.Foreground.Yellow + $PSStyle.Background.Red + $PSStyle.Italic
|
||||||
$out = $PSVersionTable | Format-List | Out-String
|
$out = $PSVersionTable | Format-List | Out-String
|
||||||
$out | Should -BeLike "*$($PSStyle.Formatting.FormatAccent.Replace('[',"``["))*"
|
$out | Should -BeLike "*$($PSStyle.Formatting.FormatAccent.Replace('[',"``["))*"
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
$PSStyle.OutputRendering = $oldRender
|
||||||
$PSStyle.Formatting.FormatAccent = $old
|
$PSStyle.Formatting.FormatAccent = $old
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
It '$PSStyle.Formatting.TableHeader is applied to Format-Table' {
|
It '$PSStyle.Formatting.TableHeader is applied to Format-Table' {
|
||||||
$old = $PSStyle.Formatting.TableHeader
|
$old = $PSStyle.Formatting.TableHeader
|
||||||
|
$oldRender = $PSStyle.OutputRendering
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$PSStyle.OutputRendering = 'Ansi'
|
||||||
$PSStyle.Formatting.TableHeader = $PSStyle.Foreground.Blue + $PSStyle.Background.White + $PSStyle.Bold
|
$PSStyle.Formatting.TableHeader = $PSStyle.Foreground.Blue + $PSStyle.Background.White + $PSStyle.Bold
|
||||||
$out = $PSVersionTable | Format-Table | Out-String
|
$out = $PSVersionTable | Format-Table | Out-String
|
||||||
$out | Should -BeLike "*$($PSStyle.Formatting.TableHeader.Replace('[',"``["))*"
|
$out | Should -BeLike "*$($PSStyle.Formatting.TableHeader.Replace('[',"``["))*"
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
$PSStyle.OutputRendering = $oldRender
|
||||||
$PSStyle.Formatting.TableHeader = $old
|
$PSStyle.Formatting.TableHeader = $old
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue