spectre.console/src/Spectre.Console/Extensions/TableColumnExtensions.cs
Patrik Svensson 3dea412785 Add live display support
This commit also adds functionality to LiveRenderable that should
fix some problems related to vertical overflow.

Closes #316
Closes #415
2021-05-20 19:41:10 -04:00

100 lines
3.1 KiB
C#

using System;
using Spectre.Console.Rendering;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="TableColumn"/>.
/// </summary>
public static class TableColumnExtensions
{
/// <summary>
/// Sets the table column header.
/// </summary>
/// <param name="column">The table column.</param>
/// <param name="header">The table column header markup text.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static TableColumn Header(this TableColumn column, string header)
{
if (column is null)
{
throw new ArgumentNullException(nameof(column));
}
if (header is null)
{
throw new ArgumentNullException(nameof(header));
}
column.Header = new Markup(header);
return column;
}
/// <summary>
/// Sets the table column header.
/// </summary>
/// <param name="column">The table column.</param>
/// <param name="header">The table column header.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static TableColumn Header(this TableColumn column, IRenderable header)
{
if (column is null)
{
throw new ArgumentNullException(nameof(column));
}
if (header is null)
{
throw new ArgumentNullException(nameof(header));
}
column.Footer = header;
return column;
}
/// <summary>
/// Sets the table column footer.
/// </summary>
/// <param name="column">The table column.</param>
/// <param name="footer">The table column footer markup text.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static TableColumn Footer(this TableColumn column, string footer)
{
if (column is null)
{
throw new ArgumentNullException(nameof(column));
}
if (footer is null)
{
throw new ArgumentNullException(nameof(footer));
}
column.Footer = new Markup(footer);
return column;
}
/// <summary>
/// Sets the table column footer.
/// </summary>
/// <param name="column">The table column.</param>
/// <param name="footer">The table column footer.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static TableColumn Footer(this TableColumn column, IRenderable footer)
{
if (column is null)
{
throw new ArgumentNullException(nameof(column));
}
if (footer is null)
{
throw new ArgumentNullException(nameof(footer));
}
column.Footer = footer;
return column;
}
}
}