mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 17:02:51 +08:00
Add Progress.HideCompleted
This commit is contained in:
parent
1cd335e785
commit
1c769c6610
@ -184,5 +184,36 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
// Then
|
// Then
|
||||||
task.Value.ShouldBe(60);
|
task.Value.ShouldBe(60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Hide_Completed_Tasks()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var task = default(ProgressTask);
|
||||||
|
var console = new FakeAnsiConsole(ColorSystem.TrueColor, width: 10);
|
||||||
|
|
||||||
|
var progress = new Progress(console)
|
||||||
|
.Columns(new[] { new ProgressBarColumn() })
|
||||||
|
.AutoRefresh(false)
|
||||||
|
.AutoClear(false)
|
||||||
|
.HideCompleted(true);
|
||||||
|
|
||||||
|
// When
|
||||||
|
progress.Start(ctx =>
|
||||||
|
{
|
||||||
|
task = ctx.AddTask("foo");
|
||||||
|
task.Value = task.MaxValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Output
|
||||||
|
.NormalizeLineEndings()
|
||||||
|
.ShouldBe(
|
||||||
|
"[?25l" + // Hide cursor
|
||||||
|
" \n" + // top padding
|
||||||
|
"…\n" + // hidden task
|
||||||
|
" \n" + // bottom padding
|
||||||
|
"[?25h"); // show cursor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,5 +75,25 @@ namespace Spectre.Console
|
|||||||
|
|
||||||
return progress;
|
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>
|
/// </summary>
|
||||||
public bool AutoClear { get; set; }
|
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>
|
/// <summary>
|
||||||
/// Gets or sets the refresh rate if <c>AutoRefresh</c> is enabled.
|
/// Gets or sets the refresh rate if <c>AutoRefresh</c> is enabled.
|
||||||
/// Defaults to 10 times/second.
|
/// Defaults to 10 times/second.
|
||||||
@ -153,7 +160,7 @@ namespace Spectre.Console
|
|||||||
if (interactive)
|
if (interactive)
|
||||||
{
|
{
|
||||||
var columns = new List<ProgressColumn>(Columns);
|
var columns = new List<ProgressColumn>(Columns);
|
||||||
return new DefaultProgressRenderer(_console, columns, RefreshRate);
|
return new DefaultProgressRenderer(_console, columns, RefreshRate, HideCompleted);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -14,10 +14,11 @@ namespace Spectre.Console
|
|||||||
private readonly object _lock;
|
private readonly object _lock;
|
||||||
private readonly Stopwatch _stopwatch;
|
private readonly Stopwatch _stopwatch;
|
||||||
private TimeSpan _lastUpdate;
|
private TimeSpan _lastUpdate;
|
||||||
|
private bool _hideCompleted;
|
||||||
|
|
||||||
public override TimeSpan RefreshRate { get; }
|
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));
|
_console = console ?? throw new ArgumentNullException(nameof(console));
|
||||||
_columns = columns ?? throw new ArgumentNullException(nameof(columns));
|
_columns = columns ?? throw new ArgumentNullException(nameof(columns));
|
||||||
@ -25,6 +26,7 @@ namespace Spectre.Console
|
|||||||
_lock = new object();
|
_lock = new object();
|
||||||
_stopwatch = new Stopwatch();
|
_stopwatch = new Stopwatch();
|
||||||
_lastUpdate = TimeSpan.Zero;
|
_lastUpdate = TimeSpan.Zero;
|
||||||
|
_hideCompleted = hideCompleted;
|
||||||
|
|
||||||
RefreshRate = refreshRate;
|
RefreshRate = refreshRate;
|
||||||
}
|
}
|
||||||
@ -91,7 +93,7 @@ namespace Spectre.Console
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add rows
|
// 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));
|
var columns = _columns.Select(column => column.Render(renderContext, task, delta));
|
||||||
grid.AddRow(columns.ToArray());
|
grid.AddRow(columns.ToArray());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user