mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 17:02:51 +08:00
Adds text and Progress bar spinner column for tasks yet to be started
This commit is contained in:
parent
102e2dc38d
commit
9312663bde
@ -16,6 +16,7 @@ namespace Spectre.Console
|
|||||||
private Spinner _spinner;
|
private Spinner _spinner;
|
||||||
private int? _maxWidth;
|
private int? _maxWidth;
|
||||||
private string? _completed;
|
private string? _completed;
|
||||||
|
private string? _pending;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected internal override bool NoWrap => true;
|
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>
|
/// <summary>
|
||||||
/// Gets or sets the completed style.
|
/// Gets or sets the completed style.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Style? CompletedStyle { get; set; }
|
public Style? CompletedStyle { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the pending style.
|
||||||
|
/// </summary>
|
||||||
|
public Style? PendingStyle { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the style of the spinner.
|
/// Gets or sets the style of the spinner.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -84,7 +104,12 @@ namespace Spectre.Console
|
|||||||
var useAscii = (context.LegacyConsole || !context.Unicode) && _spinner.IsUnicode;
|
var useAscii = (context.LegacyConsole || !context.Unicode) && _spinner.IsUnicode;
|
||||||
var spinner = useAscii ? Spinner.Known.Ascii : _spinner ?? Spinner.Known.Default;
|
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);
|
return new Markup(CompletedText ?? " ", CompletedStyle ?? Style.Plain);
|
||||||
}
|
}
|
||||||
@ -117,7 +142,9 @@ namespace Spectre.Console
|
|||||||
var spinner = useAscii ? Spinner.Known.Ascii : _spinner ?? Spinner.Known.Default;
|
var spinner = useAscii ? Spinner.Known.Ascii : _spinner ?? Spinner.Known.Default;
|
||||||
|
|
||||||
_maxWidth = Math.Max(
|
_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)));
|
spinner.Frames.Max(frame => Cell.GetCellLength(context, frame)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user