#nullable enable using System; using System.Collections.Generic; using System.Drawing; namespace Terminal.Gui.Text; /// /// Represents the result of text formatting, containing formatted lines, size requirements, and metadata. /// public sealed class FormattedText { /// /// Initializes a new instance of the class. /// /// The formatted text lines. /// The size required to display the text. /// The HotKey found in the text, if any. /// The position of the HotKey in the original text. public FormattedText( IReadOnlyList lines, Size requiredSize, Key hotKey = default, int hotKeyPosition = -1) { Lines = lines ?? throw new ArgumentNullException(nameof(lines)); RequiredSize = requiredSize; HotKey = hotKey; HotKeyPosition = hotKeyPosition; } /// Gets the formatted text lines. public IReadOnlyList Lines { get; } /// Gets the size required to display the formatted text. public Size RequiredSize { get; } /// Gets the HotKey found in the text, if any. public Key HotKey { get; } /// Gets the position of the HotKey in the original text (-1 if no HotKey). public int HotKeyPosition { get; } /// Gets a value indicating whether the text contains a HotKey. public bool HasHotKey => HotKeyPosition >= 0; } /// /// Represents a single formatted line of text. /// public sealed class FormattedLine { /// /// Initializes a new instance of the class. /// /// The text runs that make up this line. /// The display width of this line. public FormattedLine(IReadOnlyList runs, int width) { Runs = runs; Width = width; } /// Gets the text runs that make up this line. public IReadOnlyList Runs { get; } /// Gets the display width of this line. public int Width { get; } } /// /// Represents a run of text with consistent formatting. /// public sealed class FormattedRun { /// /// Initializes a new instance of the class. /// /// The text content of this run. /// Whether this run represents a HotKey. public FormattedRun(string text, bool isHotKey = false) { Text = text; IsHotKey = isHotKey; } /// Gets the text content of this run. public string Text { get; } /// Gets a value indicating whether this run represents a HotKey. public bool IsHotKey { get; } }