Adds text and Progress bar spinner column for tasks yet to be started

This commit is contained in:
Phil Scott 2021-02-14 12:03:57 -05:00 committed by GitHub
parent 102e2dc38d
commit 9312663bde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,7 @@ namespace Spectre.Console
private Spinner _spinner;
private int? _maxWidth;
private string? _completed;
private string? _pending;
/// <inheritdoc/>
protected internal override bool NoWrap => true;
@ -50,11 +51,30 @@ namespace Spectre.Console
}
}
/// <summary>
/// Gets or sets the text that should be shown instead
/// of the spinner before a task begins.
/// </summary>
public string? PendingText
{
get => _pending;
set
{
_pending = value;
_maxWidth = null;
}
}
/// <summary>
/// Gets or sets the completed style.
/// </summary>
public Style? CompletedStyle { get; set; }
/// <summary>
/// Gets or sets the pending style.
/// </summary>
public Style? PendingStyle { get; set; }
/// <summary>
/// Gets or sets the style of the spinner.
/// </summary>
@ -84,7 +104,12 @@ namespace Spectre.Console
var useAscii = (context.LegacyConsole || !context.Unicode) && _spinner.IsUnicode;
var spinner = useAscii ? Spinner.Known.Ascii : _spinner ?? Spinner.Known.Default;
if (!task.IsStarted || task.IsFinished)
if (!task.IsStarted)
{
return new Markup(PendingText ?? " ", PendingStyle ?? Style.Plain);
}
if (task.IsFinished)
{
return new Markup(CompletedText ?? " ", CompletedStyle ?? Style.Plain);
}
@ -117,7 +142,9 @@ namespace Spectre.Console
var spinner = useAscii ? Spinner.Known.Ascii : _spinner ?? Spinner.Known.Default;
_maxWidth = Math.Max(
((IRenderable)new Markup(CompletedText ?? " ")).Measure(context, int.MaxValue).Max,
Math.Max(
((IRenderable)new Markup(PendingText ?? " ")).Measure(context, int.MaxValue).Max,
((IRenderable)new Markup(CompletedText ?? " ")).Measure(context, int.MaxValue).Max),
spinner.Frames.Max(frame => Cell.GetCellLength(context, frame)));
}