mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
WIP: submitting #4429
This commit is contained in:
@@ -12,9 +12,7 @@ using Terminal.Gui.Views;
|
||||
// Example metadata
|
||||
[assembly: Terminal.Gui.Examples.ExampleMetadata ("Simple Example", "A basic login form demonstrating Terminal.Gui fundamentals")]
|
||||
[assembly: Terminal.Gui.Examples.ExampleCategory ("Getting Started")]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:500", "a", "d", "m", "i", "n", "Tab", "p", "a", "s", "s", "w", "o", "r", "d", "Enter"], Order = 1)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:500", "Enter"], Order = 2)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:100", "Esc"], Order = 3)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["a", "d", "m", "i", "n", "Tab", "p", "a", "s", "s", "w", "o", "r", "d", "Enter", "Esc"], Order = 1)]
|
||||
|
||||
// Override the default configuration for the application to use the Light theme
|
||||
ConfigurationManager.RuntimeConfig = """{ "Theme": "Light" }""";
|
||||
@@ -23,19 +21,18 @@ ConfigurationManager.Enable (ConfigLocations.All);
|
||||
IApplication app = Application.Create (example: true);
|
||||
app.Init ();
|
||||
app.Run<ExampleWindow> ();
|
||||
string? result = app.GetResult<string> ();
|
||||
|
||||
// Dispose the app to clean up and enable Console.WriteLine below
|
||||
app.Dispose ();
|
||||
|
||||
// To see this output on the screen it must be done after shutdown,
|
||||
// which restores the previous screen.
|
||||
Console.WriteLine ($@"Username: {ExampleWindow.UserName}");
|
||||
Console.WriteLine ($@"Username: {result}");
|
||||
|
||||
// Defines a top-level window with border and title
|
||||
public sealed class ExampleWindow : Window
|
||||
{
|
||||
public static string UserName { get; set; }
|
||||
|
||||
public ExampleWindow ()
|
||||
{
|
||||
Title = $"Example App ({Application.QuitKey} to quit)";
|
||||
@@ -84,8 +81,8 @@ public sealed class ExampleWindow : Window
|
||||
if (userNameText.Text == "admin" && passwordText.Text == "password")
|
||||
{
|
||||
MessageBox.Query (App, "Logging In", "Login Successful", "Ok");
|
||||
UserName = userNameText.Text;
|
||||
Application.RequestStop ();
|
||||
Result = userNameText.Text;
|
||||
App?.RequestStop ();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -98,14 +95,5 @@ public sealed class ExampleWindow : Window
|
||||
|
||||
// Add the views to the Window
|
||||
Add (usernameLabel, userNameText, passwordLabel, passwordText, btnLogin);
|
||||
|
||||
var lv = new ListView
|
||||
{
|
||||
Y = Pos.AnchorEnd (),
|
||||
Height = Dim.Auto (),
|
||||
Width = Dim.Auto ()
|
||||
};
|
||||
lv.SetSource (["One", "Two", "Three", "Four"]);
|
||||
Add (lv);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
<Version>2.0</Version>
|
||||
<InformationalVersion>2.0</InformationalVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Serilog" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" />
|
||||
<PackageReference Include="Serilog.Sinks.Debug" />
|
||||
<PackageReference Include="Serilog.Sinks.File" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Terminal.Gui\Terminal.Gui.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,16 +1,34 @@
|
||||
#nullable enable
|
||||
// Example Runner - Demonstrates discovering and running all examples using the example infrastructure
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
using Terminal.Gui.App;
|
||||
using Terminal.Gui.Configuration;
|
||||
using Terminal.Gui.Examples;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
[assembly: ExampleMetadata ("Example Runner", "Discovers and runs all examples sequentially")]
|
||||
[assembly: ExampleCategory ("Infrastructure")]
|
||||
// Configure Serilog to write to Debug output and Console
|
||||
Log.Logger = new LoggerConfiguration ()
|
||||
.MinimumLevel.Is (LogEventLevel.Verbose)
|
||||
.WriteTo.Debug ()
|
||||
.CreateLogger ();
|
||||
|
||||
ILogger logger = LoggerFactory.Create (builder =>
|
||||
{
|
||||
builder
|
||||
.AddSerilog (dispose: true) // Integrate Serilog with ILogger
|
||||
.SetMinimumLevel (LogLevel.Trace); // Set minimum log level
|
||||
}).CreateLogger ("ExampleRunner Logging");
|
||||
Logging.Logger = logger;
|
||||
|
||||
Logging.Debug ("Logging enabled - writing to Debug output\n");
|
||||
|
||||
// Parse command line arguments
|
||||
bool useFakeDriver = args.Contains ("--fake-driver") || args.Contains ("-f");
|
||||
int timeout = 5000; // Default timeout in milliseconds
|
||||
int timeout = 30000; // Default timeout in milliseconds
|
||||
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
@@ -131,4 +149,7 @@ if (useFakeDriver)
|
||||
Console.WriteLine ("\nNote: Tests run with FakeDriver. Some examples may timeout if they don't respond to Esc key.");
|
||||
}
|
||||
|
||||
// Flush logs before exiting
|
||||
Log.CloseAndFlush ();
|
||||
|
||||
return failCount == 0 ? 0 : 1;
|
||||
|
||||
@@ -10,11 +10,11 @@ using Terminal.Gui.Views;
|
||||
[assembly: Terminal.Gui.Examples.ExampleMetadata ("Runnable Wrapper Example", "Shows how to wrap any View to make it runnable without implementing IRunnable")]
|
||||
[assembly: Terminal.Gui.Examples.ExampleCategory ("API Patterns")]
|
||||
[assembly: Terminal.Gui.Examples.ExampleCategory ("Views")]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:200", "t", "e", "s", "t", "Esc"], Order = 1)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:200", "Enter", "Esc"], Order = 2)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:200", "Enter", "Esc"], Order = 3)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:200", "Enter", "Esc"], Order = 4)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["SetDelay:200", "Enter", "Esc"], Order = 5)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["t", "e", "s", "t", "Esc"], Order = 1)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["Enter", "Esc"], Order = 2)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["Enter", "Esc"], Order = 3)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["Enter", "Esc"], Order = 4)]
|
||||
[assembly: Terminal.Gui.Examples.ExampleDemoKeyStrokes (KeyStrokes = ["Enter", "Esc"], Order = 5)]
|
||||
|
||||
IApplication app = Application.Create (example: true);
|
||||
app.Init ();
|
||||
|
||||
Reference in New Issue
Block a user