environ.go
This file
Path
environ.go
34 lines · 1.2 KiB · Go
Last changed by
Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
History of this fileTake it
Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 1–34why, one step back1package tea23import uv "github.com/charmbracelet/ultraviolet"45// EnvMsg is a message that represents the environment variables of the6// program. This is useful for getting the environment variables of programs7// running in a remote session like SSH. In that case, using [os.Getenv] would8// 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.Environ2021// Getenv returns the value of the environment variable named by the key. If22// the variable is not present in the environment, the value returned will be23// the empty string.24func (msg EnvMsg) Getenv(key string) (v string) {25 return uv.Environ(msg).Getenv(key)26}2728// 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 be31// 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}