Skip to content

Get-PSReadLineOption emits the ListView window-size warning, so prompt modules trigger it on every shell start #5205

Description

@thc1006

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

N/A

Screenshot

N/A - the console output is pasted verbatim under Actual behavior.

Environment data

PS Version: 7.6.5
PS HostName: ConsoleHost
PSReadLine Version: 2.4.5
PSReadLine EditMode: Windows
OS: 10.0.26100.8875 (WinBuild.160101.0800)
BufferWidth: 49
BufferHeight: 20

Steps to reproduce

[Console]::SetWindowSize(49, 20)    # anything below 50 columns or 5 rows
[Console]::SetBufferSize(49, 20)
Set-PSReadLineOption -PredictionViewStyle ListView -WarningAction SilentlyContinue
Get-PSReadLineOption | Out-Null
Get-PSReadLineOption | Out-Null

Where I actually ran into it: oh-my-posh's PowerShell init reads the options once when its module loads, to back up the prompt settings it is about to replace (omp.ps1):

$originalPSReadLineOptions = Get-PSReadLineOption

An editor terminal is often still below the threshold at the moment the profile runs - I hit this in Zed on Windows, where the pty is created before the terminal dock has been laid out. So the warning shows up on shell start: once for that read, and again for my own Set-PSReadLineOption -PredictionViewStyle ListView in the profile.

Expected behavior

Get-PSReadLineOption reads configuration, so it should return the options without writing to the warning stream. Set-PSReadLineOption -PredictionViewStyle ListView already warns at the point where the user opts in, which is where the advice is actionable.

Actual behavior

Every call warns, for as long as ListView is the active view style and the window is below 50x5:

WindowWidth = 49, WindowHeight = 20
PredictionViewStyle is now: ListView
-- calling Get-PSReadLineOption --
WARNING: 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 '50' and the 'WindowHeight' is not less than '5'.
-- calling it again --
WARNING: 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 '50' and the 'WindowHeight' is not less than '5'.

Two things that make it awkward to live with:

  • It also fires with PredictionSource = None, where nothing is predicted at all and the view style has no effect.
  • -WarningAction and $WarningPreference belong to the caller. Here the caller is the prompt module, so the person who chose ListView cannot turn it off without redirecting the warning stream around somebody else's init script.

GetPSReadLineOption.EndProcessing has called WarnWhenWindowSizeTooSmallForView since ListView was added in #1909, so I assume it is deliberate. If you want to keep telling people on read, warning once and re-arming when the window grows back would remove the noise on its own. If you would rather drop it from the read path, that is a one-line change. Happy to send a PR for whichever you prefer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-Triage 🔍It's a new issue that core contributor team needs to triage.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions