shibayan / Sharprompt

Interactive command-line based application framework for C#
MIT License
771 stars 50 forks source link

Manually cancel/reset open forms #208

Open IbexPeak opened 2 years ago

IbexPeak commented 2 years ago

Hi shibayan,

I currently have the problem that I can't cancel a form like an input form manually.

In my application a wpf window hosts a console, which is shown upon request and can be hidden using a button. If the user inputs text without pressing enter, but than hides the console, the next time the (cleared) console is displayed, the last form is still opened, and results in strange effects with the next inputs (inputs are combined with cached inputs). Creating a fresh console instance does not resolve the problem, as the input form is still open inside Sharprompt.

Currently the only solution is when the use enters "Ctrl" + "C" in combination with Prompt.ThrowExceptionOnCancel, which internally resets the form in Sharprompt. It would be nice if this reset can be called at any time from code for all open forms.

Thanks in advance!

dan-kli commented 2 years ago

Hey, I would also love to have this feature.

I have a console app that sometimes receives requests from a server, in which case I would like to stop the current prompt question and start a new one with the request coming from the server.

Thanks for making this cool prompt, I was looking for something like this for a while and just came across this project this week.

shibayan commented 2 years ago

Do you think adding support for CancellationToken would fulfill your request?

I would like to refer to the API design.

dan-kli commented 2 years ago

For my case I would think that would definitely work, all I want to do is to cancel the current prompt question and create a new one.

I guess this is also what @IbexPeak needs?

Thank you for your reply.

IbexPeak commented 2 years ago

Sorry for the late reply, CancellationToken would be ok for me.

hheexx commented 2 years ago

CancellationToken would be nice. Additional nice feature would be to support handilng ESC in prompts (in addition to ctrl+c).