File tree Expand file tree Collapse file tree 2 files changed +68
-1
lines changed
src/Microsoft.PowerShell.ConsoleHost/host/msh Expand file tree Collapse file tree 2 files changed +68
-1
lines changed Original file line number Diff line number Diff line change @@ -60,8 +60,38 @@ internal ConsoleHostUserInterface(ConsoleHost parent)
60
60
61
61
_parent = parent ;
62
62
_rawui = new ConsoleHostRawUserInterface ( this ) ;
63
- SupportsVirtualTerminal = TryTurnOnVtMode ( ) ;
63
+ SupportsVirtualTerminal = true ;
64
64
_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
+ }
65
95
}
66
96
67
97
internal bool TryTurnOnVtMode ( )
Original file line number Diff line number Diff line change @@ -1008,3 +1008,40 @@ Describe 'Console host name' -Tag CI {
1008
1008
(Get-Process - Id $PID ).Name | Should - BeExactly ' pwsh'
1009
1009
}
1010
1010
}
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
+ }
You can’t perform that action at this time.
0 commit comments