using System;
namespace Spectre.Console
{
///
/// Contains extension methods for .
///
public static class HasBorderExtensions
{
///
/// Disables the safe border.
///
/// An object type with a border.
/// The object to set the 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 color for.
/// The border style to set.
/// The same instance so that multiple calls can be chained.
public static T SetBorderStyle(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 SetBorderColor(this T obj, Color color)
where T : class, IHasBorder
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
obj.BorderStyle = (obj.BorderStyle ?? Style.Plain).WithForeground(color);
return obj;
}
}
}