Merge pull request #1710 from BDisp/wide-runes-render-issues

Fixes remaining wide runes render issues.
This commit is contained in:
Tig Kindel
2022-05-13 13:48:47 -07:00
committed by GitHub
15 changed files with 749 additions and 193 deletions

View File

@@ -44,7 +44,6 @@ namespace Terminal.Gui.Core {
Assert.Null (Application.Top);
Assert.Null (Application.Current);
Assert.Throws<ArgumentNullException> (() => Application.HeightAsBuffer == true);
Assert.False (Application.AlwaysSetPosition);
Assert.Null (Application.MainLoop);
Assert.Null (Application.Iteration);
Assert.Null (Application.RootMouseEvent);
@@ -57,7 +56,6 @@ namespace Terminal.Gui.Core {
Assert.NotNull (Application.Top);
Assert.NotNull (Application.Current);
Assert.False (Application.HeightAsBuffer);
Assert.False (Application.AlwaysSetPosition);
Assert.NotNull (Application.MainLoop);
Assert.Null (Application.Iteration);
Assert.Null (Application.RootMouseEvent);

View File

@@ -1,14 +1,23 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Terminal.Gui;
using Terminal.Gui.Views;
using Xunit;
using Xunit.Abstractions;
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui.ConsoleDrivers {
public class ConsoleDriverTests {
readonly ITestOutputHelper output;
public ConsoleDriverTests (ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void Init_Inits ()
{
@@ -503,5 +512,101 @@ namespace Terminal.Gui.ConsoleDrivers {
Assert.True (closed);
Assert.Empty (FakeConsole.MockKeyPresses);
}
[Fact, AutoInitShutdown]
public void AddRune_On_Clip_Left_Or_Right_Replace_Previous_Or_Next_Wide_Rune_With_Space ()
{
var tv = new TextView () {
Width = Dim.Fill (),
Height = Dim.Fill (),
Text = @"これは広いルーンラインです。
これは広いルーンラインです。
これは広いルーンラインです。
これは広いルーンラインです。
これは広いルーンラインです。
これは広いルーンラインです。
これは広いルーンラインです。
これは広いルーンラインです。"
};
var win = new Window ("ワイドルーン") { Width = Dim.Fill (), Height = Dim.Fill () };
win.Add (tv);
Application.Top.Add (win);
var lbl = new Label ("ワイドルーン。");
var dg = new Dialog ("テスト", 14, 4, new Button ("選ぶ"));
dg.Add (lbl);
Application.Begin (Application.Top);
Application.Begin (dg);
((FakeDriver)Application.Driver).SetBufferSize (30, 10);
var expected = @"
┌ ワイドルーン ──────────────┐
│これは広いルーンラインです。│
│これは広いルーンラインです。│
│これは ┌ テスト ────┐ です。│
│これは │ワイドルーン│ です。│
│これは │ [ 選ぶ ] │ です。│
│これは └────────────┘ です。│
│これは広いルーンラインです。│
│これは広いルーンラインです。│
└────────────────────────────┘
";
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 10), pos);
}
[Fact, AutoInitShutdown]
public void Write_Do_Not_Change_On_ProcessKey ()
{
var win = new Window ();
Application.Begin (win);
((FakeDriver)Application.Driver).SetBufferSize (20, 8);
System.Threading.Tasks.Task.Run (() => {
System.Threading.Tasks.Task.Delay (500).Wait ();
Application.MainLoop.Invoke (() => {
var lbl = new Label ("Hello World") { X = Pos.Center () };
var dlg = new Dialog ("Test", new Button ("Ok"));
dlg.Add (lbl);
Application.Begin (dlg);
var expected = @"
┌──────────────────┐
│┌ Test ─────────┐ │
││ Hello World │ │
││ │ │
││ │ │
││ [ Ok ] │ │
│└───────────────┘ │
└──────────────────┘
";
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 20, 8), pos);
Assert.True (dlg.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
dlg.Redraw (dlg.Bounds);
expected = @"
┌──────────────────┐
│┌ Test ─────────┐ │
││ Hello World │ │
││ │ │
││ │ │
││ [ Ok ] │ │
│└───────────────┘ │
└──────────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 20, 8), pos);
win.RequestStop ();
});
});
Application.Run (win);
Application.Shutdown ();
}
}
}

View File

@@ -159,8 +159,10 @@ namespace Terminal.Gui.Views {
}
// Remove unnecessary empty lines
for (int r = lines.Count - 1; r > h - 1; r--) {
lines.RemoveAt (r);
if (lines.Count > 0) {
for (int r = lines.Count - 1; r > h - 1; r--) {
lines.RemoveAt (r);
}
}
// Remove trailing whitespace on each line

View File

@@ -26,15 +26,15 @@ namespace Terminal.Gui {
int CreateInput (string input)
{
// Put a control-q in at the end
Console.MockKeyPresses.Push (new ConsoleKeyInfo ('q', ConsoleKey.Q, shift: false, alt: false, control: true));
FakeConsole.MockKeyPresses.Push (new ConsoleKeyInfo ('q', ConsoleKey.Q, shift: false, alt: false, control: true));
foreach (var c in input.Reverse ()) {
if (char.IsLetter (c)) {
Console.MockKeyPresses.Push (new ConsoleKeyInfo (char.ToLower (c), (ConsoleKey)char.ToUpper (c), shift: char.IsUpper (c), alt: false, control: false));
FakeConsole.MockKeyPresses.Push (new ConsoleKeyInfo (char.ToLower (c), (ConsoleKey)char.ToUpper (c), shift: char.IsUpper (c), alt: false, control: false));
} else {
Console.MockKeyPresses.Push (new ConsoleKeyInfo (c, (ConsoleKey)c, shift: false, alt: false, control: false));
FakeConsole.MockKeyPresses.Push (new ConsoleKeyInfo (c, (ConsoleKey)c, shift: false, alt: false, control: false));
}
}
return Console.MockKeyPresses.Count;
return FakeConsole.MockKeyPresses.Count;
}
/// <summary>
@@ -48,59 +48,61 @@ namespace Terminal.Gui {
List<Type> scenarioClasses = Scenario.GetDerivedClasses<Scenario> ();
Assert.NotEmpty (scenarioClasses);
foreach (var scenarioClass in scenarioClasses) {
lock (FakeConsole.MockKeyPresses) {
foreach (var scenarioClass in scenarioClasses) {
// Setup some fake keypresses
// Passing empty string will cause just a ctrl-q to be fired
Console.MockKeyPresses.Clear ();
int stackSize = CreateInput ("");
// Setup some fake keypresses
// Passing empty string will cause just a ctrl-q to be fired
FakeConsole.MockKeyPresses.Clear ();
int stackSize = CreateInput ("");
Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
int iterations = 0;
Application.Iteration = () => {
iterations++;
// Stop if we run out of control...
if (iterations > 10) {
Application.RequestStop ();
int iterations = 0;
Application.Iteration = () => {
iterations++;
// Stop if we run out of control...
if (iterations > 10) {
Application.RequestStop ();
}
};
int ms;
if (scenarioClass.Name == "CharacterMap") {
ms = 2000;
} else {
ms = 1000;
}
};
var abortCount = 0;
Func<MainLoop, bool> abortCallback = (MainLoop loop) => {
abortCount++;
Application.RequestStop ();
return false;
};
var token = Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (ms), abortCallback);
int ms;
if (scenarioClass.Name == "CharacterMap") {
ms = 1500;
}else {
ms = 1000;
var scenario = (Scenario)Activator.CreateInstance (scenarioClass);
scenario.Init (Application.Top, Colors.Base);
scenario.Setup ();
// There is no need to call Application.Begin because Init already creates the Application.Top
// If Application.RunState is used then the Application.RunLoop must also be used instead Application.Run.
//var rs = Application.Begin (Application.Top);
scenario.Run ();
//Application.End (rs);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
if (abortCount != 0) {
output.WriteLine ($"Scenario {scenarioClass} had abort count of {abortCount}");
}
Assert.Equal (0, abortCount);
// # of key up events should match # of iterations
Assert.Equal (1, iterations);
Assert.Equal (stackSize, iterations);
}
var abortCount = 0;
Func<MainLoop, bool> abortCallback = (MainLoop loop) => {
abortCount++;
Application.RequestStop ();
return false;
};
var token = Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (ms), abortCallback);
var scenario = (Scenario)Activator.CreateInstance (scenarioClass);
scenario.Init (Application.Top, Colors.Base);
scenario.Setup ();
// There is no need to call Application.Begin because Init already creates the Application.Top
// If Application.RunState is used then the Application.RunLoop must also be used instead Application.Run.
//var rs = Application.Begin (Application.Top);
scenario.Run ();
//Application.End (rs);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
if(abortCount != 0) {
output.WriteLine ($"Scenario {scenarioClass} had abort count of {abortCount}");
}
Assert.Equal (0, abortCount);
// # of key up events should match # of iterations
Assert.Equal (1, iterations);
Assert.Equal (stackSize, iterations);
}
#if DEBUG_IDISPOSABLE
foreach (var inst in Responder.Instances) {

View File

@@ -1985,14 +1985,276 @@ Y
view.Frame = new Rect (0, 0, 8, 4);
((FakeDriver)Application.Driver).SetBufferSize (7, 3);
}
[Fact, AutoInitShutdown]
public void DrawTextFormatter_Respects_The_Clip_Bounds ()
{
var view = new View (new Rect (0, 0, 20, 20));
view.Add (new Label ("0123456789abcdefghij"));
view.Add (new Label (0, 1, "1\n2\n3\n4\n5\n6\n7\n8\n9\n0"));
view.Add (new Button (1, 1, "Press me!"));
var scrollView = new ScrollView (new Rect (1, 1, 15, 10)) {
ContentSize = new Size (40, 40),
ShowHorizontalScrollIndicator = true,
ShowVerticalScrollIndicator = true
};
scrollView.Add (view);
var win = new Window (new Rect (1, 1, 20, 14), "Test");
win.Add (scrollView);
Application.Top.Add (win);
Application.Begin (Application.Top);
var expected = @"
┌ Test ────────────┐
│ │
│ 0123456789abcd▲ │
│ 1[ Press me! ]┬ │
│ 2 │ │
│ 3 ┴ │
│ 4 ░ │
│ 5 ░ │
│ 6 ░ │
│ 7 ░ │
│ 8 ▼ │
│ ◄├───┤░░░░░░░► │
│ │
└──────────────────┘
";
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 1, 21, 14), pos);
Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
Application.Top.Redraw (Application.Top.Bounds);
expected = @"
┌──────
┌ Test ────────────┐
│ 123456789abcde▲
│ [ Press me! ] ┬ │
│ │ │
│ ┴ │
│ ░ │
│ ░ │
│ ░ │
│ ░ │
│ ▼ │
│ ◄├───┤░░░░░░░► │
│ │
└──────────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 7, 3), pos);
Assert.Equal (new Rect (1, 1, 21, 14), pos);
Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
Application.Top.Redraw (Application.Top.Bounds);
expected = @"
┌ Test ────────────┐
│ │
│ 23456789abcdef▲ │
│ Press me! ] ┬ │
│ │ │
│ ┴ │
│ ░ │
│ ░ │
│ ░ │
│ ░ │
│ ▼ │
│ ◄├────┤░░░░░░► │
│ │
└──────────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 1, 21, 14), pos);
Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
Application.Top.Redraw (Application.Top.Bounds);
expected = @"
┌ Test ────────────┐
│ │
│ 3456789abcdefg▲ │
│ Press me! ] ┬ │
│ │ │
│ ┴ │
│ ░ │
│ ░ │
│ ░ │
│ ░ │
│ ▼ │
│ ◄├────┤░░░░░░► │
│ │
└──────────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 1, 21, 14), pos);
Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
Application.Top.Redraw (Application.Top.Bounds);
expected = @"
┌ Test ────────────┐
│ │
│ 456789abcdefgh▲ │
│ ress me! ] ┬ │
│ │ │
│ ┴ │
│ ░ │
│ ░ │
│ ░ │
│ ░ │
│ ▼ │
│ ◄░├───┤░░░░░░► │
│ │
└──────────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 1, 21, 14), pos);
Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
Application.Top.Redraw (Application.Top.Bounds);
expected = @"
┌ Test ────────────┐
│ │
│ 56789abcdefghi▲ │
│ ess me! ] ┬ │
│ │ │
│ ┴ │
│ ░ │
│ ░ │
│ ░ │
│ ░ │
│ ▼ │
│ ◄░├────┤░░░░░► │
│ │
└──────────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 1, 21, 14), pos);
Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
Application.Top.Redraw (Application.Top.Bounds);
expected = @"
┌ Test ────────────┐
│ │
│ 6789abcdefghij▲ │
│ ss me! ] ┬ │
│ │ │
│ ┴ │
│ ░ │
│ ░ │
│ ░ │
│ ░ │
│ ▼ │
│ ◄░├────┤░░░░░► │
│ │
└──────────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 1, 21, 14), pos);
Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorRight, new KeyModifiers ())));
Application.Top.Redraw (Application.Top.Bounds);
expected = @"
┌ Test ────────────┐
│ │
│ 789abcdefghij ▲ │
│ s me! ] ┬ │
│ │ │
│ ┴ │
│ ░ │
│ ░ │
│ ░ │
│ ░ │
│ ▼ │
│ ◄░░├───┤░░░░░► │
│ │
└──────────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 1, 21, 14), pos);
Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home, new KeyModifiers ())));
Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
Application.Top.Redraw (Application.Top.Bounds);
expected = @"
┌ Test ────────────┐
│ │
│ 1[ Press me! ]▲ │
│ 2 ┬ │
│ 3 │ │
│ 4 ┴ │
│ 5 ░ │
│ 6 ░ │
│ 7 ░ │
│ 8 ░ │
│ 9 ▼ │
│ ◄├───┤░░░░░░░► │
│ │
└──────────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 1, 21, 14), pos);
Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
Application.Top.Redraw (Application.Top.Bounds);
expected = @"
┌ Test ────────────┐
│ │
│ 2 ▲ │
│ 3 ┬ │
│ 4 │ │
│ 5 ┴ │
│ 6 ░ │
│ 7 ░ │
│ 8 ░ │
│ 9 ░ │
│ 0 ▼ │
│ ◄├───┤░░░░░░░► │
│ │
└──────────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 1, 21, 14), pos);
Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
Application.Top.Redraw (Application.Top.Bounds);
expected = @"
┌ Test ────────────┐
│ │
│ 3 ▲ │
│ 4 ┬ │
│ 5 │ │
│ 6 ┴ │
│ 7 ░ │
│ 8 ░ │
│ 9 ░ │
│ 0 ░ │
│ ▼ │
│ ◄├───┤░░░░░░░► │
│ │
└──────────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 1, 21, 14), pos);
}
}
}