MCPcopy Create free account
hub / github.com/coder/coder / withTerminalEnv

Function withTerminalEnv

agent/reconnectingpty/reconnectingpty.go:36–48  ·  view source on GitHub ↗

withTerminalEnv returns env with the terminal type and UTF-8 character locale expected by the web terminal.

(env []string)

Source from the content-addressed store, hash-verified

34
35// withTerminalEnv returns env with the terminal type and UTF-8 character locale expected by the web terminal.
36func 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.
51func terminalUTF8Locale() string {

Callers 4

doAttachMethod · 0.85
sendCommandMethod · 0.85
newBufferedFunction · 0.85
TestWithTerminalEnvFunction · 0.85

Calls 3

effectiveLocaleIsUTF8Function · 0.85
hasNonEmptyEnvFunction · 0.85
terminalUTF8LocaleFunction · 0.85

Tested by 1

TestWithTerminalEnvFunction · 0.68