feat: /tui/show-toast api

This commit is contained in:
adamdotdevin
2025-08-15 08:39:58 -05:00
parent 6e0e87fb2a
commit 9609c1803e
10 changed files with 169 additions and 5 deletions

View File

@@ -705,6 +705,45 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
updated, cmd := a.executeCommand(commands.Command(command))
a = updated.(Model)
cmds = append(cmds, cmd)
case "/tui/show-toast":
var body struct {
Title string `json:"title,omitempty"`
Message string `json:"message"`
Variant string `json:"variant"`
}
json.Unmarshal((msg.Body), &body)
var toastCmd tea.Cmd
switch body.Variant {
case "info":
if body.Title != "" {
toastCmd = toast.NewInfoToast(body.Message, toast.WithTitle(body.Title))
} else {
toastCmd = toast.NewInfoToast(body.Message)
}
case "success":
if body.Title != "" {
toastCmd = toast.NewSuccessToast(body.Message, toast.WithTitle(body.Title))
} else {
toastCmd = toast.NewSuccessToast(body.Message)
}
case "warning":
if body.Title != "" {
toastCmd = toast.NewErrorToast(body.Message, toast.WithTitle(body.Title))
} else {
toastCmd = toast.NewErrorToast(body.Message)
}
case "error":
if body.Title != "" {
toastCmd = toast.NewErrorToast(body.Message, toast.WithTitle(body.Title))
} else {
toastCmd = toast.NewErrorToast(body.Message)
}
default:
slog.Error("Invalid toast variant", "variant", body.Variant)
return a, nil
}
cmds = append(cmds, toastCmd)
default:
break