environ.go

 1package tea
 2
 3import uv "github.com/charmbracelet/ultraviolet"
 4
 5// EnvMsg is a message that represents the environment variables of the
 6// program. This is useful for getting the environment variables of programs
 7// running in a remote session like SSH. In that case, using [os.Getenv] would
 8// return the server's environment variables, not the client's.
 9//
10// This message is sent to the program when it starts.
11//
12// Example:
13//
14//	switch msg := msg.(type) {
15//	case EnvMsg:
16//	  // What terminal type is being used?
17//	  term := msg.Getenv("TERM")
18//	}
19type EnvMsg uv.Environ
20
21// Getenv returns the value of the environment variable named by the key. If
22// the variable is not present in the environment, the value returned will be
23// the empty string.
24func (msg EnvMsg) Getenv(key string) (v string) {
25	return uv.Environ(msg).Getenv(key)
26}
27
28// LookupEnv retrieves the value of the environment variable named by the key.
29// If the variable is present in the environment the value (which may be empty)
30// is returned and the boolean is true. Otherwise the returned value will be
31// empty and the boolean will be false.
32func (msg EnvMsg) LookupEnv(key string) (s string, v bool) {
33	return uv.Environ(msg).LookupEnv(key)
34}