docs: add examples and godox to EnvMsg and Raw

This commit is contained in:
Ayman Bagabas 2025-01-16 17:24:18 +03:00
parent 52bd762edb
commit 57f505c01b
No known key found for this signature in database
GPG key ID: C8D51D2157C919AC
2 changed files with 35 additions and 1 deletions

View file

@ -41,7 +41,19 @@ func (p environ) LookupEnv(key string) (s string, v bool) {
}
// EnvMsg is a message that represents the environment variables of the
// program. This message is sent to the program when it starts.
// program. This is useful for getting the environment variables of programs
// running in a remote session like SSH. In that case, using [os.Getenv] would
// return the server's environment variables, not the client's.
//
// This message is sent to the program when it starts.
//
// Example:
//
// switch msg := msg.(type) {
// case EnvMsg:
// // What terminal type is being used?
// term := msg.Getenv("TERM")
// }
type EnvMsg environ
// Getenv returns the value of the environment variable named by the key. If

22
raw.go
View file

@ -8,6 +8,28 @@ type RawMsg struct {
// Raw is a command that prints the given string to the terminal without any
// formatting.
//
// This is intended for advanced use cases where you need to query the terminal
// or send escape sequences directly. Don't use this unless you know what
// you're doing :)
//
// Example:
//
// func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// switch msg := msg.(type) {
// case input.PrimaryDeviceAttributesEvent:
// for _, attr := range msg {
// if attr == 4 {
// // We have Sixel graphics support!
// break
// }
// }
// }
//
// // Request the terminal primary device attributes to detect Sixel graphics
// // support.
// return m, tea.Raw(ansi.RequestPrimaryDeviceAttributes)
// }
func Raw(r any) Cmd {
return func() Msg {
return RawMsg{r}