From ccf2daa0241eb796380843736227d1806750ba9f Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 5 Oct 2024 18:01:29 +0100 Subject: [PATCH] Change all RuneCell to Cell and move methods to the Cell record struct. --- Terminal.Gui/Drawing/Cell.cs | 137 ++++- .../CellEventArgs.cs} | 16 +- Terminal.Gui/Drawing/LineCanvas.cs | 2 +- Terminal.Gui/Drawing/StraightLine.cs | 2 +- .../Text/Autocomplete/AutocompleteContext.cs | 4 +- .../Views/AutocompleteFilepathContext.cs | 4 +- .../Views/HistoryTextItemEventArgs.cs | 6 +- Terminal.Gui/Views/TextField.cs | 14 +- Terminal.Gui/Views/TextView.cs | 536 +++++++----------- Terminal.Gui/Views/TreeView/Branch.cs | 18 +- .../TreeView/DrawTreeViewLineEventArgs.cs | 8 +- UICatalog/Scenarios/Editor.cs | 32 +- UICatalog/Scenarios/SyntaxHighlighting.cs | 59 +- UICatalog/Scenarios/TreeViewFileSystem.cs | 14 +- UnitTests/Configuration/ThemeTests.cs | 1 + .../RuneCellTests.cs => Drawing/CellTests.cs} | 164 +++--- UnitTests/Text/AutocompleteTests.cs | 2 +- UnitTests/Views/TextViewTests.cs | 22 +- UnitTests/Views/TreeViewTests.cs | 14 +- 19 files changed, 520 insertions(+), 535 deletions(-) rename Terminal.Gui/{Views/RuneCellEventArgs.cs => Drawing/CellEventArgs.cs} (57%) rename UnitTests/{Views/RuneCellTests.cs => Drawing/CellTests.cs} (61%) diff --git a/Terminal.Gui/Drawing/Cell.cs b/Terminal.Gui/Drawing/Cell.cs index 55da05184..581cc6bd6 100644 --- a/Terminal.Gui/Drawing/Cell.cs +++ b/Terminal.Gui/Drawing/Cell.cs @@ -4,19 +4,18 @@ /// Represents a single row/column in a Terminal.Gui rendering surface (e.g. and /// ). /// -public record struct Cell () +public record struct Cell (Attribute? Attribute = null, bool IsDirty = false, Rune Rune = default) { - /// The attributes to use when drawing the Glyph. - public Attribute? Attribute { get; set; } = null; + public Attribute? Attribute { get; set; } = Attribute; /// /// Gets or sets a value indicating whether this has been modified since the /// last time it was drawn. /// - public bool IsDirty { get; set; } = false; + public bool IsDirty { get; set; } = IsDirty; - private Rune _rune = default; + private Rune _rune = Rune; /// The character to display. If is , then is ignored. public Rune Rune @@ -29,6 +28,8 @@ public record struct Cell () } } + private List _combiningMarks; + /// /// The combining marks for that when combined makes this Cell a combining sequence. If /// empty, then is ignored. @@ -37,8 +38,132 @@ public record struct Cell () /// Only valid in the rare case where is a combining sequence that could not be normalized to a /// single Rune. /// - internal List CombiningMarks { get; } = new (); + internal List CombiningMarks + { + get => _combiningMarks ?? []; + private set => _combiningMarks = value ?? []; + } /// public override string ToString () { return $"[{Rune}, {Attribute}]"; } + + /// Converts the string into a . + /// The string to convert. + /// The to use. + /// + public static List ToCellList (string str, Attribute? attribute = null) + { + List cells = new (); + + foreach (Rune rune in str.EnumerateRunes ()) + { + cells.Add (new () { Rune = rune, Attribute = attribute }); + } + + return cells; + } + + /// + /// Splits a string into a List that will contain a for each line. + /// + /// The string content. + /// The color scheme. + /// A for each line. + public static List> StringToLinesOfCells (string content, Attribute? attribute = null) + { + List cells = content.EnumerateRunes () + .Select (x => new Cell { Rune = x, Attribute = attribute }) + .ToList (); + + return SplitNewLines (cells); + } + + /// Converts a generic collection into a string. + /// The enumerable cell to convert. + /// + public static string ToString (IEnumerable cells) + { + var str = string.Empty; + + foreach (Cell cell in cells) + { + str += cell.Rune.ToString (); + } + + return str; + } + + // Turns the string into cells, this does not split the contents on a newline if it is present. + + internal static List StringToCells (string str, Attribute? attribute = null) + { + List cells = []; + + foreach (Rune rune in str.ToRunes ()) + { + cells.Add (new () { Rune = rune, Attribute = attribute }); + } + + return cells; + } + + internal static List ToCells (IEnumerable runes, Attribute? attribute = null) + { + List cells = new (); + + foreach (Rune rune in runes) + { + cells.Add (new () { Rune = rune, Attribute = attribute }); + } + + return cells; + } + + private static List> SplitNewLines (List cells) + { + List> lines = []; + int start = 0, i = 0; + var hasCR = false; + + // ASCII code 13 = Carriage Return. + // ASCII code 10 = Line Feed. + for (; i < cells.Count; i++) + { + if (cells [i].Rune.Value == 13) + { + hasCR = true; + + continue; + } + + if (cells [i].Rune.Value == 10) + { + if (i - start > 0) + { + lines.Add (cells.GetRange (start, hasCR ? i - 1 - start : i - start)); + } + else + { + lines.Add (StringToCells (string.Empty)); + } + + start = i + 1; + hasCR = false; + } + } + + if (i - start >= 0) + { + lines.Add (cells.GetRange (start, i - start)); + } + + return lines; + } + + /// + /// Splits a rune cell list into a List that will contain a for each line. + /// + /// The cells list. + /// + public static List> ToCells (List cells) { return SplitNewLines (cells); } } diff --git a/Terminal.Gui/Views/RuneCellEventArgs.cs b/Terminal.Gui/Drawing/CellEventArgs.cs similarity index 57% rename from Terminal.Gui/Views/RuneCellEventArgs.cs rename to Terminal.Gui/Drawing/CellEventArgs.cs index 1283cfe57..14b98f36b 100644 --- a/Terminal.Gui/Views/RuneCellEventArgs.cs +++ b/Terminal.Gui/Drawing/CellEventArgs.cs @@ -1,27 +1,27 @@ namespace Terminal.Gui; -/// Args for events that relate to a specific . -public class RuneCellEventArgs +/// Args for events that relate to a specific . +public class CellEventArgs { - /// Creates a new instance of the class. + /// Creates a new instance of the class. /// The line. /// The col index. /// The unwrapped row and col index. - public RuneCellEventArgs (List line, int col, (int Row, int Col) unwrappedPosition) + public CellEventArgs (List line, int col, (int Row, int Col) unwrappedPosition) { Line = line; Col = col; UnwrappedPosition = unwrappedPosition; } - /// The index of the RuneCell in the line. + /// The index of the Cell in the line. public int Col { get; } - /// The list of runes the RuneCell is part of. - public List Line { get; } + /// The list of runes the Cell is part of. + public List Line { get; } /// - /// The unwrapped row and column index into the text containing the RuneCell. Unwrapped means the text without + /// The unwrapped row and column index into the text containing the Cell. Unwrapped means the text without /// word wrapping or other visual formatting having been applied. /// public (int Row, int Col) UnwrappedPosition { get; } diff --git a/Terminal.Gui/Drawing/LineCanvas.cs b/Terminal.Gui/Drawing/LineCanvas.cs index 9a7365f26..235d657d9 100644 --- a/Terminal.Gui/Drawing/LineCanvas.cs +++ b/Terminal.Gui/Drawing/LineCanvas.cs @@ -138,7 +138,7 @@ public class LineCanvas : IDisposable int length, Orientation orientation, LineStyle style, - Attribute? attribute = default + Attribute? attribute = null ) { _cachedViewport = Rectangle.Empty; diff --git a/Terminal.Gui/Drawing/StraightLine.cs b/Terminal.Gui/Drawing/StraightLine.cs index 2f36995df..fe2ccdc1d 100644 --- a/Terminal.Gui/Drawing/StraightLine.cs +++ b/Terminal.Gui/Drawing/StraightLine.cs @@ -16,7 +16,7 @@ public class StraightLine int length, Orientation orientation, LineStyle style, - Attribute? attribute = default + Attribute? attribute = null ) { Start = start; diff --git a/Terminal.Gui/Text/Autocomplete/AutocompleteContext.cs b/Terminal.Gui/Text/Autocomplete/AutocompleteContext.cs index 2686c1024..ed55b0d3f 100644 --- a/Terminal.Gui/Text/Autocomplete/AutocompleteContext.cs +++ b/Terminal.Gui/Text/Autocomplete/AutocompleteContext.cs @@ -7,7 +7,7 @@ namespace Terminal.Gui; public class AutocompleteContext { /// Creates a new instance of the class - public AutocompleteContext (List currentLine, int cursorPosition, bool canceled = false) + public AutocompleteContext (List currentLine, int cursorPosition, bool canceled = false) { CurrentLine = currentLine; CursorPosition = cursorPosition; @@ -18,7 +18,7 @@ public class AutocompleteContext public bool Canceled { get; set; } /// The text on the current line. - public List CurrentLine { get; set; } + public List CurrentLine { get; set; } /// The position of the input cursor within the . public int CursorPosition { get; set; } diff --git a/Terminal.Gui/Views/AutocompleteFilepathContext.cs b/Terminal.Gui/Views/AutocompleteFilepathContext.cs index a379f2001..b21724816 100644 --- a/Terminal.Gui/Views/AutocompleteFilepathContext.cs +++ b/Terminal.Gui/Views/AutocompleteFilepathContext.cs @@ -6,7 +6,7 @@ namespace Terminal.Gui; internal class AutocompleteFilepathContext : AutocompleteContext { public AutocompleteFilepathContext (string currentLine, int cursorPosition, FileDialogState state) - : base (RuneCell.ToRuneCellList (currentLine), cursorPosition) + : base (Cell.ToCellList (currentLine), cursorPosition) { State = state; } @@ -30,7 +30,7 @@ internal class FilepathSuggestionGenerator : ISuggestionGenerator return Enumerable.Empty (); } - var path = RuneCell.ToString (context.CurrentLine); + var path = Cell.ToString (context.CurrentLine); int last = path.LastIndexOfAny (FileDialog.Separators); if (string.IsNullOrWhiteSpace (path) || !Path.IsPathRooted (path)) diff --git a/Terminal.Gui/Views/HistoryTextItemEventArgs.cs b/Terminal.Gui/Views/HistoryTextItemEventArgs.cs index ca2ad3ad7..c75f4a5e8 100644 --- a/Terminal.Gui/Views/HistoryTextItemEventArgs.cs +++ b/Terminal.Gui/Views/HistoryTextItemEventArgs.cs @@ -9,11 +9,11 @@ internal partial class HistoryText public Point CursorPosition; public Point FinalCursorPosition; public bool IsUndoing; - public List> Lines; + public List> Lines; public LineStatus LineStatus; public HistoryTextItemEventArgs RemovedOnAdded; - public HistoryTextItemEventArgs (List> lines, Point curPos, LineStatus linesStatus) + public HistoryTextItemEventArgs (List> lines, Point curPos, LineStatus linesStatus) { Lines = lines; CursorPosition = curPos; @@ -22,7 +22,7 @@ internal partial class HistoryText public HistoryTextItemEventArgs (HistoryTextItemEventArgs historyTextItem) { - Lines = new List> (historyTextItem.Lines); + Lines = new List> (historyTextItem.Lines); CursorPosition = new Point (historyTextItem.CursorPosition.X, historyTextItem.CursorPosition.Y); LineStatus = historyTextItem.LineStatus; } diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index acbefdf9a..a352e586c 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -546,12 +546,12 @@ public class TextField : View if (!Secret && !_historyText.IsFromHistory) { _historyText.Add ( - new List> { RuneCell.ToRuneCellList (oldText) }, + new List> { Cell.ToCellList (oldText) }, new Point (_cursorPosition, 0) ); _historyText.Add ( - new List> { RuneCell.ToRuneCells (_text) }, + new List> { Cell.ToCells (_text) }, new Point (_cursorPosition, 0), HistoryText.LineStatus.Replaced ); @@ -648,7 +648,7 @@ public class TextField : View } _historyText.Add ( - new List> { RuneCell.ToRuneCells (_text) }, + new List> { Cell.ToCells (_text) }, new Point (_cursorPosition, 0) ); @@ -702,7 +702,7 @@ public class TextField : View } _historyText.Add ( - new List> { RuneCell.ToRuneCells (_text) }, + new List> { Cell.ToCells (_text) }, new Point (_cursorPosition, 0) ); @@ -1342,7 +1342,7 @@ public class TextField : View private void GenerateSuggestions () { - List currentLine = RuneCell.ToRuneCellList (Text); + List currentLine = Cell.ToCellList (Text); int cursorPosition = Math.Min (CursorPosition, currentLine.Count); Autocomplete.Context = new AutocompleteContext ( @@ -1390,7 +1390,7 @@ public class TextField : View return; } - Text = RuneCell.ToString (obj?.Lines [obj.CursorPosition.Y]); + Text = Cell.ToString (obj?.Lines [obj.CursorPosition.Y]); CursorPosition = obj.CursorPosition.X; Adjust (); } @@ -1398,7 +1398,7 @@ public class TextField : View private void InsertText (Key a, bool usePreTextChangedCursorPos) { _historyText.Add ( - new List> { RuneCell.ToRuneCells (_text) }, + new List> { Cell.ToCells (_text) }, new Point (_cursorPosition, 0) ); diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 5223c210e..67b2afe2e 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -9,163 +9,9 @@ using Terminal.Gui.Resources; namespace Terminal.Gui; -/// -/// Represents a single row/column within the . Includes the glyph and the -/// foreground/background colors. -/// -[DebuggerDisplay ("{ColorSchemeDebuggerDisplay}")] -public class RuneCell : IEquatable -{ - /// The color sets to draw the glyph with. - [JsonConverter (typeof (ColorSchemeJsonConverter))] - public ColorScheme? ColorScheme { get; set; } - - /// The glyph to draw. - [JsonConverter (typeof (RuneJsonConverter))] - public Rune Rune { get; set; } - - private string ColorSchemeDebuggerDisplay => ToString (); - - /// Indicates whether the current object is equal to another object of the same type. - /// An object to compare with this object. - /// - /// if the current object is equal to the parameter; otherwise, - /// . - /// - public bool Equals (RuneCell? other) { return other is { } && Rune.Equals (other.Rune) && ColorScheme == other.ColorScheme; } - - /// Returns a string that represents the current object. - /// A string that represents the current object. - public override string ToString () - { - string colorSchemeStr = ColorScheme?.ToString () ?? "null"; - - return $"U+{Rune.Value:X4} '{Rune.ToString ()}'; {colorSchemeStr}"; - } - - /// Converts the string into a . - /// The string to convert. - /// The to use. - /// - public static List ToRuneCellList (string str, ColorScheme? colorScheme = null) - { - List cells = new (); - - foreach (Rune rune in str.EnumerateRunes ()) - { - cells.Add (new () { Rune = rune, ColorScheme = colorScheme }); - } - - return cells; - } - - /// - /// Splits a string into a List that will contain a for each line. - /// - /// The string content. - /// The color scheme. - /// A for each line. - public static List> StringToLinesOfRuneCells (string content, ColorScheme? colorScheme = null) - { - List cells = content.EnumerateRunes () - .Select (x => new RuneCell { Rune = x, ColorScheme = colorScheme }) - .ToList (); - - return SplitNewLines (cells); - } - - /// Converts a generic collection into a string. - /// The enumerable cell to convert. - /// - public static string ToString (IEnumerable cells) - { - var str = string.Empty; - - foreach (RuneCell cell in cells) - { - str += cell.Rune.ToString (); - } - - return str; - } - - // Turns the string into cells, this does not split the contents on a newline if it is present. - internal static List StringToRuneCells (string str, ColorScheme? colorScheme = null) - { - List cells = new (); - - foreach (Rune rune in str.ToRunes ()) - { - cells.Add (new () { Rune = rune, ColorScheme = colorScheme }); - } - - return cells; - } - - internal static List ToRuneCells (IEnumerable runes, ColorScheme? colorScheme = null) - { - List cells = new (); - - foreach (Rune rune in runes) - { - cells.Add (new () { Rune = rune, ColorScheme = colorScheme }); - } - - return cells; - } - - private static List> SplitNewLines (List cells) - { - List> lines = new (); - int start = 0, i = 0; - var hasCR = false; - - // ASCII code 13 = Carriage Return. - // ASCII code 10 = Line Feed. - for (; i < cells.Count; i++) - { - if (cells [i].Rune.Value == 13) - { - hasCR = true; - - continue; - } - - if (cells [i].Rune.Value == 10) - { - if (i - start > 0) - { - lines.Add (cells.GetRange (start, hasCR ? i - 1 - start : i - start)); - } - else - { - lines.Add (StringToRuneCells (string.Empty)); - } - - start = i + 1; - hasCR = false; - } - } - - if (i - start >= 0) - { - lines.Add (cells.GetRange (start, i - start)); - } - - return lines; - } - - /// - /// Splits a rune cell list into a List that will contain a for each line. - /// - /// The cells list. - /// - public static List> ToRuneCells (List cells) { return SplitNewLines (cells); } -} - internal class TextModel { - private List> _lines = new (); + private List> _lines = new (); private (Point startPointToFind, Point currentPointToFind, bool found) _toFind; /// The number of text lines in the model @@ -175,8 +21,8 @@ internal class TextModel /// Adds a line to the model at the specified position. /// Line number where the line will be inserted. - /// The line of text and color, as a List of RuneCell. - public void AddLine (int pos, List cells) { _lines.Insert (pos, cells); } + /// The line of text and color, as a List of Cell. + public void AddLine (int pos, List cells) { _lines.Insert (pos, cells); } public bool CloseFile () { @@ -191,12 +37,12 @@ internal class TextModel return true; } - public List> GetAllLines () { return _lines; } + public List> GetAllLines () { return _lines; } /// Returns the specified line as a List of Rune /// The line. /// Line number to retrieve. - public List GetLine (int line) + public List GetLine (int line) { if (_lines.Count > 0) { @@ -224,7 +70,7 @@ internal class TextModel for (int i = first; i < last; i++) { - List line = GetLine (i); + List line = GetLine (i); int tabSum = line.Sum (c => c.Rune.Value == '\t' ? Math.Max (tabWidth - 1, 0) : 0); int l = line.Count + tabSum; @@ -251,17 +97,17 @@ internal class TextModel } } - public void LoadListRuneCells (List> cellsList, ColorScheme? colorScheme) + public void LoadListCells (List> cellsList, Attribute? attribute) { _lines = cellsList; - SetColorSchemes (colorScheme); + SetAttributes (attribute); OnLinesLoaded (); } - public void LoadRuneCells (List cells, ColorScheme? colorScheme) + public void LoadCells (List cells, Attribute? attribute) { - _lines = RuneCell.ToRuneCells (cells); - SetColorSchemes (colorScheme); + _lines = Cell.ToCells ((List)cells); + SetAttributes (attribute); OnLinesLoaded (); } @@ -310,7 +156,7 @@ internal class TextModel public void LoadString (string content) { - _lines = RuneCell.StringToLinesOfRuneCells (content); + _lines = Cell.StringToLinesOfCells (content); OnLinesLoaded (); } @@ -330,7 +176,7 @@ internal class TextModel } } - public void ReplaceLine (int pos, List runes) + public void ReplaceLine (int pos, List runes) { if (_lines.Count > 0 && pos < _lines.Count) { @@ -350,7 +196,7 @@ internal class TextModel for (var i = 0; i < _lines.Count; i++) { - sb.Append (RuneCell.ToString (_lines [i])); + sb.Append (Cell.ToString (_lines [i])); if (i + 1 < _lines.Count) { @@ -373,12 +219,12 @@ internal class TextModel try { - RuneCell? cell = RuneAt (col, row); + Cell? cell = RuneAt (col, row); Rune rune; if (cell is { }) { - rune = cell.Rune; + rune = cell.Value.Rune; } else { @@ -390,7 +236,7 @@ internal class TextModel if (col == 0 && row > 0) { row--; - List line = GetLine (row); + List line = GetLine (row); return (line.Count, row); } @@ -464,7 +310,7 @@ internal class TextModel return; } - List line = GetLine (nRow); + List line = GetLine (nRow); if (nCol == 0 && nRow == fromRow @@ -523,7 +369,7 @@ internal class TextModel try { - Rune rune = RuneAt (col, row).Rune; + Rune rune = RuneAt (col, row)!.Value.Rune; RuneType runeType = GetRuneType (rune); int lastValidCol = IsSameRuneType (rune, runeType) && (Rune.IsLetterOrDigit (rune) || Rune.IsPunctuation (rune) || Rune.IsSymbol (rune)) @@ -590,7 +436,7 @@ internal class TextModel return; } - List line = GetLine (nRow); + List line = GetLine (nRow); if (nCol == line.Count && nRow == fromRow @@ -630,11 +476,11 @@ internal class TextModel } } - internal static int CalculateLeftColumn (List t, int start, int end, int width, int tabWidth = 0) + internal static int CalculateLeftColumn (List t, int start, int end, int width, int tabWidth = 0) { List runes = new (); - foreach (RuneCell cell in t) + foreach (Cell cell in t) { runes.Add (cell.Rune); } @@ -686,7 +532,7 @@ internal class TextModel } internal static (int size, int length) DisplaySize ( - List t, + List t, int start = -1, int end = -1, bool checkNextRune = true, @@ -695,7 +541,7 @@ internal class TextModel { List runes = new (); - foreach (RuneCell cell in t) + foreach (Cell cell in t) { runes.Add (cell.Rune); } @@ -856,11 +702,11 @@ internal class TextModel return foundPos; } - internal static int GetColFromX (List t, int start, int x, int tabWidth = 0) + internal static int GetColFromX (List t, int start, int x, int tabWidth = 0) { List runes = new (); - foreach (RuneCell cell in t) + foreach (Cell cell in t) { runes.Add (cell.Rune); } @@ -909,7 +755,7 @@ internal class TextModel for (var i = 0; i < _lines.Count; i++) { - List x = _lines [i]; + List x = _lines [i]; string txt = GetText (x); string matchText = !matchCase ? text.ToUpper () : text; int col = txt.IndexOf (matchText); @@ -935,7 +781,7 @@ internal class TextModel found = true; } - _lines [i] = RuneCell.ToRuneCellList (ReplaceText (x, textToReplace!, matchText, col)); + _lines [i] = Cell.ToCellList (ReplaceText (x, textToReplace!, matchText, col)); x = _lines [i]; txt = GetText (x); pos = new (col, i); @@ -951,9 +797,9 @@ internal class TextModel } } - string GetText (List x) + string GetText (List x) { - string txt = RuneCell.ToString (x); + string txt = Cell.ToString (x); if (!matchCase) { @@ -989,7 +835,7 @@ internal class TextModel private void Append (List line) { var str = StringExtensions.ToString (line.ToArray ()); - _lines.Add (RuneCell.StringToRuneCells (str)); + _lines.Add (Cell.StringToCells (str)); } private bool ApplyToFind ((Point current, bool found) foundPos) @@ -1025,8 +871,8 @@ internal class TextModel { for (int i = start.Y; i < linesCount; i++) { - List x = _lines [i]; - string txt = RuneCell.ToString (x); + List x = _lines [i]; + string txt = Cell.ToString (x); if (!matchCase) { @@ -1065,8 +911,8 @@ internal class TextModel { for (int i = linesCount; i >= 0; i--) { - List x = _lines [i]; - string txt = RuneCell.ToString (x); + List x = _lines [i]; + string txt = Cell.ToString (x); if (!matchCase) { @@ -1148,7 +994,7 @@ internal class TextModel private bool MoveNext (ref int col, ref int row, out Rune rune) { - List line = GetLine (row); + List line = GetLine (row); if (col + 1 < line.Count) { @@ -1189,7 +1035,7 @@ internal class TextModel private bool MovePrev (ref int col, ref int row, out Rune rune) { - List line = GetLine (row); + List line = GetLine (row); if (col > 0) { @@ -1227,9 +1073,9 @@ internal class TextModel private void OnLinesLoaded () { LinesLoaded?.Invoke (this, EventArgs.Empty); } - private string ReplaceText (List source, string textToReplace, string matchText, int col) + private string ReplaceText (List source, string textToReplace, string matchText, int col) { - string origTxt = RuneCell.ToString (source); + string origTxt = Cell.ToString (source); (_, int len) = DisplaySize (source, 0, col, false); (_, int len2) = DisplaySize (source, col, col + matchText.Length, false); (_, int len3) = DisplaySize (source, col + matchText.Length, origTxt.GetRuneCount (), false); @@ -1237,25 +1083,27 @@ internal class TextModel return origTxt [..len] + textToReplace + origTxt.Substring (len + len2, len3); } - private RuneCell RuneAt (int col, int row) + private Cell? RuneAt (int col, int row) { - List line = GetLine (row); + List line = GetLine (row); if (line.Count > 0) { return line [col > line.Count - 1 ? line.Count - 1 : col]; } - return default (RuneCell)!; + return null; } - private void SetColorSchemes (ColorScheme? colorScheme) + private void SetAttributes (Attribute? attribute) { - foreach (List line in _lines) + foreach (List line in _lines) { - foreach (RuneCell cell in line) + for (var i = 0; i < line.Count; i++) { - cell.ColorScheme ??= colorScheme; + Cell cell = line [i]; + cell.Attribute ??= attribute; + line [i] = cell; } } } @@ -1286,7 +1134,7 @@ internal partial class HistoryText public bool HasHistoryChanges => _idxHistoryText > -1; public bool IsFromHistory { get; private set; } - public void Add (List> lines, Point curPos, LineStatus lineStatus = LineStatus.Original) + public void Add (List> lines, Point curPos, LineStatus lineStatus = LineStatus.Original) { if (lineStatus == LineStatus.Original && _historyTextItems.Count > 0 && _historyTextItems.Last ().LineStatus == LineStatus.Original) { @@ -1343,7 +1191,7 @@ internal partial class HistoryText } } - public void ReplaceLast (List> lines, Point curPos, LineStatus lineStatus) + public void ReplaceLast (List> lines, Point curPos, LineStatus lineStatus) { HistoryTextItemEventArgs? found = _historyTextItems.FindLast (x => x.LineStatus == lineStatus); @@ -1498,9 +1346,9 @@ internal class WordWrapManager { int modelRow = GetModelLineFromWrappedLines (row); int modelCol = GetModelColFromWrappedLines (row, col); - List line = GetCurrentLine (modelRow); + List line = GetCurrentLine (modelRow); int restCount = line.Count - modelCol; - List rest = line.GetRange (modelCol, restCount); + List rest = line.GetRange (modelCol, restCount); line.RemoveRange (modelCol, restCount); Model.AddLine (modelRow + 1, rest); _isWrapModelRefreshing = true; @@ -1584,9 +1432,9 @@ internal class WordWrapManager return modelCol - colWidthOffset; } - public bool Insert (int row, int col, RuneCell cell) + public bool Insert (int row, int col, Cell cell) { - List line = GetCurrentLine (GetModelLineFromWrappedLines (row)); + List line = GetCurrentLine (GetModelLineFromWrappedLines (row)); line.Insert (GetModelColFromWrappedLines (row, col), cell); if (line.Count > _frameWidth) @@ -1600,7 +1448,7 @@ internal class WordWrapManager public bool RemoveAt (int row, int col) { int modelRow = GetModelLineFromWrappedLines (row); - List line = GetCurrentLine (modelRow); + List line = GetCurrentLine (modelRow); int modelCol = GetModelColFromWrappedLines (row, col); if (modelCol > line.Count) @@ -1628,7 +1476,7 @@ internal class WordWrapManager { lineRemoved = false; int modelRow = GetModelLineFromWrappedLines (row); - List line = GetCurrentLine (modelRow); + List line = GetCurrentLine (modelRow); int modelCol = GetModelColFromWrappedLines (row, col); if (modelCol == 0 && line.Count == 0) @@ -1664,7 +1512,7 @@ internal class WordWrapManager return false; } - List nextLine = Model.GetLine (modelRow + 1); + List nextLine = Model.GetLine (modelRow + 1); line.AddRange (nextLine); Model.RemoveLine (modelRow + 1); @@ -1680,7 +1528,7 @@ internal class WordWrapManager return false; } - List prevLine = Model.GetLine (modelRow - 1); + List prevLine = Model.GetLine (modelRow - 1); prevLine.AddRange (line); Model.RemoveLine (modelRow); @@ -1696,7 +1544,7 @@ internal class WordWrapManager public bool RemoveRange (int row, int index, int count) { int modelRow = GetModelLineFromWrappedLines (row); - List line = GetCurrentLine (modelRow); + List line = GetCurrentLine (modelRow); int modelCol = GetModelColFromWrappedLines (row, index); try @@ -1711,13 +1559,13 @@ internal class WordWrapManager return true; } - public List> ToListRune (List textList) + public List> ToListRune (List textList) { - List> runesList = new (); + List> runesList = new (); foreach (string text in textList) { - runesList.Add (RuneCell.ToRuneCellList (text)); + runesList.Add (Cell.ToCellList (text)); } return runesList; @@ -1789,11 +1637,11 @@ internal class WordWrapManager for (var i = 0; i < Model.Count; i++) { - List line = Model.GetLine (i); + List line = Model.GetLine (i); - List> wrappedLines = ToListRune ( + List> wrappedLines = ToListRune ( TextFormatter.Format ( - RuneCell.ToString (line), + Cell.ToString (line), width, Alignment.Start, true, @@ -1805,7 +1653,7 @@ internal class WordWrapManager for (var j = 0; j < wrappedLines.Count; j++) { - List wrapLine = wrappedLines [j]; + List wrapLine = wrappedLines [j]; if (!isRowAndColSet && modelRow == i) { @@ -1863,7 +1711,9 @@ internal class WordWrapManager for (int k = j; k < wrapLine.Count; k++) { - wrapLine [k].ColorScheme = line [k].ColorScheme; + Cell cell = wrapLine [k]; + cell.Attribute = line [k].Attribute; + wrapLine [k] = cell; } wrappedModel.AddLine (lines, wrapLine); @@ -1883,7 +1733,7 @@ internal class WordWrapManager return wrappedModel; } - private List GetCurrentLine (int row) { return Model.GetLine (row); } + private List GetCurrentLine (int row) { return Model.GetLine (row); } private class WrappedLine { @@ -2613,7 +2463,7 @@ public class TextView : View get => new (CurrentColumn, CurrentRow); set { - List line = _model.GetLine (Math.Max (Math.Min (value.Y, _model.Count - 1), 0)); + List line = _model.GetLine (Math.Max (Math.Min (value.Y, _model.Count - 1), 0)); CurrentColumn = value.X < 0 ? 0 : value.X > line.Count ? line.Count : value.X; @@ -2633,11 +2483,11 @@ public class TextView : View public bool HasHistoryChanges => _historyText.HasHistoryChanges; /// - /// If and the current is null will inherit from the + /// If and the current is null will inherit from the /// previous, otherwise if (default) do nothing. If the text is load with - /// this property is automatically sets to . + /// this property is automatically sets to . /// - public bool InheritsPreviousColorScheme { get; set; } + public bool InheritsPreviousAttribute { get; set; } /// /// Indicates whatever the text was changed or not. if the text was changed @@ -2758,7 +2608,7 @@ public class TextView : View get => _selectionStartColumn; set { - List line = _model.GetLine (_selectionStartRow); + List line = _model.GetLine (_selectionStartRow); _selectionStartColumn = value < 0 ? 0 : value > line.Count ? line.Count : value; @@ -2915,8 +2765,8 @@ public class TextView : View } else { - List currentLine = GetCurrentLine (); - SetClipboard (RuneCell.ToString (currentLine)); + List currentLine = GetCurrentLine (); + SetClipboard (Cell.ToString (currentLine)); _copyWithoutSelection = true; } @@ -2978,7 +2828,7 @@ public class TextView : View ClearSelectedRegion (); - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); _historyText.Add ( new () { new (currentLine) }, @@ -3022,7 +2872,7 @@ public class TextView : View ClearSelectedRegion (); - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); _historyText.Add ( new () { new (currentLine) }, @@ -3051,19 +2901,19 @@ public class TextView : View } /// Invoked when the normal color is drawn. - public event EventHandler? DrawNormalColor; + public event EventHandler? DrawNormalColor; /// Invoked when the ready only color is drawn. - public event EventHandler? DrawReadOnlyColor; + public event EventHandler? DrawReadOnlyColor; /// Invoked when the selection color is drawn. - public event EventHandler? DrawSelectionColor; + public event EventHandler? DrawSelectionColor; /// /// Invoked when the used color is drawn. The Used Color is used to indicate if the /// was pressed and enabled. /// - public event EventHandler? DrawUsedColor; + public event EventHandler? DrawUsedColor; /// Find the next text based on the match case with the option to replace it. /// The text to find. @@ -3136,19 +2986,19 @@ public class TextView : View /// Gets all lines of characters. /// - public List> GetAllLines () { return _model.GetAllLines (); } + public List> GetAllLines () { return _model.GetAllLines (); } /// /// Returns the characters on the current line (where the cursor is positioned). Use /// to determine the position of the cursor within that line /// /// - public List GetCurrentLine () { return _model.GetLine (CurrentRow); } + public List GetCurrentLine () { return _model.GetLine (CurrentRow); } /// Returns the characters on the . /// The intended line. /// - public List GetLine (int line) { return _model.GetLine (line); } + public List GetLine (int line) { return _model.GetLine (line); } /// public override Attribute GetNormalColor () @@ -3231,26 +3081,26 @@ public class TextView : View UpdateWrapModel (); } - /// Loads the contents of the list into the . + /// Loads the contents of the list into the . /// Rune cells list to load the contents from. - public void Load (List cells) + public void Load (List cells) { SetWrapModel (); - _model.LoadRuneCells (cells, ColorScheme); + _model.LoadCells (cells, ColorScheme?.Focus); _historyText.Clear (Text); ResetPosition (); SetNeedsDisplay (); UpdateWrapModel (); - InheritsPreviousColorScheme = true; + InheritsPreviousAttribute = true; } - /// Loads the contents of the list of list into the . + /// Loads the contents of the list of list into the . /// List of rune cells list to load the contents from. - public void Load (List> cellsList) + public void Load (List> cellsList) { SetWrapModel (); - InheritsPreviousColorScheme = true; - _model.LoadListRuneCells (cellsList, ColorScheme); + InheritsPreviousAttribute = true; + _model.LoadListCells (cellsList, ColorScheme?.Focus); _historyText.Clear (Text); ResetPosition (); SetNeedsDisplay (); @@ -3347,7 +3197,7 @@ public class TextView : View } else if (ev.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition)) { - ProcessMouseClick (ev, out List line); + ProcessMouseClick (ev, out List line); PositionCursor (); if (_model.Count > 0 && _shiftSelecting && Selecting) @@ -3446,7 +3296,7 @@ public class TextView : View StopSelecting (); } - ProcessMouseClick (ev, out List line); + ProcessMouseClick (ev, out List line); (int col, int row)? newPos; if (CurrentColumn == line.Count @@ -3483,7 +3333,7 @@ public class TextView : View StopSelecting (); } - ProcessMouseClick (ev, out List line); + ProcessMouseClick (ev, out List line); CurrentColumn = 0; if (!Selecting) @@ -3509,7 +3359,7 @@ public class TextView : View public void MoveEnd () { CurrentRow = _model.Count - 1; - List line = GetCurrentLine (); + List line = GetCurrentLine (); CurrentColumn = line.Count; TrackColumn (); PositionCursor (); @@ -3554,7 +3404,7 @@ public class TextView : View for (int idxRow = _topRow; idxRow < _model.Count; idxRow++) { - List line = _model.GetLine (idxRow); + List line = _model.GetLine (idxRow); int lineRuneCount = line.Count; var col = 0; @@ -3726,12 +3576,12 @@ public class TextView : View if (_copyWithoutSelection && contents.FirstOrDefault (x => x == '\n' || x == '\r') == 0) { - List runeList = contents is null ? new () : RuneCell.ToRuneCellList (contents); - List currentLine = GetCurrentLine (); + List runeList = contents is null ? new () : Cell.ToCellList (contents); + List currentLine = GetCurrentLine (); _historyText.Add (new () { new (currentLine) }, CursorPosition); - List> addedLine = new () { new (currentLine), runeList }; + List> addedLine = new () { new (currentLine), runeList }; _historyText.Add ( new (addedLine), @@ -3797,7 +3647,7 @@ public class TextView : View SetNeedsDisplay (); } - List line = _model.GetLine (CurrentRow); + List line = _model.GetLine (CurrentRow); var col = 0; if (line.Count > 0) @@ -3956,16 +3806,16 @@ public class TextView : View /// The line. /// The col index. /// The row index. - protected virtual void OnDrawNormalColor (List line, int idxCol, int idxRow) + protected virtual void OnDrawNormalColor (List line, int idxCol, int idxRow) { (int Row, int Col) unwrappedPos = GetUnwrappedPosition (idxRow, idxCol); - var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos); + var ev = new CellEventArgs (line, idxCol, unwrappedPos); DrawNormalColor?.Invoke (this, ev); - if (line [idxCol].ColorScheme is { }) + if (line [idxCol].Attribute is { }) { - ColorScheme? colorScheme = line [idxCol].ColorScheme; - Driver.SetAttribute (Enabled ? colorScheme!.Focus : colorScheme!.Disabled); + Attribute? attribute = line [idxCol].Attribute; + Driver.SetAttribute ((Attribute)attribute!); } else { @@ -3982,22 +3832,22 @@ public class TextView : View /// The col index. /// /// /// The row index. - protected virtual void OnDrawReadOnlyColor (List line, int idxCol, int idxRow) + protected virtual void OnDrawReadOnlyColor (List line, int idxCol, int idxRow) { (int Row, int Col) unwrappedPos = GetUnwrappedPosition (idxRow, idxCol); - var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos); + var ev = new CellEventArgs (line, idxCol, unwrappedPos); DrawReadOnlyColor?.Invoke (this, ev); - ColorScheme? colorScheme = line [idxCol].ColorScheme is { } ? line [idxCol].ColorScheme : ColorScheme; + Attribute? cellAttribute = line [idxCol].Attribute is { } ? line [idxCol].Attribute : ColorScheme?.Disabled; Attribute attribute; - if (colorScheme!.Disabled.Foreground == colorScheme.Focus.Background) + if (cellAttribute!.Value.Foreground == cellAttribute.Value.Background) { - attribute = new (colorScheme.Focus.Foreground, colorScheme.Focus.Background); + attribute = new (cellAttribute.Value.Foreground, cellAttribute.Value.Background); } else { - attribute = new (colorScheme.Disabled.Foreground, colorScheme.Focus.Background); + attribute = new (cellAttribute.Value.Foreground, ColorScheme!.Focus.Background); } Driver.SetAttribute (attribute); @@ -4012,18 +3862,18 @@ public class TextView : View /// The col index. /// /// /// The row index. - protected virtual void OnDrawSelectionColor (List line, int idxCol, int idxRow) + protected virtual void OnDrawSelectionColor (List line, int idxCol, int idxRow) { (int Row, int Col) unwrappedPos = GetUnwrappedPosition (idxRow, idxCol); - var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos); + var ev = new CellEventArgs (line, idxCol, unwrappedPos); DrawSelectionColor?.Invoke (this, ev); - if (line [idxCol].ColorScheme is { }) + if (line [idxCol].Attribute is { }) { - ColorScheme? colorScheme = line [idxCol].ColorScheme; + Attribute? attribute = line [idxCol].Attribute; Driver.SetAttribute ( - new (colorScheme!.Focus.Background, colorScheme.Focus.Foreground) + new (attribute!.Value.Background, attribute.Value.Foreground) ); } else @@ -4046,20 +3896,20 @@ public class TextView : View /// The col index. /// /// /// The row index. - protected virtual void OnDrawUsedColor (List line, int idxCol, int idxRow) + protected virtual void OnDrawUsedColor (List line, int idxCol, int idxRow) { (int Row, int Col) unwrappedPos = GetUnwrappedPosition (idxRow, idxCol); - var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos); + var ev = new CellEventArgs (line, idxCol, unwrappedPos); DrawUsedColor?.Invoke (this, ev); - if (line [idxCol].ColorScheme is { }) + if (line [idxCol].Attribute is { }) { - ColorScheme? colorScheme = line [idxCol].ColorScheme; - SetValidUsedColor (colorScheme!); + Attribute? attribute = line [idxCol].Attribute; + SetValidUsedColor (attribute!); } else { - SetValidUsedColor (ColorScheme); + SetValidUsedColor (ColorScheme?.Focus); } } @@ -4072,7 +3922,7 @@ public class TextView : View private void Adjust () { (int width, int height) offB = OffSetBackground (); - List line = GetCurrentLine (); + List line = GetCurrentLine (); bool need = NeedsDisplay || _wrapNeeded || !Used; (int size, int length) tSize = TextModel.DisplaySize (line, -1, -1, false, TabWidth); (int size, int length) dSize = TextModel.DisplaySize (line, _leftColumn, CurrentColumn, true, TabWidth); @@ -4234,11 +4084,11 @@ public class TextView : View var maxrow = (int)(end >> 32); var startCol = (int)(start & 0xffffffff); var endCol = (int)(end & 0xffffffff); - List line = _model.GetLine (startRow); + List line = _model.GetLine (startRow); _historyText.Add (new () { new (line) }, new (startCol, startRow)); - List> removedLines = new (); + List> removedLines = new (); if (startRow == maxrow) { @@ -4273,7 +4123,7 @@ public class TextView : View removedLines.Add (new (line)); line.RemoveRange (startCol, line.Count - startCol); - List line2 = _model.GetLine (maxrow); + List line2 = _model.GetLine (maxrow); line.AddRange (line2.Skip (endCol)); for (int row = startRow + 1; row <= maxrow; row++) @@ -4324,7 +4174,7 @@ public class TextView : View if (CurrentColumn > 0) { // Delete backwards - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); _historyText.Add (new () { new (currentLine) }, CursorPosition); @@ -4364,11 +4214,11 @@ public class TextView : View } int prowIdx = CurrentRow - 1; - List prevRow = _model.GetLine (prowIdx); + List prevRow = _model.GetLine (prowIdx); _historyText.Add (new () { new (prevRow) }, CursorPosition); - List> removedLines = new () { new (prevRow) }; + List> removedLines = new () { new (prevRow) }; removedLines.Add (new (GetCurrentLine ())); @@ -4408,7 +4258,7 @@ public class TextView : View { SetWrapModel (); - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); if (CurrentColumn == currentLine.Count) { @@ -4421,9 +4271,9 @@ public class TextView : View _historyText.Add (new () { new (currentLine) }, CursorPosition); - List> removedLines = new () { new (currentLine) }; + List> removedLines = new () { new (currentLine) }; - List nextLine = _model.GetLine (CurrentRow + 1); + List nextLine = _model.GetLine (CurrentRow + 1); removedLines.Add (new (nextLine)); @@ -4503,7 +4353,7 @@ public class TextView : View } } - private IEnumerable<(int col, int row, RuneCell rune)> ForwardIterator (int col, int row) + private IEnumerable<(int col, int row, Cell rune)> ForwardIterator (int col, int row) { if (col < 0 || row < 0) { @@ -4515,7 +4365,7 @@ public class TextView : View yield break; } - List line = GetCurrentLine (); + List line = GetCurrentLine (); if (col >= line.Count) { @@ -4537,7 +4387,7 @@ public class TextView : View private void GenerateSuggestions () { - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); int cursorPosition = Math.Min (CurrentColumn, currentLine.Count); Autocomplete.Context = new ( @@ -4613,7 +4463,7 @@ public class TextView : View var maxrow = (int)(end >> 32); var startCol = (int)(start & 0xffffffff); var endCol = (int)(end & 0xffffffff); - List line = model is null ? _model.GetLine (startRow) : model.GetLine (startRow); + List line = model is null ? _model.GetLine (startRow) : model.GetLine (startRow); if (startRow == maxrow) { @@ -4738,9 +4588,9 @@ public class TextView : View OnContentsChanged (); } - private void Insert (RuneCell cell) + private void Insert (Cell cell) { - List line = GetCurrentLine (); + List line = GetCurrentLine (); if (Used) { @@ -4773,7 +4623,7 @@ public class TextView : View return; } - List> lines = RuneCell.StringToLinesOfRuneCells (text); + List> lines = Cell.StringToLinesOfCells (text); if (lines.Count == 0) { @@ -4782,7 +4632,7 @@ public class TextView : View SetWrapModel (); - List line = GetCurrentLine (); + List line = GetCurrentLine (); _historyText.Add (new () { new (line) }, CursorPosition); @@ -4821,7 +4671,7 @@ public class TextView : View return; } - List? rest = null; + List? rest = null; var lastp = 0; if (_model.Count > 0 && line.Count > 0 && !_copyWithoutSelection) @@ -4837,7 +4687,7 @@ public class TextView : View //model.AddLine (currentRow, lines [0]); - List> addedLines = new () { new (line) }; + List> addedLines = new () { new (line) }; for (var i = 1; i < lines.Count; i++) { @@ -4848,7 +4698,7 @@ public class TextView : View if (rest is { }) { - List last = _model.GetLine (CurrentRow + lines.Count - 1); + List last = _model.GetLine (CurrentRow + lines.Count - 1); lastp = last.Count; last.InsertRange (last.Count, rest); @@ -4872,7 +4722,7 @@ public class TextView : View OnContentsChanged (); } - private bool InsertText (Key a, ColorScheme? colorScheme = null) + private bool InsertText (Key a, Attribute? attribute = null) { //So that special keys like tab can be processed if (_isReadOnly) @@ -4891,7 +4741,7 @@ public class TextView : View if ((uint)a.KeyCode == '\n') { - _model.AddLine (CurrentRow + 1, new ()); + _model.AddLine (CurrentRow + 1, []); CurrentRow++; CurrentColumn = 0; } @@ -4903,7 +4753,7 @@ public class TextView : View { if (Used) { - Insert (new () { Rune = a.AsRune, ColorScheme = colorScheme }); + Insert (new () { Rune = a.AsRune, Attribute = attribute }); CurrentColumn++; if (CurrentColumn >= _leftColumn + Viewport.Width) @@ -4914,7 +4764,7 @@ public class TextView : View } else { - Insert (new () { Rune = a.AsRune, ColorScheme = colorScheme }); + Insert (new () { Rune = a.AsRune, Attribute = attribute }); CurrentColumn++; } } @@ -4946,7 +4796,7 @@ public class TextView : View SetWrapModel (); - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); var setLastWasKill = true; if (currentLine.Count > 0 && CurrentColumn == currentLine.Count) @@ -4964,7 +4814,7 @@ public class TextView : View { if (CurrentRow < _model.Count - 1) { - List> removedLines = new () { new (currentLine) }; + List> removedLines = new () { new (currentLine) }; _model.RemoveLine (CurrentRow); @@ -5000,7 +4850,7 @@ public class TextView : View else { int restCount = currentLine.Count - CurrentColumn; - List rest = currentLine.GetRange (CurrentColumn, restCount); + List rest = currentLine.GetRange (CurrentColumn, restCount); var val = string.Empty; val += StringFromRunes (rest); @@ -5045,7 +4895,7 @@ public class TextView : View SetWrapModel (); - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); var setLastWasKill = true; if (currentLine.Count > 0 && CurrentColumn == 0) @@ -5088,7 +4938,7 @@ public class TextView : View CurrentRow--; currentLine = _model.GetLine (CurrentRow); - List> removedLine = + List> removedLine = [ [..currentLine], [] @@ -5106,7 +4956,7 @@ public class TextView : View else { int restCount = CurrentColumn; - List rest = currentLine.GetRange (0, restCount); + List rest = currentLine.GetRange (0, restCount); var val = string.Empty; val += StringFromRunes (rest); @@ -5146,7 +4996,7 @@ public class TextView : View SetWrapModel (); - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); _historyText.Add ([ [.. GetCurrentLine ()]], CursorPosition); @@ -5214,7 +5064,7 @@ public class TextView : View SetWrapModel (); - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); _historyText.Add ([ [.. GetCurrentLine ()]], CursorPosition); @@ -5335,7 +5185,7 @@ public class TextView : View private void MoveEndOfLine () { - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); CurrentColumn = Math.Max (currentLine.Count - (ReadOnly ? 1 : 0), 0); Adjust (); DoNeededAction (); @@ -5359,7 +5209,7 @@ public class TextView : View SetNeedsDisplay (); } - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); CurrentColumn = Math.Max (currentLine.Count - (ReadOnly ? 1 : 0), 0); } else @@ -5432,7 +5282,7 @@ public class TextView : View private bool MoveRight () { - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); if ((ReadOnly ? CurrentColumn + 1 : CurrentColumn) < currentLine.Count) { @@ -5628,7 +5478,7 @@ public class TextView : View { SetWrapModel (); - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); if (currentLine.Count > 0 && currentLine [CurrentColumn - 1].Rune.Value == '\t') { @@ -5683,13 +5533,13 @@ public class TextView : View // the very most previous valid color scheme. private void ProcessInheritsPreviousColorScheme (int row, int col) { - if (!InheritsPreviousColorScheme || (Lines == 1 && GetLine (Lines).Count == 0)) + if (!InheritsPreviousAttribute || (Lines == 1 && GetLine (Lines).Count == 0)) { return; } - List line = GetLine (row); - List lineToSet = line; + List line = GetLine (row); + List lineToSet = line; while (line.Count == 0) { @@ -5704,20 +5554,25 @@ public class TextView : View } int colWithColor = Math.Max (Math.Min (col - 2, line.Count - 1), 0); - RuneCell cell = line [colWithColor]; + Cell cell = line [colWithColor]; int colWithoutColor = Math.Max (col - 1, 0); - if (cell.ColorScheme is { } && colWithColor == 0 && lineToSet [colWithoutColor].ColorScheme is { }) + Cell lineTo = lineToSet [colWithoutColor]; + + if (cell.Attribute is { } && colWithColor == 0 && lineTo.Attribute is { }) { for (int r = row - 1; r > -1; r--) { - List l = GetLine (r); + List l = GetLine (r); for (int c = l.Count - 1; c > -1; c--) { - if (l [c].ColorScheme is null) + Cell cell1 = l [c]; + + if (cell1.Attribute is null) { - l [c].ColorScheme = cell.ColorScheme; + cell1.Attribute = cell.Attribute; + l [c] = cell1; } else { @@ -5729,18 +5584,18 @@ public class TextView : View return; } - if (cell.ColorScheme is null) + if (cell.Attribute is null) { for (int r = row; r > -1; r--) { - List l = GetLine (r); + List l = GetLine (r); colWithColor = l.FindLastIndex ( colWithColor > -1 ? colWithColor : l.Count - 1, - rc => rc.ColorScheme != null + c => c.Attribute != null ); - if (colWithColor > -1 && l [colWithColor].ColorScheme is { }) + if (colWithColor > -1 && l [colWithColor].Attribute is { }) { cell = l [colWithColor]; @@ -5752,9 +5607,9 @@ public class TextView : View { int cRow = row; - while (cell.ColorScheme is null) + while (cell.Attribute is null) { - if ((colWithColor == 0 || cell.ColorScheme is null) && cRow > 0) + if ((colWithColor == 0 || cell.Attribute is null) && cRow > 0) { line = GetLine (--cRow); colWithColor = line.Count - 1; @@ -5767,11 +5622,12 @@ public class TextView : View } } - if (cell.ColorScheme is { } && colWithColor > -1 && colWithoutColor < lineToSet.Count && lineToSet [colWithoutColor].ColorScheme is null) + if (cell.Attribute is { } && colWithColor > -1 && colWithoutColor < lineToSet.Count && lineTo.Attribute is null) { - while (lineToSet [colWithoutColor].ColorScheme is null) + while (lineTo.Attribute is null) { - lineToSet [colWithoutColor].ColorScheme = cell.ColorScheme; + lineTo.Attribute = cell.Attribute; + lineToSet [colWithoutColor] = lineTo; colWithoutColor--; if (colWithoutColor == -1 && row > 0) @@ -5795,9 +5651,9 @@ public class TextView : View KillWordForward (); } - private void ProcessMouseClick (MouseEvent ev, out List line) + private void ProcessMouseClick (MouseEvent ev, out List line) { - List? r = null; + List? r = null; if (_model.Count > 0) { @@ -6069,7 +5925,7 @@ public class TextView : View SetWrapModel (); - List currentLine = GetCurrentLine (); + List currentLine = GetCurrentLine (); _historyText.Add (new () { new (currentLine) }, CursorPosition); @@ -6080,10 +5936,10 @@ public class TextView : View } int restCount = currentLine.Count - CurrentColumn; - List rest = currentLine.GetRange (CurrentColumn, restCount); + List rest = currentLine.GetRange (CurrentColumn, restCount); currentLine.RemoveRange (CurrentColumn, restCount); - List> addedLines = new () { new (currentLine) }; + List> addedLines = new () { new (currentLine) }; _model.AddLine (CurrentRow + 1, rest); @@ -6269,11 +6125,11 @@ public class TextView : View DoNeededAction (); } - private static void SetValidUsedColor (ColorScheme? colorScheme) + private static void SetValidUsedColor (Attribute? attribute) { // BUGBUG: (v2 truecolor) This code depends on 8-bit color names; disabling for now //if ((colorScheme!.HotNormal.Foreground & colorScheme.Focus.Background) == colorScheme.Focus.Foreground) { - Driver.SetAttribute (new (colorScheme!.Focus.Background, colorScheme!.Focus.Foreground)); + Driver.SetAttribute (new (attribute!.Value.Background, attribute!.Value.Foreground)); } /// Restore from original model. @@ -6328,7 +6184,7 @@ public class TextView : View _isButtonShift = false; } - private string StringFromRunes (List cells) + private string StringFromRunes (List cells) { if (cells is null) { @@ -6337,7 +6193,7 @@ public class TextView : View var size = 0; - foreach (RuneCell cell in cells) + foreach (Cell cell in cells) { size += cell.Rune.GetEncodingLength (); } @@ -6345,7 +6201,7 @@ public class TextView : View var encoded = new byte [size]; var offset = 0; - foreach (RuneCell cell in cells) + foreach (Cell cell in cells) { offset += cell.Rune.Encode (encoded, offset); } @@ -6389,7 +6245,7 @@ public class TextView : View private void TrackColumn () { // Now track the column - List line = GetCurrentLine (); + List line = GetCurrentLine (); if (line.Count < _columnTrack) { diff --git a/Terminal.Gui/Views/TreeView/Branch.cs b/Terminal.Gui/Views/TreeView/Branch.cs index 0b37314cd..2b9f637d8 100644 --- a/Terminal.Gui/Views/TreeView/Branch.cs +++ b/Terminal.Gui/Views/TreeView/Branch.cs @@ -75,7 +75,7 @@ internal class Branch where T : class /// public virtual void Draw (ConsoleDriver driver, ColorScheme colorScheme, int y, int availableWidth) { - List cells = new (); + List cells = new (); int? indexOfExpandCollapseSymbol = null; int indexOfModelText; @@ -106,7 +106,7 @@ internal class Branch where T : class } else { - cells.Add (NewRuneCell (attr, r)); + cells.Add (NewCell (attr, r)); availableWidth -= r.GetColumns (); } } @@ -148,7 +148,7 @@ internal class Branch where T : class else { indexOfExpandCollapseSymbol = cells.Count; - cells.Add (NewRuneCell (attr, expansion)); + cells.Add (NewCell (attr, expansion)); availableWidth -= expansion.GetColumns (); } @@ -211,7 +211,7 @@ internal class Branch where T : class } attr = modelColor; - cells.AddRange (lineBody.Select (r => NewRuneCell (attr, new Rune (r)))); + cells.AddRange (lineBody.Select (r => NewCell (attr, new Rune (r)))); if (availableWidth > 0) { @@ -219,7 +219,7 @@ internal class Branch where T : class cells.AddRange ( Enumerable.Repeat ( - NewRuneCell (attr, new Rune (' ')), + NewCell (attr, new Rune (' ')), availableWidth ) ); @@ -229,7 +229,7 @@ internal class Branch where T : class { Model = Model, Y = y, - RuneCells = cells, + Cells = cells, Tree = tree, IndexOfExpandCollapseSymbol = indexOfExpandCollapseSymbol, @@ -239,9 +239,9 @@ internal class Branch where T : class if (!e.Handled) { - foreach (RuneCell cell in cells) + foreach (Cell cell in cells) { - driver.SetAttribute (cell.ColorScheme.Normal); + driver.SetAttribute ((Attribute)cell.Attribute!); driver.AddRune (cell.Rune); } } @@ -529,5 +529,5 @@ internal class Branch where T : class return Parent.ChildBranches.Values.LastOrDefault () == this; } - private static RuneCell NewRuneCell (Attribute attr, Rune r) { return new RuneCell { Rune = r, ColorScheme = new ColorScheme (attr) }; } + private static Cell NewCell (Attribute attr, Rune r) { return new Cell { Rune = r, Attribute = new (attr) }; } } diff --git a/Terminal.Gui/Views/TreeView/DrawTreeViewLineEventArgs.cs b/Terminal.Gui/Views/TreeView/DrawTreeViewLineEventArgs.cs index 1454abff7..6cd03747d 100644 --- a/Terminal.Gui/Views/TreeView/DrawTreeViewLineEventArgs.cs +++ b/Terminal.Gui/Views/TreeView/DrawTreeViewLineEventArgs.cs @@ -12,16 +12,16 @@ public class DrawTreeViewLineEventArgs where T : class public bool Handled { get; set; } /// - /// If line contains a branch that can be expanded/collapsed then this is the index in at + /// If line contains a branch that can be expanded/collapsed then this is the index in at /// which the symbol is (or null for leaf elements). /// public int? IndexOfExpandCollapseSymbol { get; init; } /// - /// The notional index in which contains the first character of the + /// The notional index in which contains the first character of the /// text (i.e. after all branch lines and expansion/collapse symbols). /// - /// May be negative or outside of bounds of if the view has been scrolled horizontally. + /// May be negative or outside of bounds of if the view has been scrolled horizontally. public int IndexOfModelText { get; init; } /// The object at this line in the tree @@ -32,7 +32,7 @@ public class DrawTreeViewLineEventArgs where T : class /// respected. You can modify these to change what is rendered. /// /// Changing the length of this collection may result in corrupt rendering - public List RuneCells { get; init; } + public List Cells { get; init; } /// The that is performing the rendering. public TreeView Tree { get; init; } diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs index 1fcc6dafd..ec17e6a39 100644 --- a/UICatalog/Scenarios/Editor.cs +++ b/UICatalog/Scenarios/Editor.cs @@ -210,22 +210,18 @@ public class Editor : Scenario { if (!PromptForColor ( "Colors", - GetSelectedRuneCellAttribute (), + GetSelectedCellAttribute (), out Attribute newAttribute )) { return; } - var cs = new ColorScheme (_textView.ColorScheme) - { - Focus = new ( - newAttribute.Foreground, + var attribute = new Attribute (newAttribute.Foreground, newAttribute.Background - ) - }; + ); - ApplyRuneCellAttribute (cs); + ApplyCellAttribute (attribute); }) } ), @@ -341,7 +337,7 @@ public class Editor : Scenario } - private void ApplyRuneCellAttribute (ColorScheme cs) + private void ApplyCellAttribute (Attribute attribute) { if (!_textView.ReadOnly && _textView.SelectedLength > 0) { @@ -352,29 +348,31 @@ public class Editor : Scenario for (int r = startRow; r <= endRow; r++) { - List line = _textView.GetLine (r); + List line = _textView.GetLine (r); for (int c = r == startRow ? startCol : 0; c < (r == endRow ? endCol : line.Count); c++) { - line [c].ColorScheme = cs; + Cell cell = line [c]; // Copy value to a new variable + cell.Attribute = attribute; // Modify the copy + line [c] = cell; // Assign the modified copy back } } } } - private Attribute? GetSelectedRuneCellAttribute () + private Attribute? GetSelectedCellAttribute () { - List line; + List line; if (_textView.SelectedLength > 0) { line = _textView.GetLine (_textView.SelectionStartRow); - if (line [Math.Min (_textView.SelectionStartColumn, line.Count - 1)].ColorScheme is { } csSel) + if (line [Math.Min (_textView.SelectionStartColumn, line.Count - 1)].Attribute is { } attributeSel) { - return new (csSel.Focus); + return new (attributeSel); } return new (_textView.ColorScheme!.Focus); @@ -382,9 +380,9 @@ public class Editor : Scenario line = _textView.GetCurrentLine (); - if (line [Math.Min (_textView.CurrentColumn, line.Count - 1)].ColorScheme is { } cs) + if (line [Math.Min (_textView.CurrentColumn, line.Count - 1)].Attribute is { } attribute) { - return new (cs!.Focus); + return new (attribute); } return new (_textView.ColorScheme!.Focus); diff --git a/UICatalog/Scenarios/SyntaxHighlighting.cs b/UICatalog/Scenarios/SyntaxHighlighting.cs index ce4e970a2..398355e34 100644 --- a/UICatalog/Scenarios/SyntaxHighlighting.cs +++ b/UICatalog/Scenarios/SyntaxHighlighting.cs @@ -85,13 +85,13 @@ public class SyntaxHighlighting : Scenario "exists" }; - private readonly string _path = "RuneCells.rce"; - private ColorScheme _blue; - private ColorScheme _green; - private ColorScheme _magenta; + private readonly string _path = "Cells.rce"; + private Attribute _blue; + private Attribute _green; + private Attribute _magenta; private MenuItem _miWrap; private TextView _textView; - private ColorScheme _white; + private Attribute _white; /// /// Reads an object instance from an Json file. @@ -155,12 +155,12 @@ public class SyntaxHighlighting : Scenario new ( "_Load Rune Cells", "", - () => ApplyLoadRuneCells () + () => ApplyLoadCells () ), new ( "_Save Rune Cells", "", - () => SaveRuneCells () + () => SaveCells () ), null, new ("_Quit", "", () => Quit ()) @@ -231,11 +231,11 @@ public class SyntaxHighlighting : Scenario } } - private void ApplyLoadRuneCells () + private void ApplyLoadCells () { ClearAllEvents (); - List runeCells = new (); + List cells = new (); foreach (KeyValuePair color in Colors.ColorSchemes) { @@ -243,21 +243,21 @@ public class SyntaxHighlighting : Scenario foreach (Rune rune in csName.EnumerateRunes ()) { - runeCells.Add (new() { Rune = rune, ColorScheme = color.Value }); + cells.Add (new() { Rune = rune, Attribute = color.Value.Normal }); } - runeCells.Add (new() { Rune = (Rune)'\n', ColorScheme = color.Value }); + cells.Add (new() { Rune = (Rune)'\n', Attribute = color.Value.Focus }); } if (File.Exists (_path)) { - //Reading the file - List> cells = ReadFromJsonFile>> (_path); - _textView.Load (cells); + //Reading the file + List> fileCells = ReadFromJsonFile>> (_path); + _textView.Load (fileCells); } else { - _textView.Load (runeCells); + _textView.Load (cells); } _textView.Autocomplete.SuggestionGenerator = new SingleWordSuggestionGenerator (); @@ -267,11 +267,11 @@ public class SyntaxHighlighting : Scenario { ClearAllEvents (); - _green = new (new Attribute (Color.Green, Color.Black)); - _blue = new (new Attribute (Color.Blue, Color.Black)); - _magenta = new (new Attribute (Color.Magenta, Color.Black)); - _white = new (new Attribute (Color.White, Color.Black)); - _textView.ColorScheme = _white; + _green = new Attribute (Color.Green, Color.Black); + _blue = new Attribute (Color.Blue, Color.Black); + _magenta = new Attribute (Color.Magenta, Color.Black); + _white = new Attribute (Color.White, Color.Black); + _textView.ColorScheme = new () { Focus = _white }; _textView.Text = "/*Query to select:\nLots of data*/\nSELECT TOP 100 * \nfrom\n MyDb.dbo.Biochemistry where TestCode = 'blah';"; @@ -292,7 +292,7 @@ public class SyntaxHighlighting : Scenario _textView.ClearEventHandlers ("DrawContent"); _textView.ClearEventHandlers ("DrawContentComplete"); - _textView.InheritsPreviousColorScheme = false; + _textView.InheritsPreviousAttribute = false; } private bool ContainsPosition (Match m, int pos) { return pos >= m.Index && pos < m.Index + m.Length; } @@ -317,27 +317,30 @@ public class SyntaxHighlighting : Scenario for (var y = 0; y < _textView.Lines; y++) { - List line = _textView.GetLine (y); + List line = _textView.GetLine (y); for (var x = 0; x < line.Count; x++) { + Cell cell = line [x]; + if (commentMatches.Any (m => ContainsPosition (m, pos))) { - line [x].ColorScheme = _green; + cell.Attribute = _green; } else if (singleQuoteMatches.Any (m => ContainsPosition (m, pos))) { - line [x].ColorScheme = _magenta; + cell.Attribute = _magenta; } else if (keywordMatches.Any (m => ContainsPosition (m, pos))) { - line [x].ColorScheme = _blue; + cell.Attribute = _blue; } else { - line [x].ColorScheme = _white; + cell.Attribute = _white; } + line [x] = cell; pos++; } @@ -384,10 +387,10 @@ public class SyntaxHighlighting : Scenario private void Quit () { Application.RequestStop (); } - private void SaveRuneCells () + private void SaveCells () { //Writing to file - List> cells = _textView.GetAllLines (); + List> cells = _textView.GetAllLines (); WriteToJsonFile (_path, cells); } diff --git a/UICatalog/Scenarios/TreeViewFileSystem.cs b/UICatalog/Scenarios/TreeViewFileSystem.cs index d2073bd18..590af81b1 100644 --- a/UICatalog/Scenarios/TreeViewFileSystem.cs +++ b/UICatalog/Scenarios/TreeViewFileSystem.cs @@ -441,16 +441,14 @@ public class TreeViewFileSystem : Scenario { if (_iconProvider.UseNerdIcons || _iconProvider.UseUnicodeCharacters) { - if (e.IndexOfModelText > 0 && e.IndexOfModelText < e.RuneCells.Count) + if (e.IndexOfModelText > 0 && e.IndexOfModelText < e.Cells.Count) { - RuneCell cell = e.RuneCells [e.IndexOfModelText]; + Cell cell = e.Cells [e.IndexOfModelText]; - cell.ColorScheme = new ColorScheme ( - new Attribute ( - Color.BrightYellow, - cell.ColorScheme.Normal.Background - ) - ); + cell.Attribute = new Attribute ( + Color.BrightYellow, + cell.Attribute!.Value.Background + ); } } } diff --git a/UnitTests/Configuration/ThemeTests.cs b/UnitTests/Configuration/ThemeTests.cs index ffce969d8..e7d023d10 100644 --- a/UnitTests/Configuration/ThemeTests.cs +++ b/UnitTests/Configuration/ThemeTests.cs @@ -10,6 +10,7 @@ public class ThemeTests Converters = { new AttributeJsonConverter (), new ColorJsonConverter () } }; + [Fact] [AutoInitShutdown (configLocation: ConfigLocations.DefaultOnly)] public void TestApply () { diff --git a/UnitTests/Views/RuneCellTests.cs b/UnitTests/Drawing/CellTests.cs similarity index 61% rename from UnitTests/Views/RuneCellTests.cs rename to UnitTests/Drawing/CellTests.cs index ccbce08c9..459c6d136 100644 --- a/UnitTests/Views/RuneCellTests.cs +++ b/UnitTests/Drawing/CellTests.cs @@ -1,59 +1,59 @@ using System.Text; using Xunit.Abstractions; -namespace Terminal.Gui.ViewsTests; +namespace Terminal.Gui.DrawingTests; -public class RuneCellTests (ITestOutputHelper output) +public class CellTests (ITestOutputHelper output) { [Fact] public void Constructor_Defaults () { - var rc = new RuneCell (); - Assert.NotNull (rc); - Assert.Equal (0, rc.Rune.Value); - Assert.Null (rc.ColorScheme); + var c = new Cell (); + Assert.True (c is { }); + Assert.Equal (0, c.Rune.Value); + Assert.Null (c.Attribute); } [Fact] public void Equals_False () { - var rc1 = new RuneCell (); + var c1 = new Cell (); - var rc2 = new RuneCell + var c2 = new Cell { - Rune = new ('a'), ColorScheme = new() { Normal = new (Color.Red) } + Rune = new ('a'), Attribute = new (Color.Red) }; - Assert.False (rc1.Equals (rc2)); - Assert.False (rc2.Equals (rc1)); + Assert.False (c1.Equals (c2)); + Assert.False (c2.Equals (c1)); - rc1.Rune = new ('a'); - rc1.ColorScheme = new (); - Assert.Equal (rc1.Rune, rc2.Rune); - Assert.False (rc1.Equals (rc2)); - Assert.False (rc2.Equals (rc1)); + c1.Rune = new ('a'); + c1.Attribute = new (); + Assert.Equal (c1.Rune, c2.Rune); + Assert.False (c1.Equals (c2)); + Assert.False (c2.Equals (c1)); } [Fact] public void Equals_True () { - var rc1 = new RuneCell (); - var rc2 = new RuneCell (); - Assert.True (rc1.Equals (rc2)); - Assert.True (rc2.Equals (rc1)); + var c1 = new Cell (); + var c2 = new Cell (); + Assert.True (c1.Equals (c2)); + Assert.True (c2.Equals (c1)); - rc1.Rune = new ('a'); - rc1.ColorScheme = new (); - rc2.Rune = new ('a'); - rc2.ColorScheme = new (); - Assert.True (rc1.Equals (rc2)); - Assert.True (rc2.Equals (rc1)); + c1.Rune = new ('a'); + c1.Attribute = new (); + c2.Rune = new ('a'); + c2.Attribute = new (); + Assert.True (c1.Equals (c2)); + Assert.True (c2.Equals (c1)); } [Fact] [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)] - public void RuneCell_LoadRuneCells_InheritsPreviousColorScheme () + public void Cell_LoadCells_InheritsPreviousAttribute () { - List runeCells = new (); + List cells = []; foreach (KeyValuePair color in Colors.ColorSchemes) { @@ -61,18 +61,18 @@ public class RuneCellTests (ITestOutputHelper output) foreach (Rune rune in csName.EnumerateRunes ()) { - runeCells.Add (new() { Rune = rune, ColorScheme = color.Value }); + cells.Add (new() { Rune = rune, Attribute = color.Value.Normal }); } - runeCells.Add (new() { Rune = (Rune)'\n', ColorScheme = color.Value }); + cells.Add (new() { Rune = (Rune)'\n', Attribute = color.Value.Focus }); } TextView tv = CreateTextView (); - tv.Load (runeCells); + tv.Load (cells); var top = new Toplevel (); top.Add (tv); RunState rs = Application.Begin (top); - Assert.True (tv.InheritsPreviousColorScheme); + Assert.True (tv.InheritsPreviousAttribute); var expectedText = @" TopLevel @@ -85,27 +85,30 @@ Error "; Attribute [] attributes = { // 0 - Colors.ColorSchemes ["TopLevel"].Focus, + Colors.ColorSchemes ["TopLevel"].Normal, // 1 - Colors.ColorSchemes ["Base"].Focus, + Colors.ColorSchemes ["Base"].Normal, // 2 - Colors.ColorSchemes ["Dialog"].Focus, + Colors.ColorSchemes ["Dialog"].Normal, // 3 - Colors.ColorSchemes ["Menu"].Focus, + Colors.ColorSchemes ["Menu"].Normal, // 4 - Colors.ColorSchemes ["Error"].Focus + Colors.ColorSchemes ["Error"].Normal, + + // 5 + tv.ColorScheme!.Focus }; var expectedColor = @" -0000000000 -1111000000 -2222220000 -3333000000 -4444400000"; +0000000055 +1111555555 +2222225555 +3333555555 +4444455555"; TestHelpers.AssertDriverAttributesAre (expectedColor, Application.Driver, attributes); tv.WordWrap = true; @@ -134,13 +137,13 @@ Dialogror "; TestHelpers.AssertDriverContentsWithFrameAre (expectedText, output); expectedColor = @" -0000000000 -1111000000 -2222220000 -3333000000 -4444444444 -4444000000 -4444444440"; +0000000055 +1111555555 +2222225555 +3333555555 +4455555555 +5555555555 +5555544445"; TestHelpers.AssertDriverAttributesAre (expectedColor, Application.Driver, attributes); tv.Undo (); @@ -170,14 +173,14 @@ ror "; TestHelpers.AssertDriverContentsWithFrameAre (expectedText, output); expectedColor = @" -0000000000 -1111000000 -2222220000 -3333000000 +0000000055 +1111555555 +2222225555 +3333555555 4444444444 -4444000000 -4444440000 -4440000000"; +4444555555 +4444445555 +4445555555"; TestHelpers.AssertDriverAttributesAre (expectedColor, Application.Driver, attributes); Application.End (rs); @@ -185,9 +188,9 @@ ror "; } [Fact] - public void RuneCell_LoadRuneCells_Without_ColorScheme_Is_Never_Null () + public void Cell_LoadCells_Without_ColorScheme_Is_Never_Null () { - List cells = new () + List cells = new () { new() { Rune = new ('T') }, new() { Rune = new ('e') }, @@ -201,43 +204,44 @@ ror "; for (var i = 0; i < tv.Lines; i++) { - List line = tv.GetLine (i); + List line = tv.GetLine (i); - foreach (RuneCell rc in line) + foreach (Cell c in line) { - Assert.NotNull (rc.ColorScheme); + Assert.NotNull (c.Attribute); } } } [Fact] [AutoInitShutdown] - public void RuneCellEventArgs_WordWrap_True () + public void CellEventArgs_WordWrap_True () { var eventCount = 0; - List> text = new () - { - RuneCell.ToRuneCells ( - "This is the first line.".ToRunes () - ), - RuneCell.ToRuneCells ( - "This is the second line.".ToRunes () - ) - }; + List> text = + [ + Cell.ToCells ( + "This is the first line.".ToRunes () + ), + + Cell.ToCells ( + "This is the second line.".ToRunes () + ) + ]; TextView tv = CreateTextView (); tv.DrawNormalColor += _textView_DrawColor; tv.DrawReadOnlyColor += _textView_DrawColor; tv.DrawSelectionColor += _textView_DrawColor; tv.DrawUsedColor += _textView_DrawColor; - void _textView_DrawColor (object sender, RuneCellEventArgs e) + void _textView_DrawColor (object sender, CellEventArgs e) { Assert.Equal (e.Line [e.Col], text [e.UnwrappedPosition.Row] [e.UnwrappedPosition.Col]); eventCount++; } - tv.Text = $"{RuneCell.ToString (text [0])}\n{RuneCell.ToString (text [1])}\n"; + tv.Text = $"{Cell.ToString (text [0])}\n{Cell.ToString (text [1])}\n"; Assert.False (tv.WordWrap); var top = new Toplevel (); top.Add (tv); @@ -275,20 +279,20 @@ line. ", [Fact] public void ToString_Override () { - var rc1 = new RuneCell (); + var c1 = new Cell (); - var rc2 = new RuneCell + var c2 = new Cell { - Rune = new ('a'), ColorScheme = new() { Normal = new (Color.Red) } + Rune = new ('a'), Attribute = new (Color.Red) }; - Assert.Equal ("U+0000 '\0'; null", rc1.ToString ()); + Assert.Equal ("[\0, ]", c1.ToString ()); Assert.Equal ( - "U+0061 'a'; Normal: [Red,Red]; Focus: [White,Black]; HotNormal: [White,Black]; HotFocus: [White,Black]; Disabled: [White,Black]", - rc2.ToString () + "[a, [Red,Red]]", + c2.ToString () ); } - // TODO: Move the tests below to View or Color - they test ColorScheme, not RuneCell primitives. + // TODO: Move the tests below to View or Color - they test ColorScheme, not Cell primitives. private TextView CreateTextView () { return new() { Width = 30, Height = 10 }; } } diff --git a/UnitTests/Text/AutocompleteTests.cs b/UnitTests/Text/AutocompleteTests.cs index 1689c70c8..e5b1cf4b9 100644 --- a/UnitTests/Text/AutocompleteTests.cs +++ b/UnitTests/Text/AutocompleteTests.cs @@ -254,7 +254,7 @@ This an long line and against TextView.", ac.GenerateSuggestions ( new ( - RuneCell.ToRuneCellList (tv.Text), + Cell.ToCellList (tv.Text), 2 ) ); diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index 84a0c931e..213abf614 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -1160,7 +1160,7 @@ This is the second line. { Assert.Throws ( () => ht.Add ( - new List> { new () }, + new List> { new () }, Point.Empty, (HistoryText.LineStatus)ls ) @@ -1168,7 +1168,7 @@ This is the second line. } } - Assert.Null (Record.Exception (() => ht.Add (new List> { new () }, Point.Empty))); + Assert.Null (Record.Exception (() => ht.Add (new List> { new () }, Point.Empty))); } [Fact] @@ -4717,7 +4717,7 @@ This is the second line. public void Internal_Tests () { var txt = "This is a text."; - List txtRunes = RuneCell.StringToRuneCells (txt); + List txtRunes = Cell.StringToCells (txt); Assert.Equal (txt.Length, txtRunes.Count); Assert.Equal ('T', txtRunes [0].Rune.Value); Assert.Equal ('h', txtRunes [1].Rune.Value); @@ -4757,8 +4757,8 @@ This is the second line. Assert.Equal (2, TextModel.CalculateLeftColumn (txtRunes, 0, 9, 8)); var tm = new TextModel (); - tm.AddLine (0, RuneCell.StringToRuneCells ("This is first line.")); - tm.AddLine (1, RuneCell.StringToRuneCells ("This is last line.")); + tm.AddLine (0, Cell.StringToCells ("This is first line.")); + tm.AddLine (1, Cell.StringToCells ("This is last line.")); Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out bool gaveFullTurn)); Assert.False (gaveFullTurn); Assert.Equal ((new Point (5, 0), true), tm.FindNextText ("is", out gaveFullTurn)); @@ -4782,14 +4782,14 @@ This is the second line. Assert.True (gaveFullTurn); Assert.Equal ((new Point (9, 1), true), tm.ReplaceAllText ("is", false, false, "really")); - Assert.Equal (RuneCell.StringToRuneCells ("Threally really first line."), tm.GetLine (0)); - Assert.Equal (RuneCell.StringToRuneCells ("Threally really last line."), tm.GetLine (1)); + Assert.Equal (Cell.StringToCells ("Threally really first line."), tm.GetLine (0)); + Assert.Equal (Cell.StringToCells ("Threally really last line."), tm.GetLine (1)); tm = new TextModel (); - tm.AddLine (0, RuneCell.StringToRuneCells ("This is first line.")); - tm.AddLine (1, RuneCell.StringToRuneCells ("This is last line.")); + tm.AddLine (0, Cell.StringToCells ("This is first line.")); + tm.AddLine (1, Cell.StringToCells ("This is last line.")); Assert.Equal ((new Point (5, 1), true), tm.ReplaceAllText ("is", false, true, "really")); - Assert.Equal (RuneCell.StringToRuneCells ("This really first line."), tm.GetLine (0)); - Assert.Equal (RuneCell.StringToRuneCells ("This really last line."), tm.GetLine (1)); + Assert.Equal (Cell.StringToCells ("This really first line."), tm.GetLine (0)); + Assert.Equal (Cell.StringToCells ("This really last line."), tm.GetLine (1)); } [Fact] diff --git a/UnitTests/Views/TreeViewTests.cs b/UnitTests/Views/TreeViewTests.cs index 915630267..47124f8f8 100644 --- a/UnitTests/Views/TreeViewTests.cs +++ b/UnitTests/Views/TreeViewTests.cs @@ -970,10 +970,10 @@ public class TreeViewTests Assert.All (eventArgs, ea => Assert.Equal (ea.Tree, tv)); Assert.All (eventArgs, ea => Assert.False (ea.Handled)); - Assert.Equal ("├-root one", eventArgs [0].RuneCells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); - Assert.Equal ("│ ├─leaf 1", eventArgs [1].RuneCells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); - Assert.Equal ("│ └─leaf 2", eventArgs [2].RuneCells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); - Assert.Equal ("└─root two", eventArgs [3].RuneCells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); + Assert.Equal ("├-root one", eventArgs [0].Cells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); + Assert.Equal ("│ ├─leaf 1", eventArgs [1].Cells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); + Assert.Equal ("│ └─leaf 2", eventArgs [2].Cells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); + Assert.Equal ("└─root two", eventArgs [3].Cells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); Assert.Equal (1, eventArgs [0].IndexOfExpandCollapseSymbol); Assert.Equal (3, eventArgs [1].IndexOfExpandCollapseSymbol); @@ -1083,9 +1083,9 @@ oot two Assert.All (eventArgs, ea => Assert.Equal (ea.Tree, tv)); Assert.All (eventArgs, ea => Assert.False (ea.Handled)); - Assert.Equal ("─leaf 1", eventArgs [0].RuneCells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); - Assert.Equal ("─leaf 2", eventArgs [1].RuneCells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); - Assert.Equal ("oot two", eventArgs [2].RuneCells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); + Assert.Equal ("─leaf 1", eventArgs [0].Cells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); + Assert.Equal ("─leaf 2", eventArgs [1].Cells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); + Assert.Equal ("oot two", eventArgs [2].Cells.Aggregate ("", (s, n) => s += n.Rune).TrimEnd ()); Assert.Equal (0, eventArgs [0].IndexOfExpandCollapseSymbol); Assert.Equal (0, eventArgs [1].IndexOfExpandCollapseSymbol);