From b8414c47e891b451ffa84775644a5ee7cf623755 Mon Sep 17 00:00:00 2001 From: Michael Kelley Date: Sat, 3 Aug 2024 19:54:24 -0700 Subject: [PATCH] Set console to UTF-8 encoding on Windows --- src/tui/light_windows.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/tui/light_windows.go b/src/tui/light_windows.go index e2a2bbfe19b..1c1c80ae70b 100644 --- a/src/tui/light_windows.go +++ b/src/tui/light_windows.go @@ -20,6 +20,25 @@ var ( consoleFlagsOutput = uint32(windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING | windows.ENABLE_PROCESSED_OUTPUT | windows.DISABLE_NEWLINE_AUTO_RETURN) ) +func SetConsoleUTF8() error { + var err error + var result uintptr = 0 + + const utf8CodePage = 65001 + + k32 := syscall.MustLoadDLL("kernel32.dll") + result, _, err = k32.MustFindProc("SetConsoleCP").Call(utf8CodePage) + if result == 0 { + return err + } + result, _, err = k32.MustFindProc("SetConsoleOutputCP").Call(utf8CodePage) + if result == 0 { + return err + } + + return nil +} + // IsLightRendererSupported checks to see if the Light renderer is supported func IsLightRendererSupported() bool { var oldState uint32 @@ -61,6 +80,10 @@ func (r *LightRenderer) initPlatform() error { } r.inHandle = uintptr(inHandle) + if err := SetConsoleUTF8(); err != nil { + return err + } + r.setupTerminal() // channel for non-blocking reads. Buffer to make sure