diff options
| author | ewy <ewy0@protonmail.com> | 2026-04-14 16:37:17 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-04-14 16:37:17 +0200 |
| commit | 45a297a8e526094e8fce6e2c5c0fd89b381d1765 (patch) | |
| tree | 852ebc3a0112c94dc9726d0b27ab057bf6383660 /menu/menu.go | |
i have to commit at some point!
Diffstat (limited to 'menu/menu.go')
| -rw-r--r-- | menu/menu.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/menu/menu.go b/menu/menu.go new file mode 100644 index 0000000..232a837 --- /dev/null +++ b/menu/menu.go @@ -0,0 +1,47 @@ +package menu + +import ( + "errors" + tea "github.com/charmbracelet/bubbletea" + "pik/model" + "pik/spool" +) + +var WrongModelTypeError = errors.New("wrong model type") + +func Show(st *model.State, hydrators []model.Hydrator) (*model.HydratedSource, model.HydratedTarget, error) { + md := NewModel(st, hydrators) + program := tea.NewProgram(md) + resultModel, err := program.Run() + if err != nil { + return nil, nil, err + } + result, ok := resultModel.(*Model) + if !ok { + return nil, nil, WrongModelTypeError + } + + src, t := result.Result() + return src, t, nil +} + +func Hydrate(st *model.State, hydrators []model.Hydrator) *model.HydratedState { + hyd := &model.HydratedState{ + State: st, + HydratedSources: make([]*model.HydratedSource, len(st.Sources)), + } + for i, s := range st.Sources { + hydSrc := s.Hydrate(hydrators) + + for _, h := range hydrators { + err := h.Hydrate(s, hydSrc) + if err != nil { + spool.Warn("%v\n", err) + continue + } + } + + hyd.HydratedSources[i] = hydSrc + } + return hyd +} |
