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

Ouverte Adaptée aux débutants
#5,205 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
78/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
csharp
Domaine
cli

Piste de recherche

Commencez par localiser GetPSReadLineOption.EndProcessing et WarnWhenWindowSizeTooSmallForView, que l’issue identifie comme le chemin d’avertissement. Reproduisez le comportement avec les commandes Set-PSReadLineOption et Get-PSReadLineOption fournies, avec une fenêtre de taille 49x20. Le travail est terminé lorsque la lecture des options n’écrit plus l’avertissement, tandis que l’activation de ListView continue de générer un avertissement lorsque cela est approprié.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Needs-Triage :mag:
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.

Langage dominant
C#
Étoiles
4.4k
Forks
341
Métriques de merge des PR
Aucune PR mergée en 30 j

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de PowerShell/PSReadLine

Toutes les issues de PowerShell/PSReadLine

Issues similaires

Plus d'issues C#

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.