From 0f16ddd20631158ab84cc60387b4bec91d5a0bbc Mon Sep 17 00:00:00 2001 From: Rustam Gilyazov <16064414+rusq@users.noreply.github.com> Date: Mon, 4 Nov 2024 21:54:24 +1000 Subject: [PATCH] make a menu bubble --- cmd/slackdump/internal/diag/wizdebug.go | 6 +++--- .../ui/{dumpui => bubbles/menu}/focusmodel.go | 2 +- .../ui/{dumpui => bubbles/menu}/keymap.go | 2 +- .../ui/{dumpui => bubbles/menu}/menuitem.go | 2 +- .../ui/{dumpui => bubbles/menu}/model.go | 4 ++-- .../ui/{dumpui => bubbles/menu}/style.go | 2 +- cmd/slackdump/internal/ui/dumpui/dumpui.go | 21 ++++++++++--------- 7 files changed, 20 insertions(+), 19 deletions(-) rename cmd/slackdump/internal/ui/{dumpui => bubbles/menu}/focusmodel.go (92%) rename cmd/slackdump/internal/ui/{dumpui => bubbles/menu}/keymap.go (97%) rename cmd/slackdump/internal/ui/{dumpui => bubbles/menu}/menuitem.go (98%) rename cmd/slackdump/internal/ui/{dumpui => bubbles/menu}/model.go (98%) rename cmd/slackdump/internal/ui/{dumpui => bubbles/menu}/style.go (98%) diff --git a/cmd/slackdump/internal/diag/wizdebug.go b/cmd/slackdump/internal/diag/wizdebug.go index 1465081e..8ce811d1 100644 --- a/cmd/slackdump/internal/diag/wizdebug.go +++ b/cmd/slackdump/internal/diag/wizdebug.go @@ -6,8 +6,8 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/huh" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/bubbles/menu" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/cfgui" - "github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/dumpui" ) var CmdWizDebug = &base.Command{ @@ -56,7 +56,7 @@ func runWizDebug(ctx context.Context, cmd *base.Command, args []string) error { } func debugDumpUI(ctx context.Context) error { - menu := []dumpui.MenuItem{ + mnu := []menu.MenuItem{ { ID: "run", Name: "Run", @@ -79,7 +79,7 @@ func debugDumpUI(ctx context.Context) error { Help: "Exit to main menu", }, } - w := dumpui.NewModel("Wizard Debug", menu, false) + w := menu.New("Wizard Debug", mnu, false) if _, err := tea.NewProgram(w, tea.WithContext(ctx)).Run(); err != nil { return err diff --git a/cmd/slackdump/internal/ui/dumpui/focusmodel.go b/cmd/slackdump/internal/ui/bubbles/menu/focusmodel.go similarity index 92% rename from cmd/slackdump/internal/ui/dumpui/focusmodel.go rename to cmd/slackdump/internal/ui/bubbles/menu/focusmodel.go index b531d8d8..970a228d 100644 --- a/cmd/slackdump/internal/ui/dumpui/focusmodel.go +++ b/cmd/slackdump/internal/ui/bubbles/menu/focusmodel.go @@ -1,4 +1,4 @@ -package dumpui +package menu import tea "github.com/charmbracelet/bubbletea" diff --git a/cmd/slackdump/internal/ui/dumpui/keymap.go b/cmd/slackdump/internal/ui/bubbles/menu/keymap.go similarity index 97% rename from cmd/slackdump/internal/ui/dumpui/keymap.go rename to cmd/slackdump/internal/ui/bubbles/menu/keymap.go index f8fb7dbb..e9a55840 100644 --- a/cmd/slackdump/internal/ui/dumpui/keymap.go +++ b/cmd/slackdump/internal/ui/bubbles/menu/keymap.go @@ -1,4 +1,4 @@ -package dumpui +package menu import "github.com/charmbracelet/bubbles/key" diff --git a/cmd/slackdump/internal/ui/dumpui/menuitem.go b/cmd/slackdump/internal/ui/bubbles/menu/menuitem.go similarity index 98% rename from cmd/slackdump/internal/ui/dumpui/menuitem.go rename to cmd/slackdump/internal/ui/bubbles/menu/menuitem.go index 7d202ce5..41fa62b3 100644 --- a/cmd/slackdump/internal/ui/dumpui/menuitem.go +++ b/cmd/slackdump/internal/ui/bubbles/menu/menuitem.go @@ -1,4 +1,4 @@ -package dumpui +package menu // MenuItem is an item in a menu. type MenuItem struct { diff --git a/cmd/slackdump/internal/ui/dumpui/model.go b/cmd/slackdump/internal/ui/bubbles/menu/model.go similarity index 98% rename from cmd/slackdump/internal/ui/dumpui/model.go rename to cmd/slackdump/internal/ui/bubbles/menu/model.go index 4cb12298..041bd963 100644 --- a/cmd/slackdump/internal/ui/dumpui/model.go +++ b/cmd/slackdump/internal/ui/bubbles/menu/model.go @@ -1,4 +1,4 @@ -package dumpui +package menu import ( "strings" @@ -30,7 +30,7 @@ type Model struct { cursor int } -func NewModel(title string, items []MenuItem, preview bool) *Model { +func New(title string, items []MenuItem, preview bool) *Model { return &Model{ title: title, items: items, diff --git a/cmd/slackdump/internal/ui/dumpui/style.go b/cmd/slackdump/internal/ui/bubbles/menu/style.go similarity index 98% rename from cmd/slackdump/internal/ui/dumpui/style.go rename to cmd/slackdump/internal/ui/bubbles/menu/style.go index 2b1f216a..6172b6be 100644 --- a/cmd/slackdump/internal/ui/dumpui/style.go +++ b/cmd/slackdump/internal/ui/bubbles/menu/style.go @@ -1,4 +1,4 @@ -package dumpui +package menu import ( "github.com/charmbracelet/lipgloss" diff --git a/cmd/slackdump/internal/ui/dumpui/dumpui.go b/cmd/slackdump/internal/ui/dumpui/dumpui.go index 08ec98b6..08e34f7f 100644 --- a/cmd/slackdump/internal/ui/dumpui/dumpui.go +++ b/cmd/slackdump/internal/ui/dumpui/dumpui.go @@ -6,6 +6,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/bubbles/menu" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/cfgui" ) @@ -42,10 +43,10 @@ var description = map[string]string{ } func (w *Wizard) Run(ctx context.Context) error { - var menu = func() *Model { - var items []MenuItem + var menu = func() *menu.Model { + var items []menu.MenuItem if w.LocalConfig != nil { - items = append(items, MenuItem{ + items = append(items, menu.MenuItem{ ID: actLocalConfig, Name: "Configure " + w.Name + "...", Help: description[actLocalConfig], @@ -55,7 +56,7 @@ func (w *Wizard) Run(ctx context.Context) error { items = append( items, - MenuItem{ + menu.MenuItem{ ID: actRun, Name: "Run " + w.Name, Help: description[actRun], @@ -68,7 +69,7 @@ func (w *Wizard) Run(ctx context.Context) error { }, ) if w.Help != "" { - items = append(items, MenuItem{ + items = append(items, menu.MenuItem{ ID: "help", Name: "Help", Help: "Read help for " + w.Name, @@ -76,18 +77,18 @@ func (w *Wizard) Run(ctx context.Context) error { } items = append(items, - MenuItem{Separator: true}, - MenuItem{ + menu.MenuItem{Separator: true}, + menu.MenuItem{ ID: actGlobalConfig, Name: "Global Configuration...", Help: description[actGlobalConfig], Model: cfgui.NewConfigUI(cfgui.DefaultStyle(), cfgui.GlobalConfig), // TODO: filthy cast }, - MenuItem{Separator: true}, - MenuItem{ID: actExit, Name: "Exit", Help: description[actExit]}, + menu.MenuItem{Separator: true}, + menu.MenuItem{ID: actExit, Name: "Exit", Help: description[actExit]}, ) - return NewModel(w.Title, items, false) + return menu.New(w.Title, items, false) } LOOP: