diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 20971d9ab..726d3fd16 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -1022,7 +1022,7 @@ namespace Terminal.Gui { for (int line = 0; line < h; line++) { Move (0, line); for (int col = 0; col < w; col++) - Driver.AddStr (" "); + Driver.AddRune (' '); } } diff --git a/UnitTests/GraphViewTests.cs b/UnitTests/GraphViewTests.cs index 513380b98..e4d654469 100644 --- a/UnitTests/GraphViewTests.cs +++ b/UnitTests/GraphViewTests.cs @@ -207,7 +207,7 @@ namespace Terminal.Gui.Views { Assert.Equal (expectedLook, actualLook); } - return new Rect (x, y, w > -1 ? w : 0, h > -1 ? h : 0); + return new Rect (x > -1 ? x : 0, y > -1 ? y : 0, w > -1 ? w : 0, h > -1 ? h : 0); } #pragma warning disable xUnit1013 // Public method should be marked as test diff --git a/UnitTests/ViewTests.cs b/UnitTests/ViewTests.cs index 8a88eaac3..c10cf515f 100644 --- a/UnitTests/ViewTests.cs +++ b/UnitTests/ViewTests.cs @@ -2256,5 +2256,101 @@ Y pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new Rect (1, 1, 21, 14), pos); } + + [Fact, AutoInitShutdown] + public void Clear_Can_Use_Driver_AddRune_Or_AddStr_Methods () + { + var view = new View () { + Width = Dim.Fill (), + Height = Dim.Fill () + }; + view.LayoutComplete += e => { + view.DrawFrame (view.Bounds); + var savedClip = Application.Driver.Clip; + Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2); + for (int row = 0; row < view.Bounds.Height - 2; row++) { + Application.Driver.Move (1, row + 1); + for (int col = 0; col < view.Bounds.Width - 2; col++) { + Application.Driver.AddStr ($"{col}"); + } + } + Application.Driver.Clip = savedClip; + }; + Application.Top.Add (view); + Application.Begin (Application.Top); + ((FakeDriver)Application.Driver).SetBufferSize (20, 10); + + var expected = @" +┌──────────────────┐ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +└──────────────────┘ +"; + + var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output); + Assert.Equal (new Rect (0, 0, 20, 10), pos); + + view.Clear (); + + expected = @" +"; + + pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output); + Assert.Equal (Rect.Empty, pos); + } + + [Fact, AutoInitShutdown] + public void Clear_Bounds_Can_Use_Driver_AddRune_Or_AddStr_Methods () + { + var view = new View () { + Width = Dim.Fill (), + Height = Dim.Fill () + }; + view.LayoutComplete += e => { + view.DrawFrame (view.Bounds); + var savedClip = Application.Driver.Clip; + Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2); + for (int row = 0; row < view.Bounds.Height - 2; row++) { + Application.Driver.Move (1, row + 1); + for (int col = 0; col < view.Bounds.Width - 2; col++) { + Application.Driver.AddStr ($"{col}"); + } + } + Application.Driver.Clip = savedClip; + }; + Application.Top.Add (view); + Application.Begin (Application.Top); + ((FakeDriver)Application.Driver).SetBufferSize (20, 10); + + var expected = @" +┌──────────────────┐ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +│012345678910111213│ +└──────────────────┘ +"; + + var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output); + Assert.Equal (new Rect (0, 0, 20, 10), pos); + + view.Clear (view.Bounds); + + expected = @" +"; + + pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output); + Assert.Equal (Rect.Empty, pos); + } } }