shibayan / Sharprompt

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

Support for better prompt cancellation #144

Closed shibayan closed 3 years ago

shibayan commented 3 years ago

I can't think of a use case where interactive console input would require a timeout. In most cases, if you can handle the behavior after sending Ctrl+C, you should be fine.

I haven't checked if it is possible to implement it, but it looks like the following code would be good.

Proposal

try
{
    // Needs `throwExceptionOnCancel` set `true`
    var name = Prompt.Input<string>("What's your name?", throwExceptionOnCancel: true);

    Console.WriteLine($"Hello, {name}!");
}
catch (PromptCancelledException ex)
{
    // handling
}

Additional context