diff --git a/Terminal.Gui/Application/Application.Initialization.cs b/Terminal.Gui/Application/Application.Initialization.cs
index 02351612f..94aab2b17 100644
--- a/Terminal.Gui/Application/Application.Initialization.cs
+++ b/Terminal.Gui/Application/Application.Initialization.cs
@@ -39,7 +39,15 @@ public static partial class Application // Initialization (Init/Shutdown)
[RequiresDynamicCode ("AOT")]
public static void Init (ConsoleDriver? driver = null, string? driverName = null) { InternalInit (driver, driverName); }
- internal static bool IsInitialized { get; set; }
+ ///
+ /// Gets whether the application has been initialized with and not yet shutdown with .
+ ///
+ ///
+ ///
+ /// The event is raised after the and methods have been called.
+ ///
+ ///
+ public static bool IsInitialized { get; private set; }
internal static int MainThreadId { get; set; } = -1;
// INTERNAL function for initializing an app with a Toplevel factory object, driver, and mainloop.
diff --git a/UICatalog/Properties/launchSettings.json b/UICatalog/Properties/launchSettings.json
index dc5a6a722..e1bc9cdfc 100644
--- a/UICatalog/Properties/launchSettings.json
+++ b/UICatalog/Properties/launchSettings.json
@@ -11,7 +11,7 @@
"commandName": "Project",
"commandLineArgs": "--driver WindowsDriver"
},
- "WSL : UICatalog": {
+ "WSL: UICatalog": {
"commandName": "Executable",
"executablePath": "wsl",
"commandLineArgs": "dotnet UICatalog.dll",
@@ -23,56 +23,30 @@
"commandLineArgs": "dotnet UICatalog.dll --driver NetDriver",
"distributionName": ""
},
- "WizardAsView": {
+ "Benchmark All": {
"commandName": "Project",
- "commandLineArgs": "WizardAsView"
+ "commandLineArgs": "--benchmark"
},
- "CollectionNavigatorTester": {
+ "Benchmark All --driver NetDriver": {
"commandName": "Project",
- "commandLineArgs": "\"Search Collection Nav\""
+ "commandLineArgs": "--driver NetDriver --benchmark"
},
- "Charmap": {
- "commandName": "Project",
- "commandLineArgs": "\"Character Map\" -b"
+ "WSL: Benchmark All": {
+ "commandName": "Executable",
+ "executablePath": "wsl",
+ "commandLineArgs": "dotnet UICatalog.dll --benchmark",
+ "distributionName": ""
+ },
+ "Docker": {
+ "commandName": "Docker"
},
"All Views Tester": {
"commandName": "Project",
"commandLineArgs": "\"All Views Tester\" -b"
},
- "Windows & FrameViews": {
+ "Charmap": {
"commandName": "Project",
- "commandLineArgs": "\"Windows & FrameViews\""
- },
- "Docker": {
- "commandName": "Docker"
- },
- "MenuBarScenario": {
- "commandName": "Project",
- "commandLineArgs": "MenuBar"
- },
- "ListView & ComboBox": {
- "commandName": "Project",
- "commandLineArgs": "\"ListView & ComboBox\""
- },
- "Generic": {
- "commandName": "Project",
- "commandLineArgs": "--benchmark Generic"
- },
- "Arrangement": {
- "commandName": "Project",
- "commandLineArgs": "Arrangement"
- },
- "Benchmark All": {
- "commandName": "Project",
- "commandLineArgs": "--benchmark"
- },
- "ContextMenus": {
- "commandName": "Project",
- "commandLineArgs": "ContextMenus -b"
- },
- "Animation": {
- "commandName": "Project",
- "commandLineArgs": "Animation -b"
+ "commandLineArgs": "\"Character Map\" -b"
}
}
}
\ No newline at end of file
diff --git a/UICatalog/Scenario.cs b/UICatalog/Scenario.cs
index e5d2369cc..a4da47d62 100644
--- a/UICatalog/Scenario.cs
+++ b/UICatalog/Scenario.cs
@@ -151,8 +151,8 @@ public class Scenario : IDisposable
///
public virtual void Main () { }
- private const uint MAX_NATURAL_ITERATIONS = 1000; // not including needed for demo keys
- private const uint ABORT_TIMEOUT_MS = 5000;
+ private const uint MAX_NATURAL_ITERATIONS = 500; // not including needed for demo keys
+ private const uint ABORT_TIMEOUT_MS = 2500;
private const int DEMO_KEY_PACING_MS = 1; // Must be non-zero
private readonly object _timeoutLock = new ();
diff --git a/UICatalog/Scenarios/AnimationScenario/AnimationScenario.cs b/UICatalog/Scenarios/AnimationScenario/AnimationScenario.cs
index f233ddc1e..3df1fc88e 100644
--- a/UICatalog/Scenarios/AnimationScenario/AnimationScenario.cs
+++ b/UICatalog/Scenarios/AnimationScenario/AnimationScenario.cs
@@ -16,12 +16,10 @@ namespace UICatalog.Scenarios;
[ScenarioCategory ("Drawing")]
public class AnimationScenario : Scenario
{
- private bool _appInitialized;
+ private ImageView _imageView;
public override void Main ()
{
- Application.InitializedChanged += OnAppInitializedChanged;
-
Application.Init ();
var win = new Window
@@ -33,9 +31,9 @@ public class AnimationScenario : Scenario
Height = Dim.Fill (),
};
- var imageView = new ImageView { Width = Dim.Fill (), Height = Dim.Fill () - 2 };
+ _imageView = new ImageView { Width = Dim.Fill (), Height = Dim.Fill () - 2 };
- win.Add (imageView);
+ win.Add (_imageView);
var lbl = new Label { Y = Pos.AnchorEnd (), Text = "Image by Wikiscient" };
win.Add (lbl);
@@ -52,59 +50,55 @@ public class AnimationScenario : Scenario
Application.Run (win);
win.Dispose ();
Application.Shutdown ();
- Debug.Assert (!_appInitialized);
+ Debug.Assert (!Application.IsInitialized);
+ }
- Application.InitializedChanged -= OnAppInitializedChanged;
- return;
+ private void OnWinOnInitialized (object sender, EventArgs args)
+ {
+ DirectoryInfo dir;
- void OnWinOnInitialized (object sender, EventArgs args)
+ string assemblyLocation = Assembly.GetExecutingAssembly ().Location;
+
+ if (!string.IsNullOrEmpty (assemblyLocation))
{
- DirectoryInfo dir;
-
- string assemblyLocation = Assembly.GetExecutingAssembly ().Location;
-
- if (!string.IsNullOrEmpty (assemblyLocation))
- {
- dir = new DirectoryInfo (Path.GetDirectoryName (assemblyLocation));
- }
- else
- {
- dir = new DirectoryInfo (AppContext.BaseDirectory);
- }
-
- var f = new FileInfo (
- Path.Combine (dir.FullName, "Scenarios/AnimationScenario", "Spinning_globe_dark_small.gif")
- );
-
- if (!f.Exists)
- {
- Debug.WriteLine ($"Could not find {f.FullName}");
- MessageBox.ErrorQuery ("Could not find gif", $"Could not find\n{f.FullName}", "Ok");
-
- return;
- }
-
- imageView.SetImage (Image.Load (File.ReadAllBytes (f.FullName)));
-
- Task.Run (
- () =>
- {
- while (_appInitialized)
- {
- // When updating from a Thread/Task always use Invoke
- Application.Invoke (
- () =>
- {
- imageView.NextFrame ();
- imageView.SetNeedsDisplay ();
- });
-
- Task.Delay (100).Wait ();
- }
- });
+ dir = new DirectoryInfo (Path.GetDirectoryName (assemblyLocation));
}
- void OnAppInitializedChanged (object sender, EventArgs args) => _appInitialized = args.CurrentValue;
+ else
+ {
+ dir = new DirectoryInfo (AppContext.BaseDirectory);
+ }
+
+ var f = new FileInfo (
+ Path.Combine (dir.FullName, "Scenarios/AnimationScenario", "Spinning_globe_dark_small.gif")
+ );
+
+ if (!f.Exists)
+ {
+ Debug.WriteLine ($"Could not find {f.FullName}");
+ MessageBox.ErrorQuery ("Could not find gif", $"Could not find\n{f.FullName}", "Ok");
+
+ return;
+ }
+
+ _imageView.SetImage (Image.Load (File.ReadAllBytes (f.FullName)));
+
+ Task.Run (
+ () =>
+ {
+ while (Application.IsInitialized)
+ {
+ // When updating from a Thread/Task always use Invoke
+ Application.Invoke (
+ () =>
+ {
+ _imageView.NextFrame ();
+ _imageView.SetNeedsDisplay ();
+ });
+
+ Task.Delay (100).Wait ();
+ }
+ });
}
// This is a C# port of https://github.com/andraaspar/bitmap-to-braille by Andraaspar
diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs
index 0ecea1606..dca481cc3 100644
--- a/UICatalog/UICatalog.cs
+++ b/UICatalog/UICatalog.cs
@@ -4,6 +4,9 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.CommandLine;
+using System.CommandLine.Builder;
+using System.CommandLine.Help;
+using System.CommandLine.Parsing;
using System.Data;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
@@ -139,17 +142,17 @@ public class UICatalogApp
driverOption.AddAlias ("-d");
driverOption.AddAlias ("--d");
- Option benchmarkFlag = new Option ("--benchmark", "Enables benchmarking.");
+ Option benchmarkFlag = new Option ("--benchmark", "Enables benchmarking. If a Scenario is specified, just that Scenario will be benchmarked.");
benchmarkFlag.AddAlias ("-b");
benchmarkFlag.AddAlias ("--b");
- Option resultsFile = new Option ("--file", "The file to save benchmark results to. If not specified with --benchmark, the results will be displayed in a TableView.");
+ Option resultsFile = new Option ("--file", "The file to save benchmark results to. If not specified, the results will be displayed in a TableView.");
resultsFile.AddAlias ("-f");
resultsFile.AddAlias ("--f");
Argument scenarioArgument = new Argument (
- "scenario",
- description: "The name of the scenario to run.",
+ name: "scenario",
+ description: "The name of the Scenario to run. If not provided, the UI Catalog UI will be shown.",
getDefaultValue: () => "none"
).FromAmong (
_scenarios.Select (s => s.GetName ())
@@ -180,8 +183,17 @@ public class UICatalogApp
}
);
- rootCommand.Invoke (args);
+ bool helpShown = false;
+ var parser = new CommandLineBuilder (rootCommand)
+ .UseHelp (ctx => helpShown = true)
+ .Build ();
+ parser.Invoke (args);
+
+ if (helpShown)
+ {
+ return 0;
+ }
UICatalogMain (_options);
@@ -401,9 +413,9 @@ public class UICatalogApp
return;
}
- private static BenchmarkResults? RunScenario (Scenario scenario, bool benchsmark)
+ private static BenchmarkResults? RunScenario (Scenario scenario, bool benchmark)
{
- if (benchsmark)
+ if (benchmark)
{
scenario.StartBenchmark ();
}
@@ -411,12 +423,16 @@ public class UICatalogApp
Application.Init (driverName: _forceDriver);
scenario.TopLevelColorScheme = _topLevelColorScheme;
- Application.Screen = new (0, 0, 120, 40);
+ if (benchmark)
+ {
+ Application.Screen = new (0, 0, 120, 40);
+ }
+
scenario.Main ();
BenchmarkResults? results = null;
- if (benchsmark)
+ if (benchmark)
{
results = scenario.EndBenchmark ();
}
@@ -442,7 +458,7 @@ public class UICatalogApp
if (maxScenarios == 0)
{
- // break;
+ // break;
}
}