Skip to content

Commit 9c136e8

Browse files
feat(prediction): support dynamic list height and remove history caps
Replace hardcoded prediction list limits with user-configurable sizing. Summary: - Remove the fixed 10-line cap and legacy auto-adjustment logic - Prediction list height and capacity now scale based on user settings - History suggestions are no longer artificially capped when plugins are active Key changes: - Convert ListMaxCount and HistoryMaxCount into dynamic properties on PredictionListView - Introduce layout constraints: - PhysicalMax: based on console buffer height (-2 for jitter protection) - PredictionViewHeight: limited by screen space and list capacity - HistoryMaxCount: adjusted to fill the visible view - Remove history cap in AggregateSuggestions (previously limited to 3) Configuration: Add new PSConsoleReadLineOptions properties: - PredictionViewHeight: visible list height - PredictionListCount: total scrollable items - PredictionHistoryCount: history fetch limit Signed-off-by: Konstantin Glukhov <KGlukhov@Hotmail.com>
1 parent 2984546 commit 9c136e8

4 files changed

Lines changed: 84 additions & 11 deletions

File tree

PSReadLine/Cmdlets.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ public class PSConsoleReadLineOptions
112112
/// </summary>
113113
public const int DefaultMaximumHistoryCount = 4096;
114114

115+
/// <summary>
116+
/// The number of lines in prediction list;
117+
/// </summary>
118+
public const int DefaultPredictionListCount = 50;
119+
120+
/// <summary>
121+
/// The number of lines in history prediction list;
122+
/// </summary>
123+
public const int DefaultPredictionHistoryCount = 10;
124+
125+
/// <summary>
126+
/// The number of lines to show from prediction list;
127+
/// </summary>
128+
public const int DefaultPredictionViewHeight = 10;
129+
115130
/// <summary>
116131
/// The maximum number of items to store in the kill ring.
117132
/// </summary>
@@ -202,6 +217,9 @@ public PSConsoleReadLineOptions(string hostName, bool usingLegacyConsole)
202217
ContinuationPromptColor = Console.ForegroundColor;
203218
ExtraPromptLineCount = DefaultExtraPromptLineCount;
204219
AddToHistoryHandler = DefaultAddToHistoryHandler;
220+
PredictionListCount = DefaultPredictionListCount;
221+
PredictionHistoryCount = DefaultPredictionHistoryCount;
222+
PredictionViewHeight = DefaultPredictionViewHeight;
205223
HistoryNoDuplicates = DefaultHistoryNoDuplicates;
206224
MaximumKillRingCount = DefaultMaximumKillRingCount;
207225
HistorySearchCursorMovesToEnd = DefaultHistorySearchCursorMovesToEnd;
@@ -342,6 +360,9 @@ public object ContinuationPromptColor
342360

343361
public int MaximumHistoryCount { get; set; }
344362
public int MaximumKillRingCount { get; set; }
363+
public int PredictionListCount { get; set; }
364+
public int PredictionHistoryCount { get; set; }
365+
public int PredictionViewHeight { get; set; }
345366
public bool HistorySearchCursorMovesToEnd { get; set; }
346367
public bool ShowToolTips { get; set; }
347368
public int DingTone { get; set; }
@@ -655,6 +676,33 @@ public EditMode EditMode
655676
[AllowEmptyString]
656677
public string ContinuationPrompt { get; set; }
657678

679+
[Parameter]
680+
[ValidateRange(1, int.MaxValue)]
681+
public int PredictionListCount
682+
{
683+
get => _predictionListCount.GetValueOrDefault();
684+
set => _predictionListCount = value;
685+
}
686+
internal int? _predictionListCount;
687+
688+
[Parameter]
689+
[ValidateRange(1, int.MaxValue)]
690+
public int PredictionHistoryCount
691+
{
692+
get => _predictionHistoryCount.GetValueOrDefault();
693+
set => _predictionHistoryCount = value;
694+
}
695+
internal int? _predictionHistoryCount;
696+
697+
[Parameter]
698+
[ValidateRange(1, int.MaxValue)]
699+
public int PredictionViewHeight
700+
{
701+
get => _predictionViewHeight.GetValueOrDefault();
702+
set => _predictionViewHeight = value;
703+
}
704+
internal int? _predictionViewHeight;
705+
658706
[Parameter]
659707
public SwitchParameter HistoryNoDuplicates
660708
{

PSReadLine/Options.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ private void SetOptionsInternal(SetPSReadLineOption options)
2626
{
2727
Options.ContinuationPrompt = options.ContinuationPrompt;
2828
}
29+
if (options._predictionListCount.HasValue)
30+
{
31+
Options.PredictionListCount = options.PredictionListCount;
32+
}
33+
if (options._predictionHistoryCount.HasValue)
34+
{
35+
Options.PredictionHistoryCount = options.PredictionHistoryCount;
36+
}
37+
if (options._predictionViewHeight.HasValue)
38+
{
39+
Options.PredictionViewHeight = options.PredictionViewHeight;
40+
}
2941
if (options._historyNoDuplicates.HasValue)
3042
{
3143
Options.HistoryNoDuplicates = options.HistoryNoDuplicates;

PSReadLine/PSReadLine.format.ps1xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ $d = [Microsoft.PowerShell.KeyHandler]::GetGroupingDescription($_.Group)
111111
<ListItem>
112112
<PropertyName>MaximumHistoryCount</PropertyName>
113113
</ListItem>
114+
<ListItem>
115+
<PropertyName>PredictionViewHeight</PropertyName>
116+
</ListItem>
114117
<ListItem>
115118
<PropertyName>ContinuationPrompt</PropertyName>
116119
</ListItem>

PSReadLine/Prediction.Views.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,21 @@ protected List<PredictionResult> GetPredictionResults()
208208
/// </summary>
209209
private class PredictionListView : PredictionViewBase
210210
{
211-
// Item count constants.
212-
internal const int ListMaxCount = 50;
213-
internal const int HistoryMaxCount = 10;
211+
// Physical limit: What can actually fit on the screen?
212+
// We use -2 for the cursor line and the "jitter buffer."
213+
private int PhysicalMax => Math.Max(1, _singleton._console.BufferHeight - 2);
214+
215+
// Visible View: The smaller of (User Request) and (Physical Space)
216+
internal int PredictionViewHeight => Math.Min(_singleton._options.PredictionViewHeight, PhysicalMax);
217+
218+
// Global Ceiling: Remains the total scrollable capacity
219+
internal int ListMaxCount => _singleton._options.PredictionListCount;
220+
221+
// History Fetch: At least enough to fill the view, up to the total ListCount
222+
internal int HistoryMaxCount => Math.Min(
223+
Math.Max(_singleton._options.PredictionHistoryCount, PredictionViewHeight),
224+
ListMaxCount
225+
);
214226

215227
// List view constants.
216228
internal const int ListViewMaxHeight = 10;
@@ -327,19 +339,17 @@ internal PredictionListView(PSConsoleReadLine singleton)
327339
internal override bool HasActiveSuggestion => _listItems != null;
328340

329341
/// <summary>
330-
/// Calculate the max width and height of the list view based on the current terminal size.
342+
/// Calculate the max width and height of the list view based on option value.
331343
/// </summary>
332344
private (int, int, int, bool) RefreshMaxViewSize()
333345
{
334346
var console = _singleton._console;
335347
int maxListWidth = Math.Min(console.BufferWidth, ListViewMaxWidth);
336348

337-
(int maxListHeight, int maxTooltipHeigth, bool moreCheck) = console.BufferHeight switch
338-
{
339-
> ListViewMaxHeight * 2 => (ListViewMaxHeight, TooltipMaxHeight, false),
340-
> ListViewMaxHeight => (ListViewMaxHeight / 2, TooltipMaxHeight / 2, false),
341-
_ => (ListViewMaxHeight / 3, TooltipMaxHeight / 3, true)
342-
};
349+
int maxListHeight = PredictionViewHeight;
350+
int maxTooltipHeigth = TooltipMaxHeight;
351+
352+
bool moreCheck = console.BufferHeight < maxListHeight + 2;
343353

344354
return (maxListWidth, maxListHeight, maxTooltipHeigth, moreCheck);
345355
}
@@ -444,7 +454,7 @@ private void AggregateSuggestions()
444454
_cacheList2 ??= new List<int>(); // This list holds the final number of suggestions that will be rendered for each of the predictors.
445455

446456
int pCount = 0;
447-
int hCount = Math.Min(3, _listItems.Count);
457+
int hCount = Math.Min(PredictionViewHeight, _listItems.Count);
448458
int remRows = ListMaxCount - hCount;
449459

450460
// Calculate the number of plugins that we need to handle,

0 commit comments

Comments
 (0)