Skip to content

Commit

Permalink
make a menu bubble
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Nov 4, 2024
1 parent 06152e9 commit 0f16ddd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions cmd/slackdump/internal/diag/wizdebug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dumpui
package menu

import tea "github.com/charmbracelet/bubbletea"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dumpui
package menu

import "github.com/charmbracelet/bubbles/key"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dumpui
package menu

// MenuItem is an item in a menu.
type MenuItem struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dumpui
package menu

import (
"strings"
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dumpui
package menu

import (
"github.com/charmbracelet/lipgloss"
Expand Down
21 changes: 11 additions & 10 deletions cmd/slackdump/internal/ui/dumpui/dumpui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -68,26 +69,26 @@ 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,
})
}

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:
Expand Down

0 comments on commit 0f16ddd

Please sign in to comment.