mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-12-29 20:05:48 +08:00
Add column support
Adds support for rendering arbitrary data into columns. Closes #67
This commit is contained in:
committed by
Patrik Svensson
parent
e946289bd9
commit
ae6d2c63a3
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user