-
Notifications
You must be signed in to change notification settings - Fork 632
Abort SelectionPrompt and MultiSelectionPrompt with Escape key
#711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
09f1b68
daacd53
a040f49
edb254e
c38a03e
723212b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,16 @@ public sealed class SelectionPrompt<T> : IPrompt<T>, IListPromptStrategy<T> | |
| /// </summary> | ||
| public SelectionMode Mode { get; set; } = SelectionMode.Leaf; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value indicating whether the prompt can be aborted. | ||
jariq marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// </summary> | ||
| public bool AllowAbort { get; set; } = false; | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether or not the prompt was aborted. | ||
| /// </summary> | ||
| public bool Aborted { get; private set; } = false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of mutating the Prompt item. @phil-scott-78 @nils-a What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use ShowSortable then it should contain ShowSortableAsync too. I more like solution with AllowAbort method. var item = await new SelectionPrompt<string>()
.AllowAbort(true)
.AddChoices( chocies )
.ShowAsync( AnsiConsole.Console, CancellationToken.None );Also, It will be interesting if this feature could be a part of IPrompt. I think that option to abort TextPrompt could be usefull. But I know that is bigger change. Adding it to selection without interface is still one step forward. |
||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SelectionPrompt{T}"/> class. | ||
| /// </summary> | ||
|
|
@@ -95,9 +105,16 @@ ListPromptInputResult IListPromptStrategy<T>.HandleInput(ConsoleKeyInfo key, Lis | |
| return ListPromptInputResult.None; | ||
| } | ||
|
|
||
| Aborted = false; | ||
| return ListPromptInputResult.Submit; | ||
| } | ||
|
|
||
| if (key.Key == ConsoleKey.Escape && AllowAbort) | ||
| { | ||
| Aborted = true; | ||
| return ListPromptInputResult.Abort; | ||
| } | ||
|
|
||
| return ListPromptInputResult.None; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.