Most of the new models have been reimplemented

This commit is contained in:
Leon Mika 2022-03-27 23:19:38 +00:00 committed by GitHub
parent 7a5584cf9a
commit aa828df3ae
19 changed files with 226 additions and 156 deletions

View file

@ -23,9 +23,9 @@ func NewCommandController(commands map[string]uimodels.Operation) *CommandContro
func (c *CommandController) Prompt() uimodels.Operation {
return uimodels.OperationFn(func(ctx context.Context) error {
uiCtx := uimodels.Ctx(ctx)
uiCtx.Send(events.PromptForInput{
uiCtx.Send(events.PromptForInputMsg{
Prompt: ":",
OnDone: c.Execute(),
// OnDone: c.Execute(),
})
return nil
})

View file

@ -1,10 +1,7 @@
package dispatcher
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/lmika/awstools/internal/common/ui/events"
"github.com/lmika/awstools/internal/common/ui/uimodels"
)
@ -13,20 +10,20 @@ type DispatcherContext struct {
}
func (dc DispatcherContext) Messagef(format string, args ...interface{}) {
dc.Publisher.Send(events.Message(fmt.Sprintf(format, args...)))
// dc.Publisher.Send(events.Message(fmt.Sprintf(format, args...)))
}
func (dc DispatcherContext) Send(teaMessage tea.Msg) {
dc.Publisher.Send(teaMessage)
// dc.Publisher.Send(teaMessage)
}
func (dc DispatcherContext) Message(msg string) {
dc.Publisher.Send(events.Message(msg))
// dc.Publisher.Send(events.Message(msg))
}
func (dc DispatcherContext) Input(prompt string, onDone uimodels.Operation) {
dc.Publisher.Send(events.PromptForInput{
Prompt: prompt,
OnDone: onDone,
})
// dc.Publisher.Send(events.PromptForInput{
// Prompt: prompt,
// OnDone: onDone,
// })
}

View file

@ -0,0 +1,26 @@
package events
import tea "github.com/charmbracelet/bubbletea"
func Error(err error) tea.Msg {
return ErrorMsg(err)
}
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,
}
}
}
type MessageWithStatus interface {
StatusMessage() string
}

View file

@ -1,17 +1,17 @@
package events
import (
"github.com/lmika/awstools/internal/common/ui/uimodels"
tea "github.com/charmbracelet/bubbletea"
)
// Error indicates that an error occurred
type Error error
type ErrorMsg error
// Message indicates that a message should be shown to the user
type Message string
type StatusMsg string
// PromptForInput indicates that the context is requesting a line of input
type PromptForInput struct {
type PromptForInputMsg struct {
Prompt string
OnDone uimodels.Operation
OnDone func(value string) tea.Cmd
}