spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

Allow user to cancel input during Prompt()

Open kentico-ericd opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. When requesting user input multiple times, it would be nice to provide a way for the user to return to previous steps in case they've entered some wrong information.

Describe the solution you'd like We could capture the ESC keypress during AnsiConsole.Prompt and set a variable, e.g. AnsiConsole.Prompt(prompt, out var cancelled) to indicate the user pressed escape. Or, the return value of AnsiConsole.Prompt could be null if the input was cancelled.

Describe alternatives you've considered There are some incomplete code samples here that I've tried, but there are multiple issues with the code such as exceptions and formatting problems. It would be great if this was a native solution in Spectre.Console.


Please upvote :+1: this issue if you are interested in it.

kentico-ericd avatar Dec 01 '23 19:12 kentico-ericd

I did request some thing similar last year, but it did not go anywhere unfortunately. It would be nice to make keyboard handling extensible to support something like this:

image

where we could tell prompt to listen for several keys depending on user scenario, like Esc or Ctrl+C or q for exit, back key or help key etc.

abpiskunov avatar Jan 03 '24 18:01 abpiskunov

Yeah, cancel would be nice.

schlechtOptimiziert avatar Mar 13 '24 10:03 schlechtOptimiziert