From 311af8916ca4d02ce12c0a4e0b511eba23db2f5d Mon Sep 17 00:00:00 2001 From: thc1006 Date: Mon, 31 Aug 2026 22:22:53 +0800 Subject: [PATCH 1/2] Don't warn about the list view window size from `Get-PSReadLineOption` `Set-PSReadLineOption -PredictionViewStyle ListView` already warns when the user opts into a view the window cannot show, which is where the advice is actionable. Repeating it on every read means any caller triggers it, including prompt modules that read the options once at load time, and the person who configured ListView cannot suppress a warning raised from someone else's code. --- PSReadLine/Cmdlets.cs | 4 +--- test/ListScrollableViewTest.cs | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/PSReadLine/Cmdlets.cs b/PSReadLine/Cmdlets.cs index 596b1548e..c0287a141 100644 --- a/PSReadLine/Cmdlets.cs +++ b/PSReadLine/Cmdlets.cs @@ -634,9 +634,7 @@ public class GetPSReadLineOption : PSCmdlet [ExcludeFromCodeCoverage] protected override void EndProcessing() { - var options = PSConsoleReadLine.GetOptions(); - WriteObject(options); - PSConsoleReadLine.WarnWhenWindowSizeTooSmallForView(options.PredictionViewStyle, this); + WriteObject(PSConsoleReadLine.GetOptions()); } } diff --git a/test/ListScrollableViewTest.cs b/test/ListScrollableViewTest.cs index 3452c4625..169b38375 100644 --- a/test/ListScrollableViewTest.cs +++ b/test/ListScrollableViewTest.cs @@ -1,4 +1,5 @@ using System; +using System.Management.Automation.Runspaces; using Microsoft.PowerShell; using Xunit; @@ -910,5 +911,31 @@ public void ListView_TermSize_Warning() NextLine)) )); } + + [SkippableFact] + public void ListView_TermSize_WarningOnlyFromSetOption() + { + Skip.If(ScreenReaderModeEnabled, "List view is not supported in screen reader mode."); + + // The console is under the list view minimum. 'F2' switches the view without + // 'Set-PSReadLineOption', so the two cmdlets can be measured separately. + TestSetup(new TestConsole(keyboardLayout: _, width: 40, height: 4), KeyMode.Cmd); + using var disp = SetPrediction(PredictionSource.History, PredictionViewStyle.InlineView); + Test("", Keys(_.F2, _.Enter)); + + var iss = InitialSessionState.CreateDefault(); + iss.Commands.Add(new SessionStateCmdletEntry("Get-PSReadLineOption", typeof(GetPSReadLineOption), helpFileName: null)); + iss.Commands.Add(new SessionStateCmdletEntry("Set-PSReadLineOption", typeof(SetPSReadLineOption), helpFileName: null)); + using var ps = System.Management.Automation.PowerShell.Create(iss); + + var result = ps.AddCommand("Get-PSReadLineOption").Invoke(); + var options = Assert.IsType(Assert.Single(result).BaseObject); + Assert.Equal(PredictionViewStyle.ListView, options.PredictionViewStyle); + Assert.Empty(ps.Streams.Warning); + + ps.Commands.Clear(); + ps.AddCommand("Set-PSReadLineOption").AddParameter("PredictionViewStyle", PredictionViewStyle.ListView).Invoke(); + Assert.Single(ps.Streams.Warning); + } } } From 17ebf3aa1ea73df46f60ad1d7e656c9d01d4a659 Mon Sep 17 00:00:00 2001 From: thc1006 Date: Mon, 31 Aug 2026 22:33:02 +0800 Subject: [PATCH 2/2] Sync `MinWindowHeight` in the list view tests with `PredictionListView` #3583 lowered `PredictionListView.MinWindowHeight` from 15 to 5 and updated the mirrored `MinWindowWidth` in the tests, but left `MinWindowHeight` at 15. --- test/ListPredictionTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ListPredictionTest.cs b/test/ListPredictionTest.cs index a0a426962..1dd6eaed5 100644 --- a/test/ListPredictionTest.cs +++ b/test/ListPredictionTest.cs @@ -9,7 +9,7 @@ public partial class ReadLine // The source of truth is defined in 'Microsoft.PowerShell.PSConsoleReadLine+PredictionListView'. // Make sure the values are in sync. private const int MinWindowWidth = 50; - private const int MinWindowHeight = 15; + private const int MinWindowHeight = 5; private const int ListMaxWidth = 100; private const int SourceMaxWidth = 15;