dynamo-browse/internal/common/ui/events/commands.go
Leon Mika 8dafa6fa8f
All checks were successful
ci / build (push) Successful in 3m41s
Added ui:prompt-keypress to support single key presses
Have also fixed a bug in ui:prompt which was keeping the script running when the prompt was being cancelled
2025-10-26 07:34:14 +11:00

76 lines
1.4 KiB
Go

package events
import (
"log"
tea "github.com/charmbracelet/bubbletea"
"lmika.dev/cmd/dynamo-browse/internal/dynamo-browse/services"
)
func Error(err error) tea.Msg {
log.Println(err)
return ErrorMsg(err)
}
func SetStatus(msg string) tea.Cmd {
return func() tea.Msg {
return StatusMsg(msg)
}
}
func SetTeaMessage(event tea.Msg) tea.Cmd {
return func() tea.Msg {
return event
}
}
func PromptForInput(prompt string, history services.HistoryProvider, onDone func(value string) tea.Msg) tea.Msg {
return PromptForInputMsg{
Prompt: prompt,
History: history,
OnDone: onDone,
}
}
func PromptForKey(prompt string, onDone func(key string) tea.Msg) tea.Msg {
return PromptForKeyMsg{
Prompt: prompt,
OnDone: onDone,
}
}
func Confirm(prompt string, onResult func(yes bool) tea.Msg) tea.Msg {
return PromptForInputMsg{
Prompt: prompt,
OnDone: func(value string) tea.Msg {
return onResult(value == "y")
},
OnCancel: func() tea.Msg {
return onResult(false)
},
}
}
func ConfirmYes(prompt string, onYes func() tea.Msg) tea.Msg {
return PromptForInput(prompt, nil, func(value string) tea.Msg {
if value == "y" {
return onYes()
}
return nil
})
}
type MessageWithStatus interface {
StatusMessage() string
}
type MessageWithMode interface {
MessageWithStatus
ModeMessage() string
}
type MessageWithRightMode interface {
MessageWithStatus
RightModeMessage() string
}