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:
parent
1969504611
commit
7526c095ee
24 changed files with 602 additions and 97 deletions
15
internal/common/ui/uimodels/context.go
Normal file
15
internal/common/ui/uimodels/context.go
Normal 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)
|
||||
}
|
||||
10
internal/common/ui/uimodels/iface.go
Normal file
10
internal/common/ui/uimodels/iface.go
Normal 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)
|
||||
}
|
||||
14
internal/common/ui/uimodels/operations.go
Normal file
14
internal/common/ui/uimodels/operations.go
Normal 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)
|
||||
}
|
||||
|
||||
15
internal/common/ui/uimodels/promptvalue.go
Normal file
15
internal/common/ui/uimodels/promptvalue.go
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue