charmbracelet / charmbracelet/bubbletea
Automatic command chaining: Cmd -> Cmd -> Msg
- Dominant language
- Go
- Stars
- 44.9k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
No.
**Describe the solution you'd like**
```go
switch msg := msg.(type) {
case tea.Cmd:
return m, msg
}
```
**Describe alternatives you've considered**
N/A
**Additional context**
I have a Cmd which produces other Cmds:
```go
func (m *Model) Create(name string) tea.Cmd {
return func() tea.Msg {
if !isAlphaNumeric(name) {
return tea.Println("Only alphanumeric characters are allowed.")
}
var game db.Game
m.app.db.Where("name = ?", name).First(&game)
if game.ID != 0 {
return tea.Printf("Game %q already exists. Please choose another name.", name)
}
game = db.Game{
Name: name,
}
if err := m.app.db.Create(&game).Error; err != nil {
slog.Error("Failed to create game", "err", err.Error())
}
return tea.Printf("Game created!")
}
}
```
It will be cool it cmds can produce other cmds.
This is easily solvable via:
```go
switch msg := msg.(type) {
case tea.Cmd:
return m, msg
}
```
But as Msg == any it took me some time to understand why nothing is printed. What about adding this as default behavior?
Contributor guide
Assessment
This issue has not been assessed yet.