mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Add Progress.HideCompleted
This commit is contained in:
@ -75,5 +75,25 @@ namespace Spectre.Console
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether or not hide completed is enabled.
|
||||
/// If enabled, the task tabled will be removed once it is
|
||||
/// completed.
|
||||
/// </summary>
|
||||
/// <param name="progress">The <see cref="Progress"/> instance.</param>
|
||||
/// <param name="enabled">Whether or not hide completed is enabled.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Progress HideCompleted(this Progress progress, bool enabled)
|
||||
{
|
||||
if (progress is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(progress));
|
||||
}
|
||||
|
||||
progress.HideCompleted = enabled;
|
||||
|
||||
return progress;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,13 @@ namespace Spectre.Console
|
||||
/// </summary>
|
||||
public bool AutoClear { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the task list should
|
||||
/// only include tasks not completed
|
||||
/// Defaults to <c>false</c>.
|
||||
/// </summary>
|
||||
public bool HideCompleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the refresh rate if <c>AutoRefresh</c> is enabled.
|
||||
/// Defaults to 10 times/second.
|
||||
@ -153,7 +160,7 @@ namespace Spectre.Console
|
||||
if (interactive)
|
||||
{
|
||||
var columns = new List<ProgressColumn>(Columns);
|
||||
return new DefaultProgressRenderer(_console, columns, RefreshRate);
|
||||
return new DefaultProgressRenderer(_console, columns, RefreshRate, HideCompleted);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -14,10 +14,11 @@ namespace Spectre.Console
|
||||
private readonly object _lock;
|
||||
private readonly Stopwatch _stopwatch;
|
||||
private TimeSpan _lastUpdate;
|
||||
private bool _hideCompleted;
|
||||
|
||||
public override TimeSpan RefreshRate { get; }
|
||||
|
||||
public DefaultProgressRenderer(IAnsiConsole console, List<ProgressColumn> columns, TimeSpan refreshRate)
|
||||
public DefaultProgressRenderer(IAnsiConsole console, List<ProgressColumn> columns, TimeSpan refreshRate, bool hideCompleted)
|
||||
{
|
||||
_console = console ?? throw new ArgumentNullException(nameof(console));
|
||||
_columns = columns ?? throw new ArgumentNullException(nameof(columns));
|
||||
@ -25,6 +26,7 @@ namespace Spectre.Console
|
||||
_lock = new object();
|
||||
_stopwatch = new Stopwatch();
|
||||
_lastUpdate = TimeSpan.Zero;
|
||||
_hideCompleted = hideCompleted;
|
||||
|
||||
RefreshRate = refreshRate;
|
||||
}
|
||||
@ -91,7 +93,7 @@ namespace Spectre.Console
|
||||
}
|
||||
|
||||
// Add rows
|
||||
foreach (var task in context.GetTasks())
|
||||
foreach (var task in context.GetTasks().Where(tsk => !(_hideCompleted && tsk.IsFinished)))
|
||||
{
|
||||
var columns = _columns.Select(column => column.Render(renderContext, task, delta));
|
||||
grid.AddRow(columns.ToArray());
|
||||
|
Reference in New Issue
Block a user