Skip to content

Commit

Permalink
update readmes
Browse files Browse the repository at this point in the history
Add ConsoloniaApplication<MainWindow>
Cleaned up turbovision stuff
  • Loading branch information
tomlm committed Dec 5, 2024
1 parent 31611eb commit 2dfb3fb
Show file tree
Hide file tree
Showing 27 changed files with 232 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>disable</Nullable>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>11.0.9</VersionPrefix>
<VersionPrefix>11.2.1</VersionPrefix>
<Authors>https://github.com/jinek/Consolonia/graphs/contributors</Authors>
<Description>Text User Interface implementation of Avalonia UI (GUI Framework)</Description>
<Copyright>Copyright © Evgeny Gorbovoy 2021 - 2022</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion src/Consolonia.Core/Consolonia.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<None Include="../../Icon.png" Pack="True" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions src/Consolonia.Core/Infrastructure/ConsoloniaApplication.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -59,4 +61,16 @@ public override void OnFrameworkInitializationCompleted()
}
}
}

public class ConsoloniaApplication<TMainWindow> : ConsoloniaApplication
where TMainWindow: Window
{
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
desktop.MainWindow = Activator.CreateInstance<TMainWindow>();

base.OnFrameworkInitializationCompleted();
}
}
}
57 changes: 55 additions & 2 deletions src/Consolonia.Core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="HelloWorldWindow">
<TextBlock Text="Hello World">
</Window>
```

## 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<HelloWorldWindow>
{
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<HelloWorldApp>()
.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
11 changes: 0 additions & 11 deletions src/Consolonia.Designer/ConsolePreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using Avalonia;
using Avalonia.Controls;
#if DEBUG
using Consolonia.PreviewHost;
using System;
using System.Diagnostics;
Expand All @@ -15,7 +14,6 @@
using Avalonia.Threading;
using Consolonia.Core.Drawing.PixelBufferImplementation;
using Newtonsoft.Json;
#endif

namespace Consolonia.Designer
{
Expand Down Expand Up @@ -45,7 +43,6 @@ public class ConsolePreview : UserControl

public ConsolePreview()
{
#if DEBUG
_process = null;
FontFamily = FontFamily.Parse("Cascadia Mono");
Initialized += (_, _) => LoadXaml();
Expand All @@ -54,7 +51,6 @@ public ConsolePreview()
{
if (e.Property == FileNameProperty) LoadXaml();
};
#endif
}


Expand Down Expand Up @@ -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)
{
Expand All @@ -111,7 +106,6 @@ protected void Dispose(bool disposing)
_process = null;
}
#pragma warning restore CA1416 // Validate platform compatibility
#endif
}

_disposedValue = true;
Expand All @@ -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()
{
Expand Down Expand Up @@ -451,6 +441,5 @@ public void Flush()
_textRunCharWidth = 0;
}
}
#endif
}
}
7 changes: 5 additions & 2 deletions src/Consolonia.Designer/Consolonia.Designer.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Core.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.FreeDesktop" Version="$(AvaloniaVersion)" />
Expand All @@ -17,7 +20,7 @@

<ItemGroup>
<None Include="../../Icon.png" Pack="True" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
4 changes: 1 addition & 3 deletions src/Consolonia.Designer/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ public static class Extensions
/// </remarks>
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();
}
Expand Down
19 changes: 18 additions & 1 deletion src/Consolonia.Designer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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<App>()
.UseConsoloniaDesigner()
.UseAutoDetectedConsole()
.LogToException();
```

8 changes: 4 additions & 4 deletions src/Consolonia.Gallery/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Consolonia.NUnit/Consolonia.NUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<None Include="../../Icon.png" Pack="True" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
33 changes: 31 additions & 2 deletions src/Consolonia.NUnit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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&lt;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<App>
{
public Tests : base(new PixelBufferSize(80, 40))
{
}


[Test]
public async Task DisplaysBasicText()
{
await UITest.KeyInput(Key.Tab);
await UITest.AssertHasText("This is TextBlock");
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<ItemGroup>
<None Include="../../Icon.png" Pack="True" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

<!--
Expand Down
12 changes: 10 additions & 2 deletions src/Consolonia.PlatformSupport/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ 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 Consolonia IConsole platform support for adapting to consoles on Windows, Linux and MacOS environments.

Solution contains one more readme file with coding information.
## Usage
```csharp
AppBuilder BuildAvaloniaApp()
{
return AppBuilder.Configure<App>()
.UseConsolonia()
.UseAutoDetectedConsole();
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<None Include="../../Icon.png" Pack="True" PackagePath="\" />
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
9 changes: 6 additions & 3 deletions src/Consolonia.Themes.TurboVision/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ 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

Solution contains one more readme file with coding information.
This package defines 4 themes for Consolonia
* **MaterialTheme** - Material Design
* **FluentTheme** - Fluent Design
* **TurboVisionTheme** - Turbo Vision
* **TurboVisionDarkTheme** - Turbo Vision Dark
* **TurboVisionBlackTheme** - Turbo Vision Black
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
using System.Diagnostics.CodeAnalysis;
using Consolonia.Core.Styles;

namespace Consolonia.Themes.TurboVision.Themes.Fluent
namespace Consolonia.Themes
{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public class FluentTheme : ResourceIncludeBase
{
public FluentTheme() : base(new Uri("avares://Consolonia.Themes.TurboVision/Themes/Fluent/Fluent.axaml"))
{
}
public FluentTheme(Uri baseUri) : base(baseUri)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
using System.Diagnostics.CodeAnalysis;
using Consolonia.Core.Styles;

namespace Consolonia.Themes.TurboVision.Themes.Material
namespace Consolonia.Themes
{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public class MaterialTheme : ResourceIncludeBase
{
public MaterialTheme() : base(new Uri("avares://Consolonia.Themes.TurboVision/Themes/Material/Material.axaml"))
{
}

public MaterialTheme(Uri baseUri) : base(baseUri)
{
}
Expand Down
Loading

0 comments on commit 2dfb3fb

Please sign in to comment.