mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-17 17:32:50 +08:00
Add progress and status result overloads
This commit is contained in:
parent
11e192e750
commit
3a593857c8
@ -68,6 +68,18 @@ namespace Spectre.Console
|
|||||||
task.GetAwaiter().GetResult();
|
task.GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts the progress task list and returns a result.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The result type.</typeparam>
|
||||||
|
/// <param name="func">he action to execute.</param>
|
||||||
|
/// <returns>The result.</returns>
|
||||||
|
public T Start<T>(Func<ProgressContext, T> func)
|
||||||
|
{
|
||||||
|
var task = StartAsync(ctx => Task.FromResult(func(ctx)));
|
||||||
|
return task.GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts the progress task list.
|
/// Starts the progress task list.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -82,13 +94,13 @@ namespace Spectre.Console
|
|||||||
|
|
||||||
_ = await StartAsync<object?>(async progressContext =>
|
_ = await StartAsync<object?>(async progressContext =>
|
||||||
{
|
{
|
||||||
await action(progressContext);
|
await action(progressContext).ConfigureAwait(false);
|
||||||
return default;
|
return default;
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts the progress task list.
|
/// Starts the progress task list and returns a result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="action">The action to execute.</param>
|
/// <param name="action">The action to execute.</param>
|
||||||
/// <typeparam name="T">The result type of task.</typeparam>
|
/// <typeparam name="T">The result type of task.</typeparam>
|
||||||
|
@ -52,6 +52,19 @@ namespace Spectre.Console
|
|||||||
task.GetAwaiter().GetResult();
|
task.GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts a new status display.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The result type.</typeparam>
|
||||||
|
/// <param name="status">The status to display.</param>
|
||||||
|
/// <param name="func">he action to execute.</param>
|
||||||
|
/// <returns>The result.</returns>
|
||||||
|
public T Start<T>(string status, Func<StatusContext, T> func)
|
||||||
|
{
|
||||||
|
var task = StartAsync(status, ctx => Task.FromResult(func(ctx)));
|
||||||
|
return task.GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts a new status display.
|
/// Starts a new status display.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -67,23 +80,23 @@ namespace Spectre.Console
|
|||||||
|
|
||||||
_ = await StartAsync<object?>(status, async statusContext =>
|
_ = await StartAsync<object?>(status, async statusContext =>
|
||||||
{
|
{
|
||||||
await action(statusContext);
|
await action(statusContext).ConfigureAwait(false);
|
||||||
return default;
|
return default;
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts a new status display.
|
/// Starts a new status display and returns a result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="status">The status to display.</param>
|
|
||||||
/// <param name="action">he action to execute.</param>
|
|
||||||
/// <typeparam name="T">The result type of task.</typeparam>
|
/// <typeparam name="T">The result type of task.</typeparam>
|
||||||
|
/// <param name="status">The status to display.</param>
|
||||||
|
/// <param name="func">he action to execute.</param>
|
||||||
/// <returns>A <see cref="Task{T}"/> representing the asynchronous operation.</returns>
|
/// <returns>A <see cref="Task{T}"/> representing the asynchronous operation.</returns>
|
||||||
public async Task<T> StartAsync<T>(string status, Func<StatusContext, Task<T>> action)
|
public async Task<T> StartAsync<T>(string status, Func<StatusContext, Task<T>> func)
|
||||||
{
|
{
|
||||||
if (action is null)
|
if (func is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(action));
|
throw new ArgumentNullException(nameof(func));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the progress columns
|
// Set the progress columns
|
||||||
@ -108,7 +121,7 @@ namespace Spectre.Console
|
|||||||
return await progress.StartAsync(async ctx =>
|
return await progress.StartAsync(async ctx =>
|
||||||
{
|
{
|
||||||
var statusContext = new StatusContext(ctx, ctx.AddTask(status), spinnerColumn);
|
var statusContext = new StatusContext(ctx, ctx.AddTask(status), spinnerColumn);
|
||||||
return await action(statusContext).ConfigureAwait(false);
|
return await func(statusContext).ConfigureAwait(false);
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user