diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs
index 33249b5ee..4ca0d9907 100644
--- a/Terminal.Gui/Core/Application.cs
+++ b/Terminal.Gui/Core/Application.cs
@@ -478,7 +478,7 @@ namespace Terminal.Gui {
/// Building block API: completes the execution of a that was started with .
///
/// The runstate returned by the method.
- /// trueCloses the application.falseCloses the toplevels only.
+ /// If true, closes the application. If false closes the toplevels only.
public static void End (RunState runState, bool closeDriver = true)
{
if (runState == null)
@@ -491,7 +491,7 @@ namespace Terminal.Gui {
///
/// Shutdown an application initialized with
///
- /// /// trueCloses the application.falseCloses toplevels only.
+ /// trueCloses the application.falseCloses toplevels only.
public static void Shutdown (bool closeDriver = true)
{
// Shutdown is the bookend for Init. As such it needs to clean up all resources
@@ -651,6 +651,8 @@ namespace Terminal.Gui {
/// then return control immediately.
///
///
+ /// The tu run modally.
+ /// Set to to cause the MainLoop to end when is called, clsing the toplevels only.
public static void Run (Toplevel view, bool closeDriver = true)
{
var runToken = Begin (view);
diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs
index 3e2aaaaf1..36b848544 100644
--- a/Terminal.Gui/Views/Button.cs
+++ b/Terminal.Gui/Views/Button.cs
@@ -154,10 +154,10 @@ namespace Terminal.Gui {
}
}
- Rune _leftBracket = new Rune (Driver.LeftBracket);
- Rune _rightBracket = new Rune (Driver.RightBracket);
- Rune _leftDefault = new Rune (Driver.LeftDefaultIndicator);
- Rune _rightDefault = new Rune (Driver.RightDefaultIndicator);
+ Rune _leftBracket = new Rune (Driver != null ? Driver.LeftBracket : '[');
+ Rune _rightBracket = new Rune (Driver != null ? Driver.RightBracket : ']');
+ Rune _leftDefault = new Rune (Driver != null ? Driver.LeftDefaultIndicator : '<');
+ Rune _rightDefault = new Rune (Driver != null ? Driver.RightDefaultIndicator : '>');
internal void Update ()
{
diff --git a/Terminal.Gui/Windows/MessageBox.cs b/Terminal.Gui/Windows/MessageBox.cs
index ce8ad5bf4..ae1834749 100644
--- a/Terminal.Gui/Windows/MessageBox.cs
+++ b/Terminal.Gui/Windows/MessageBox.cs
@@ -148,7 +148,8 @@ namespace Terminal.Gui {
};
}
- Application.Run (d);
+ // Rin the modal; do not shutdown the mainloop driver when done
+ Application.Run (d, false);
return clicked;
}
}
diff --git a/UICatalog/Scenarios/HexEditor.cs b/UICatalog/Scenarios/HexEditor.cs
index c9015f72a..03631edb6 100644
--- a/UICatalog/Scenarios/HexEditor.cs
+++ b/UICatalog/Scenarios/HexEditor.cs
@@ -102,7 +102,7 @@ namespace UICatalog {
private void Open ()
{
var d = new OpenDialog ("Open", "Open a file") { AllowsMultipleSelection = false };
- Application.Run (d);
+ Application.Run (d, false);
if (!d.Canceled) {
_fileName = d.FilePaths [0];
diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs
index 859ea0ea9..bdfa43b9f 100644
--- a/UICatalog/UICatalog.cs
+++ b/UICatalog/UICatalog.cs
@@ -118,7 +118,7 @@ namespace UICatalog {
}
};
- Application.Run (_top, false);
+ Application.Run (_top, true);
Application.Shutdown ();
return _runningScenario;
}
diff --git a/UnitTests/ScenarioTests.cs b/UnitTests/ScenarioTests.cs
index 04eed8ce6..193dfd020 100644
--- a/UnitTests/ScenarioTests.cs
+++ b/UnitTests/ScenarioTests.cs
@@ -38,6 +38,7 @@ namespace Terminal.Gui {
foreach (var scenarioClass in scenarioClasses) {
// Setup some fake kepresses
// Passing empty string will cause just a ctrl-q to be fired
+ Console.MockKeyPresses.Clear ();
int stackSize = CreateInput ("");
int iterations = 0;
Application.Iteration = () => {
@@ -49,6 +50,15 @@ namespace Terminal.Gui {
};
Application.Init (new FakeDriver (), new NetMainLoop (() => FakeConsole.ReadKey (true)));
+ var ms = 1000;
+ var abortCount = 0;
+ Func abortCallback = (MainLoop loop) => {
+ abortCount++;
+ Application.RequestStop ();
+ return false;
+ };
+ var token = Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (ms), abortCallback);
+
var scenario = (Scenario)Activator.CreateInstance (scenarioClass);
scenario.Init (Application.Top, Colors.Base);
scenario.Setup ();
@@ -56,10 +66,59 @@ namespace Terminal.Gui {
Application.Shutdown ();
+ Assert.Equal (0, abortCount);
// # of key up events should match # of iterations
Assert.Equal (1, iterations);
Assert.Equal (stackSize, iterations);
}
}
+
+ [Fact]
+ public void Run_Generic ()
+ {
+ List scenarioClasses = Scenario.GetDerivedClasses ();
+ Assert.NotEmpty (scenarioClasses);
+
+ var item = scenarioClasses.FindIndex (t => Scenario.ScenarioMetadata.GetName (t).Equals ("Generic", StringComparison.OrdinalIgnoreCase));
+ var scenarioClass = scenarioClasses[item];
+ // Setup some fake kepresses
+ // Passing empty string will cause just a ctrl-q to be fired
+ int stackSize = CreateInput ("");
+
+ int iterations = 0;
+ Application.Iteration = () => {
+ iterations++;
+ // Stop if we run out of control...
+ if (iterations == 10) {
+ Application.RequestStop ();
+ }
+ };
+ Application.Init (new FakeDriver (), new NetMainLoop (() => FakeConsole.ReadKey (true)));
+
+ var ms = 1000;
+ var abortCount = 0;
+ Func abortCallback = (MainLoop loop) => {
+ abortCount++;
+ Application.RequestStop ();
+ return false;
+ };
+ var token = Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (ms), abortCallback);
+
+ Application.Top.KeyPress += (View.KeyEventEventArgs args) => {
+ Assert.Equal (Key.ControlQ, args.KeyEvent.Key);
+ };
+
+ var scenario = (Scenario)Activator.CreateInstance (scenarioClass);
+ scenario.Init (Application.Top, Colors.Base);
+ scenario.Setup ();
+ scenario.Run ();
+
+ Application.Shutdown ();
+
+ Assert.Equal (0, abortCount);
+ // # of key up events should match # of iterations
+ //Assert.Equal (1, iterations);
+ Assert.Equal (stackSize, iterations);
+ }
}
}