sqs-browse: a lot of work to try to keep UI complexity down

Added the notion of controllers and a dispatcher which will queue up operations
This commit is contained in:
Leon Mika 2022-03-23 15:40:31 +11:00
parent 1969504611
commit 7526c095ee
24 changed files with 602 additions and 97 deletions

View file

@ -0,0 +1,15 @@
package uimodels
import "context"
type uiContextKeyType struct {}
var uiContextKey = uiContextKeyType{}
func Ctx(ctx context.Context) UIContext {
uiCtx, _ := ctx.Value(uiContextKey).(UIContext)
return uiCtx
}
func WithContext(ctx context.Context, uiContext UIContext) context.Context {
return context.WithValue(ctx, uiContextKey, uiContext)
}

View file

@ -0,0 +1,10 @@
package uimodels
import tea "github.com/charmbracelet/bubbletea"
type UIContext interface {
Send(teaMessage tea.Msg)
Message(msg string)
Messagef(format string, args ...interface{})
Input(prompt string, onDone Operation)
}

View file

@ -0,0 +1,14 @@
package uimodels
import "context"
type Operation interface {
Execute(ctx context.Context) error
}
type OperationFn func(ctx context.Context) error
func (f OperationFn) Execute(ctx context.Context) error {
return f(ctx)
}

View file

@ -0,0 +1,15 @@
package uimodels
import "context"
type promptValueKeyType struct {}
var promptValueKey = promptValueKeyType{}
func PromptValue(ctx context.Context) string {
value, _ := ctx.Value(promptValueKey).(string)
return value
}
func WithPromptValue(ctx context.Context, value string) context.Context {
return context.WithValue(ctx, promptValueKey, value)
}