diff --git a/Terminal.Gui/Application/Application.Run.cs b/Terminal.Gui/Application/Application.Run.cs index a225f916a..bdc8dd24b 100644 --- a/Terminal.Gui/Application/Application.Run.cs +++ b/Terminal.Gui/Application/Application.Run.cs @@ -197,7 +197,7 @@ public static partial class Application // Run (Begin, Run, End, Stop) // DEBATE: Should Begin call Refresh (or Draw) here? It previously did. // FOR: the screen has something on it after Begin is called. // AGAINST: the screen is cleared and then redrawn in RunLoop. We don't want to draw twice. - Refresh (); + //Refresh (); toplevel.OnLoaded (); diff --git a/Terminal.Gui/View/Adornment/ShadowView.cs b/Terminal.Gui/View/Adornment/ShadowView.cs index 10e54cfc3..3d0088ed3 100644 --- a/Terminal.Gui/View/Adornment/ShadowView.cs +++ b/Terminal.Gui/View/Adornment/ShadowView.cs @@ -111,9 +111,9 @@ internal class ShadowView : View // Fill the rest of the rectangle - note we skip the last since vertical will draw it for (int i = Math.Max(0, screen.X + 1); i < screen.X + screen.Width - 1; i++) { - Driver.Move (i, screen.Y); + Driver?.Move (i, screen.Y); - if (i < Driver.Contents!.GetLength (1) && screen.Y < Driver.Contents.GetLength (0)) + if (i < Driver?.Contents!.GetLength (1) && screen.Y < Driver?.Contents?.GetLength (0)) { Driver.AddRune (Driver.Contents [screen.Y, i].Rune); } diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 6c9b37261..97003c30d 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -738,7 +738,6 @@ public class UICatalogApp } ColorScheme = Colors.ColorSchemes [_topLevelColorScheme]; - Application.Top!.SetNeedsDisplay (); }; item.ShortcutKey = ((Key)sc.Key [0].ToString ().ToLower ()).WithCtrl; schemeMenuItems.Add (item); @@ -862,7 +861,6 @@ public class UICatalogApp } Diagnostics = _diagnosticFlags; - Application.Top!.SetNeedsDisplay (); }; menuItems.Add (item); } diff --git a/UnitTests/Dialogs/DialogTests.cs b/UnitTests/Dialogs/DialogTests.cs index d6c133e1b..e125b256a 100644 --- a/UnitTests/Dialogs/DialogTests.cs +++ b/UnitTests/Dialogs/DialogTests.cs @@ -46,6 +46,9 @@ public class DialogTests dlg.Border.Thickness = new (1, 0, 1, 0); runstate = Begin (dlg); var buttonRow = $"{CM.Glyphs.VLine} {btn1} {CM.Glyphs.VLine}"; + + RunIteration (ref runstate); + TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); // Now add a second button @@ -70,6 +73,9 @@ public class DialogTests // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..) dlg.Border.Thickness = new (1, 0, 1, 0); runstate = Begin (dlg); + + RunIteration (ref runstate); + buttonRow = $"{CM.Glyphs.VLine}{btn1} {CM.Glyphs.VLine}"; TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); @@ -94,6 +100,9 @@ public class DialogTests // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..) dlg.Border.Thickness = new (1, 0, 1, 0); runstate = Begin (dlg); + + RunIteration (ref runstate); + buttonRow = $"{CM.Glyphs.VLine}{new (' ', width - btn1.Length - 2)}{btn1}{CM.Glyphs.VLine}"; TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); @@ -119,6 +128,8 @@ public class DialogTests // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..) dlg.Border.Thickness = new (1, 0, 1, 0); runstate = Begin (dlg); + RunIteration (ref runstate); + buttonRow = $"{CM.Glyphs.VLine}{btn1}{new (' ', width - btn1.Length - 2)}{CM.Glyphs.VLine}"; TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); @@ -1027,6 +1038,8 @@ public class DialogTests } else if (iterations == 1) { + Refresh (); + // BUGBUG: This seems wrong; is it a bug in Dim.Percent(85)?? No _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); } @@ -1092,13 +1105,23 @@ public class DialogTests { iterations++; - if (iterations == 0) + switch (iterations) { - Assert.False (btn1.NewKeyDownEvent (Key.Space)); - } - else if (iterations == 1) - { - expected = @$" + case 0: + Top.SetLayoutNeeded(); + Top.SetNeedsDisplay(); + Refresh (); + + break; + + case 1: + Assert.False (btn1.NewKeyDownEvent (Key.Space)); + + break; + case 2: + Refresh (); + + expected = @$" ┌───────────────────────┐ │ │ │ │ @@ -1107,14 +1130,16 @@ public class DialogTests │ │ │{CM.Glyphs.LeftBracket} Show Sub {CM.Glyphs.RightBracket} {CM.Glyphs.LeftBracket} Close {CM.Glyphs.RightBracket} │ └───────────────────────┘"; - TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.False (btn2.NewKeyDownEvent (Key.Space)); - } - else if (iterations == 2) - { - TestHelpers.AssertDriverContentsWithFrameAre ( - @$" + Assert.False (btn2.NewKeyDownEvent (Key.Space)); + + break; + case 3: + Refresh (); + + TestHelpers.AssertDriverContentsWithFrameAre ( + @$" ┌───────────────────────┐ │ ┌──────────────────┐ │ │ │ya │ │ @@ -1123,29 +1148,33 @@ public class DialogTests │ └──────────────────┘ │ │{CM.Glyphs.LeftBracket} Show Sub {CM.Glyphs.RightBracket} {CM.Glyphs.LeftBracket} Close {CM.Glyphs.RightBracket} │ └───────────────────────┘", - _output - ); + _output + ); - Assert.False (Top!.NewKeyDownEvent (Key.Enter)); - } - else if (iterations == 3) - { - TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + Assert.False (Top!.NewKeyDownEvent (Key.Enter)); - Assert.False (btn3.NewKeyDownEvent (Key.Space)); - } - else if (iterations == 4) - { - TestHelpers.AssertDriverContentsWithFrameAre ("", _output); + break; + case 4: + Refresh (); - RequestStop (); + TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); + + Assert.False (btn3.NewKeyDownEvent (Key.Space)); + + break; + case 5: + TestHelpers.AssertDriverContentsWithFrameAre ("", _output); + + RequestStop (); + + break; } }; Run ().Dispose (); Shutdown (); - Assert.Equal (4, iterations); + Assert.Equal (5, iterations); } [Fact] diff --git a/UnitTests/View/TextTests.cs b/UnitTests/View/TextTests.cs index 8be8df33b..ba7cafaa5 100644 --- a/UnitTests/View/TextTests.cs +++ b/UnitTests/View/TextTests.cs @@ -705,6 +705,8 @@ w "; var top = new Toplevel (); top.Add (lbl); RunState rs = Application.Begin (top); + Application.RunIteration (ref rs); + Assert.Equal (new (0, 0, 3, 1), lbl.Frame); Assert.Equal ("123 ", GetContents ()); diff --git a/UnitTests/View/ViewTests.cs b/UnitTests/View/ViewTests.cs index 7285b7a8a..c057a1a13 100644 --- a/UnitTests/View/ViewTests.cs +++ b/UnitTests/View/ViewTests.cs @@ -156,6 +156,7 @@ public class ViewTests (ITestOutputHelper output) var top = new Toplevel (); top.Add (root); RunState runState = Application.Begin (top); + Application.RunIteration (ref runState); if (label) { @@ -244,6 +245,7 @@ cccccccccccccccccccc", Toplevel top = new (); top.Add (label, view); RunState runState = Application.Begin (top); + Application.RunIteration (ref runState); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -340,6 +342,7 @@ At 0,0 Toplevel top = new (); top.Add (label, view); RunState runState = Application.Begin (top); + Application.RunIteration (ref runState); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -447,7 +450,8 @@ At 0,0 var top = new Toplevel (); top.Add (view, tv); - Application.Begin (top); + RunState runState = Application.Begin (top); + Application.RunIteration (ref runState); Assert.True (viewCalled); Assert.True (tvCalled); @@ -554,6 +558,7 @@ At 0,0 Toplevel top = new (); top.Add (label, view); RunState runState = Application.Begin (top); + Application.RunIteration (ref runState); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -598,8 +603,7 @@ At 0,0 Toplevel top = new (); top.Add (label, view); RunState runState = Application.Begin (top); - - view.Draw (); + Application.RunIteration (ref runState); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -648,6 +652,7 @@ At 0,0 Toplevel top = new (); top.Add (label, view); RunState runState = Application.Begin (top); + Application.RunIteration (ref runState); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -693,8 +698,7 @@ At 0,0 Toplevel top = new (); top.Add (label, view); RunState runState = Application.Begin (top); - - view.Draw (); + Application.RunIteration (ref runState); TestHelpers.AssertDriverContentsWithFrameAre ( @" diff --git a/UnitTests/Views/AppendAutocompleteTests.cs b/UnitTests/Views/AppendAutocompleteTests.cs index eaabc43a6..3670d5281 100644 --- a/UnitTests/Views/AppendAutocompleteTests.cs +++ b/UnitTests/Views/AppendAutocompleteTests.cs @@ -57,8 +57,8 @@ public class AppendAutocompleteTests (ITestOutputHelper output) // Should reappear when you press next letter Application.Driver?.SendKeys ('i', ConsoleKey.I, false, false, false); - tf.Draw (); tf.PositionCursor (); + tf.Draw (); TestHelpers.AssertDriverContentsAre ("fish", output); Assert.Equal ("fi", tf.Text); Application.Top.Dispose (); diff --git a/UnitTests/Views/ContextMenuTests.cs b/UnitTests/Views/ContextMenuTests.cs index 13af3c9d2..668b46952 100644 --- a/UnitTests/Views/ContextMenuTests.cs +++ b/UnitTests/Views/ContextMenuTests.cs @@ -138,6 +138,7 @@ public class ContextMenuTests (ITestOutputHelper output) var top = new Toplevel { X = 2, Y = 2, Width = 15, Height = 4 }; top.Add (new TextField { X = Pos.Center (), Width = 10, Text = "Test" }); RunState rs = Application.Begin (top); + Application.Refresh (); Assert.Equal (new Rectangle (2, 2, 15, 4), top.Frame); Assert.Equal (top, Application.Top); @@ -208,6 +209,7 @@ public class ContextMenuTests (ITestOutputHelper output) var testWindow = new Window { X = 2, Y = 2, Width = 15, Height = 4 }; testWindow.Add (new TextField { X = Pos.Center (), Width = 10, Text = "Test" }); RunState rsDialog = Application.Begin (testWindow); + Application.Refresh (); Assert.Equal (new Rectangle (2, 2, 15, 4), testWindow.Frame); @@ -273,6 +275,7 @@ public class ContextMenuTests (ITestOutputHelper output) var dialog = new Window { X = 2, Y = 2, Width = 15, Height = 4 }; dialog.Add (new TextField { X = Pos.Center (), Width = 10, Text = "Test" }); RunState rs = Application.Begin (dialog); + Application.Refresh (); Assert.Equal (new Rectangle (2, 2, 15, 4), dialog.Frame); Assert.Equal (dialog, Application.Top); diff --git a/UnitTests/Views/LabelTests.cs b/UnitTests/Views/LabelTests.cs index 64c3ac981..183434940 100644 --- a/UnitTests/Views/LabelTests.cs +++ b/UnitTests/Views/LabelTests.cs @@ -192,7 +192,8 @@ public class LabelTests (ITestOutputHelper output) var top = new Toplevel (); top.Add (label); - Application.Begin (top); + RunState runState = Application.Begin (top); + Application.RunIteration (ref runState); Assert.False (label.TextFormatter.FillRemaining); Assert.False (tf1.FillRemaining); @@ -243,6 +244,7 @@ This TextFormatter (tf2) is rewritten. ", var top = new Toplevel (); top.Add (label); Application.Begin (top); + Application.Refresh (); Assert.Equal (new (0, 0, 16, 1), label.Frame); @@ -263,7 +265,7 @@ Demo Simple Rune var top = new Toplevel (); top.Add (label); Application.Begin (top); - + Application.Refresh (); Assert.NotNull (label.Width); Assert.NotNull (label.Height); @@ -299,6 +301,7 @@ e var top = new Toplevel (); top.Add (label); Application.Begin (top); + Application.Refresh (); var expected = @" デ @@ -469,6 +472,7 @@ e var top = new Toplevel (); top.Add (label); Application.Begin (top); + Application.Refresh (); Assert.Equal (new (0, 0, 6, 3), label.Frame); Assert.Equal (new (0, 0, 4, 1), label.Viewport); @@ -492,7 +496,7 @@ e var top = new Toplevel (); top.Add (label); Application.Begin (top); - + Application.Refresh (); Assert.Equal (new (0, 0, 6, 2), label.Frame); Assert.Equal (new (0, 0, 4, 1), label.Viewport); Application.Begin (top); diff --git a/UnitTests/Views/ListViewTests.cs b/UnitTests/Views/ListViewTests.cs index 1f5553c2c..0ab0ecb33 100644 --- a/UnitTests/Views/ListViewTests.cs +++ b/UnitTests/Views/ListViewTests.cs @@ -305,6 +305,7 @@ public class ListViewTests (ITestOutputHelper output) var top = new Toplevel (); top.Add (lv); Application.Begin (top); + Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -342,6 +343,7 @@ Item 6", var top = new Toplevel (); top.Add (lv); Application.Begin (top); + Application.Refresh (); Assert.Equal ("Second ", GetContents (0)); Assert.Equal (new (' ', 7), GetContents (1)); @@ -723,6 +725,7 @@ Item 6", var top = new Toplevel (); top.Add (lv); Application.Begin (top); + Application.Refresh (); Assert.Equal (new (1), lv.Border.Thickness); Assert.Equal (-1, lv.SelectedItem); @@ -796,6 +799,7 @@ Item 6", var top = new Toplevel (); top.Add (lv); Application.Begin (top); + Application.Refresh (); TestHelpers.AssertDriverContentsWithFrameAre ( @" diff --git a/UnitTests/Views/MenuBarTests.cs b/UnitTests/Views/MenuBarTests.cs index 2b01ae118..f85981e02 100644 --- a/UnitTests/Views/MenuBarTests.cs +++ b/UnitTests/Views/MenuBarTests.cs @@ -569,6 +569,7 @@ public class MenuBarTests (ITestOutputHelper output) } RunState rsDialog = Application.Begin (dialog); + Application.RunIteration (ref rsDialog); Assert.Equal (new (2, 2, 15, 4), dialog.Frame); @@ -594,8 +595,7 @@ public class MenuBarTests (ITestOutputHelper output) Assert.Equal ("File", menu.Menus [0].Title); menu.OpenMenu (); - var firstIteration = false; - Application.RunIteration (ref rsDialog, firstIteration); + Application.RunIteration (ref rsDialog); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -619,10 +619,9 @@ public class MenuBarTests (ITestOutputHelper output) Application.RaiseMouseEvent (new () { ScreenPosition = new (20, 5), Flags = MouseFlags.Button1Clicked }); - firstIteration = false; - // Need to fool MainLoop into thinking it's running Application.MainLoop.Running = true; + bool firstIteration = true; Application.RunIteration (ref rsDialog, firstIteration); Assert.Equal (items [0], menu.Menus [0].Title); @@ -652,15 +651,13 @@ public class MenuBarTests (ITestOutputHelper output) Application.RaiseMouseEvent (new () { ScreenPosition = new (20, 5 + i), Flags = MouseFlags.Button1Clicked }); - firstIteration = false; - Application.RunIteration (ref rsDialog, firstIteration); + Application.RunIteration (ref rsDialog); Assert.Equal (items [i], menu.Menus [0].Title); } ((FakeDriver)Application.Driver!).SetBufferSize (20, 15); menu.OpenMenu (); - firstIteration = false; - Application.RunIteration (ref rsDialog, firstIteration); + Application.RunIteration (ref rsDialog); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -781,6 +778,7 @@ public class MenuBarTests (ITestOutputHelper output) } RunState rs = Application.Begin (dialog); + Application.RunIteration (ref rs); Assert.Equal (new (2, 2, 15, 4), dialog.Frame); @@ -795,8 +793,7 @@ public class MenuBarTests (ITestOutputHelper output) Assert.Equal ("File", menu.Menus [0].Title); menu.OpenMenu (); - var firstIteration = false; - Application.RunIteration (ref rs, firstIteration); + Application.RunIteration (ref rs); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -815,11 +812,9 @@ public class MenuBarTests (ITestOutputHelper output) Application.RaiseMouseEvent (new () { ScreenPosition = new (20, 5), Flags = MouseFlags.Button1Clicked }); - firstIteration = false; - // Need to fool MainLoop into thinking it's running Application.MainLoop.Running = true; - Application.RunIteration (ref rs, firstIteration); + Application.RunIteration (ref rs); Assert.Equal (items [0], menu.Menus [0].Title); TestHelpers.AssertDriverContentsWithFrameAre ( @@ -837,15 +832,13 @@ public class MenuBarTests (ITestOutputHelper output) Application.RaiseMouseEvent (new () { ScreenPosition = new (20, 5 + i), Flags = MouseFlags.Button1Clicked }); - firstIteration = false; - Application.RunIteration (ref rs, firstIteration); + Application.RunIteration (ref rs); Assert.Equal (items [i], menu.Menus [0].Title); } ((FakeDriver)Application.Driver!).SetBufferSize (20, 15); menu.OpenMenu (); - firstIteration = false; - Application.RunIteration (ref rs, firstIteration); + Application.RunIteration (ref rs); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -1857,7 +1850,8 @@ wo }; win.Add (menu); ((FakeDriver)Application.Driver!).SetBufferSize (40, 8); - Application.Begin (win); + RunState rs = Application.Begin (win); + Application.RunIteration (ref rs); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -1873,7 +1867,7 @@ wo ); Assert.True (win.NewKeyDownEvent (menu.Key)); - win.Draw (); + Application.RunIteration (ref rs); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -1889,7 +1883,7 @@ wo ); Assert.True (menu.NewKeyDownEvent (Key.CursorRight)); - Application.Refresh (); + Application.RunIteration (ref rs); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -1905,7 +1899,7 @@ wo ); Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight)); - win.Draw (); + Application.RunIteration (ref rs); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -1921,7 +1915,7 @@ wo ); Assert.True (menu._openMenu.NewKeyDownEvent (Key.CursorRight)); - win.Draw (); + Application.RunIteration (ref rs); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -1947,6 +1941,7 @@ wo Application.Iteration += (s, a) => { Toplevel top = Application.Top; + Application.Refresh(); TestHelpers.AssertDriverContentsWithFrameAre ( @" diff --git a/UnitTests/Views/ScrollBarViewTests.cs b/UnitTests/Views/ScrollBarViewTests.cs index 9e4abf1be..431b7177f 100644 --- a/UnitTests/Views/ScrollBarViewTests.cs +++ b/UnitTests/Views/ScrollBarViewTests.cs @@ -178,6 +178,7 @@ public class ScrollBarViewTests Application.Begin (top); ((FakeDriver)Application.Driver!).SetBufferSize (width, height); + Application.Refresh (); var expected = @" ┌─┐ @@ -230,6 +231,7 @@ public class ScrollBarViewTests { _scrollBar = new ScrollBarView (_hostView, true); Application.Begin (_hostView.SuperView as Toplevel); + Application.Refresh (); AddHandlers (); @@ -250,6 +252,7 @@ public class ScrollBarViewTests { _scrollBar = new ScrollBarView (_hostView, true); Application.Begin (_hostView.SuperView as Toplevel); + Application.Refresh (); AddHandlers (); @@ -285,6 +288,7 @@ public class ScrollBarViewTests { _scrollBar = new ScrollBarView (_hostView, true); Application.Begin (_hostView.SuperView as Toplevel); + Application.Refresh (); AddHandlers (); @@ -308,6 +312,7 @@ public class ScrollBarViewTests var sbv = new ScrollBarView (label, true, false) { Size = 100 }; Application.Begin (top); + Application.Refresh (); Assert.True (sbv.Visible); @@ -425,6 +430,8 @@ This is a test Assert.Equal (newScrollBarView.Position, listView.LeftItem); listView.SetNeedsDisplay (); + Application.Refresh (); + }; listView.DrawContent += (s, e) => @@ -504,6 +511,8 @@ This is a test Assert.Equal (newScrollBarView.Position, listView.TopItem); listView.SetNeedsDisplay (); + Application.Refresh (); + }; listView.DrawContent += (s, e) => @@ -553,6 +562,7 @@ This is a test var sbv = new ScrollBarView (label, true) { Size = 100 }; sbv.OtherScrollBarView.Size = 100; Application.Begin (top); + Application.Refresh (); Assert.Equal (100, sbv.Size); Assert.Equal (100, sbv.OtherScrollBarView.Size); @@ -636,6 +646,7 @@ This is a tes▼ var sbv = new ScrollBarView (label, true, false) { Size = 100 }; Application.Begin (top); + Application.Refresh (); Assert.Equal (100, sbv.Size); Assert.Null (sbv.OtherScrollBarView); @@ -680,6 +691,7 @@ This is a test { _scrollBar = new ScrollBarView (_hostView, true); Application.Begin (_hostView.SuperView as Toplevel); + Application.Refresh (); AddHandlers (); @@ -1156,6 +1168,7 @@ This is a test var sbv = new ScrollBarView (label, true, false) { Size = 5 }; Application.Begin (top); + Application.Refresh (); Assert.Equal (5, sbv.Size); Assert.Null (sbv.OtherScrollBarView);