Skip to content

Commit

Permalink
docs: add examples and godox to EnvMsg and Raw
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jan 16, 2025
1 parent 52bd762 commit 57f505c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
14 changes: 13 additions & 1 deletion environ.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 57f505c

Please sign in to comment.