src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

runewidth_windows.go (608B)


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