withTerminalEnv returns env with the terminal type and UTF-8 character locale expected by the web terminal.
(env []string)
| 34 | |
| 35 | // withTerminalEnv returns env with the terminal type and UTF-8 character locale expected by the web terminal. |
| 36 | func withTerminalEnv(env []string) []string { |
| 37 | next := make([]string, 0, len(env)+2) |
| 38 | next = append(next, env...) |
| 39 | next = append(next, "TERM="+xterm256Color) |
| 40 | // Some terminal applications use the process locale for glyph width and |
| 41 | // replacement behavior. Set only LC_CTYPE so other locale categories keep |
| 42 | // the user's settings. Preserve non-empty LC_ALL because it has higher |
| 43 | // precedence than LC_CTYPE. |
| 44 | if runtime.GOOS != "windows" && !effectiveLocaleIsUTF8(next) && !hasNonEmptyEnv(next, "LC_ALL") { |
| 45 | next = append(next, "LC_CTYPE="+terminalUTF8Locale()) |
| 46 | } |
| 47 | return next |
| 48 | } |
| 49 | |
| 50 | // terminalUTF8Locale returns a widely available UTF-8 character locale for the host OS. |
| 51 | func terminalUTF8Locale() string { |