Skip to content

Update PSReadline documentation for InvokePrompt behavior change. #12157

Open
@jftkcs

Description

@jftkcs

Prerequisites

  • Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
  • Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Document new Get-Foo cmdlet" instead of "New cmdlet."

Summary

InvokePrompt behavior will be updated to silently return if it's not possible to rewrite the prompt instead of throwing an exception. Existing exception behavior will continue for callers explicitly specifying an invalid Y position.

Previous description of InvokePrompt

Erases the current prompt and calls the prompt function to redisplay the
prompt. Useful for custom key handlers that change state. For example, change
the current directory.

Proposed Description

Attempt to erase the current prompt and call the prompt function to redisplay
the prompt. Useful for custom key handlers that change state. For example,
change the current directory. This method cannot overwrite a prompt that has
left the screen buffer. Calls to InvokePrompt with no Y position argument will 
immediately return if the prompt cannot be overwritten.

Details

Aligns behavior with that stated in issue PowerShell/PSReadLine#4790:

  • Calls to InvokePrompt silently return if it's not possible to redraw the entire prompt and no Y position was specified by the caller.
  • An exception is thrown if a call is made to InvokePrompt with an explicit Y position that is not possible.

Since implicit callers (i.e. those not specifying a Y position) can't know where the prompt will get written, they can't guard against accidentally trying to update a prompt that's left the buffer. The only thing that can be done by anyone once the prompt has left the screen is to accept the line or abort.

Explicit callers passing a Y value in 'arg' at least know where they are trying to write the prompt so we can throw the exception and let them handle/recover (if desired).

Articles

  • reference\5.1\PSReadLine\About\about_PSReadLine_Functions.md
  • reference\7.4\PSReadLine\About\about_PSReadLine_Functions.md
  • reference\7.5\PSReadLine\About\about_PSReadLine_Functions.md
  • reference\7.6\PSReadLine\About\about_PSReadLine_Functions.md

Related Source Pull Requests

Related Source Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions