8000 resolve merge conflict (#14969) · PowerShell/PowerShell@2f3f399 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f3f399

Browse files
authored
resolve merge conflict (#14969)
1 parent 44d5ce9 commit 2f3f399

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,38 @@ internal ConsoleHostUserInterface(ConsoleHost parent)
6060

6161
_parent = parent;
6262
_rawui = new ConsoleHostRawUserInterface(this);
63-
SupportsVirtualTerminal = TryTurnOnVtMode();
63+
SupportsVirtualTerminal = true;
6464
_isInteractiveTestToolListening = false;
65+
66+
if (ExperimentalFeature.IsEnabled("PSAnsiRendering"))
67+
{
68+
// check if TERM env var is set
69+
// `dumb` means explicitly don't use VT
70+
// `xterm-mono` and `xtermm` means support VT, but emit plaintext
71+
switch (Environment.GetEnvironmentVariable("TERM"))
72+
{
73+
case "dumb":
74+
SupportsVirtualTerminal = false;
75+
break;
76+
case "xterm-mono":
77+
case "xtermm":
78+
PSStyle.Instance.OutputRendering = OutputRendering.PlainText;
79+
break;
80+
default:
81+
break;
82+
}
83+
84+
// widely supported by CLI tools via https://no-color.org/
85+
if (Environment.GetEnvironmentVariable("NO_COLOR") != null)
86+
{
87+
PSStyle.Instance.OutputRendering = OutputRendering.PlainText;
88+
}
89+
}
90+
91+
if (SupportsVirtualTerminal)
92+
{
93+
SupportsVirtualTerminal = TryTurnOnVtMode();
94+
}
6595
}
6696

6797
internal bool TryTurnOnVtMode()

test/powershell/Host/ConsoleHost.Tests.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,3 +1008,40 @@ Describe 'Console host name' -Tag CI {
10081008
(Get-Process -Id $PID).Name | Should -BeExactly 'pwsh'
10091009
}
10101010
}
1011+
1012+
Describe 'TERM env var' -Tag CI {
1013+
BeforeAll {
1014+
$oldTERM = $env:TERM
1015+
$PSDefaultParameterValues.Add('It:Skip', (-not $EnabledExperimentalFeatures.Contains('PSAnsiRendering')))
1016+
}
1017+
1018+
AfterAll {
1019+
$env:TERM = $oldTERM
1020+
$PSDefaultParameterValues.Remove('It:Skip')
1021+
}
1022+
1023+
It 'TERM = "dumb"' {
1024+
$env:TERM = 'dumb'
1025+
pwsh -noprofile -command '$Host.UI.SupportsVirtualTerminal' | Should -BeExactly 'False'
1026+
}
1027+
1028+
It 'TERM = "<term>"' -TestCases @(
1029+
@{ term = "xterm-mono" }
1030+
@{ term = "xtermm" }
1031+
) {
1032+
param ($term)
1033+
1034+
$env:TERM = $term
1035+
pwsh -noprofile -command '$PSStyle.OutputRendering' | Should -BeExactly 'PlainText'
1036+
}
1037+
1038+
It 'NO_COLOR' {
1039+
try {
1040+
$env:NO_COLOR = 1
1041+
pwsh -noprofile -command '$PSStyle.OutputRendering' | Should -BeExactly 'PlainText'
1042+
}
1043+
finally {
1044+
$env:NO_COLOR = $null
1045+
}
1046+
}
1047+
}

0 commit comments

Comments
 (0)
0