mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
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:

committed by
Patrik Svensson

parent
e48ae9600a
commit
d1d94cdebe
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user