Add live display support

This commit also adds functionality to LiveRenderable that should
fix some problems related to vertical overflow.

Closes #316
Closes #415
This commit is contained in:
Patrik Svensson
2021-05-20 12:05:47 +02:00
committed by Phil Scott
parent 5d68020abb
commit 3dea412785
22 changed files with 756 additions and 20 deletions

View File

@ -0,0 +1,32 @@
using System;
using Spectre.Console.Rendering;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="IAnsiConsole"/>.
/// </summary>
public static partial class AnsiConsoleExtensions
{
/// <summary>
/// Creates a new <see cref="LiveDisplay"/> instance for the console.
/// </summary>
/// <param name="console">The console.</param>
/// <param name="target">The target renderable to update.</param>
/// <returns>A <see cref="LiveDisplay"/> instance.</returns>
public static LiveDisplay Live(this IAnsiConsole console, IRenderable target)
{
if (console is null)
{
throw new ArgumentNullException(nameof(console));
}
if (target is null)
{
throw new ArgumentNullException(nameof(target));
}
return new LiveDisplay(console, target);
}
}
}

View File

@ -0,0 +1,65 @@
using System;
namespace Spectre.Console
{
/// <summary>
/// Contains extension methods for <see cref="LiveDisplay"/>.
/// </summary>
public static class LiveDisplayExtensions
{
/// <summary>
/// Sets whether or not auto clear is enabled.
/// If enabled, the live display will be cleared when done.
/// </summary>
/// <param name="live">The <see cref="LiveDisplay"/> instance.</param>
/// <param name="enabled">Whether or not auto clear is enabled.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static LiveDisplay AutoClear(this LiveDisplay live, bool enabled)
{
if (live is null)
{
throw new ArgumentNullException(nameof(live));
}
live.AutoClear = enabled;
return live;
}
/// <summary>
/// Sets the vertical overflow strategy.
/// </summary>
/// <param name="live">The <see cref="LiveDisplay"/> instance.</param>
/// <param name="overflow">The overflow strategy to use.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static LiveDisplay Overflow(this LiveDisplay live, VerticalOverflow overflow)
{
if (live is null)
{
throw new ArgumentNullException(nameof(live));
}
live.Overflow = overflow;
return live;
}
/// <summary>
/// Sets the vertical overflow cropping strategy.
/// </summary>
/// <param name="live">The <see cref="LiveDisplay"/> instance.</param>
/// <param name="cropping">The overflow cropping strategy to use.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static LiveDisplay Cropping(this LiveDisplay live, VerticalOverflowCropping cropping)
{
if (live is null)
{
throw new ArgumentNullException(nameof(live));
}
live.Cropping = cropping;
return live;
}
}
}

View File

@ -8,11 +8,55 @@ namespace Spectre.Console
/// </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 markup text.</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)
{