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:
Patrik Svensson
2021-04-02 18:41:25 +02:00
committed by Phil Scott
parent 6121203fee
commit 6f16081f42
15 changed files with 196 additions and 42 deletions

View File

@ -9,6 +9,11 @@ namespace Spectre.Console.Rendering
{
private readonly IReadOnlyCapabilities _capabilities;
/// <summary>
/// Gets the current color system.
/// </summary>
public ColorSystem ColorSystem { get; }
/// <summary>
/// Gets a value indicating whether or not unicode is supported.
/// </summary>
@ -28,17 +33,19 @@ namespace Spectre.Console.Rendering
/// <summary>
/// Initializes a new instance of the <see cref="RenderContext"/> class.
/// </summary>
/// <param name="colorSystem">The color system.</param>
/// <param name="capabilities">The capabilities.</param>
/// <param name="justification">The justification.</param>
public RenderContext(IReadOnlyCapabilities capabilities, Justify? justification = null)
: this(capabilities, justification, false)
public RenderContext(ColorSystem colorSystem, IReadOnlyCapabilities capabilities, Justify? justification = null)
: this(colorSystem, capabilities, justification, false)
{
}
private RenderContext(IReadOnlyCapabilities capabilities, Justify? justification = null, bool singleLine = false)
private RenderContext(ColorSystem colorSystem, IReadOnlyCapabilities capabilities, Justify? justification = null, bool singleLine = false)
{
_capabilities = capabilities ?? throw new ArgumentNullException(nameof(capabilities));
ColorSystem = colorSystem;
Justification = justification;
SingleLine = singleLine;
}
@ -50,7 +57,7 @@ namespace Spectre.Console.Rendering
/// <returns>A new <see cref="RenderContext"/> instance.</returns>
public RenderContext WithJustification(Justify? justification)
{
return new RenderContext(_capabilities, justification, SingleLine);
return new RenderContext(ColorSystem, _capabilities, justification, SingleLine);
}
/// <summary>
@ -65,7 +72,7 @@ namespace Spectre.Console.Rendering
/// <returns>A new <see cref="RenderContext"/> instance.</returns>
internal RenderContext WithSingleLine()
{
return new RenderContext(_capabilities, Justification, true);
return new RenderContext(ColorSystem, _capabilities, Justification, true);
}
}
}