Add column support

Adds support for rendering arbitrary data into columns.

Closes #67
This commit is contained in:
Patrik Svensson
2020-09-04 01:34:31 +02:00
committed by Patrik Svensson
parent e946289bd9
commit ae6d2c63a3
19 changed files with 340 additions and 35 deletions

View File

@@ -13,10 +13,25 @@ namespace Spectre.Console.Rendering
[DebuggerDisplay("{Text,nq}")]
public class Segment
{
private readonly bool _mutable;
private string _text;
/// <summary>
/// Gets the segment text.
/// </summary>
public string Text { get; internal set; }
public string Text
{
get => _text;
private set
{
if (!_mutable)
{
throw new NotSupportedException();
}
_text = value;
}
}
/// <summary>
/// Gets a value indicating whether or not this is an expicit line break
@@ -39,12 +54,12 @@ namespace Spectre.Console.Rendering
/// <summary>
/// Gets a segment representing a line break.
/// </summary>
public static Segment LineBreak { get; } = new Segment(Environment.NewLine, Style.Plain, true);
public static Segment LineBreak { get; } = new Segment(Environment.NewLine, Style.Plain, true, false);
/// <summary>
/// Gets an empty segment.
/// </summary>
public static Segment Empty { get; } = new Segment(string.Empty, Style.Plain);
public static Segment Empty { get; } = new Segment(string.Empty, Style.Plain, false, false);
/// <summary>
/// Initializes a new instance of the <see cref="Segment"/> class.
@@ -65,14 +80,16 @@ namespace Spectre.Console.Rendering
{
}
private Segment(string text, Style style, bool lineBreak)
private Segment(string text, Style style, bool lineBreak, bool mutable = true)
{
if (text is null)
{
throw new ArgumentNullException(nameof(text));
}
Text = text.NormalizeLineEndings();
_mutable = mutable;
_text = text.NormalizeLineEndings();
Style = style;
IsLineBreak = lineBreak;
IsWhiteSpace = string.IsNullOrWhiteSpace(text);