Support cancellation of prompts

Closes #417
This commit is contained in:
Patrik Svensson
2021-07-10 21:03:13 +02:00
committed by Phil Scott
parent 884cb8ddd4
commit 5f97f2300c
15 changed files with 117 additions and 26 deletions

View File

@ -2,6 +2,8 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Spectre.Console.Rendering;
namespace Spectre.Console
@ -85,10 +87,16 @@ namespace Spectre.Console
/// <inheritdoc/>
public List<T> Show(IAnsiConsole console)
{
return ShowAsync(console, CancellationToken.None).GetAwaiter().GetResult();
}
/// <inheritdoc/>
public async Task<List<T>> ShowAsync(IAnsiConsole console, CancellationToken cancellationToken)
{
// Create the list prompt
var prompt = new ListPrompt<T>(console, this);
var result = prompt.Show(Tree, PageSize);
var result = await prompt.Show(Tree, cancellationToken, PageSize).ConfigureAwait(false);
if (Mode == SelectionMode.Leaf)
{