Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3771. TextView doesn't consider no-printable rune in draw and cursor position. #3772

Merged
merged 55 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
6a6c210
Fixes #3771. TextView doesn't consider no-printable rune in draw and …
BDisp Oct 1, 2024
7bf6aaa
Add unit test which already works in TextField.
BDisp Oct 1, 2024
e4d30a1
Replace Frame to Viewport in TextField.
BDisp Oct 1, 2024
026a20e
Fixes #3774. TextModel.ToRuneCellList is internal and is better move …
BDisp Oct 2, 2024
2292a86
Merge branch 'v2_develop' into v2_3771_textview-no-printable-rune-fix
BDisp Oct 2, 2024
153a9f2
Trying fix unit test error.
BDisp Oct 2, 2024
29799f4
Move necessary methods to the RuneCell class per https://github.com/g…
BDisp Oct 3, 2024
5a1a0ce
Fix LineDrawing PromptForColor to support 16 colors and true color.
BDisp Oct 3, 2024
bb5af01
Add support for colored runes in the Editor scenario.
BDisp Oct 3, 2024
bd42a48
Add borders to the 16 colors.
BDisp Oct 3, 2024
d3be2ac
Only consider SelectionStartRow and SelectionStartColumn when Selecte…
BDisp Oct 3, 2024
a4f2352
Fix ApplyRuneCellAttribute method.
BDisp Oct 4, 2024
439bddf
Fix width for 16 colors.
BDisp Oct 4, 2024
903827a
Fix start/end row and cols.
BDisp Oct 4, 2024
ccf2daa
Change all RuneCell to Cell and move methods to the Cell record struct.
BDisp Oct 5, 2024
f93b475
Using the attribute at the cursor position on paste.
BDisp Oct 5, 2024
c54041e
Fix unit test.
BDisp Oct 5, 2024
6a0aa9a
Add feature to copy, cut and paste with the cells attributes.
BDisp Oct 6, 2024
d5e367b
Merge branch 'v2_develop' into v2_3771_textview-no-printable-rune-fix
tig Oct 6, 2024
e58c15f
Add undo and redo support for cells attribute.
BDisp Oct 6, 2024
35a1916
Replace with record struct per @tig.
BDisp Oct 6, 2024
853f95f
Move unit tests per @tig.
BDisp Oct 6, 2024
22cf92d
Fix newline unit test error on Linux.
BDisp Oct 6, 2024
17ad70f
Make _originalCellsList field as readonly.
BDisp Oct 7, 2024
52435e4
Move Prompt method and all ColorPicker*.cs to ColorPicker.*.cs.
BDisp Oct 8, 2024
614bb69
Resolving merge conflicts.
BDisp Oct 9, 2024
a6234da
Fix merge errors.
BDisp Oct 9, 2024
8d09971
Fixes #3784. SelfContained and NativeAot projects should use the loca…
BDisp Oct 9, 2024
4afe694
Run dotnet restore before build.
BDisp Oct 9, 2024
4288b71
Using local_packages folder for CI.
BDisp Oct 9, 2024
e130bfd
Add build_release_consumer.
BDisp Oct 9, 2024
bd8ff63
Remove build_release_consumer.
BDisp Oct 9, 2024
5db3af9
Fix folder for CI.
BDisp Oct 9, 2024
d77b899
Fix System.Text.Json vulnerability.
BDisp Oct 9, 2024
3361eed
Fix local_packageslocation.
BDisp Oct 9, 2024
f9f3431
Add package sources to the packageSourceMapping tag.
BDisp Oct 9, 2024
0dc3a52
Using the original configuration.
BDisp Oct 9, 2024
88e2ee6
Only add the Terminal.Gui pattern in the LocalPackages.
BDisp Oct 9, 2024
2c01b33
Fix the path folder separator with unit style.
BDisp Oct 9, 2024
820bf44
Using pack instead of build.
BDisp Oct 9, 2024
d3192df
Create LocalPackages Directory
BDisp Oct 9, 2024
ad69b9d
Add local_packages source.
BDisp Oct 9, 2024
5b108a9
Using scripts to build release for NativeAot and SelfContained.
BDisp Oct 10, 2024
0b4227b
Trying to fix path.
BDisp Oct 10, 2024
a57db4e
Again.
BDisp Oct 10, 2024
c12a2cf
Fix the path for the package,
BDisp Oct 10, 2024
214d109
Need to build before pack.
BDisp Oct 10, 2024
29b902b
Needs also build before pack locally.
BDisp Oct 10, 2024
3bcc34b
Fix build path.
BDisp Oct 10, 2024
3383ce1
Merge branch 'v2_develop' into v2_3771_textview-no-printable-rune-fix
BDisp Oct 10, 2024
bc20229
Merge branch 'v2_develop' into v2_3784_selfcontained_nativeaot-local-…
BDisp Oct 10, 2024
fae9675
Merge branch 'v2_develop' into v2_3771_textview-no-printable-rune-fix
BDisp Oct 10, 2024
7d197c6
Merge branch 'v2_3784_selfcontained_nativeaot-local-release-package' …
BDisp Oct 10, 2024
b6b60b1
Merge branch 'v2_develop' into v2_3771_textview-no-printable-rune-fix
tig Oct 11, 2024
ffe5154
Merge branch 'v2_develop' into v2_3771_textview-no-printable-rune-fix
tig Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 152 additions & 6 deletions Terminal.Gui/Drawing/Cell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
/// Represents a single row/column in a Terminal.Gui rendering surface (e.g. <see cref="LineCanvas"/> and
/// <see cref="ConsoleDriver"/>).
/// </summary>
public record struct Cell ()
public record struct Cell (Attribute? Attribute = null, bool IsDirty = false, Rune Rune = default)
{

/// <summary>The attributes to use when drawing the Glyph.</summary>
public Attribute? Attribute { get; set; } = null;
public Attribute? Attribute { get; set; } = Attribute;

/// <summary>
/// Gets or sets a value indicating whether this <see cref="T:Terminal.Gui.Cell"/> has been modified since the
/// last time it was drawn.
/// </summary>
public bool IsDirty { get; set; } = false;
public bool IsDirty { get; set; } = IsDirty;

private Rune _rune = default;
private Rune _rune = Rune;

/// <summary>The character to display. If <see cref="Rune"/> is <see langword="null"/>, then <see cref="Rune"/> is ignored.</summary>
public Rune Rune
Expand All @@ -29,6 +28,8 @@ public Rune Rune
}
}

private List<Rune> _combiningMarks;

/// <summary>
/// The combining marks for <see cref="Rune"/> that when combined makes this Cell a combining sequence. If
/// <see cref="CombiningMarks"/> empty, then <see cref="CombiningMarks"/> is ignored.
Expand All @@ -37,8 +38,153 @@ public Rune Rune
/// Only valid in the rare case where <see cref="Rune"/> is a combining sequence that could not be normalized to a
/// single Rune.
/// </remarks>
internal List<Rune> CombiningMarks { get; } = new ();
internal List<Rune> CombiningMarks
{
get => _combiningMarks ?? [];
private set => _combiningMarks = value ?? [];
}

/// <inheritdoc/>
public override string ToString () { return $"[{Rune}, {Attribute}]"; }

/// <summary>Converts the string into a <see cref="List{Cell}"/>.</summary>
/// <param name="str">The string to convert.</param>
/// <param name="attribute">The <see cref="Gui.ColorScheme"/> to use.</param>
/// <returns></returns>
public static List<Cell> ToCellList (string str, Attribute? attribute = null)
{
List<Cell> cells = new ();

foreach (Rune rune in str.EnumerateRunes ())
{
cells.Add (new () { Rune = rune, Attribute = attribute });
}

return cells;
}

/// <summary>
/// Splits a string into a List that will contain a <see cref="List{Cell}"/> for each line.
/// </summary>
/// <param name="content">The string content.</param>
/// <param name="attribute">The color scheme.</param>
/// <returns>A <see cref="List{Cell}"/> for each line.</returns>
public static List<List<Cell>> StringToLinesOfCells (string content, Attribute? attribute = null)
{
List<Cell> cells = content.EnumerateRunes ()
.Select (x => new Cell { Rune = x, Attribute = attribute })
.ToList ();

return SplitNewLines (cells);
}

/// <summary>Converts a <see cref="Cell"/> generic collection into a string.</summary>
/// <param name="cells">The enumerable cell to convert.</param>
/// <returns></returns>
public static string ToString (IEnumerable<Cell> cells)
{
var str = string.Empty;

foreach (Cell cell in cells)
{
str += cell.Rune.ToString ();
}

return str;
}

/// <summary>Converts a <see cref="List{Cell}"/> generic collection into a string.</summary>
/// <param name="cellsList">The enumerable cell to convert.</param>
/// <returns></returns>
public static string ToString (List<List<Cell>> cellsList)
{
var str = string.Empty;

for (var i = 0; i < cellsList.Count; i++)
{
IEnumerable<Cell> cellList = cellsList [i];
str += ToString (cellList);

if (i + 1 < cellsList.Count)
{
str += Environment.NewLine;
}
}

return str;
}

// Turns the string into cells, this does not split the contents on a newline if it is present.

internal static List<Cell> StringToCells (string str, Attribute? attribute = null)
{
List<Cell> cells = [];

foreach (Rune rune in str.ToRunes ())
{
cells.Add (new () { Rune = rune, Attribute = attribute });
}

return cells;
}

internal static List<Cell> ToCells (IEnumerable<Rune> runes, Attribute? attribute = null)
{
List<Cell> cells = new ();

foreach (Rune rune in runes)
{
cells.Add (new () { Rune = rune, Attribute = attribute });
}

return cells;
}

private static List<List<Cell>> SplitNewLines (List<Cell> cells)
{
List<List<Cell>> 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;
}

/// <summary>
/// Splits a rune cell list into a List that will contain a <see cref="List{Cell}"/> for each line.
/// </summary>
/// <param name="cells">The cells list.</param>
/// <returns></returns>
public static List<List<Cell>> ToCells (List<Cell> cells) { return SplitNewLines (cells); }
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
namespace Terminal.Gui;

/// <summary>Args for events that relate to a specific <see cref="RuneCell"/>.</summary>
public class RuneCellEventArgs
/// <summary>Args for events that relate to a specific <see cref="Cell"/>.</summary>
public record struct CellEventArgs
{
/// <summary>Creates a new instance of the <see cref="RuneCellEventArgs"/> class.</summary>
/// <summary>Creates a new instance of the <see cref="CellEventArgs"/> class.</summary>
/// <param name="line">The line.</param>
/// <param name="col">The col index.</param>
/// <param name="unwrappedPosition">The unwrapped row and col index.</param>
public RuneCellEventArgs (List<RuneCell> line, int col, (int Row, int Col) unwrappedPosition)
public CellEventArgs (List<Cell> line, int col, (int Row, int Col) unwrappedPosition)
{
Line = line;
Col = col;
UnwrappedPosition = unwrappedPosition;
}

/// <summary>The index of the RuneCell in the line.</summary>
/// <summary>The index of the Cell in the line.</summary>
public int Col { get; }

/// <summary>The list of runes the RuneCell is part of.</summary>
public List<RuneCell> Line { get; }
/// <summary>The list of runes the Cell is part of.</summary>
public List<Cell> Line { get; }

/// <summary>
/// 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.
/// </summary>
public (int Row, int Col) UnwrappedPosition { get; }
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Drawing/LineCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void AddLine (
int length,
Orientation orientation,
LineStyle style,
Attribute? attribute = default
Attribute? attribute = null
)
{
_cachedViewport = Rectangle.Empty;
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Drawing/StraightLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public StraightLine (
int length,
Orientation orientation,
LineStyle style,
Attribute? attribute = default
Attribute? attribute = null
)
{
Start = start;
Expand Down
9 changes: 9 additions & 0 deletions Terminal.Gui/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 15 additions & 12 deletions Terminal.Gui/Resources/Strings.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,27 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ctxSelectAll" xml:space="preserve">
<value>Tout _sélectionner</value>
</data>
<data name="ctxDeleteAll" xml:space="preserve">
<value>_Tout supprimer</value>
</data>
<data name="ctxCopy" xml:space="preserve">
<value>_Copier</value>
</data>
<data name="ctxCut" xml:space="preserve">
<value>Co_uper</value>
</data>
<data name="ctxDeleteAll" xml:space="preserve">
<value>_Tout supprimer</value>
</data>
<data name="ctxPaste" xml:space="preserve">
<value>C_oller</value>
</data>
<data name="ctxRedo" xml:space="preserve">
<value>_Rétablir</value>
</data>
<data name="ctxSelectAll" xml:space="preserve">
<value>Tout _sélectionner</value>
</data>
<data name="ctxUndo" xml:space="preserve">
<value>_Annuler</value>
</data>
<data name="ctxRedo" xml:space="preserve">
<value>_Rétablir</value>
</data>
<data name="fdDirectory" xml:space="preserve">
<value>_Dossier</value>
</data>
Expand Down Expand Up @@ -168,16 +168,19 @@
<data name="wzNext" xml:space="preserve">
<value>Prochai_n...</value>
</data>
<data name="btnOpen" xml:space="preserve">
<value>Ouvrir</value>
</data>
<data name="btnSave" xml:space="preserve">
<value>Enregistrer</value>
</data>
<data name="btnSaveAs" xml:space="preserve">
<value>E_nregistrer sous</value>
</data>
<data name="btnOpen" xml:space="preserve">
<value>Ouvrir</value>
</data>
<data name="dpTitle" xml:space="preserve">
<value>Sélecteur de Date</value>
</data>
<data name="ctxColors" xml:space="preserve">
<value>Cou_leurs</value>
</data>
</root>
Loading
Loading