Information
- OS: Windows
- Version: 0.45.0
- Terminal: Windows Terminal
Describe the bug
Issue #417 mentions that cancellation should be supported, and PR #477 is said to fix it, but it you, for example, press Ctrl+C while selecting items from a list, the process gets stuck.
I debugged the source, and I believe I found the root cause.
This is the only line of code that checks for cancellation, at all, and this is correct:
|
if (cancellationToken.IsCancellationRequested) |
|
{ |
|
return null; |
|
} |
The problem is that the SelectionPrompt, and likely all other Prompts, are doing this:
|
while (true) |
|
{ |
|
var rawKey = await _console.Input.ReadKeyAsync(true, cancellationToken).ConfigureAwait(false); |
|
if (rawKey == null) |
|
{ |
|
continue; |
They should also check for the cancellation of the cancellation token before they call the underlying method.
To Reproduce
await new SelectionPrompt<T>()
...
.AddChoices(choices)
.ShowAsync(AnsiConsole.Console, ct)
Then simply cancel the cancellation token ct, and the process will get stuck.
Expected behavior
The SelectionPrompt.ShowAsync(...) method should return when the cancellation token is cancelled.
Information
Describe the bug
Issue #417 mentions that cancellation should be supported, and PR #477 is said to fix it, but it you, for example, press Ctrl+C while selecting items from a list, the process gets stuck.
I debugged the source, and I believe I found the root cause.
This is the only line of code that checks for cancellation, at all, and this is correct:
spectre.console/src/Spectre.Console/Internal/DefaultInput.cs
Lines 41 to 44 in 52c1d91
The problem is that the SelectionPrompt, and likely all other Prompts, are doing this:
spectre.console/src/Spectre.Console/Prompts/List/ListPrompt.cs
Lines 49 to 54 in a9b97fa
They should also check for the cancellation of the cancellation token before they call the underlying method.
To Reproduce
Then simply cancel the cancellation token
ct, and the process will get stuck.Expected behavior
The SelectionPrompt.ShowAsync(...) method should return when the cancellation token is cancelled.