Clean up status related code a bit

This commit is contained in:
Patrik Svensson
2020-12-09 08:23:44 +01:00
committed by Patrik Svensson
parent 501db5d287
commit acf01e056f
12 changed files with 9 additions and 56 deletions

View File

@@ -0,0 +1,79 @@
using System;
using System.Linq;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="Progress"/>.
/// </summary>
public static class ProgressExtensions
{
/// <summary>
/// Sets the columns to be used for an <see cref="Progress"/> instance.
/// </summary>
/// <param name="progress">The <see cref="Progress"/> instance.</param>
/// <param name="columns">The columns to use.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Progress Columns(this Progress progress, ProgressColumn[] columns)
{
if (progress is null)
{
throw new ArgumentNullException(nameof(progress));
}
if (columns is null)
{
throw new ArgumentNullException(nameof(columns));
}
if (!columns.Any())
{
throw new InvalidOperationException("At least one column must be specified.");
}
progress.Columns.Clear();
progress.Columns.AddRange(columns);
return progress;
}
/// <summary>
/// Sets whether or not auto refresh is enabled.
/// If disabled, you will manually have to refresh the progress.
/// </summary>
/// <param name="progress">The <see cref="Progress"/> instance.</param>
/// <param name="enabled">Whether or not auto refresh is enabled.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Progress AutoRefresh(this Progress progress, bool enabled)
{
if (progress is null)
{
throw new ArgumentNullException(nameof(progress));
}
progress.AutoRefresh = enabled;
return progress;
}
/// <summary>
/// Sets whether or not auto clear is enabled.
/// If enabled, the task tabled will be removed once
/// all tasks have completed.
/// </summary>
/// <param name="progress">The <see cref="Progress"/> instance.</param>
/// <param name="enabled">Whether or not auto clear is enabled.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Progress AutoClear(this Progress progress, bool enabled)
{
if (progress is null)
{
throw new ArgumentNullException(nameof(progress));
}
progress.AutoClear = enabled;
return progress;
}
}
}