mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* touching publish.yml * Moved Examples into ./Examples * Moved Benchmarks into ./Tests * Moved Benchmarks into ./Tests * Moved UICatalog into ./Examples * Moved UICatalog into ./Examples 2 * Moved tests into ./Tests * Updated nuget
This commit is contained in:
114
Examples/SelfContained/Program.cs
Normal file
114
Examples/SelfContained/Program.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
// This is a test application for a self-contained single file.
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using Terminal.Gui;
|
||||
|
||||
namespace SelfContained;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
[RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Run<T>(Func<Exception, Boolean>, IConsoleDriver)")]
|
||||
private static void Main (string [] args)
|
||||
{
|
||||
Application.Init ();
|
||||
|
||||
#region The code in this region is not intended for use in a self-contained single-file. It's just here to make sure there is no functionality break with localization in Terminal.Gui using single-file
|
||||
|
||||
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.Accepting += (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");
|
||||
}
|
||||
// Anytime Accepting is handled, make sure to set e.Cancel to false.
|
||||
e.Cancel = false;
|
||||
};
|
||||
|
||||
// Add the views to the Window
|
||||
Add (usernameLabel, userNameText, passwordLabel, passwordText, btnLogin);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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\linux-x64\</PublishDir>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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\linux-x64\</PublishDir>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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\osx-x64\</PublishDir>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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\osx-x64\</PublishDir>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<_TargetId>Folder</_TargetId>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
|
||||
<SelfContained>true</SelfContained>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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>
|
||||
<PublishReadyToRun>false</PublishReadyToRun>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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>
|
||||
<PublishReadyToRun>false</PublishReadyToRun>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
9
Examples/SelfContained/README.md
Normal file
9
Examples/SelfContained/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Terminal.Gui C# SelfContained
|
||||
|
||||
This project aims to test the `Terminal.Gui` library to create a simple `self-contained` `single-file` 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`.
|
||||
|
||||
To publish the self-contained single 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`.
|
||||
|
||||
When executing the file directly from the self-contained single file and needing to debug it, it will be necessary to attach it to the debugger, just like any other standalone application. However, when trying to attach the file running on `Linux` or `macOS` to the debugger, it will issue the error "`Failed to attach to process: Unknown Error: 0x80131c3c`". This issue has already been reported on [Developer Community](https://developercommunity.visualstudio.com/t/Failed-to-attach-to-process:-Unknown-Err/10694351). Maybe it would be a good idea to vote in favor of this fix because I think `Visual Studio for macOS` is going to be discontinued and we need this fix to remotely attach a process running on `Linux` or `macOS` to `Windows 11`.
|
||||
23
Examples/SelfContained/SelfContained.csproj
Normal file
23
Examples/SelfContained/SelfContained.csproj
Normal file
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
<TrimMode>Link</TrimMode>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<InvariantGlobalization>false</InvariantGlobalization>
|
||||
<DebugType>embedded</DebugType>
|
||||
</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" />
|
||||
<TrimmerRootAssembly Include="Terminal.Gui" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user