@@ -95,17 +95,14 @@ public class PSConsoleReadLineOptions
95
95
96
96
// Find the most suitable color using https://stackoverflow.com/a/33206814
97
97
// Default prediction color settings:
98
- // - use FG color 'dim white italic' for the inline-view suggestion text
99
98
// - use FG color 'yellow' for the list-view suggestion text
100
99
// - use BG color 'dark black' for the selected list-view suggestion text
101
- public const string DefaultInlinePredictionColor = "\x1b [97;2;3m" ;
102
100
public const string DefaultListPredictionColor = "\x1b [33m" ;
103
101
public const string DefaultListPredictionSelectedColor = "\x1b [48;5;238m" ;
104
- public const string DefaultListPredictionTooltipColor = "\x1b [97;2;3m" ;
105
102
106
- public static EditMode DefaultEditMode = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows )
107
- ? EditMode . Windows
108
- : EditMode . Emacs ;
103
+ public static readonly string DefaultInlinePredictionColor ;
104
+ public static readonly string DefaultListPredictionTooltipColor ;
105
+ public static readonly EditMode DefaultEditMode ;
109
106
110
107
public const string DefaultContinuationPrompt = ">> " ;
111
108
@@ -166,6 +163,40 @@ public class PSConsoleReadLineOptions
166
163
/// </summary>
167
164
public const int DefaultAnsiEscapeTimeout = 100 ;
168
165
166
+ static PSConsoleReadLineOptions ( )
167
+ {
168
+ // For inline-view suggestion text, we use the new FG color 'dim white italic' when possible, because it provides
169
+ // sufficient contrast in terminals that don't use a pure black background (like VSCode terminal).
170
+ // However, on Windows 10 and Windows Server, the ConHost doesn't support font effect VT sequences, such as 'dim'
171
+ // and 'italic', so we need to use the old FG color 'dark black' as in the v2.2.6.
172
+ const string newInlinePredictionColor = "\x1b [97;2;3m" ;
173
+ const string oldInlinePredictionColor = "\x1b [38;5;238m" ;
174
+
175
+ ColorSetters = null ;
176
+ DefaultEditMode = EditMode . Emacs ;
177
+ DefaultInlinePredictionColor = newInlinePredictionColor ;
178
+
179
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
180
+ {
181
+ DefaultEditMode = EditMode . Windows ;
182
+
183
+ // Our tests expect that the default inline-view color is set to the new color, so we configure
184
+ // the color based on system environment only if we are not in test runs.
185
+ if ( AppDomain . CurrentDomain . FriendlyName is not "PSReadLine.Tests" )
186
+ {
187
+ DefaultInlinePredictionColor =
188
+ Environment . OSVersion . Version . Build >= 22621 // on Windows 11 22H2 or newer versions
189
+ || Environment . GetEnvironmentVariable ( "WT_SESSION" ) is not null // in Windows Terminal
190
+ ? newInlinePredictionColor
191
+ : oldInlinePredictionColor ;
192
+ }
193
+ }
194
+
195
+ // Use the same color for the list prediction tooltips.
196
+ DefaultListPredictionTooltipColor = DefaultInlinePredictionColor ;
197
+ DefaultAddToHistoryHandler = s => PSConsoleReadLine . GetDefaultAddToHistoryOption ( s ) ;
198
+ }
199
+
169
200
public PSConsoleReadLineOptions ( string hostName , bool usingLegacyConsole )
170
201
{
171
202
ResetColors ( ) ;
@@ -285,8 +316,7 @@ public object ContinuationPromptColor
285
316
/// or added to memory only, or added to both memory and history file.
286
317
/// </summary>
287
318
public Func < string , object > AddToHistoryHandler { get ; set ; }
288
- public static readonly Func < string , object > DefaultAddToHistoryHandler =
289
- s => PSConsoleReadLine . GetDefaultAddToHistoryOption ( s ) ;
319
+ public static readonly Func < string , object > DefaultAddToHistoryHandler ;
290
320
291
321
/// <summary>
292
322
/// This handler is called from ValidateAndAcceptLine.
@@ -305,7 +335,6 @@ public object ContinuationPromptColor
305
335
/// odd things with script blocks, we create a white-list of commands
306
336
/// that do invoke the script block - this covers the most useful cases.
307
337
/// </summary>
308
- [ SuppressMessage ( "Microsoft.Usage" , "CA2227:CollectionPropertiesShouldBeReadOnly" ) ]
309
338
public HashSet < string > CommandsToValidateScriptBlockArguments { get ; set ; }
310
339
311
340
/// <summary>
@@ -555,7 +584,7 @@ internal void ResetColors()
555
584
SelectionColor = VTColorUtils . AsEscapeSequence ( bg , fg ) ;
556
585
}
557
586
558
- private static Dictionary < string , Action < PSConsoleReadLineOptions , object > > ColorSetters = null ;
587
+ private static Dictionary < string , Action < PSConsoleReadLineOptions , object > > ColorSetters ;
559
588
560
589
internal void SetColor ( string property , object value )
561
590
{
@@ -830,7 +859,6 @@ public class ChangePSReadLineKeyHandlerCommandBase : PSCmdlet
830
859
[ Parameter ( Position = 0 , Mandatory = true ) ]
831
860
[ Alias ( "Key" ) ]
832
861
[ ValidateNotNullOrEmpty ]
833
- [ SuppressMessage ( "Microsoft.Performance" , "CA1819:PropertiesShouldNotReturnArrays" ) ]
834
862
public string [ ] Chord { get ; set ; }
835
863
836
864
[ Parameter ]
@@ -903,8 +931,7 @@ protected override void EndProcessing()
903
931
}
904
932
}
905
933
906
- private readonly Lazy < RuntimeDefinedParameterDictionary > _dynamicParameters =
907
- new Lazy < RuntimeDefinedParameterDictionary > ( CreateDynamicParametersResult ) ;
934
+ private readonly Lazy < RuntimeDefinedParameterDictionary > _dynamicParameters = new ( CreateDynamicParametersResult ) ;
908
935
909
936
private static RuntimeDefinedParameterDictionary CreateDynamicParametersResult ( )
910
937
{
@@ -1027,7 +1054,7 @@ public static class VTColorUtils
1027
1054
1028
1055
public const ConsoleColor UnknownColor = ( ConsoleColor ) ( - 1 ) ;
1029
1056
private static readonly Dictionary < string , ConsoleColor > ConsoleColors =
1030
- new Dictionary < string , ConsoleColor > ( StringComparer . OrdinalIgnoreCase )
1057
+ new ( StringComparer . OrdinalIgnoreCase )
1031
1058
{
1032
1059
{ "Black" , ConsoleColor . Black } ,
1033
1060
{ "DarkBlue" , ConsoleColor . DarkBlue } ,
0 commit comments