Cleaned up launch settings

This commit is contained in:
Tig
2024-10-26 12:00:58 -07:00
parent 1a498962b1
commit 68bc258439
5 changed files with 99 additions and 107 deletions

View File

@@ -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; }
/// <summary>
/// Gets whether the application has been initialized with <see cref="Init"/> and not yet shutdown with <see cref="Shutdown"/>.
/// </summary>
/// <remarks>
/// <para>
/// The <see cref="InitializedChanged"/> event is raised after the <see cref="Init"/> and <see cref="Shutdown"/> methods have been called.
/// </para>
/// </remarks>
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.

View File

@@ -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"
}
}
}

View File

@@ -151,8 +151,8 @@ public class Scenario : IDisposable
/// </summary>
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 ();

View File

@@ -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<Rgba32> (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<bool> 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<Rgba32> (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

View File

@@ -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<bool> benchmarkFlag = new Option<bool> ("--benchmark", "Enables benchmarking.");
Option<bool> benchmarkFlag = new Option<bool> ("--benchmark", "Enables benchmarking. If a Scenario is specified, just that Scenario will be benchmarked.");
benchmarkFlag.AddAlias ("-b");
benchmarkFlag.AddAlias ("--b");
Option<string> resultsFile = new Option<string> ("--file", "The file to save benchmark results to. If not specified with --benchmark, the results will be displayed in a TableView.");
Option<string> resultsFile = new Option<string> ("--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<string> scenarioArgument = new Argument<string> (
"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;
}
}