Repository: gui-cs/Terminal.Gui (2026-03-21T12:05:22Z)

Issue:
Something's wrong with `SchemeName = "Dialog"`
<img width="718" height="402" alt="Image" src="https://github.com/user-attachments/assets/24bef36a-f558-4c42-afdf-4cf74634cfd2" />

Oddly, MessageBox is fine:


<img width="703" height="424" alt="Image" src="https://github.com/user-attachments/assets/a2bac8f1-6b3d-4883-92f7-fbdbb82eea7a" />

This does not just impact Dialog. I see artifacts of this in other places where the "dialog" scheme name is used.

Step one is to write a set of unit tests that fail, illustrating precisely where the issue is. 

Step two is to use the commit history and determine what broke this by running those tests on those branches to see where they pass. It was recent. 

Step three is to fix the bug. 


Discussion:

Patch:
diff --git a/Terminal.Gui/Views/DialogTResult.cs b/Terminal.Gui/Views/DialogTResult.cs
index 94f4d990ec..e18d73f658 100644
--- a/Terminal.Gui/Views/DialogTResult.cs
+++ b/Terminal.Gui/Views/DialogTResult.cs
@@ -354,6 +354,14 @@ private void SetStyle ()
     {
         if (IsRunning)
         {
+            // When running, restore to Dialog scheme only if it was set to Base by SetStyle
+            // (i.e., the scheme was not explicitly overridden before running, e.g. by
+            // MessageBox.ErrorQuery which sets SchemeName = "Error" before calling app.Run).
+            if (SchemeName == SchemeManager.SchemesToSchemeName (Schemes.Base))
+            {
+                SchemeName = SchemeManager.SchemesToSchemeName (Schemes.Dialog);
+            }
+
             Arrangement |= ViewArrangement.Movable | ViewArrangement.Resizable | ViewArrangement.Overlapped;
         }
         else


Test patch:
diff --git a/Tests/UnitTestsParallelizable/Views/DialogTests.cs b/Tests/UnitTestsParallelizable/Views/DialogTests.cs
index 5c64f21083..aa1f553741 100644
--- a/Tests/UnitTestsParallelizable/Views/DialogTests.cs
+++ b/Tests/UnitTestsParallelizable/Views/DialogTests.cs
@@ -412,6 +412,45 @@ public void ShadowStyle_Can_Be_Changed ()
         dialog.Dispose ();
     }
 
+    // Copilot
+    [Fact]
+    public void SchemeName_IsBase_WhenNotRunning ()
+    {
+        // When a Dialog is not running, it should use the Base scheme (not Dialog)
+        Dialog dialog = new ();
+
+        Assert.Equal (SchemeManager.SchemesToSchemeName (Schemes.Base), dialog.SchemeName);
+
+        dialog.Dispose ();
+    }
+
+    // Copilot
+    [Fact]
+    public void SchemeName_IsDialog_WhenRunning ()
+    {
+        using IApplication app = Application.Create ();
+        app.Init (DriverRegistry.Names.ANSI);
+
+        using Dialog dialog = new ();
+
+        string? schemeNameWhileRunning = null;
+
+        app.Iteration += AppOnIteration;
+        app.Run (dialog);
+        app.Iteration -= AppOnIteration;
+
+        Assert.Equal (SchemeManager.SchemesToSchemeName (Schemes.Dialog), schemeNameWhileRunning);
+
+        return;
+
+        void AppOnIteration (object? sender, EventArgs<IApplication?> e)
+        {
+            schemeNameWhileRunning = dialog.SchemeName;
+            app.Iteration -= AppOnIteration;
+            app.RequestStop ();
+        }
+    }
+
     [Fact]
     public void Text_Property ()
     {