Browse Source

Revert "Fixes #4274. Using Windows Host Console v2win is rendering window siz…" (#4286)

This reverts commit 75f5a847c06d0b45e7c7533bb85f9adf219ae98b.
Tig 1 month ago
parent
commit
3a8cbf3ca7

+ 1 - 1
Examples/UICatalog/Scenarios/CombiningMarks.cs

@@ -13,7 +13,7 @@ public class CombiningMarks : Scenario
         top.DrawComplete += (s, e) =>
         {
             // Forces reset _lineColsOffset because we're dealing with direct draw
-            Application.Top!.SetNeedsDraw ();
+            Application.ClearScreenNextIteration = true;
 
             var i = -1;
             top.AddStr ("Terminal.Gui only supports combining marks that normalize. See Issue #2616.");

+ 0 - 2
Examples/UICatalog/Scenarios/Shortcuts.cs

@@ -12,7 +12,6 @@ public class Shortcuts : Scenario
     public override void Main ()
     {
         Application.Init ();
-        var quitKey = Application.QuitKey;
         Window app = new ();
 
         app.Loaded += App_Loaded;
@@ -20,7 +19,6 @@ public class Shortcuts : Scenario
         Application.Run (app);
         app.Dispose ();
         Application.Shutdown ();
-        Application.QuitKey = quitKey;
     }
 
     // Setting everything up in Loaded handler because we change the

+ 2 - 2
Terminal.Gui/App/Application.Screen.cs

@@ -82,8 +82,8 @@ public static partial class Application // Screen related stuff
     ///     Gets or sets whether the screen will be cleared, and all Views redrawn, during the next Application iteration.
     /// </summary>
     /// <remarks>
-    ///     This is typical set to true when a View's <see cref="View.Frame"/> changes and that view has no
+    ///     This is typicall set to true when a View's <see cref="View.Frame"/> changes and that view has no
     ///     SuperView (e.g. when <see cref="Application.Top"/> is moved or resized.
     /// </remarks>
-    internal static bool ClearScreenNextIteration { get; set; }
+    public static bool ClearScreenNextIteration { get; set; }
 }

+ 4 - 24
Terminal.Gui/Drivers/WindowsDriver/WindowsOutput.cs

@@ -100,8 +100,6 @@ internal partial class WindowsOutput : OutputBase, IConsoleOutput
     private readonly nint _outputHandle;
     private nint _screenBuffer;
     private readonly bool _isVirtualTerminal;
-    private readonly ConsoleColor _foreground;
-    private readonly ConsoleColor _background;
 
     public WindowsOutput ()
     {
@@ -119,16 +117,8 @@ internal partial class WindowsOutput : OutputBase, IConsoleOutput
 
         if (_isVirtualTerminal)
         {
-            if (Environment.GetEnvironmentVariable ("VSAPPIDNAME") is null)
-            {
-                //Enable alternative screen buffer.
-                Console.Out.Write (EscSeqUtils.CSI_SaveCursorAndActivateAltBufferNoBackscroll);
-            }
-            else
-            {
-                _foreground = Console.ForegroundColor;
-                _background = Console.BackgroundColor;
-            }
+            //Enable alternative screen buffer.
+            Console.Out.Write (EscSeqUtils.CSI_SaveCursorAndActivateAltBufferNoBackscroll);
         }
         else
         {
@@ -512,18 +502,8 @@ internal partial class WindowsOutput : OutputBase, IConsoleOutput
 
         if (_isVirtualTerminal)
         {
-            if (Environment.GetEnvironmentVariable ("VSAPPIDNAME") is null)
-            {
-                //Disable alternative screen buffer.
-                Console.Out.Write (EscSeqUtils.CSI_RestoreCursorAndRestoreAltBufferWithBackscroll);
-            }
-            else
-            {
-                // Simulate restoring the color and clearing the screen.
-                Console.ForegroundColor = _foreground;
-                Console.BackgroundColor = _background;
-                Console.Clear ();
-            }
+            //Disable alternative screen buffer.
+            Console.Out.Write (EscSeqUtils.CSI_RestoreCursorAndRestoreAltBufferWithBackscroll);
         }
         else
         {

+ 3 - 19
Terminal.Gui/ViewBase/View.Layout.cs

@@ -239,8 +239,6 @@ public partial class View // Layout APIs
             _x = value ?? throw new ArgumentNullException (nameof (value), @$"{nameof (X)} cannot be null");
 
             PosDimSet ();
-
-            NeedsClearScreenNextIteration ();
         }
     }
 
@@ -283,8 +281,6 @@ public partial class View // Layout APIs
 
             _y = value ?? throw new ArgumentNullException (nameof (value), @$"{nameof (Y)} cannot be null");
             PosDimSet ();
-
-            NeedsClearScreenNextIteration ();
         }
     }
 
@@ -343,8 +339,6 @@ public partial class View // Layout APIs
                                               OnHeightChanged,
                                               HeightChanged,
                                               out Dim _);
-
-            NeedsClearScreenNextIteration ();
         }
     }
 
@@ -431,17 +425,6 @@ public partial class View // Layout APIs
                                               OnWidthChanged,
                                               WidthChanged,
                                               out Dim _);
-
-            NeedsClearScreenNextIteration ();
-        }
-    }
-
-    private void NeedsClearScreenNextIteration ()
-    {
-        if (Application.Top is { } && Application.Top == this && Application.TopLevels.Count == 1)
-        {
-            // If this is the only TopLevel, we need to redraw the screen
-            Application.ClearScreenNextIteration = true;
         }
     }
 
@@ -670,9 +653,10 @@ public partial class View // Layout APIs
             {
                 SuperView?.SetNeedsDraw ();
             }
-            else
+            else if (Application.TopLevels.Count == 1)
             {
-                NeedsClearScreenNextIteration ();
+                // If this is the only TopLevel, we need to redraw the screen
+                Application.ClearScreenNextIteration = true;
             }
         }
 

+ 1 - 1
Terminal.Gui/ViewBase/View.cs

@@ -378,7 +378,7 @@ public partial class View : IDisposable, ISupportInitializeNotification
             }
             else
             {
-                NeedsClearScreenNextIteration ();
+                Application.ClearScreenNextIteration = true;
             }
         }
     }

+ 7 - 12
Tests/IntegrationTests/UICatalog/ScenarioTests.cs

@@ -41,9 +41,8 @@ public class ScenarioTests : TestsAllViews
 
         _output.WriteLine ($"Running Scenario '{scenarioType}'");
         var scenario = Activator.CreateInstance (scenarioType) as Scenario;
-        var scenarioName = scenario!.GetName ();
 
-        uint abortTime = 2200;
+        uint abortTime = 2000;
         object? timeout = null;
         var initialized = false;
         var shutdownGracefully = false;
@@ -71,7 +70,7 @@ public class ScenarioTests : TestsAllViews
         Assert.True (initialized);
 
 
-        Assert.True (shutdownGracefully, $"Scenario '{scenarioName}' Failed to Quit with {quitKey} after {abortTime}ms and {iterationCount} iterations. Force quit.");
+        Assert.True (shutdownGracefully, $"Scenario Failed to Quit with {quitKey} after {abortTime}ms and {iterationCount} iterations. Force quit.");
 
 #if DEBUG_IDISPOSABLE
         Assert.Empty (View.Instances);
@@ -92,6 +91,11 @@ public class ScenarioTests : TestsAllViews
             {
                 Application.Iteration += OnApplicationOnIteration;
                 initialized = true;
+
+                lock (_timeoutLock)
+                {
+                    timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback);
+                }
             }
             else
             {
@@ -122,15 +126,6 @@ public class ScenarioTests : TestsAllViews
 
         void OnApplicationOnIteration (object? s, IterationEventArgs a)
         {
-            if (iterationCount == 0)
-            {
-                // Start the timeout countdown on the first iteration
-                lock (_timeoutLock)
-                {
-                    timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback);
-                }
-            }
-
             iterationCount++;
 
             if (Application.Initialized)

+ 1 - 15
Tests/UnitTests/Application/ApplicationScreenTests.cs

@@ -47,7 +47,7 @@ public class ApplicationScreenTests
         Assert.Equal (0, clearedContentsRaised);
 
         // Act
-        Application.Top!.SetNeedsLayout ();
+        Application.Top.SetNeedsLayout ();
         Application.LayoutAndDraw ();
 
         // Assert
@@ -67,20 +67,6 @@ public class ApplicationScreenTests
         // Assert
         Assert.Equal (2, clearedContentsRaised);
 
-        // Act
-        Application.Top.Y = 1;
-        Application.LayoutAndDraw ();
-
-        // Assert
-        Assert.Equal (3, clearedContentsRaised);
-
-        // Act
-        Application.Top.Height = 10;
-        Application.LayoutAndDraw ();
-
-        // Assert
-        Assert.Equal (4, clearedContentsRaised);
-
         Application.End (rs);
 
         return;

+ 1 - 1
Tests/UnitTests/Application/SynchronizatonContextTests.cs

@@ -10,7 +10,7 @@ public class SyncrhonizationContextTests
     public void SynchronizationContext_CreateCopy ()
     {
         ConsoleDriver.RunningUnitTests = true;
-        Application.Init (null, "fake");
+        Application.Init ();
         SynchronizationContext context = SynchronizationContext.Current;
         Assert.NotNull (context);
 

+ 2 - 0
Tests/UnitTests/Configuration/ConfigurationMangerTests.cs

@@ -1010,6 +1010,8 @@ public class ConfigurationManagerTests (ITestOutputHelper output)
         finally
         {
             Disable (resetToHardCodedDefaults: true);
+
         }
     }
+
 }

+ 1 - 3
Tests/UnitTests/Views/ComboBoxTests.cs

@@ -525,9 +525,7 @@ public class ComboBoxTests (ITestOutputHelper output)
         Assert.True (cb.IsShow);
         Assert.Equal (-1, cb.SelectedItem);
         Assert.Equal ("", cb.Text);
-        Assert.False (Application.ClearScreenNextIteration);
-        Assert.True (cb.NeedsLayout);
-        Assert.True (cb.NeedsDraw);
+
         cb.Layout ();
 
         cb.Draw ();