From 2dfb3fb79855bf87e7d5c1b5fcc5e761e92c02c8 Mon Sep 17 00:00:00 2001 From: Tom Laird-McConnell Date: Thu, 5 Dec 2024 10:18:59 -0800 Subject: [PATCH] update readmes Add ConsoloniaApplication Cleaned up turbovision stuff --- Directory.Build.props | 2 +- src/Consolonia.Core/Consolonia.Core.csproj | 2 +- .../Infrastructure/ConsoloniaApplication.cs | 14 +++++ src/Consolonia.Core/README.md | 57 ++++++++++++++++++- src/Consolonia.Designer/ConsolePreview.cs | 11 ---- .../Consolonia.Designer.csproj | 7 ++- src/Consolonia.Designer/Extensions.cs | 4 +- src/Consolonia.Designer/README.md | 19 ++++++- src/Consolonia.Gallery/App.cs | 8 +-- src/Consolonia.NUnit/Consolonia.NUnit.csproj | 2 +- src/Consolonia.NUnit/README.md | 33 ++++++++++- .../Consolonia.PlatformSupport.csproj | 2 +- src/Consolonia.PlatformSupport/README.md | 12 +++- .../Consolonia.Themes.TurboVision.csproj | 2 +- src/Consolonia.Themes.TurboVision/README.md | 9 ++- .../Themes/{Fluent => }/FluentTheme.cs | 5 +- .../Themes/{Material => }/MaterialTheme.cs | 6 +- .../TurboVisionBlackTheme.cs | 5 +- .../TurboVisionDarkTheme.cs | 6 +- .../{Templates => Themes}/TurboVisionTheme.cs | 6 +- src/Example/App.axaml | 9 --- src/Example/App.axaml.cs | 18 ------ src/Example/App.cs | 20 +++++++ src/Example/Program.cs | 19 ++++--- src/Tests/Consolonia.Core.Tests/MiscTests.cs | 26 +++++++++ .../Base/GalleryTestsBaseBase.cs | 2 +- .../Consolonia.PreviewHost.csproj | 2 +- 27 files changed, 232 insertions(+), 76 deletions(-) rename src/Consolonia.Themes.TurboVision/Themes/{Fluent => }/FluentTheme.cs (76%) rename src/Consolonia.Themes.TurboVision/Themes/{Material => }/MaterialTheme.cs (75%) rename src/Consolonia.Themes.TurboVision/Themes/{TurboVisionBlack => }/TurboVisionBlackTheme.cs (74%) rename src/Consolonia.Themes.TurboVision/Themes/{TurboVisionDark => }/TurboVisionDarkTheme.cs (72%) rename src/Consolonia.Themes.TurboVision/{Templates => Themes}/TurboVisionTheme.cs (75%) delete mode 100644 src/Example/App.axaml delete mode 100644 src/Example/App.axaml.cs create mode 100644 src/Example/App.cs create mode 100644 src/Tests/Consolonia.Core.Tests/MiscTests.cs diff --git a/Directory.Build.props b/Directory.Build.props index 30484437..34cdf1ee 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,7 +5,7 @@ disable - 11.0.9 + 11.2.1 https://github.com/jinek/Consolonia/graphs/contributors Text User Interface implementation of Avalonia UI (GUI Framework) Copyright © Evgeny Gorbovoy 2021 - 2022 diff --git a/src/Consolonia.Core/Consolonia.Core.csproj b/src/Consolonia.Core/Consolonia.Core.csproj index 32e010f8..ef64cb24 100644 --- a/src/Consolonia.Core/Consolonia.Core.csproj +++ b/src/Consolonia.Core/Consolonia.Core.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs b/src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs index cda946f7..15176ce3 100644 --- a/src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs +++ b/src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs @@ -1,5 +1,7 @@ +using System; using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Media; @@ -59,4 +61,16 @@ public override void OnFrameworkInitializationCompleted() } } } + + public class ConsoloniaApplication : ConsoloniaApplication + where TMainWindow: Window + { + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + desktop.MainWindow = Activator.CreateInstance(); + + base.OnFrameworkInitializationCompleted(); + } + } } \ No newline at end of file diff --git a/src/Consolonia.Core/README.md b/src/Consolonia.Core/README.md index 4287de91..febb1204 100644 --- a/src/Consolonia.Core/README.md +++ b/src/Consolonia.Core/README.md @@ -3,7 +3,60 @@ TUI (Text User Interface) (GUI Framework) implementation for [Avalonia UI](https Supports XAML, data bindings, animation, styling and the rest from Avalonia. -## Showcase (click picture to see video) +# Showcase (click picture to see video) [![datagridpic](https://user-images.githubusercontent.com/10516222/141980173-4eb4057a-6996-45bf-83f6-931316c98d88.png)](https://youtu.be/ttgZmbruk3Y) -This package is the core Consolonia support. \ No newline at end of file +This package is the core Consolonia library. + +# Usage +Define an application with a theme (See Consolonia.Themes.TurboVision for themes) + +## Define a Window +HelloWorldWindow.axaml +```xaml + + + +``` + +## Define an application +You need to define an application that defines a theme and sets the main window. + +HelloWorldApp.cs +```csharp +// use HelloWorldWindow as the MainWindow for the application +public class HelloWorldApp : ConsoloniaApplication +{ + public override void Initialize() + { + // set the theme + Styles.Add(new MaterialTheme()); + } +} +``` + + +## Setup program.cs + +Program.cs +```csharp +[STAThread] +private static void Main(string[] args) +{ + BuildAvaloniaApp() + .StartWithConsoleLifetime(args); +} + +public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UseConsolonia() + .UseAutoDetectedConsole() + .LogToException(); +``` + +> **NOTE:** +> * You need package **Consolonia**.**Themes**.**TurboVision** for themes +> * You need package **Consolonia**.**PlatformSupport** to add an IConsole implementation via the .UseAutoDetectedConsole() method + \ No newline at end of file diff --git a/src/Consolonia.Designer/ConsolePreview.cs b/src/Consolonia.Designer/ConsolePreview.cs index 92a40bb9..5be89b3e 100644 --- a/src/Consolonia.Designer/ConsolePreview.cs +++ b/src/Consolonia.Designer/ConsolePreview.cs @@ -2,7 +2,6 @@ using Avalonia; using Avalonia.Controls; -#if DEBUG using Consolonia.PreviewHost; using System; using System.Diagnostics; @@ -15,7 +14,6 @@ using Avalonia.Threading; using Consolonia.Core.Drawing.PixelBufferImplementation; using Newtonsoft.Json; -#endif namespace Consolonia.Designer { @@ -45,7 +43,6 @@ public class ConsolePreview : UserControl public ConsolePreview() { -#if DEBUG _process = null; FontFamily = FontFamily.Parse("Cascadia Mono"); Initialized += (_, _) => LoadXaml(); @@ -54,7 +51,6 @@ public ConsolePreview() { if (e.Property == FileNameProperty) LoadXaml(); }; -#endif } @@ -102,7 +98,6 @@ protected void Dispose(bool disposing) if (disposing) { // TODO: dispose managed state (managed objects) -#if DEBUG #pragma warning disable CA1416 // Validate platform compatibility if (_process != null) { @@ -111,7 +106,6 @@ protected void Dispose(bool disposing) _process = null; } #pragma warning restore CA1416 // Validate platform compatibility -#endif } _disposedValue = true; @@ -125,14 +119,10 @@ public void Dispose() Dispose(true); } -#if DEBUG private Process? _process; private readonly Typeface _typeface = new("Cascadia Mono"); private double _charWidth; private double _charHeight; -#endif - -#if DEBUG private void LoadXaml() { @@ -451,6 +441,5 @@ public void Flush() _textRunCharWidth = 0; } } -#endif } } \ No newline at end of file diff --git a/src/Consolonia.Designer/Consolonia.Designer.csproj b/src/Consolonia.Designer/Consolonia.Designer.csproj index 375a4be5..0ad7294e 100644 --- a/src/Consolonia.Designer/Consolonia.Designer.csproj +++ b/src/Consolonia.Designer/Consolonia.Designer.csproj @@ -1,7 +1,10 @@ - + + false + + @@ -17,7 +20,7 @@ - + diff --git a/src/Consolonia.Designer/Extensions.cs b/src/Consolonia.Designer/Extensions.cs index e6722a4d..12cfb558 100644 --- a/src/Consolonia.Designer/Extensions.cs +++ b/src/Consolonia.Designer/Extensions.cs @@ -19,13 +19,11 @@ public static class Extensions /// public static AppBuilder UseConsoloniaDesigner(this AppBuilder builder) { -#if DEBUG - if (Design.IsDesignMode) //AppDomain.CurrentDomain.FriendlyName == "Avalonia.Designer.HostApp") + if (Design.IsDesignMode) return builder .UsePlatformDetect() .WithInterFont() .LogToTrace(); -#endif return builder.UseConsolonia(); } diff --git a/src/Consolonia.Designer/README.md b/src/Consolonia.Designer/README.md index 7f576338..8e8f844d 100644 --- a/src/Consolonia.Designer/README.md +++ b/src/Consolonia.Designer/README.md @@ -6,4 +6,21 @@ Supports XAML, data bindings, animation, styling and the rest from Avalonia. ## Showcase (click picture to see video) [![datagridpic](https://user-images.githubusercontent.com/10516222/141980173-4eb4057a-6996-45bf-83f6-931316c98d88.png)](https://youtu.be/ttgZmbruk3Y) -This package is the Consolonia support for design time previews. \ No newline at end of file +This package **EXPERIMENTAL** Consolonia support for design time previews. + +## Usage +```csharp +[STAThread] +private static void Main(string[] args) +{ + BuildAvaloniaApp() + .StartWithConsoleLifetime(args); +} + +public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UseConsoloniaDesigner() + .UseAutoDetectedConsole() + .LogToException(); +``` + diff --git a/src/Consolonia.Gallery/App.cs b/src/Consolonia.Gallery/App.cs index dee28c8f..8fb77bc2 100644 --- a/src/Consolonia.Gallery/App.cs +++ b/src/Consolonia.Gallery/App.cs @@ -5,7 +5,7 @@ using Avalonia.Styling; using Consolonia.Core.Infrastructure; using Consolonia.Gallery.View; -using Consolonia.Themes.TurboVision.Themes.Material; +using Consolonia.Themes.TurboVision.Themes; namespace Consolonia.Gallery { @@ -19,9 +19,9 @@ static App() public App() { - // Styles.Add(new TurboVisionTheme(new Uri("avares://Consolonia.Themes.TurboVision/Themes/TurboVisionDark/TurboVisionDark.axaml"))); - Styles.Add(new MaterialTheme(new Uri("avares://Consolonia.Themes.TurboVision/Themes/Material/Material.axaml"))); - // Styles.Add(new FluentTheme(new Uri("avares://Consolonia.Themes.TurboVision/Themes/Fluent/Fluent.axaml"))); + // Styles.Add(new TurboVisionTheme()); + Styles.Add(new MaterialTheme()); + // Styles.Add(new FluentTheme()); } public override void RegisterServices() diff --git a/src/Consolonia.NUnit/Consolonia.NUnit.csproj b/src/Consolonia.NUnit/Consolonia.NUnit.csproj index 2c4bda34..5f104704 100644 --- a/src/Consolonia.NUnit/Consolonia.NUnit.csproj +++ b/src/Consolonia.NUnit/Consolonia.NUnit.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Consolonia.NUnit/README.md b/src/Consolonia.NUnit/README.md index 92292772..d890c865 100644 --- a/src/Consolonia.NUnit/README.md +++ b/src/Consolonia.NUnit/README.md @@ -9,6 +9,35 @@ Supports XAML, data bindings, animation, styling and the rest from Avalonia. ## Showcase (click picture to see video) [![datagridpic](https://user-images.githubusercontent.com/10516222/141980173-4eb4057a-6996-45bf-83f6-931316c98d88.png)](https://youtu.be/ttgZmbruk3Y) -Example of usage: https://github.com/jinek/ToolUI +This package provides testing support for testing consolonia controls using NUnit. -Solution contains one more readme file with coding information. +## Usage +To create a unit test against your consolonia application your test class should derive from ConsoloniaAppTestBase<App$gt;. + +You can define the size of your console by passing size parameter to base class. + +Then you can use UITest to interact with your application, and use UITest.AssertHasText() to verify the screen of text matches your expectation. + +### UITest.AssertHasText() +Takes one or more Regex patterns and verifies that the screen contains the text that matches the pattern. + +### UITest.AssertHasNoText() +Takes one or more Regex patterns and verifies that the screen does not contain the text that matches the pattern. + +## Example +```csharp + public class Tests : ConsoloniaAppTestBase + { + public Tests : base(new PixelBufferSize(80, 40)) + { + } + + + [Test] + public async Task DisplaysBasicText() + { + await UITest.KeyInput(Key.Tab); + await UITest.AssertHasText("This is TextBlock"); + } + } +``` diff --git a/src/Consolonia.PlatformSupport/Consolonia.PlatformSupport.csproj b/src/Consolonia.PlatformSupport/Consolonia.PlatformSupport.csproj index 1e193695..1c672ec2 100644 --- a/src/Consolonia.PlatformSupport/Consolonia.PlatformSupport.csproj +++ b/src/Consolonia.PlatformSupport/Consolonia.PlatformSupport.csproj @@ -11,7 +11,7 @@ - +