Skip to content

Commit

Permalink
Merge branch 'main' into qodana-automation-1498580887
Browse files Browse the repository at this point in the history
  • Loading branch information
jinek authored Dec 8, 2024
2 parents ac0bcc2 + 62b0f1b commit 30b34de
Show file tree
Hide file tree
Showing 341 changed files with 10,165 additions and 2,481 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/PublishIncrementalNuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Publish Incremental Nuget Release

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: Bump build version
id: bump
uses: vers-one/[email protected]
with:
files: |
"**/Consolonia.csproj"
version: bump-build

- name: Restore dependencies
run: dotnet restore src/Consolonia.sln

- name: Build
run: dotnet build src/Consolonia.sln -c Release --no-restore

- name: dotnet pack
run: |
dotnet pack src/Consolonia.sln -c Release -o packages --include-symbols --property WarningLevel=0
- name: Publish NuGet and symbols
id: nuget-push
uses: edumserrano/nuget-push@v1
with:
api-key: '${{ secrets.NUGET_KEY }}'
working-directory: 'packages'
fail-if-exists: false

- name: Commit new version changes
run: |
git config --global user.name "Github Action"
git config --global user.email "[email protected]"
git commit -a -m "Bumped version for published nuget artifacts"
git push
35 changes: 35 additions & 0 deletions .github/workflows/PublishNuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish Nuget Release

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: Restore dependencies
run: dotnet restore src/Consolonia.sln

- name: Build
run: dotnet build src/Consolonia.sln -c Release --no-restore

- name: dotnet pack
run: |
dotnet pack src/Consolonia.sln -c Release -o packages --include-symbols --property WarningLevel=0
- name: Publish NuGet and symbols
id: nuget-push
uses: edumserrano/nuget-push@v1
with:
api-key: '${{ secrets.NUGET_KEY }}'
working-directory: 'packages'
fail-if-exists: false

2 changes: 1 addition & 1 deletion .github/workflows/editorconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x

- name: Restore
run: dotnet restore
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/general_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -766,3 +766,4 @@ fabric.properties
.idea/
*.sln.iml

/src/Tools/Consolonia.PreviewHost/Properties/launchSettings.json
13 changes: 10 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<Project>
<PropertyGroup>
<!--todo: add mono-->
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<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>
<PackageIcon>Icon.png</PackageIcon>
<NoWarn>AVA3001</NoWarn>
<IsPackable>False</IsPackable>
</PropertyGroup>
<PropertyGroup>
<AvaloniaVersion>11.0.9</AvaloniaVersion>
<AvaloniaVersion>11.2.1</AvaloniaVersion>
</PropertyGroup>
<ItemGroup Condition="'$(IsPackable)' != 'false'">
<None Include="$(SolutionDir)/../Icon.png" Pack="True" PackagePath="\" />
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>
Binary file added Icon.ico
Binary file not shown.
Binary file added Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ dotnet_diagnostic.ca1043.severity = none # todo: why not to use indexer rather t
dotnet_diagnostic.ca1814.severity = none # sometimes we need rectangle array
dotnet_diagnostic.ca1058.severity = none # check why new documentation warns not to derive from ApplicationException. The purpose of last is to distinguish system exceptions like OOM, AssemblyLoadException etc from application logic
dotnet_diagnostic.ca2000.severity = none # exceptions which are listed in the rule can be applied to any type
dotnet_diagnostic.CA2007.severity = none # we are assuming task continuation thread is fine by default
dotnet_diagnostic.ca2213.severity = none # keeping field does not mean necessarity to dispose - it can be dispose somwhere else
dotnet_diagnostic.ca2248.severity = none # https://github.com/dotnet/roslyn-analyzers/issues/4432
dotnet_diagnostic.ca1062.severity = none # we are fine with NRE - no need for additional checks
dotnet_diagnostic.ca1065.severity = none # senseless rules. Any code in .NET is executed in context of possible exceptions. Exception can happen anywhere
dotnet_diagnostic.CA1303.severity = none # we are assuming not to display any user-text. For the moment we are not supporting localization for exception messages
dotnet_diagnostic.cs0067.severity = warning
dotnet_diagnostic.cs0078.severity = warning
dotnet_diagnostic.cs0108.severity = warning
Expand Down
54 changes: 54 additions & 0 deletions src/Consolonia.Blazor/BuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using BlazorBindingsAvalonia;
using Microsoft.Extensions.DependencyInjection;

// ReSharper disable once CheckNamespace
namespace Consolonia
{
public static class BuilderExtensions
{
/// <summary>
/// Use Consolonize in Blazor mode
/// </summary>
/// <param name="builder"></param>
/// <param name="configureServices"></param>
/// <returns></returns>
public static AppBuilder UseConsoloniaBlazor(this AppBuilder builder,
Action<IServiceCollection> configureServices = null)
{
return builder
.UseConsolonia()
.UseAvaloniaBlazorBindings(sc =>
{
// Register services for injectoin
sc.AddSingleton(_ =>
{
var lifetime =
(IClassicDesktopStyleApplicationLifetime)Application.Current?.ApplicationLifetime;
ArgumentNullException.ThrowIfNull(lifetime);
return lifetime;
});
sc.AddTransient(sp =>
sp.GetRequiredService<IClassicDesktopStyleApplicationLifetime>().MainWindow?.StorageProvider);
sc.AddTransient(sp =>
sp.GetRequiredService<IClassicDesktopStyleApplicationLifetime>().MainWindow?.Clipboard);
sc.AddTransient(sp =>
sp.GetRequiredService<IClassicDesktopStyleApplicationLifetime>().MainWindow?.InsetsManager);
sc.AddTransient(sp =>
sp.GetRequiredService<IClassicDesktopStyleApplicationLifetime>().MainWindow?.InputPane);
sc.AddTransient(sp =>
sp.GetRequiredService<IClassicDesktopStyleApplicationLifetime>().MainWindow?.Launcher);
sc.AddTransient(sp =>
sp.GetRequiredService<IClassicDesktopStyleApplicationLifetime>().MainWindow?.Screens);
sc.AddTransient(sp =>
sp.GetRequiredService<IClassicDesktopStyleApplicationLifetime>().MainWindow?.FocusManager);
sc.AddTransient(sp =>
sp.GetRequiredService<IClassicDesktopStyleApplicationLifetime>().MainWindow?.PlatformSettings);

if (configureServices != null) configureServices(sc);
});
}
}
}
13 changes: 13 additions & 0 deletions src/Consolonia.Blazor/Consolonia.Blazor.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Core.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<ItemGroup>
<ProjectReference Include="..\Consolonia\Consolonia.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="BlazorBindingsAvalonia" Version="0.1.2" />
</ItemGroup>
</Project>
32 changes: 32 additions & 0 deletions src/Consolonia.Blazor/ConsoloniaBlazorApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Avalonia;
using Avalonia.Input;
using BlazorBindingsAvalonia;
using Consolonia.Core.Helpers;
using Consolonia.Core.Infrastructure;
using Microsoft.AspNetCore.Components;

namespace Consolonia.Blazor
{
/// <summary>
/// Use this application as your app base class to use Consolonia.Blazor Blazor engine.
/// </summary>
/// <typeparam name="TComponent">The root window for the application.</typeparam>
public class ConsoloniaBlazorApplication<TComponent> : BlazorBindingsApplication<TComponent>
where TComponent : IComponent
{
public override void RegisterServices()
{
base.RegisterServices();

AvaloniaLocator.CurrentMutable.Bind<IKeyboardNavigationHandler>()
.ToTransient<ArrowsAndKeyboardNavigationHandler>();
}

public override void OnFrameworkInitializationCompleted()
{
base.OnFrameworkInitializationCompleted();

this.AddConsoloniaDesignMode();
}
}
}
81 changes: 81 additions & 0 deletions src/Consolonia.Blazor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Consolonia.Blazor
This package provides the ability to use Blazor .razor files to create Consolonia applications.
* Use [⚡ Blazor](https://dotnet.microsoft.com/en-us/apps/aspnet/web-apps/blazor) syntax for [Avalonia](https://avaloniaui.net/) apps
* 😎 Simpler syntax than XAML
* 🪄 IntelliSense support
* Get free [🔥 Hot Reload](https://devblogs.microsoft.com/dotnet/introducing-net-hot-reload/) support on-top
* See https://github.com/Epictek/Avalonia-Blazor-Bindings

## Background
Consolonia is a TUI (Text User Interface) (GUI Framework) implementation for [Avalonia UI](https://github.com/AvaloniaUI)

## 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 Razor file
Things to note:
* Method binding to code behind
* Conditional layout of elements
* Full intellisense for renaming going to code behind autocomplete etc.
* injection of **INavigation** so you can push and pop views off of the nav stack
* injection of **IClassicDesktopStyleApplicationLifetime** so you can access Args and shutdown the app.
* HOT RELOAD. simple save the file and your view gets rebuilt and rerendered!

![blazor](https://github.com/user-attachments/assets/ae1ba484-b3a9-46c6-8c1b-99026e7f924c)

```razor
@page "/"
@inject INavigation navigation
@inject IClassicDesktopStyleApplicationLifetime lifetime
@namespace Example.Blazor.Components
<Window Title="Blazor Bindings for Consolonia" Topmost="true">
<StackPanel Orientation="Orientation.Vertical" VerticalAlignment="VerticalAlignment.Center">
@if (showCounter)
{
<TextBlock HorizontalAlignment="HorizontalAlignment.Center">Counter: @CounterText</TextBlock>
}
<StackPanel Orientation="Orientation.Vertical" HorizontalAlignment="HorizontalAlignment.Center" Margin="@Thickness.Parse("4")">
<Button OnClick="@OnIncrement">Increment counter support</Button>
<Button OnClick="@OnToggleCounter">@ToggleText</Button>
<Button OnClick="@OnMessageBox">Message Box</Button>
<Button OnClick="@OnGotoSubPage">Go to SubPage</Button>
<Button OnClick="@OnExit">Exit</Button>
</StackPanel>
</StackPanel>
</Window>
@code {
int counter = 0;
bool showCounter = true;
string CounterText => counter switch
{
0 => "Not clicked",
1 => $"Clicked 1 time",
_ => $"Clicked {counter} times"
};
string ToggleText => showCounter ? "Hide Counter" : "Show Counter";
void OnIncrement()
=> counter++;
void OnToggleCounter()
=> showCounter = !showCounter;
void OnGotoSubPage()
=> navigation.PushAsync<SubPage>();
async void OnMessageBox(RoutedEventArgs args)
{
await new MessageBox()
.ShowDialogAsync((AC.Control)args.Source!, "Hello, Blazor!", "Blazor Bindings for Consolonia");
}
void OnExit()
=> lifetime.Shutdown();
}
```
4 changes: 2 additions & 2 deletions src/Consolonia.Core/ApplicationStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
using Consolonia.Core.Infrastructure;

// ReSharper disable UnusedMember.Global //todo: how to disable it for public methods?

// ReSharper disable CheckNamespace
// ReSharper disable MemberCanBePrivate.Global

namespace Consolonia.Core
namespace Consolonia
{
public static class ApplicationStartup
{
Expand Down
3 changes: 2 additions & 1 deletion src/Consolonia.Core/Assembly.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Consolonia.TestsCore")]
[assembly: InternalsVisibleTo("Consolonia.Core.Tests")]
[assembly: InternalsVisibleTo("Consolonia.Designer")]

[assembly: CLSCompliant(false)] //todo: should we make it compliant?
12 changes: 7 additions & 5 deletions src/Consolonia.Core/Consolonia.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Core.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Core.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.FreeDesktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="$(AvaloniaVersion)" />
<PackageReference Include="Crayon" Version="2.0.69" />
<PackageReference Include="NullLib.ConsoleEx" Version="1.0.4.4" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
<PackageReference Include="Unicode.net" Version="2.0.0" />
<PackageReference Include="Wcwidth" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Avalonia.VisualTree;
using Consolonia.Core.Helpers;

namespace Consolonia.Themes.TurboVision.Templates.Controls.Dialog
namespace Consolonia.Core.Controls.Dialog
{
public class DialogHost
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:drawing1="clr-namespace:Consolonia.Core.Drawing;assembly=Consolonia.Core"
x:Class="Consolonia.Themes.TurboVision.Templates.Controls.DialogWrap">
x:Class="Consolonia.Core.Controls.Dialog.DialogWrap">

<Panel>
<Border Background="{drawing1:ConsoleBrush Mode=Shaded}"
Expand Down
Loading

0 comments on commit 30b34de

Please sign in to comment.