From 6faf87ca92c6681b902f00e87f12eaf8594b6148 Mon Sep 17 00:00:00 2001 From: Tig Date: Tue, 24 Mar 2026 13:31:05 -0500 Subject: [PATCH] Fixes #4848. Set Console.OutputEncoding to UTF-8 in AnsiOutput The ANSI driver writes UTF-8 encoded bytes via WriteFile but never set the console output code page to 65001 (UTF-8). On a fresh Windows terminal with the default OEM code page (e.g. 437), multi-byte UTF-8 characters (box-drawing glyphs) were misinterpreted as multiple single-byte OEM characters, producing garbled borders and shifted text. Added Console.OutputEncoding = Encoding.UTF8 to the AnsiOutput constructor, matching what NetOutput already does. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Terminal.Gui/Drivers/AnsiDriver/AnsiOutput.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Terminal.Gui/Drivers/AnsiDriver/AnsiOutput.cs b/Terminal.Gui/Drivers/AnsiDriver/AnsiOutput.cs index 22c15a368f..a90ee85366 100644 --- a/Terminal.Gui/Drivers/AnsiDriver/AnsiOutput.cs +++ b/Terminal.Gui/Drivers/AnsiDriver/AnsiOutput.cs @@ -58,6 +58,13 @@ public AnsiOutput () try { + // Ensure the console output code page is UTF-8 (65001). The ANSI driver writes + // UTF-8 encoded bytes via WriteFile; without this, a fresh Windows terminal uses + // its default OEM code page (e.g. 437), causing multi-byte UTF-8 characters + // (box-drawing glyphs, etc.) to be misinterpreted as garbled single-byte characters. + // See https://github.com/gui-cs/Terminal.Gui/issues/4848 + Console.OutputEncoding = Encoding.UTF8; + // Check if we have a real console first if (!IsAttachedToTerminal) {