-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add a native AOT project. * Fixes Text.Json to work with native AOT. * Fix silent errors on unit tests when testing the Red color which has a length of 3. * Allowing test custom configuration without the config.json file match the unit tests configurations. * Fix unit test if tested alone. * Add native project into solution. * Fix merge errors. * Setting ConfigurationManager.ThrowOnJsonErrors as true to throw any serialization issue when published file runs. * Remove unnecessary using's. * Added unit test to ensure all serialization is properly configured. * Fix warnings. * Remove ThrowOnJsonErrors. * Fix warnings. --------- Co-authored-by: Tig <[email protected]>
- Loading branch information
Showing
27 changed files
with
443 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PublishAot>true</PublishAot> | ||
<InvariantGlobalization>false</InvariantGlobalization> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<ProjectReference Include="..\Terminal.Gui\Terminal.Gui.csproj" /> | ||
<TrimmerRootAssembly Include="Terminal.Gui" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<PackageReference Include="Terminal.Gui" Version="[2.0.0-pre.1788,3)" /> | ||
<TrimmerRootAssembly Include="Terminal.Gui" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// This is a test application for a native Aot file. | ||
|
||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Globalization; | ||
using Terminal.Gui; | ||
|
||
namespace NativeAot; | ||
|
||
public static class Program | ||
{ | ||
[RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Init(ConsoleDriver, String)")] | ||
[RequiresDynamicCode ("Calls Terminal.Gui.Application.Init(ConsoleDriver, String)")] | ||
private static void Main (string [] args) | ||
{ | ||
Application.Init (); | ||
|
||
#region The code in this region is not intended for use in a native Aot self-contained. It's just here to make sure there is no functionality break with localization in Terminal.Gui using self-contained | ||
|
||
if (Equals(Thread.CurrentThread.CurrentUICulture, CultureInfo.InvariantCulture) && Application.SupportedCultures.Count == 0) | ||
{ | ||
// Only happens if the project has <InvariantGlobalization>true</InvariantGlobalization> | ||
Debug.Assert (Application.SupportedCultures.Count == 0); | ||
} | ||
else | ||
{ | ||
Debug.Assert (Application.SupportedCultures.Count > 0); | ||
Debug.Assert (Equals (CultureInfo.CurrentCulture, Thread.CurrentThread.CurrentUICulture)); | ||
} | ||
|
||
#endregion | ||
|
||
ExampleWindow app = new (); | ||
Application.Run (app); | ||
|
||
// Dispose the app object before shutdown | ||
app.Dispose (); | ||
|
||
// Before the application exits, reset Terminal.Gui for clean shutdown | ||
Application.Shutdown (); | ||
|
||
// To see this output on the screen it must be done after shutdown, | ||
// which restores the previous screen. | ||
Console.WriteLine ($@"Username: {ExampleWindow.UserName}"); | ||
} | ||
} | ||
|
||
// Defines a top-level window with border and title | ||
public class ExampleWindow : Window | ||
{ | ||
public static string? UserName; | ||
|
||
public ExampleWindow () | ||
{ | ||
Title = $"Example App ({Application.QuitKey} to quit)"; | ||
|
||
// Create input components and labels | ||
var usernameLabel = new Label { Text = "Username:" }; | ||
|
||
var userNameText = new TextField | ||
{ | ||
// Position text field adjacent to the label | ||
X = Pos.Right (usernameLabel) + 1, | ||
|
||
// Fill remaining horizontal space | ||
Width = Dim.Fill () | ||
}; | ||
|
||
var passwordLabel = new Label | ||
{ | ||
Text = "Password:", X = Pos.Left (usernameLabel), Y = Pos.Bottom (usernameLabel) + 1 | ||
}; | ||
|
||
var passwordText = new TextField | ||
{ | ||
Secret = true, | ||
|
||
// align with the text box above | ||
X = Pos.Left (userNameText), | ||
Y = Pos.Top (passwordLabel), | ||
Width = Dim.Fill () | ||
}; | ||
|
||
// Create login button | ||
var btnLogin = new Button | ||
{ | ||
Text = "Login", | ||
Y = Pos.Bottom (passwordLabel) + 1, | ||
|
||
// center the login button horizontally | ||
X = Pos.Center (), | ||
IsDefault = true | ||
}; | ||
|
||
// When login button is clicked display a message popup | ||
btnLogin.Accept += (s, e) => | ||
{ | ||
if (userNameText.Text == "admin" && passwordText.Text == "password") | ||
{ | ||
MessageBox.Query ("Logging In", "Login Successful", "Ok"); | ||
UserName = userNameText.Text; | ||
Application.RequestStop (); | ||
} | ||
else | ||
{ | ||
MessageBox.ErrorQuery ("Logging In", "Incorrect username or password", "Ok"); | ||
} | ||
}; | ||
|
||
// Add the views to the Window | ||
Add (usernameLabel, userNameText, passwordLabel, passwordText, btnLogin); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
NativeAot/Properties/PublishProfiles/FolderProfile_net8.0_win-x64_Debug.pubxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
https://go.microsoft.com/fwlink/?LinkID=208121. | ||
--> | ||
<Project> | ||
<PropertyGroup> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Any CPU</Platform> | ||
<PublishDir>bin\Debug\net8.0\publish\win-x64\</PublishDir> | ||
<PublishProtocol>FileSystem</PublishProtocol> | ||
<_TargetId>Folder</_TargetId> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RuntimeIdentifier>win-x64</RuntimeIdentifier> | ||
<SelfContained>true</SelfContained> | ||
<PublishSingleFile>false</PublishSingleFile> | ||
<PublishReadyToRun>false</PublishReadyToRun> | ||
</PropertyGroup> | ||
</Project> |
18 changes: 18 additions & 0 deletions
18
NativeAot/Properties/PublishProfiles/FolderProfile_net8.0_win-x64_Release.pubxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
https://go.microsoft.com/fwlink/?LinkID=208121. | ||
--> | ||
<Project> | ||
<PropertyGroup> | ||
<Configuration>Release</Configuration> | ||
<Platform>Any CPU</Platform> | ||
<PublishDir>bin\Release\net8.0\publish\win-x64\</PublishDir> | ||
<PublishProtocol>FileSystem</PublishProtocol> | ||
<_TargetId>Folder</_TargetId> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RuntimeIdentifier>win-x64</RuntimeIdentifier> | ||
<SelfContained>true</SelfContained> | ||
<PublishSingleFile>false</PublishSingleFile> | ||
<PublishReadyToRun>false</PublishReadyToRun> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
dotnet clean | ||
dotnet build | ||
dotnet publish -c Debug -r linux-x64 --self-contained |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
dotnet clean | ||
dotnet build | ||
dotnet publish -c Release -r linux-x64 --self-contained |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
dotnet clean | ||
dotnet build | ||
dotnet publish -c Debug -r osx-x64 --self-contained |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
dotnet clean | ||
dotnet build | ||
dotnet publish -c Release -r osx-x64 --self-contained |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Terminal.Gui C# SelfContained | ||
|
||
This project aims to test the `Terminal.Gui` library to create a simple `native AOT` `self-container` GUI application in C#, ensuring that all its features are available. | ||
|
||
With `Debug` the `.csproj` is used and with `Release` the latest `nuget package` is used, either in `Solution Configurations` or in `Profile Publish` or in the `Publish_linux-x64` or in the `Publish_osx-x64` files. | ||
Unlike self-contained single-file publishing, native AOT publishing must be generated on the same platform as the target execution version. Therefore, if the target execution is Linux, then the publishing must be generated on a Linux operating system. Attempting to generate on Windows for the Linux target will throw an exception. | ||
|
||
To publish the `native AOT` file in `Debug` or `Release` mode, it is not necessary to select it in the `Solution Configurations`, just choose the `Debug` or `Release` configuration in the `Publish Profile` or the `*.sh` files. | ||
|
||
When executing the file directly from the `native AOT` file and needing to debug it, it will be necessary to attach it to the debugger, just like any other standalone application and selecting `Native Code`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,6 @@ | |
// Miguel de Icaza ([email protected]) | ||
// | ||
|
||
using System.Text.Json.Serialization; | ||
|
||
namespace Terminal.Gui; | ||
|
||
/// <summary>Button is a <see cref="View"/> that provides an item that invokes raises the <see cref="View.Accept"/> event.</summary> | ||
|
@@ -39,8 +37,6 @@ public class Button : View, IDesignable | |
/// Gets or sets whether <see cref="Button"/>s are shown with a shadow effect by default. | ||
/// </summary> | ||
[SerializableConfigurationProperty (Scope = typeof (ThemeScope))] | ||
[JsonConverter (typeof (JsonStringEnumConverter<ShadowStyle>))] | ||
|
||
public static ShadowStyle DefaultShadow { get; set; } = ShadowStyle.None; | ||
|
||
/// <summary>Initializes a new instance of <see cref="Button"/>.</summary> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.