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

Partially Addresses #2616. Support combining sequences that don't normalize #2932

Merged
merged 21 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
9 changes: 6 additions & 3 deletions Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,14 @@ public void AddRune (Rune rune)
// Normalize to Form C (Canonical Composition)
string normalized = combined.Normalize (NormalizationForm.FormC);

Contents [Row, Col - 1].Runes = new List<Rune> { (Rune)normalized [0] }; ;
List<Rune> runes = new List<Rune> ();
tig marked this conversation as resolved.
Show resolved Hide resolved

foreach (var c in normalized) {
runes.Add((Rune) c);
}
Contents [Row, Col - 1].Runes = runes;
Contents [Row, Col - 1].Attribute = CurrentAttribute;
Contents [Row, Col - 1].IsDirty = true;

//Col--;
} else {
Contents [Row, Col].Attribute = CurrentAttribute;
Contents [Row, Col].IsDirty = true;
Expand Down
10 changes: 8 additions & 2 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ namespace Terminal.Gui;
/// </summary>
internal class CursesDriver : ConsoleDriver {

public override int Cols => Curses.Cols;
public override int Rows => Curses.Lines;
public override int Cols {
get => Curses.Cols;
internal set => Curses.Cols = value;
}
public override int Rows {
get => Curses.Lines;
internal set => Curses.Lines = value;
}

CursorVisibility? _initialCursorVisibility = null;
CursorVisibility? _currentCursorVisibility = null;
Expand Down
8 changes: 8 additions & 0 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,20 @@ static public Window initscr ()
get {
return lines;
}
internal set {
// For unit tests
lines = value;
}
}

public static int Cols {
get {
return cols;
}
internal set {
// For unit tests
cols = value;
}
}

//
Expand Down
44 changes: 21 additions & 23 deletions Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -807,28 +807,26 @@ public WindowsDriver ()
internal override MainLoop Init ()
{
_mainLoopDriver = new WindowsMainLoop (this);
if (RunningUnitTests) {
return new MainLoop (_mainLoopDriver);
}

try {
if (WinConsole != null) {
// BUGBUG: The results from GetConsoleOutputWindow are incorrect when called from Init.
// Our thread in WindowsMainLoop.CheckWin will get the correct results. See #if HACK_CHECK_WINCHANGED
var winSize = WinConsole.GetConsoleOutputWindow (out Point pos);
Cols = winSize.Width;
Rows = winSize.Height;
}
WindowsConsole.SmallRect.MakeEmpty (ref _damageRegion);
if (!RunningUnitTests) {
try {
if (WinConsole != null) {
// BUGBUG: The results from GetConsoleOutputWindow are incorrect when called from Init.
// Our thread in WindowsMainLoop.CheckWin will get the correct results. See #if HACK_CHECK_WINCHANGED
var winSize = WinConsole.GetConsoleOutputWindow (out Point pos);
Cols = winSize.Width;
Rows = winSize.Height;
}
WindowsConsole.SmallRect.MakeEmpty (ref _damageRegion);

if (_isWindowsTerminal) {
Console.Out.Write (EscSeqUtils.CSI_SaveCursorAndActivateAltBufferNoBackscroll);
if (_isWindowsTerminal) {
Console.Out.Write (EscSeqUtils.CSI_SaveCursorAndActivateAltBufferNoBackscroll);
}
} catch (Win32Exception e) {
// We are being run in an environment that does not support a console
// such as a unit test, or a pipe.
Debug.WriteLine ($"Likely running unit tests. Setting WinConsole to null so we can test it elsewhere. Exception: {e}");
WinConsole = null;
}
} catch (Win32Exception e) {
// We are being run in an environment that does not support a console
// such as a unit test, or a pipe.
Debug.WriteLine ($"Likely running unit tests. Setting WinConsole to null so we can test it elsewhere. Exception: {e}");
WinConsole = null;
}

CurrentAttribute = new Attribute (Color.White, Color.Black);
Expand Down Expand Up @@ -885,7 +883,7 @@ private void ChangeWin (Object s, SizeChangedEventArgs e)
// It also is broken when modifiers keys are down too
//
//Key _keyDown = (Key)0xffffffff;

internal void ProcessInput (WindowsConsole.InputRecord inputEvent)
{
switch (inputEvent.EventType) {
Expand Down Expand Up @@ -976,9 +974,9 @@ internal void ProcessInput (WindowsConsole.InputRecord inputEvent)
_keyModifiers ??= new KeyModifiers ();

//if (_keyDown == (Key)0xffffffff) {
// Avoid sending repeat keydowns
// Avoid sending repeat keydowns
// _keyDown = map;
OnKeyDown (new KeyEventEventArgs (new KeyEvent (map, _keyModifiers)));
OnKeyDown (new KeyEventEventArgs (new KeyEvent (map, _keyModifiers)));
//}
OnKeyPressed (new KeyEventEventArgs (new KeyEvent (map, _keyModifiers)));
} else {
Expand Down
22 changes: 13 additions & 9 deletions UnitTests/ConsoleDrivers/AddRuneTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Buffers;
using System;
using System.Buffers;
using System.Text;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -11,22 +12,27 @@ public class AddRuneTests {

public AddRuneTests (ITestOutputHelper output)
{
ConsoleDriver.RunningUnitTests = true;
this._output = output;
}

[Fact]
public void AddRune ()
[Theory]
[InlineData (typeof (FakeDriver))]
[InlineData (typeof (NetDriver))]
[InlineData (typeof (CursesDriver))]
[InlineData (typeof (WindowsDriver))]
public void AddRune (Type driverType)
{

var driver = new FakeDriver ();
Application.Init (driver);
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
driver.Init ();

driver.Rows = 25;
driver.Cols = 80;
driver.Init ();
driver.AddRune (new Rune ('a'));
Assert.Equal ((Rune)'a', driver.Contents [0, 0].Runes [0]);

driver.End ();
Application.Shutdown ();
}

[Fact]
Expand Down Expand Up @@ -142,7 +148,6 @@ public void AddRune_MovesToNextColumn_Wide ()
public void AddRune_Accented_Letter_With_Three_Combining_Unicode_Chars ()
{
var driver = new FakeDriver ();
Application.Init (driver);
driver.Init ();

var expected = new Rune ('ắ');
Expand Down Expand Up @@ -189,6 +194,5 @@ public void AddRune_Accented_Letter_With_Three_Combining_Unicode_Chars ()
// TestHelpers.AssertDriverContentsWithFrameAre (@"
//ắ", output);
driver.End ();
Application.Shutdown ();
}
}
Loading
Loading