Add status support

This commit is contained in:
Patrik Svensson
2020-12-08 00:43:24 +01:00
committed by Patrik Svensson
parent cbed41e637
commit 501db5d287
36 changed files with 1290 additions and 476 deletions

View File

@ -21,5 +21,20 @@ namespace Spectre.Console
return new Progress(console);
}
/// <summary>
/// Creates a new <see cref="Status"/> instance for the console.
/// </summary>
/// <param name="console">The console.</param>
/// <returns>A <see cref="Status"/> instance.</returns>
public static Status Status(this IAnsiConsole console)
{
if (console is null)
{
throw new ArgumentNullException(nameof(console));
}
return new Status(console);
}
}
}

View File

@ -13,19 +13,18 @@ namespace Spectre.Console
/// <param name="column">The column.</param>
/// <param name="style">The style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static SpinnerColumn Style(this SpinnerColumn column, Style style)
public static SpinnerColumn Style(this SpinnerColumn column, Style? style)
{
if (column is null)
{
throw new ArgumentNullException(nameof(column));
}
if (style is null)
if (style != null)
{
throw new ArgumentNullException(nameof(style));
column.Style = style;
}
column.Style = style;
return column;
}
}

View File

@ -0,0 +1,61 @@
using System;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="StatusContext"/>.
/// </summary>
public static class StatusContextExtensions
{
/// <summary>
/// Sets the status message.
/// </summary>
/// <param name="context">The status context.</param>
/// <param name="status">The status message.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static StatusContext Status(this StatusContext context, string status)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
context.Status = status;
return context;
}
/// <summary>
/// Sets the spinner.
/// </summary>
/// <param name="context">The status context.</param>
/// <param name="spinner">The spinner.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static StatusContext Spinner(this StatusContext context, Spinner spinner)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
context.Spinner = spinner;
return context;
}
/// <summary>
/// Sets the spinner style.
/// </summary>
/// <param name="context">The status context.</param>
/// <param name="style">The spinner style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static StatusContext SpinnerStyle(this StatusContext context, Style? style)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
context.SpinnerStyle = style;
return context;
}
}
}

View File

@ -0,0 +1,62 @@
using System;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="Status"/>.
/// </summary>
public static class StatusExtensions
{
/// <summary>
/// Sets whether or not auto refresh is enabled.
/// If disabled, you will manually have to refresh the progress.
/// </summary>
/// <param name="status">The <see cref="Status"/> 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 Status AutoRefresh(this Status status, bool enabled)
{
if (status is null)
{
throw new ArgumentNullException(nameof(status));
}
status.AutoRefresh = enabled;
return status;
}
/// <summary>
/// Sets the spinner.
/// </summary>
/// <param name="status">The <see cref="Status"/> instance.</param>
/// <param name="spinner">The spinner.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Status Spinner(this Status status, Spinner spinner)
{
if (status is null)
{
throw new ArgumentNullException(nameof(status));
}
status.Spinner = spinner;
return status;
}
/// <summary>
/// Sets the spinner style.
/// </summary>
/// <param name="status">The <see cref="Status"/> instance.</param>
/// <param name="style">The spinner style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Status SpinnerStyle(this Status status, Style? style)
{
if (status is null)
{
throw new ArgumentNullException(nameof(status));
}
status.SpinnerStyle = style;
return status;
}
}
}