Add Length and Lines properties to Paragraph

* Adds Length and Lines to `Paragraph`, `Markup` and `Text`.
* Do not use Environment.NewLine
This commit is contained in:
Patrik Svensson
2021-04-29 17:59:49 +02:00
committed by Patrik Svensson
parent e48ae9600a
commit d1d94cdebe
12 changed files with 113 additions and 19 deletions

View File

@ -27,6 +27,16 @@ namespace Spectre.Console
set => _paragraph.Overflow = value;
}
/// <summary>
/// Gets the character count.
/// </summary>
public int Length => _paragraph.Length;
/// <summary>
/// Gets the number of lines.
/// </summary>
public int Lines => _paragraph.Lines;
/// <summary>
/// Initializes a new instance of the <see cref="Markup"/> class.
/// </summary>

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Spectre.Console.Rendering;
namespace Spectre.Console
@ -25,6 +26,16 @@ namespace Spectre.Console
/// </summary>
public Overflow? Overflow { get; set; }
/// <summary>
/// Gets the character count of the paragraph.
/// </summary>
public int Length => _lines.Sum(line => line.Length) + Math.Max(0, Lines - 1);
/// <summary>
/// Gets the number of lines in the paragraph.
/// </summary>
public int Lines => _lines.Count;
/// <summary>
/// Initializes a new instance of the <see cref="Paragraph"/> class.
/// </summary>

View File

@ -29,7 +29,7 @@ namespace Spectre.Console
if (_lastStatus != task.Description)
{
_lastStatus = task.Description;
_renderable = new Markup(task.Description + Environment.NewLine);
_renderable = new Markup(task.Description + "\n");
return;
}
}

View File

@ -47,6 +47,16 @@ namespace Spectre.Console
set => _paragraph.Overflow = value;
}
/// <summary>
/// Gets the character count.
/// </summary>
public int Length => _paragraph.Length;
/// <summary>
/// Gets the number of lines in the text.
/// </summary>
public int Lines => _paragraph.Lines;
/// <inheritdoc/>
protected override Measurement Measure(RenderContext context, int maxWidth)
{