mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Add support for indeterminate progress
This commit also changes the behavior of ProgressContext.IsFinished. Only tasks that have been started will be taken into consideration, and not indeterminate tasks. Closes #329 Closes #331
This commit is contained in:

committed by
Phil Scott

parent
6121203fee
commit
6f16081f42
@ -6,6 +6,17 @@ namespace Spectre.Console
|
||||
{
|
||||
internal static class EnumerableExtensions
|
||||
{
|
||||
public static IEnumerable<T> Repeat<T>(this IEnumerable<T> source, int count)
|
||||
{
|
||||
while (count-- > 0)
|
||||
{
|
||||
foreach (var item in source)
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int IndexOf<T>(this IEnumerable<T> source, T item)
|
||||
where T : class
|
||||
{
|
||||
|
@ -57,5 +57,22 @@ namespace Spectre.Console
|
||||
task.Value = value;
|
||||
return task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether the task is considered indeterminate or not.
|
||||
/// </summary>
|
||||
/// <param name="task">The task.</param>
|
||||
/// <param name="indeterminate">Whether the task is considered indeterminate or not.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static ProgressTask IsIndeterminate(this ProgressTask task, bool indeterminate = true)
|
||||
{
|
||||
if (task is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(task));
|
||||
}
|
||||
|
||||
task.IsIndeterminate = indeterminate;
|
||||
return task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace Spectre.Console
|
||||
throw new ArgumentNullException(nameof(renderable));
|
||||
}
|
||||
|
||||
var context = new RenderContext(console.Profile.Capabilities);
|
||||
var context = new RenderContext(console.Profile.ColorSystem, console.Profile.Capabilities);
|
||||
var renderables = console.Pipeline.Process(context, new[] { renderable });
|
||||
|
||||
return GetSegments(console, context, renderables);
|
||||
|
Reference in New Issue
Block a user