Skip to content

Commit ae08ca6

Browse files
authored
Support tooltip rendering in the prediction list view (#3667)
1 parent 18b5614 commit ae08ca6

14 files changed

+789
-25
lines changed

PSReadLine/Cmdlets.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public class PSConsoleReadLineOptions
101101
public const string DefaultInlinePredictionColor = "\x1b[97;2;3m";
102102
public const string DefaultListPredictionColor = "\x1b[33m";
103103
public const string DefaultListPredictionSelectedColor = "\x1b[48;5;238m";
104+
public const string DefaultListPredictionTooltipColor = "\x1b[97;2;3m";
104105

105106
public static EditMode DefaultEditMode = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
106107
? EditMode.Windows
@@ -495,6 +496,12 @@ public object ListPredictionSelectedColor
495496
set => _listPredictionSelectedColor = VTColorUtils.AsEscapeSequence(value);
496497
}
497498

499+
public object ListPredictionTooltipColor
500+
{
501+
get => _listPredictionTooltipColor;
502+
set => _listPredictionTooltipColor = VTColorUtils.AsEscapeSequence(value);
503+
}
504+
498505
internal string _defaultTokenColor;
499506
internal string _commentColor;
500507
internal string _keywordColor;
@@ -512,6 +519,7 @@ public object ListPredictionSelectedColor
512519
internal string _inlinePredictionColor;
513520
internal string _listPredictionColor;
514521
internal string _listPredictionSelectedColor;
522+
internal string _listPredictionTooltipColor;
515523

516524
internal void ResetColors()
517525
{
@@ -532,6 +540,7 @@ internal void ResetColors()
532540
InlinePredictionColor = DefaultInlinePredictionColor;
533541
ListPredictionColor = DefaultListPredictionColor;
534542
ListPredictionSelectedColor = DefaultListPredictionSelectedColor;
543+
ListPredictionTooltipColor = DefaultListPredictionTooltipColor;
535544

536545
var bg = Console.BackgroundColor;
537546
if (fg == VTColorUtils.UnknownColor || bg == VTColorUtils.UnknownColor)
@@ -571,6 +580,7 @@ internal void SetColor(string property, object value)
571580
{"InlinePrediction", (o, v) => o.InlinePredictionColor = v},
572581
{"ListPrediction", (o, v) => o.ListPredictionColor = v},
573582
{"ListPredictionSelected", (o, v) => o.ListPredictionSelectedColor = v},
583+
{"ListPredictionTooltip", (o, v) => o.ListPredictionTooltipColor = v},
574584
};
575585

576586
Interlocked.CompareExchange(ref ColorSetters, setters, null);

PSReadLine/DynamicHelp.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public partial class PSConsoleReadLine
1919
[ExcludeFromCodeCoverage]
2020
void IPSConsoleReadLineMockableMethods.RenderFullHelp(string content, string regexPatternToScrollTo)
2121
{
22+
_pager ??= new Pager();
2223
_pager.Write(content, regexPatternToScrollTo);
2324
}
2425

@@ -142,11 +143,6 @@ private void WriteDynamicHelpContent(string commandName, string parameterName, b
142143

143144
private void DynamicHelpImpl(bool isFullHelp)
144145
{
145-
if (isFullHelp)
146-
{
147-
_pager ??= new Pager();
148-
}
149-
150146
int cursor = _singleton._current;
151147
string commandName = null;
152148
string parameterName = null;

PSReadLine/KeyBindings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ void SetDefaultWindowsBindings()
235235
{ Keys.F2, MakeKeyHandler(SwitchPredictionView, "SwitchPredictionView") },
236236
{ Keys.F3, MakeKeyHandler(CharacterSearch, "CharacterSearch") },
237237
{ Keys.ShiftF3, MakeKeyHandler(CharacterSearchBackward, "CharacterSearchBackward") },
238+
{ Keys.F4, MakeKeyHandler(ShowFullPredictionTooltip, "ShowFullPredictionTooltip") },
238239
{ Keys.F8, MakeKeyHandler(HistorySearchBackward, "HistorySearchBackward") },
239240
{ Keys.ShiftF8, MakeKeyHandler(HistorySearchForward, "HistorySearchForward") },
240241
// Added for xtermjs-based terminals that send different key combinations.
@@ -339,6 +340,7 @@ void SetDefaultEmacsBindings()
339340
{ Keys.AltH, MakeKeyHandler(ShowParameterHelp, "ShowParameterHelp") },
340341
{ Keys.F1, MakeKeyHandler(ShowCommandHelp, "ShowCommandHelp") },
341342
{ Keys.F2, MakeKeyHandler(SwitchPredictionView, "SwitchPredictionView") },
343+
{ Keys.F4, MakeKeyHandler(ShowFullPredictionTooltip, "ShowFullPredictionTooltip") },
342344
{ Keys.AltU, MakeKeyHandler(UpcaseWord, "UpcaseWord") },
343345
{ Keys.AltL, MakeKeyHandler(DowncaseWord, "DowncaseWord") },
344346
{ Keys.AltC, MakeKeyHandler(CapitalizeWord, "CapitalizeWord") },
@@ -566,6 +568,7 @@ public static KeyHandlerGroup GetDisplayGrouping(string function)
566568
case nameof(NextSuggestion):
567569
case nameof(PreviousSuggestion):
568570
case nameof(SwitchPredictionView):
571+
case nameof(ShowFullPredictionTooltip):
569572
return KeyHandlerGroup.Prediction;
570573

571574
case nameof(CaptureScreen):

PSReadLine/KeyBindings.vi.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ private void SetDefaultViBindings()
9191
{ Keys.CtrlG, MakeKeyHandler(Abort, "Abort") },
9292
{ Keys.AltH, MakeKeyHandler(ShowParameterHelp, "ShowParameterHelp") },
9393
{ Keys.F1, MakeKeyHandler(ShowCommandHelp, "ShowCommandHelp") },
94+
{ Keys.F2, MakeKeyHandler(SwitchPredictionView, "SwitchPredictionView") },
95+
{ Keys.F4, MakeKeyHandler(ShowFullPredictionTooltip, "ShowFullPredictionTooltip") },
9496
};
9597

9698
// Some bindings are not available on certain platforms

PSReadLine/PSReadLine.format.ps1xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ $d = [Microsoft.PowerShell.KeyHandler]::GetGroupingDescription($_.Group)
204204
<Label>ListPredictionSelectedColor</Label>
205205
<ScriptBlock>[Microsoft.PowerShell.VTColorUtils]::FormatColor($_.ListPredictionSelectedColor)</ScriptBlock>
206206
</ListItem>
207+
<ListItem>
208+
<Label>ListPredictionTooltipColor</Label>
209+
<ScriptBlock>[Microsoft.PowerShell.VTColorUtils]::FormatColor($_.ListPredictionTooltipColor)</ScriptBlock>
210+
</ListItem>
207211
<ListItem>
208212
<Label>MemberColor</Label>
209213
<ScriptBlock>[Microsoft.PowerShell.VTColorUtils]::FormatColor($_.MemberColor)</ScriptBlock>

PSReadLine/PSReadLineResources.Designer.cs

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PSReadLine/PSReadLineResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,9 @@ Or not saving history with:
837837
<data name="SwitchPredictionViewDescription" xml:space="preserve">
838838
<value>Switch between the inline and list prediction views.</value>
839839
</data>
840+
<data name="ShowFullPredictionTooltipDescription" xml:space="preserve">
841+
<value>Show the full tooltip of the selected list-view item in the terminal's alternate screen buffer.</value>
842+
</data>
840843
<data name="WindowSizeTooSmallForListView" xml:space="preserve">
841844
<value>The prediction 'ListView' is temporarily disabled because the current window size of the console is too small. To use the 'ListView', please make sure the 'WindowWidth' is not less than '{0}' and the 'WindowHeight' is not less than '{1}'.</value>
842845
</data>

PSReadLine/Prediction.Entry.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,25 @@ private struct SuggestionEntry
4747
internal readonly Guid PredictorId;
4848
internal readonly uint? PredictorSession;
4949
internal readonly string Source;
50+
internal readonly string ToolTip;
5051
internal readonly string SuggestionText;
5152
internal readonly int InputMatchIndex;
5253

5354
private string _listItemTextRegular;
5455
private string _listItemTextSelected;
5556

5657
internal SuggestionEntry(string suggestion, int matchIndex)
57-
: this(source: HistorySource, predictorId: Guid.Empty, predictorSession: null, suggestion, matchIndex)
58+
: this(source: HistorySource, predictorId: Guid.Empty, predictorSession: null, suggestion, tooltip: null, matchIndex)
5859
{
5960
}
6061

61-
internal SuggestionEntry(string source, Guid predictorId, uint? predictorSession, string suggestion, int matchIndex)
62+
internal SuggestionEntry(string source, Guid predictorId, uint? predictorSession, string suggestion, string tooltip, int matchIndex)
6263
{
6364
Source = source;
6465
PredictorId = predictorId;
6566
PredictorSession = predictorSession;
6667
SuggestionText = suggestion;
68+
ToolTip = tooltip;
6769
InputMatchIndex = matchIndex;
6870

6971
_listItemTextRegular = _listItemTextSelected = null;

0 commit comments

Comments
 (0)