Fixes remaining wide runes render issues.

This commit is contained in:
BDisp
2022-05-11 00:24:57 +01:00
parent 736d10598b
commit 4382a2c2c2
7 changed files with 363 additions and 60 deletions

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