Add support for table footers

This commit is contained in:
Patrik Svensson
2020-10-24 17:15:19 +02:00
committed by Patrik Svensson
parent c9c0ad733f
commit 03334f693d
31 changed files with 504 additions and 132 deletions

View File

@ -12,7 +12,7 @@ namespace Spectre.Console
/// <param name="obj">The alignable object.</param>
/// <param name="alignment">The alignment.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static T Alignment<T>(this T obj, Justify alignment)
public static T Alignment<T>(this T obj, Justify? alignment)
where T : class, IAlignable
{
if (obj is null)

View File

@ -1,7 +1,5 @@
using System;
using System.Linq;
using Spectre.Console.Internal;
using Spectre.Console.Rendering;
using System.ComponentModel;
namespace Spectre.Console
{
@ -17,6 +15,7 @@ namespace Spectre.Console
/// <param name="width">The width.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Width(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Table SetWidth(this Table table, int width)
{
if (table is null)
@ -36,6 +35,7 @@ namespace Spectre.Console
/// <param name="style">The style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Heading(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Table SetHeading(this Table table, string text, Style? style = null)
{
if (table is null)
@ -58,6 +58,7 @@ namespace Spectre.Console
/// <param name="heading">The heading.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Heading(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Table SetHeading(this Table table, TableTitle heading)
{
if (table is null)
@ -65,7 +66,7 @@ namespace Spectre.Console
throw new ArgumentNullException(nameof(table));
}
table.Heading = heading;
table.Title = heading;
return table;
}
@ -76,7 +77,8 @@ namespace Spectre.Console
/// <param name="text">The footnote.</param>
/// <param name="style">The style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Footnote(..) instead.")]
[Obsolete("Use Caption(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Table SetFootnote(this Table table, string text, Style? style = null)
{
if (table is null)
@ -98,7 +100,8 @@ namespace Spectre.Console
/// <param name="table">The table.</param>
/// <param name="footnote">The footnote.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Footnote(..) instead.")]
[Obsolete("Use Caption(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Table SetFootnote(this Table table, TableTitle footnote)
{
if (table is null)
@ -106,7 +109,93 @@ namespace Spectre.Console
throw new ArgumentNullException(nameof(table));
}
table.Footnote = footnote;
table.Caption = footnote;
return table;
}
/// <summary>
/// Sets the table footnote.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="text">The footnote.</param>
/// <param name="style">The style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Caption(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Table Footnote(this Table table, string text, Style? style = null)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}
if (text is null)
{
throw new ArgumentNullException(nameof(text));
}
return Footnote(table, new TableTitle(text, style));
}
/// <summary>
/// Sets the table footnote.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="footnote">The footnote.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Caption(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Table Footnote(this Table table, TableTitle footnote)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}
table.Caption = footnote;
return table;
}
/// <summary>
/// Sets the table heading.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="text">The heading.</param>
/// <param name="style">The style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Title(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Table Heading(this Table table, string text, Style? style = null)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}
if (text is null)
{
throw new ArgumentNullException(nameof(text));
}
return Heading(table, new TableTitle(text, style));
}
/// <summary>
/// Sets the table heading.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="heading">The heading.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
[Obsolete("Use Title(..) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Table Heading(this Table table, TableTitle heading)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}
table.Title = heading;
return table;
}
}

View File

@ -0,0 +1,55 @@
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 footer.
/// </summary>
/// <param name="column">The table column.</param>
/// <param name="footer">The table column 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;
}
}
}

View File

@ -178,52 +178,45 @@ namespace Spectre.Console
}
/// <summary>
/// Sets the table heading.
/// Shows table footers.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="text">The heading.</param>
/// <param name="style">The style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Table Heading(this Table table, string text, Style? style = null)
public static Table ShowFooters(this Table table)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}
if (text is null)
{
throw new ArgumentNullException(nameof(text));
}
return Heading(table, new TableTitle(text, style));
}
/// <summary>
/// Sets the table heading.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="heading">The heading.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Table Heading(this Table table, TableTitle heading)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}
table.Heading = heading;
table.ShowFooters = true;
return table;
}
/// <summary>
/// Sets the table footnote.
/// Hides table footers.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="text">The footnote.</param>
/// <param name="style">The style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Table Footnote(this Table table, string text, Style? style = null)
public static Table HideFooters(this Table table)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}
table.ShowFooters = false;
return table;
}
/// <summary>
/// Sets the table title.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="text">The table title markup text.</param>
/// <param name="style">The table title style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Table Title(this Table table, string text, Style? style = null)
{
if (table is null)
{
@ -235,23 +228,62 @@ namespace Spectre.Console
throw new ArgumentNullException(nameof(text));
}
return Footnote(table, new TableTitle(text, style));
return Title(table, new TableTitle(text, style));
}
/// <summary>
/// Sets the table footnote.
/// Sets the table title.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="footnote">The footnote.</param>
/// <param name="title">The table title.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Table Footnote(this Table table, TableTitle footnote)
public static Table Title(this Table table, TableTitle title)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}
table.Footnote = footnote;
table.Title = title;
return table;
}
/// <summary>
/// Sets the table caption.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="text">The caption markup text.</param>
/// <param name="style">The style.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Table Caption(this Table table, string text, Style? style = null)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}
if (text is null)
{
throw new ArgumentNullException(nameof(text));
}
return Caption(table, new TableTitle(text, style));
}
/// <summary>
/// Sets the table caption.
/// </summary>
/// <param name="table">The table.</param>
/// <param name="caption">The caption.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Table Caption(this Table table, TableTitle caption)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}
table.Caption = caption;
return table;
}
}