resolve merge conflict (#14969)

This commit is contained in:
Steve Lee 2021-04-12 20:11:50 -07:00 committed by GitHub
parent 44d5ce9e01
commit 2f3f39906f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 1 deletions

View File

@ -60,8 +60,38 @@ namespace Microsoft.PowerShell
_parent = parent;
_rawui = new ConsoleHostRawUserInterface(this);
SupportsVirtualTerminal = TryTurnOnVtMode();
SupportsVirtualTerminal = true;
_isInteractiveTestToolListening = false;
if (ExperimentalFeature.IsEnabled("PSAnsiRendering"))
{
// check if TERM env var is set
// `dumb` means explicitly don't use VT
// `xterm-mono` and `xtermm` means support VT, but emit plaintext
switch (Environment.GetEnvironmentVariable("TERM"))
{
case "dumb":
SupportsVirtualTerminal = false;
break;
case "xterm-mono":
case "xtermm":
PSStyle.Instance.OutputRendering = OutputRendering.PlainText;
break;
default:
break;
}
// widely supported by CLI tools via https://no-color.org/
if (Environment.GetEnvironmentVariable("NO_COLOR") != null)
{
PSStyle.Instance.OutputRendering = OutputRendering.PlainText;
}
}
if (SupportsVirtualTerminal)
{
SupportsVirtualTerminal = TryTurnOnVtMode();
}
}
internal bool TryTurnOnVtMode()

View File

@ -1008,3 +1008,40 @@ Describe 'Console host name' -Tag CI {
(Get-Process -Id $PID).Name | Should -BeExactly 'pwsh'
}
}
Describe 'TERM env var' -Tag CI {
BeforeAll {
$oldTERM = $env:TERM
$PSDefaultParameterValues.Add('It:Skip', (-not $EnabledExperimentalFeatures.Contains('PSAnsiRendering')))
}
AfterAll {
$env:TERM = $oldTERM
$PSDefaultParameterValues.Remove('It:Skip')
}
It 'TERM = "dumb"' {
$env:TERM = 'dumb'
pwsh -noprofile -command '$Host.UI.SupportsVirtualTerminal' | Should -BeExactly 'False'
}
It 'TERM = "<term>"' -TestCases @(
@{ term = "xterm-mono" }
@{ term = "xtermm" }
) {
param ($term)
$env:TERM = $term
pwsh -noprofile -command '$PSStyle.OutputRendering' | Should -BeExactly 'PlainText'
}
It 'NO_COLOR' {
try {
$env:NO_COLOR = 1
pwsh -noprofile -command '$PSStyle.OutputRendering' | Should -BeExactly 'PlainText'
}
finally {
$env:NO_COLOR = $null
}
}
}