From d423702c68e78a0182e04e55ed6e853b808bf15b Mon Sep 17 00:00:00 2001 From: Nightt <87569709+nightt5879@users.noreply.github.com> Date: Sat, 9 May 2026 11:50:59 +0800 Subject: [PATCH 1/2] Fix Windows console UTF-8 encoding --- src/Program.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Program.cs b/src/Program.cs index b710776..a4d94b1 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Text; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Serilog; @@ -13,6 +14,8 @@ using fuseraft.Infrastructure; using fuseraft.Infrastructure.Plugins; +ConfigureWindowsConsoleEncoding(); + // Catch crashes on background threads (not covered by Spectre's SetExceptionHandler). AppDomain.CurrentDomain.UnhandledException += (_, e) => { @@ -226,3 +229,22 @@ { await Log.CloseAndFlushAsync(); } + +static void ConfigureWindowsConsoleEncoding() +{ + if (!OperatingSystem.IsWindows()) return; + + TrySetConsoleEncoding(() => Console.OutputEncoding = Encoding.UTF8); + TrySetConsoleEncoding(() => Console.InputEncoding = Encoding.UTF8); +} + +static void TrySetConsoleEncoding(Action setEncoding) +{ + try + { + setEncoding(); + } + catch (Exception ex) when (ex is IOException or NotSupportedException or UnauthorizedAccessException) + { + } +} From baee77f2375e90004b3e3623afa8fab89dd4df0d Mon Sep 17 00:00:00 2001 From: Nightt <87569709+nightt5879@users.noreply.github.com> Date: Mon, 11 May 2026 09:48:33 +0800 Subject: [PATCH 2/2] Simplify console encoding configuration --- src/Program.cs | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index a4d94b1..678717f 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -14,7 +14,7 @@ using fuseraft.Infrastructure; using fuseraft.Infrastructure.Plugins; -ConfigureWindowsConsoleEncoding(); +ConfigureConsoleEncoding(); // Catch crashes on background threads (not covered by Spectre's SetExceptionHandler). AppDomain.CurrentDomain.UnhandledException += (_, e) => @@ -230,21 +230,11 @@ await Log.CloseAndFlushAsync(); } -static void ConfigureWindowsConsoleEncoding() +static void ConfigureConsoleEncoding() { - if (!OperatingSystem.IsWindows()) return; + try { Console.OutputEncoding = Encoding.UTF8; } + catch (Exception ex) when (ex is IOException or NotSupportedException or UnauthorizedAccessException) { } - TrySetConsoleEncoding(() => Console.OutputEncoding = Encoding.UTF8); - TrySetConsoleEncoding(() => Console.InputEncoding = Encoding.UTF8); -} - -static void TrySetConsoleEncoding(Action setEncoding) -{ - try - { - setEncoding(); - } - catch (Exception ex) when (ex is IOException or NotSupportedException or UnauthorizedAccessException) - { - } + try { Console.InputEncoding = Encoding.UTF8; } + catch (Exception ex) when (ex is IOException or NotSupportedException or UnauthorizedAccessException) { } }