Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions PSReadLine/Cmdlets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ public class PSConsoleReadLineOptions
/// </summary>
public const int DefaultMaximumHistoryCount = 4096;

/// <summary>
/// The number of lines in prediction list;
/// </summary>
public const int DefaultPredictionListCount = 50;

/// <summary>
/// The number of lines in history prediction list;
/// </summary>
public const int DefaultPredictionHistoryCount = 10;

/// <summary>
/// The number of lines to show from prediction list;
/// </summary>
public const int DefaultPredictionViewHeight = 10;

/// <summary>
/// The maximum number of items to store in the kill ring.
/// </summary>
Expand Down Expand Up @@ -202,6 +217,9 @@ public PSConsoleReadLineOptions(string hostName, bool usingLegacyConsole)
ContinuationPromptColor = Console.ForegroundColor;
ExtraPromptLineCount = DefaultExtraPromptLineCount;
AddToHistoryHandler = DefaultAddToHistoryHandler;
PredictionListCount = DefaultPredictionListCount;
PredictionHistoryCount = DefaultPredictionHistoryCount;
PredictionViewHeight = DefaultPredictionViewHeight;
HistoryNoDuplicates = DefaultHistoryNoDuplicates;
MaximumKillRingCount = DefaultMaximumKillRingCount;
HistorySearchCursorMovesToEnd = DefaultHistorySearchCursorMovesToEnd;
Expand Down Expand Up @@ -342,6 +360,9 @@ public object ContinuationPromptColor

public int MaximumHistoryCount { get; set; }
public int MaximumKillRingCount { get; set; }
public int PredictionListCount { get; set; }
public int PredictionHistoryCount { get; set; }
public int PredictionViewHeight { get; set; }
public bool HistorySearchCursorMovesToEnd { get; set; }
public bool ShowToolTips { get; set; }
public int DingTone { get; set; }
Expand Down Expand Up @@ -655,6 +676,33 @@ public EditMode EditMode
[AllowEmptyString]
public string ContinuationPrompt { get; set; }

[Parameter]
[ValidateRange(1, int.MaxValue)]
public int PredictionListCount
{
get => _predictionListCount.GetValueOrDefault();
set => _predictionListCount = value;
}
internal int? _predictionListCount;

[Parameter]
[ValidateRange(1, int.MaxValue)]
public int PredictionHistoryCount
{
get => _predictionHistoryCount.GetValueOrDefault();
set => _predictionHistoryCount = value;
}
internal int? _predictionHistoryCount;

[Parameter]
[ValidateRange(1, int.MaxValue)]
public int PredictionViewHeight
{
get => _predictionViewHeight.GetValueOrDefault();
set => _predictionViewHeight = value;
}
internal int? _predictionViewHeight;

[Parameter]
public SwitchParameter HistoryNoDuplicates
{
Expand Down
12 changes: 12 additions & 0 deletions PSReadLine/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ private void SetOptionsInternal(SetPSReadLineOption options)
{
Options.ContinuationPrompt = options.ContinuationPrompt;
}
if (options._predictionListCount.HasValue)
{
Options.PredictionListCount = options.PredictionListCount;
}
if (options._predictionHistoryCount.HasValue)
{
Options.PredictionHistoryCount = options.PredictionHistoryCount;
}
if (options._predictionViewHeight.HasValue)
{
Options.PredictionViewHeight = options.PredictionViewHeight;
}
if (options._historyNoDuplicates.HasValue)
{
Options.HistoryNoDuplicates = options.HistoryNoDuplicates;
Expand Down
3 changes: 3 additions & 0 deletions PSReadLine/PSReadLine.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ $d = [Microsoft.PowerShell.KeyHandler]::GetGroupingDescription($_.Group)
<ListItem>
<PropertyName>MaximumHistoryCount</PropertyName>
</ListItem>
<ListItem>
<PropertyName>PredictionViewHeight</PropertyName>
</ListItem>
<ListItem>
<PropertyName>ContinuationPrompt</PropertyName>
</ListItem>
Expand Down
32 changes: 21 additions & 11 deletions PSReadLine/Prediction.Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,21 @@ protected List<PredictionResult> GetPredictionResults()
/// </summary>
private class PredictionListView : PredictionViewBase
{
// Item count constants.
internal const int ListMaxCount = 50;
internal const int HistoryMaxCount = 10;
// Physical limit: What can actually fit on the screen?
// We use -2 for the cursor line and the "jitter buffer."
private int PhysicalMax => Math.Max(1, _singleton._console.BufferHeight - 2);

// Visible View: The smaller of (User Request) and (Physical Space)
internal int PredictionViewHeight => Math.Min(_singleton._options.PredictionViewHeight, PhysicalMax);

// Global Ceiling: Remains the total scrollable capacity
internal int ListMaxCount => _singleton._options.PredictionListCount;

// History Fetch: At least enough to fill the view, up to the total ListCount
internal int HistoryMaxCount => Math.Min(
Math.Max(_singleton._options.PredictionHistoryCount, PredictionViewHeight),
ListMaxCount
);

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

/// <summary>
/// Calculate the max width and height of the list view based on the current terminal size.
/// Calculate the max width and height of the list view based on option value.
/// </summary>
private (int, int, int, bool) RefreshMaxViewSize()
{
var console = _singleton._console;
int maxListWidth = Math.Min(console.BufferWidth, ListViewMaxWidth);

(int maxListHeight, int maxTooltipHeigth, bool moreCheck) = console.BufferHeight switch
{
> ListViewMaxHeight * 2 => (ListViewMaxHeight, TooltipMaxHeight, false),
> ListViewMaxHeight => (ListViewMaxHeight / 2, TooltipMaxHeight / 2, false),
_ => (ListViewMaxHeight / 3, TooltipMaxHeight / 3, true)
};
int maxListHeight = PredictionViewHeight;
int maxTooltipHeigth = TooltipMaxHeight;

bool moreCheck = console.BufferHeight < maxListHeight + 2;

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

int pCount = 0;
int hCount = Math.Min(3, _listItems.Count);
int hCount = Math.Min(PredictionViewHeight, _listItems.Count);
int remRows = ListMaxCount - hCount;

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