using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using Spectre.Console.Rendering; namespace Spectre.Console { /// /// A renderable piece of text. /// [DebuggerDisplay("{_text,nq}")] [SuppressMessage("Naming", "CA1724:Type names should not match namespaces")] public sealed class Text : Renderable, IAlignable, IOverflowable { private readonly Paragraph _paragraph; /// /// Gets an empty instance. /// public static Text Empty { get; } = new Text(string.Empty); /// /// Gets an instance of containing a new line. /// public static Text NewLine { get; } = new Text(Environment.NewLine, Style.Plain); /// /// Initializes a new instance of the class. /// /// The text. /// The style of the text or if . public Text(string text, Style? style = null) { _paragraph = new Paragraph(text, style); } /// /// Gets or sets the text alignment. /// public Justify? Alignment { get => _paragraph.Alignment; set => _paragraph.Alignment = value; } /// /// Gets or sets the text overflow strategy. /// public Overflow? Overflow { get => _paragraph.Overflow; set => _paragraph.Overflow = value; } /// /// Gets the character count. /// public int Length => _paragraph.Length; /// /// Gets the number of lines in the text. /// public int Lines => _paragraph.Lines; /// protected override Measurement Measure(RenderContext context, int maxWidth) { return ((IRenderable)_paragraph).Measure(context, maxWidth); } /// protected override IEnumerable Render(RenderContext context, int maxWidth) { return ((IRenderable)_paragraph).Render(context, maxWidth); } } }