runewidth_windows.go 416 B

12345678910111213141516171819202122232425
  1. package runewidth
  2. import (
  3. "syscall"
  4. )
  5. var (
  6. kernel32 = syscall.NewLazyDLL("kernel32")
  7. procGetConsoleOutputCP = kernel32.NewProc("GetConsoleOutputCP")
  8. )
  9. // IsEastAsian return true if the current locale is CJK
  10. func IsEastAsian() bool {
  11. r1, _, _ := procGetConsoleOutputCP.Call()
  12. if r1 == 0 {
  13. return false
  14. }
  15. switch int(r1) {
  16. case 932, 51932, 936, 949, 950:
  17. return true
  18. }
  19. return false
  20. }