mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2025-12-29 17:28:06 +01:00
Closes #85 * Split Border into BoxBorder and TableBorder * Change how different table parts are composed * Add markdown table border
67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using System;
|
|
|
|
namespace Spectre.Console
|
|
{
|
|
/// <summary>
|
|
/// Contains extension methods for <see cref="IHasBorder"/>.
|
|
/// </summary>
|
|
public static class HasBorderExtensions
|
|
{
|
|
/// <summary>
|
|
/// Disables the safe border.
|
|
/// </summary>
|
|
/// <typeparam name="T">An object type with a border.</typeparam>
|
|
/// <param name="obj">The object to set the border for.</param>
|
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
public static T NoSafeBorder<T>(this T obj)
|
|
where T : class, IHasBorder
|
|
{
|
|
if (obj is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(obj));
|
|
}
|
|
|
|
obj.UseSafeBorder = false;
|
|
return obj;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the border style.
|
|
/// </summary>
|
|
/// <typeparam name="T">An object type with a border.</typeparam>
|
|
/// <param name="obj">The object to set the border color for.</param>
|
|
/// <param name="style">The border style to set.</param>
|
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
public static T SetBorderStyle<T>(this T obj, Style style)
|
|
where T : class, IHasBorder
|
|
{
|
|
if (obj is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(obj));
|
|
}
|
|
|
|
obj.BorderStyle = style;
|
|
return obj;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the border color.
|
|
/// </summary>
|
|
/// <typeparam name="T">An object type with a border.</typeparam>
|
|
/// <param name="obj">The object to set the border color for.</param>
|
|
/// <param name="color">The border color to set.</param>
|
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
public static T SetBorderColor<T>(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;
|
|
}
|
|
}
|
|
}
|