()
| 43 | } |
| 44 | |
| 45 | func IsTerminalSupportChinese() bool { |
| 46 | // 获取终端的环境变量 |
| 47 | env := os.Environ() |
| 48 | |
| 49 | // 查找 LANG 环境变量 |
| 50 | isSupportUTF8 := false |
| 51 | for _, v := range env { |
| 52 | if strings.Index(v, "LANG") != -1 && strings.Index(v, "UTF-8") != -1 { |
| 53 | isSupportUTF8 = true |
| 54 | } |
| 55 | } |
| 56 | if isSupportUTF8 { |
| 57 | // 在终端中打印中文字符 |
| 58 | cmd := exec.Command("echo", "你好!") |
| 59 | _, err := cmd.CombinedOutput() |
| 60 | if err == nil { |
| 61 | return true |
| 62 | } |
| 63 | return false |
| 64 | } |
| 65 | return false |
| 66 | } |