@@ -66,8 +66,16 @@ public enum AddToHistoryOption
66
66
67
67
public enum PredictionSource
68
68
{
69
- None ,
70
- History ,
69
+ None = 1 ,
70
+ History = 2 ,
71
+ Plugin = 4 ,
72
+ HistoryAndPlugin = History | Plugin ,
73
+ }
74
+
75
+ public enum PredictionViewStyle
76
+ {
77
+ InlineView ,
78
+ ListView ,
71
79
}
72
80
73
81
public class PSConsoleReadLineOptions
@@ -85,9 +93,14 @@ public class PSConsoleReadLineOptions
85
93
public const ConsoleColor DefaultEmphasisColor = ConsoleColor . Cyan ;
86
94
public const ConsoleColor DefaultErrorColor = ConsoleColor . Red ;
87
95
88
- // Use dark black by default for the suggestion text.
89
96
// Find the most suitable color using https://stackoverflow.com/a/33206814
90
- public const string DefaultInlinePredictionColor = "\x1b [38;5;238m" ;
97
+ // Default prediction color settings:
98
+ // - use FG color 'dark black' for the inline-view suggestion text
99
+ // - use FG color 'yellow' for the list-view suggestion text
100
+ // - use BG color 'dark black' for the selected list-view suggestion text
101
+ public const string DefaultInlinePredictionColor = "\x1b [38;5;238m" ;
102
+ public const string DefaultListPredictionColor = "\x1b [33m" ;
103
+ public const string DefaultListPredictionSelectedColor = "\x1b [48;5;238m" ;
91
104
92
105
public static EditMode DefaultEditMode = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows )
93
106
? EditMode . Windows
@@ -144,6 +157,8 @@ public class PSConsoleReadLineOptions
144
157
/// </summary>
145
158
public const PredictionSource DefaultPredictionSource = PredictionSource . None ;
146
159
160
+ public const PredictionViewStyle DefaultPredictionViewStyle = PredictionViewStyle . InlineView ;
161
+
147
162
/// <summary>
148
163
/// How long in milliseconds should we wait before concluding
149
164
/// the input is not an escape sequence?
@@ -171,6 +186,7 @@ public PSConsoleReadLineOptions(string hostName)
171
186
HistorySaveStyle = DefaultHistorySaveStyle ;
172
187
AnsiEscapeTimeout = DefaultAnsiEscapeTimeout ;
173
188
PredictionSource = DefaultPredictionSource ;
189
+ PredictionViewStyle = DefaultPredictionViewStyle ;
174
190
MaximumHistoryCount = 0 ;
175
191
176
192
var historyFileName = hostName + "_history.txt" ;
@@ -309,6 +325,7 @@ public object ContinuationPromptColor
309
325
310
326
public bool HistorySearchCaseSensitive { get ; set ; }
311
327
internal StringComparison HistoryStringComparison => HistorySearchCaseSensitive ? StringComparison . Ordinal : StringComparison . OrdinalIgnoreCase ;
328
+ internal StringComparer HistoryStringComparer => HistorySearchCaseSensitive ? StringComparer . Ordinal : StringComparer . OrdinalIgnoreCase ;
312
329
313
330
/// <summary>
314
331
/// How are command and insert modes indicated when in vi edit mode?
@@ -331,6 +348,11 @@ public object ContinuationPromptColor
331
348
/// </summary>
332
349
public PredictionSource PredictionSource { get ; set ; }
333
350
351
+ /// <summary>
352
+ /// Sets the view style for rendering predictive suggestions.
353
+ /// </summary>
354
+ public PredictionViewStyle PredictionViewStyle { get ; set ; }
355
+
334
356
/// <summary>
335
357
/// How long in milliseconds should we wait before concluding
336
358
/// the input is not an escape sequence?
@@ -457,6 +479,18 @@ public object InlinePredictionColor
457
479
set => _inlinePredictionColor = VTColorUtils . AsEscapeSequence ( value ) ;
458
480
}
459
481
482
+ public object ListPredictionColor
483
+ {
484
+ get => _listPredictionColor ;
485
+ set => _listPredictionColor = VTColorUtils . AsEscapeSequence ( value ) ;
486
+ }
487
+
488
+ public object ListPredictionSelectedColor
489
+ {
490
+ get => _listPredictionSelectedColor ;
491
+ set => _listPredictionSelectedColor = VTColorUtils . AsEscapeSequence ( value ) ;
492
+ }
493
+
460
494
internal string _defaultTokenColor ;
461
495
internal string _commentColor ;
462
496
internal string _keywordColor ;
@@ -472,6 +506,8 @@ public object InlinePredictionColor
472
506
internal string _errorColor ;
473
507
internal string _selectionColor ;
474
508
internal string _inlinePredictionColor ;
509
+ internal string _listPredictionColor ;
510
+ internal string _listPredictionSelectedColor ;
475
511
476
512
internal void ResetColors ( )
477
513
{
@@ -489,7 +525,9 @@ internal void ResetColors()
489
525
MemberColor = DefaultNumberColor ;
490
526
EmphasisColor = DefaultEmphasisColor ;
491
527
ErrorColor = DefaultErrorColor ;
492
- InlinePredictionColor = DefaultInlinePredictionColor ;
528
+ InlinePredictionColor = DefaultInlinePredictionColor ;
529
+ ListPredictionColor = DefaultListPredictionColor ;
530
+ ListPredictionSelectedColor = DefaultListPredictionSelectedColor ;
493
531
494
532
var bg = Console . BackgroundColor ;
495
533
if ( fg == VTColorUtils . UnknownColor || bg == VTColorUtils . UnknownColor )
@@ -527,6 +565,8 @@ internal void SetColor(string property, object value)
527
565
{ "Member" , ( o , v ) => o . MemberColor = v } ,
528
566
{ "Selection" , ( o , v ) => o . SelectionColor = v } ,
529
567
{ "InlinePrediction" , ( o , v ) => o . InlinePredictionColor = v } ,
568
+ { "ListPrediction" , ( o , v ) => o . ListPredictionColor = v } ,
569
+ { "ListPredictionSelected" , ( o , v ) => o . ListPredictionSelectedColor = v } ,
530
570
} ;
531
571
532
572
Interlocked . CompareExchange ( ref ColorSetters , setters , null ) ;
@@ -550,7 +590,9 @@ public class GetPSReadLineOption : PSCmdlet
550
590
[ ExcludeFromCodeCoverage ]
551
591
protected override void EndProcessing ( )
552
592
{
553
- WriteObject ( PSConsoleReadLine . GetOptions ( ) ) ;
593
+ var options = PSConsoleReadLine . GetOptions ( ) ;
594
+ WriteObject ( options ) ;
595
+ PSConsoleReadLine . WarnWhenWindowSizeTooSmallForView ( options . PredictionViewStyle , this ) ;
554
596
}
555
597
}
556
598
@@ -741,6 +783,14 @@ public PredictionSource PredictionSource
741
783
}
742
784
internal PredictionSource ? _predictionSource ;
743
785
786
+ [ Parameter ]
787
+ public PredictionViewStyle PredictionViewStyle
788
+ {
789
+ get => _predictionViewStyle . GetValueOrDefault ( ) ;
790
+ set => _predictionViewStyle = value ;
791
+ }
792
+ internal PredictionViewStyle ? _predictionViewStyle ;
793
+
744
794
[ Parameter ]
745
795
public Hashtable Colors { get ; set ; }
746
796
0 commit comments