using System;
namespace Spectre.Console
{
///
/// Contains extension methods for .
///
public static class HasBorderExtensions
{
///
/// Enables the safe border.
///
/// An object type with a border.
/// The object to enable the safe border for.
/// The same instance so that multiple calls can be chained.
public static T SafeBorder(this T obj)
where T : class, IHasBorder
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
obj.UseSafeBorder = true;
return obj;
}
///
/// Disables the safe border.
///
/// An object type with a border.
/// The object to disable the safe border for.
/// The same instance so that multiple calls can be chained.
public static T NoSafeBorder(this T obj)
where T : class, IHasBorder
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
obj.UseSafeBorder = false;
return obj;
}
///
/// Sets the border style.
///
/// An object type with a border.
/// The object to set the border style for.
/// The border style to set.
/// The same instance so that multiple calls can be chained.
public static T BorderStyle(this T obj, Style style)
where T : class, IHasBorder
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
obj.BorderStyle = style;
return obj;
}
///
/// Sets the border color.
///
/// An object type with a border.
/// The object to set the border color for.
/// The border color to set.
/// The same instance so that multiple calls can be chained.
public static T BorderColor(this T obj, Color color)
where T : class, IHasBorder
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
obj.BorderStyle = (obj.BorderStyle ?? Style.Plain).Foreground(color);
return obj;
}
}
}