Added ui:prompt-keypress to support single key presses
All checks were successful
ci / build (push) Successful in 3m41s
All checks were successful
ci / build (push) Successful in 3m41s
Have also fixed a bug in ui:prompt which was keeping the script running when the prompt was being cancelled
This commit is contained in:
parent
022cec7393
commit
8dafa6fa8f
5 changed files with 122 additions and 18 deletions
|
|
@ -1,9 +1,10 @@
|
|||
package events
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"lmika.dev/cmd/dynamo-browse/internal/dynamo-browse/services"
|
||||
"log"
|
||||
)
|
||||
|
||||
func Error(err error) tea.Msg {
|
||||
|
|
@ -31,10 +32,23 @@ func PromptForInput(prompt string, history services.HistoryProvider, onDone func
|
|||
}
|
||||
}
|
||||
|
||||
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 PromptForInput(prompt, nil, func(value string) tea.Msg {
|
||||
return onResult(value == "y")
|
||||
})
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -27,3 +27,10 @@ type PromptForInputMsg struct {
|
|||
OnCancel func() tea.Msg
|
||||
OnTabComplete func(value string) (string, bool)
|
||||
}
|
||||
|
||||
// PromptForKey indicates that the context is requesting a single key press
|
||||
type PromptForKeyMsg struct {
|
||||
Prompt string
|
||||
OnDone func(key string) tea.Msg
|
||||
OnCancel func() tea.Msg
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue