using System;
using System.Linq;
namespace Spectre.Console
{
///
/// Contains extension methods for .
///
public static class ProgressExtensions
{
///
/// Sets the columns to be used for an instance.
///
/// The instance.
/// The columns to use.
/// The same instance so that multiple calls can be chained.
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;
}
///
/// Sets whether or not auto refresh is enabled.
/// If disabled, you will manually have to refresh the progress.
///
/// The instance.
/// Whether or not auto refresh is enabled.
/// The same instance so that multiple calls can be chained.
public static Progress AutoRefresh(this Progress progress, bool enabled)
{
if (progress is null)
{
throw new ArgumentNullException(nameof(progress));
}
progress.AutoRefresh = enabled;
return progress;
}
///
/// Sets whether or not auto clear is enabled.
/// If enabled, the task tabled will be removed once
/// all tasks have completed.
///
/// The instance.
/// Whether or not auto clear is enabled.
/// The same instance so that multiple calls can be chained.
public static Progress AutoClear(this Progress progress, bool enabled)
{
if (progress is null)
{
throw new ArgumentNullException(nameof(progress));
}
progress.AutoClear = enabled;
return progress;
}
///
/// Sets whether or not hide completed is enabled.
/// If enabled, the task tabled will be removed once it is
/// completed.
///
/// The instance.
/// Whether or not hide completed is enabled.
/// The same instance so that multiple calls can be chained.
public static Progress HideCompleted(this Progress progress, bool enabled)
{
if (progress is null)
{
throw new ArgumentNullException(nameof(progress));
}
progress.HideCompleted = enabled;
return progress;
}
}
}