From 39b39ddc7048324fc84d692486b0b8c9c53ea226 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 13 Jul 2024 19:40:33 +0100 Subject: [PATCH 01/11] Fixes #3611. Localization not working on self-contained single-file. --- SelfContained/Program.cs | 19 ++++++++++- SelfContained/SelfContained.csproj | 2 +- Terminal.Gui/Application/Application.cs | 40 ++++++++++++++++++----- UnitTests/Application/ApplicationTests.cs | 1 + 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/SelfContained/Program.cs b/SelfContained/Program.cs index b723bcbd4..f2f157670 100644 --- a/SelfContained/Program.cs +++ b/SelfContained/Program.cs @@ -1,6 +1,7 @@ // This is a simple example application for a self-contained single file. using System.Diagnostics.CodeAnalysis; +using System.Globalization; using Terminal.Gui; namespace SelfContained; @@ -10,7 +11,23 @@ public static class Program [RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Run(Func, ConsoleDriver)")] private static void Main (string [] args) { - Application.Run ().Dispose (); + Application.Init (); + + if (Equals (Thread.CurrentThread.CurrentUICulture, CultureInfo.InvariantCulture)) + { + System.Diagnostics.Debug.Assert (Application.SupportedCultures.Count == 0); + } + else + { + System.Diagnostics.Debug.Assert (Application.SupportedCultures.Count == 4); + System.Diagnostics.Debug.Assert (Equals (CultureInfo.CurrentCulture, Thread.CurrentThread.CurrentUICulture)); + } + + 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 (); diff --git a/SelfContained/SelfContained.csproj b/SelfContained/SelfContained.csproj index b4ffbe030..af651e3ca 100644 --- a/SelfContained/SelfContained.csproj +++ b/SelfContained/SelfContained.csproj @@ -8,7 +8,7 @@ true Link true - true + false embedded diff --git a/Terminal.Gui/Application/Application.cs b/Terminal.Gui/Application/Application.cs index 477553263..225eb17f3 100644 --- a/Terminal.Gui/Application/Application.cs +++ b/Terminal.Gui/Application/Application.cs @@ -48,7 +48,7 @@ public static partial class Application internal static List GetSupportedCultures () { - CultureInfo [] culture = CultureInfo.GetCultures (CultureTypes.AllCultures); + CultureInfo [] cultures = CultureInfo.GetCultures (CultureTypes.AllCultures); // Get the assembly var assembly = Assembly.GetExecutingAssembly (); @@ -57,15 +57,37 @@ public static partial class Application string assemblyLocation = AppDomain.CurrentDomain.BaseDirectory; // Find the resource file name of the assembly - var resourceFilename = $"{Path.GetFileNameWithoutExtension (AppContext.BaseDirectory)}.resources.dll"; + var resourceFilename = $"{assembly.GetName ().Name}.resources.dll"; - // Return all culture for which satellite folder found with culture code. - return culture.Where ( - cultureInfo => - Directory.Exists (Path.Combine (assemblyLocation, cultureInfo.Name)) - && File.Exists (Path.Combine (assemblyLocation, cultureInfo.Name, resourceFilename)) - ) - .ToList (); + if (cultures.Length > 1 && Directory.Exists (Path.Combine (assemblyLocation, "pt-PT"))) + { + // Return all culture for which satellite folder found with culture code. + return cultures.Where ( + cultureInfo => + Directory.Exists (Path.Combine (assemblyLocation, cultureInfo.Name)) + && File.Exists (Path.Combine (assemblyLocation, cultureInfo.Name, resourceFilename)) + ) + .ToList (); + } + + // It's called from a self-contained single.file. + try + { + // false + return + [ + new ("fr-FR"), + new ("ja-JP"), + new ("pt-PT"), + new ("zh-Hans") + ]; + } + catch (CultureNotFoundException) + { + // true + // Only the invariant culture is supported in globalization-invariant mode. + return []; + } } // When `End ()` is called, it is possible `RunState.Toplevel` is a different object than `Top`. diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index a7c1fc64a..e2d707e3d 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -193,6 +193,7 @@ public class ApplicationTests // Internal properties Assert.False (Application._initialized); Assert.Equal (Application.GetSupportedCultures (), Application.SupportedCultures); + Assert.Equal (4, Application.SupportedCultures.Count); Assert.False (Application._forceFakeConsole); Assert.Equal (-1, Application._mainThreadId); Assert.Empty (Application._topLevels); From ba4ab0c8c6aab183a704ab2016f6c765a27b9d5c Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 14 Jul 2024 18:34:57 +0100 Subject: [PATCH 02/11] Involving assertive code within a region. --- SelfContained/Program.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/SelfContained/Program.cs b/SelfContained/Program.cs index f2f157670..b16c8cd3e 100644 --- a/SelfContained/Program.cs +++ b/SelfContained/Program.cs @@ -1,5 +1,6 @@ // This is a simple example application for a self-contained single file. +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using Terminal.Gui; @@ -13,16 +14,20 @@ public static class Program { 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)) { - System.Diagnostics.Debug.Assert (Application.SupportedCultures.Count == 0); + Debug.Assert (Application.SupportedCultures.Count == 0); } else { - System.Diagnostics.Debug.Assert (Application.SupportedCultures.Count == 4); - System.Diagnostics.Debug.Assert (Equals (CultureInfo.CurrentCulture, Thread.CurrentThread.CurrentUICulture)); + Debug.Assert (Application.SupportedCultures.Count == 4); + Debug.Assert (Equals (CultureInfo.CurrentCulture, Thread.CurrentThread.CurrentUICulture)); } + #endregion + ExampleWindow app = new (); Application.Run (app); From 918299b86dcabaac9af8c65c12477afaa90ac24d Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 15 Jul 2024 22:35:39 +0100 Subject: [PATCH 03/11] Changing README explaining the purpose of this project. --- SelfContained/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SelfContained/README.md b/SelfContained/README.md index 91cc1eb5f..f4bd041ee 100644 --- a/SelfContained/README.md +++ b/SelfContained/README.md @@ -1,6 +1,6 @@ # Terminal.Gui C# SelfContained -This example shows how to use the `Terminal.Gui` library to create a simple `self-contained` `single file` GUI application in C#. +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`. From fbd7dc745e5034798d273f6f32709269cecdd8e1 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 16 Jul 2024 23:55:58 +0100 Subject: [PATCH 04/11] Changes comment for clarification. --- SelfContained/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SelfContained/Program.cs b/SelfContained/Program.cs index b16c8cd3e..ff6dd12b9 100644 --- a/SelfContained/Program.cs +++ b/SelfContained/Program.cs @@ -1,4 +1,4 @@ -// This is a simple example application for a self-contained single file. +// This is a test application for a self-contained single file. using System.Diagnostics; using System.Diagnostics.CodeAnalysis; From 88954b9ab772fdeb7dd339a9be8c23512a96128a Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 25 Jul 2024 18:04:46 +0100 Subject: [PATCH 05/11] Fix WSL InvariantCulture test. --- SelfContained/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SelfContained/Program.cs b/SelfContained/Program.cs index ff6dd12b9..51f4d7bb1 100644 --- a/SelfContained/Program.cs +++ b/SelfContained/Program.cs @@ -16,7 +16,7 @@ public static class Program #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)) + if (Equals (Thread.CurrentThread.CurrentUICulture, CultureInfo.InvariantCulture) && Application.SupportedCultures.Count == 0) { Debug.Assert (Application.SupportedCultures.Count == 0); } From 3e9f585348871a0b6fa131279c038dd5274276d7 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 26 Jul 2024 14:49:05 +0100 Subject: [PATCH 06/11] Fixes #3628. SixLabors.ImageSharp prior to version 3.1.5 are vulnerable. --- UICatalog/UICatalog.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UICatalog/UICatalog.csproj b/UICatalog/UICatalog.csproj index 8988e1ef4..6731e0395 100644 --- a/UICatalog/UICatalog.csproj +++ b/UICatalog/UICatalog.csproj @@ -31,7 +31,7 @@ - + From a225b421c813bac407e2a4b145971026428bc222 Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Sun, 28 Jul 2024 12:23:09 +0100 Subject: [PATCH 07/11] Update ReactiveUI Example --- ReactiveExample/FodyWeavers.xml | 3 - ReactiveExample/FodyWeavers.xsd | 26 --- ReactiveExample/LoginView.cs | 300 +++++++++++-------------- ReactiveExample/LoginViewModel.cs | 77 +++---- ReactiveExample/README.md | 2 +- ReactiveExample/ReactiveExample.csproj | 2 +- ReactiveExample/ViewExtensions.cs | 24 ++ 7 files changed, 188 insertions(+), 246 deletions(-) delete mode 100644 ReactiveExample/FodyWeavers.xml delete mode 100644 ReactiveExample/FodyWeavers.xsd create mode 100644 ReactiveExample/ViewExtensions.cs diff --git a/ReactiveExample/FodyWeavers.xml b/ReactiveExample/FodyWeavers.xml deleted file mode 100644 index 63fc14848..000000000 --- a/ReactiveExample/FodyWeavers.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/ReactiveExample/FodyWeavers.xsd b/ReactiveExample/FodyWeavers.xsd deleted file mode 100644 index f3ac47620..000000000 --- a/ReactiveExample/FodyWeavers.xsd +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. - - - - - A comma-separated list of error codes that can be safely ignored in assembly verification. - - - - - 'false' to turn off automatic generation of the XML Schema file. - - - - - \ No newline at end of file diff --git a/ReactiveExample/LoginView.cs b/ReactiveExample/LoginView.cs index 154bfbece..2a4876399 100644 --- a/ReactiveExample/LoginView.cs +++ b/ReactiveExample/LoginView.cs @@ -8,20 +8,137 @@ namespace ReactiveExample; public class LoginView : Window, IViewFor { - private readonly CompositeDisposable _disposable = new (); + private const string SuccessMessage = "The input is valid!"; + private const string ErrorMessage = "Please enter a valid user name and password."; + private const string ProgressMessage = "Logging in..."; + private const string IdleMessage = "Press 'Login' to log in."; + + private readonly CompositeDisposable _disposable = []; public LoginView (LoginViewModel viewModel) { Title = $"Reactive Extensions Example - {Application.QuitKey} to Exit"; ViewModel = viewModel; - Label usernameLengthLabel = UsernameLengthLabel (TitleLabel ()); - TextField usernameInput = UsernameInput (usernameLengthLabel); - Label passwordLengthLabel = PasswordLengthLabel (usernameLengthLabel); - TextField passwordInput = PasswordInput (passwordLengthLabel); - Label validationLabel = ValidationLabel (passwordInput); - Button loginButton = LoginButton (validationLabel); - Button clearButton = ClearButton (loginButton); - LoginProgressLabel (clearButton); + var title = this.AddControl