Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set console to UTF-8 encoding on Windows #3951

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/tui/light_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down