runewidth_windows.go 608 B

12345678910111213141516171819202122232425262728293031323334
  1. //go:build windows && !appengine
  2. // +build windows,!appengine
  3. package runewidth
  4. import (
  5. "os"
  6. "syscall"
  7. )
  8. var (
  9. kernel32 = syscall.NewLazyDLL("kernel32")
  10. procGetConsoleOutputCP = kernel32.NewProc("GetConsoleOutputCP")
  11. )
  12. // IsEastAsian return true if the current locale is CJK
  13. func IsEastAsian() bool {
  14. if os.Getenv("WT_SESSION") != "" {
  15. // Windows Terminal always not use East Asian Ambiguous Width(s).
  16. return false
  17. }
  18. r1, _, _ := procGetConsoleOutputCP.Call()
  19. if r1 == 0 {
  20. return false
  21. }
  22. switch int(r1) {
  23. case 932, 51932, 936, 949, 950:
  24. return true
  25. }
  26. return false
  27. }