ctrlret: replaced return types of controllers from tea.Cmd to tea.Msg

This dramatically cuts downs the number of closures.
This commit is contained in:
Leon Mika 2022-08-18 21:39:13 +10:00
parent 931b11cd0d
commit 5b6bf1f0ae
17 changed files with 472 additions and 562 deletions

View file

@ -10,29 +10,19 @@ func Error(err error) tea.Msg {
return ErrorMsg(err)
}
func SetError(err error) tea.Cmd {
return func() tea.Msg {
return Error(err)
func SetStatus(msg string) tea.Msg {
return StatusMsg(msg)
}
func PromptForInput(prompt string, onDone func(value string) tea.Msg) tea.Msg {
return PromptForInputMsg{
Prompt: prompt,
OnDone: onDone,
}
}
func SetStatus(msg string) tea.Cmd {
return func() tea.Msg {
return StatusMsg(msg)
}
}
func PromptForInput(prompt string, onDone func(value string) tea.Cmd) tea.Cmd {
return func() tea.Msg {
return PromptForInputMsg{
Prompt: prompt,
OnDone: onDone,
}
}
}
func Confirm(prompt string, onYes func() tea.Cmd) tea.Cmd {
return PromptForInput(prompt, func(value string) tea.Cmd {
func Confirm(prompt string, onYes func() tea.Msg) tea.Msg {
return PromptForInput(prompt, func(value string) tea.Msg {
if value == "y" {
return onYes()
}

View file

@ -16,5 +16,5 @@ type ModeMessage string
// PromptForInput indicates that the context is requesting a line of input
type PromptForInputMsg struct {
Prompt string
OnDone func(value string) tea.Cmd
OnDone func(value string) tea.Msg
}