Skip to content

Commit

Permalink
Fixed UTF-8 console encoding setup for Windows OS (#2889)
Browse files Browse the repository at this point in the history
Not only the input console encoding should be set to UTF-8, but also the output console encoding.
  • Loading branch information
hrumhurum authored Oct 19, 2023
1 parent 0c0a8eb commit 5f713a7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/cli/cli_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package cli
import "golang.org/x/sys/windows"

func init() {

kernel32 := windows.NewLazySystemDLL("kernel32.dll")

setConsoleCP := kernel32.NewProc("SetConsoleCP")
// Set codepage to UTF-8
// Set console input codepage to UTF-8
// https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers#:~:text=Unicode%20(UTF%2D7)-,65001,-utf%2D8
setConsoleCP.Call(uintptr(65001))

setConsoleOutputCP := kernel32.NewProc("SetConsoleOutputCP")
// Set console ouput codepage to UTF-8
setConsoleOutputCP.Call(uintptr(65001))
}

0 comments on commit 5f713a7

Please sign in to comment.