diff --git a/SelfContained/Program.cs b/SelfContained/Program.cs new file mode 100644 index 000000000..6c4aac778 --- /dev/null +++ b/SelfContained/Program.cs @@ -0,0 +1,87 @@ +// This is a simple example application for a self-contained single file. + +using System.Diagnostics.CodeAnalysis; +using Terminal.Gui; + +namespace SelfContained; + +public static class Program +{ + [RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Run(Func, ConsoleDriver)")] + private static void Main (string [] args) + { + Application.Run ().Dispose (); + + // Before the application exits, reset Terminal.Gui for clean shutdown + Application.Shutdown (); + + 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); + } +} diff --git a/SelfContained/Properties/PublishProfiles/FolderProfile_net8.0_linux-x64.pubxml b/SelfContained/Properties/PublishProfiles/FolderProfile_net8.0_linux-x64.pubxml new file mode 100644 index 000000000..e6a8e8980 --- /dev/null +++ b/SelfContained/Properties/PublishProfiles/FolderProfile_net8.0_linux-x64.pubxml @@ -0,0 +1,16 @@ + + + + + Release + Any CPU + bin\Release\net8.0\publish\linux-x64\ + FileSystem + <_TargetId>Folder + net8.0 + linux-x64 + true + + \ No newline at end of file diff --git a/SelfContained/Properties/PublishProfiles/FolderProfile_net8.0_osx-x64.pubxml b/SelfContained/Properties/PublishProfiles/FolderProfile_net8.0_osx-x64.pubxml new file mode 100644 index 000000000..669139a88 --- /dev/null +++ b/SelfContained/Properties/PublishProfiles/FolderProfile_net8.0_osx-x64.pubxml @@ -0,0 +1,16 @@ + + + + + Release + Any CPU + bin\Release\net8.0\publish\osx-x64\ + FileSystem + <_TargetId>Folder + net8.0 + osx-x64 + true + + \ No newline at end of file diff --git a/SelfContained/Properties/PublishProfiles/FolderProfile_net8.0_win-x64.pubxml b/SelfContained/Properties/PublishProfiles/FolderProfile_net8.0_win-x64.pubxml new file mode 100644 index 000000000..4fadc2fd2 --- /dev/null +++ b/SelfContained/Properties/PublishProfiles/FolderProfile_net8.0_win-x64.pubxml @@ -0,0 +1,17 @@ + + + + + Release + Any CPU + bin\Release\net8.0\publish\win-x64\ + FileSystem + <_TargetId>Folder + net8.0 + win-x64 + true + false + + \ No newline at end of file diff --git a/SelfContained/SelfContained.csproj b/SelfContained/SelfContained.csproj new file mode 100644 index 000000000..eb3bcb4f4 --- /dev/null +++ b/SelfContained/SelfContained.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + enable + enable + true + Link + true + true + embedded + + + + + + + +