mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-29 17:28:01 +01:00
Fixes #4391. Weird situation where ForceDriver with args doesn't persists on open scenario
This commit is contained in:
@@ -55,13 +55,31 @@ namespace UICatalog;
|
||||
/// </remarks>
|
||||
public class UICatalog
|
||||
{
|
||||
private static string? _forceDriver = null;
|
||||
private static string? _forceDriver;
|
||||
private static bool _forTesting;
|
||||
private static bool _iterationHandlerRemoved;
|
||||
private static string? _uiCatalogDriver;
|
||||
private static string? _scenarioDriver;
|
||||
|
||||
public static string LogFilePath { get; set; } = string.Empty;
|
||||
public static LoggingLevelSwitch LogLevelSwitch { get; } = new ();
|
||||
public const string LOGFILE_LOCATION = "logs";
|
||||
public static UICatalogCommandLineOptions Options { get; set; }
|
||||
|
||||
public static (string? UiCatalogDriver, string? ScenarioDriver) Run (string [] args)
|
||||
{
|
||||
// Flag for testing
|
||||
_forTesting = true;
|
||||
|
||||
// Start app
|
||||
Main (args);
|
||||
|
||||
// Unset testing flag
|
||||
_forTesting = false;
|
||||
|
||||
return new (_uiCatalogDriver, _scenarioDriver);
|
||||
}
|
||||
|
||||
private static int Main (string [] args)
|
||||
{
|
||||
Console.OutputEncoding = Encoding.Default;
|
||||
@@ -194,6 +212,8 @@ public class UICatalog
|
||||
|
||||
UICatalogMain (Options);
|
||||
|
||||
Debug.Assert (Application.ForceDriver == string.Empty);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -247,6 +267,11 @@ public class UICatalog
|
||||
/// <returns></returns>
|
||||
private static Scenario RunUICatalogTopLevel ()
|
||||
{
|
||||
if (_iterationHandlerRemoved)
|
||||
{
|
||||
return null!;
|
||||
}
|
||||
|
||||
// Run UI Catalog UI. When it exits, if _selectedScenario is != null then
|
||||
// a Scenario was selected. Otherwise, the user wants to quit UI Catalog.
|
||||
|
||||
@@ -255,7 +280,22 @@ public class UICatalog
|
||||
|
||||
Application.Init (driverName: _forceDriver);
|
||||
|
||||
var top = Application.Run<UICatalogTop> ();
|
||||
Toplevel top;
|
||||
|
||||
if (_forTesting)
|
||||
{
|
||||
top = new UICatalogTop ();
|
||||
SessionToken sessionToken = Application.Begin (top);
|
||||
UICatalogTop.CachedSelectedScenario = Scenario.GetScenarios () [0];
|
||||
Application.End (sessionToken);
|
||||
|
||||
_uiCatalogDriver = Application.Driver!.GetName ();
|
||||
}
|
||||
else
|
||||
{
|
||||
top = Application.Run<UICatalogTop> ();
|
||||
}
|
||||
|
||||
top.Dispose ();
|
||||
Application.Shutdown ();
|
||||
VerifyObjectsWereDisposed ();
|
||||
@@ -412,6 +452,8 @@ public class UICatalog
|
||||
Application.InitializedChanged += ApplicationOnInitializedChanged;
|
||||
#endif
|
||||
|
||||
Application.ForceDriver = _forceDriver;
|
||||
|
||||
scenario.Main ();
|
||||
scenario.Dispose ();
|
||||
|
||||
@@ -430,6 +472,43 @@ public class UICatalog
|
||||
if (e.Value)
|
||||
{
|
||||
sw.Start ();
|
||||
|
||||
if (_forTesting)
|
||||
{
|
||||
int iterationCount = 0;
|
||||
Key quitKey;
|
||||
|
||||
Application.Iteration += OnApplicationOnIteration;
|
||||
|
||||
void OnApplicationOnIteration (object? s, IterationEventArgs a)
|
||||
{
|
||||
iterationCount++;
|
||||
|
||||
if (Application.Initialized)
|
||||
{
|
||||
// Press QuitKey
|
||||
quitKey = Application.QuitKey;
|
||||
|
||||
Logging.Trace (
|
||||
$"Attempting to quit with {quitKey} after {iterationCount} iterations.");
|
||||
|
||||
try
|
||||
{
|
||||
Application.RaiseKeyDownEvent (quitKey);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Trace (
|
||||
$"Exception raising quit key: {ex.Message}");
|
||||
}
|
||||
|
||||
Application.Iteration -= OnApplicationOnIteration;
|
||||
_iterationHandlerRemoved = true;
|
||||
|
||||
_scenarioDriver = Application.Driver?.GetName ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user