Skip to content

Commit

Permalink
per-menuitem preview
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Nov 6, 2024
1 parent cbd952b commit d243915
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions cmd/slackdump/internal/ui/bubbles/menu/menuitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type MenuItem struct {
// Model is any model that should be displayed when the item is selected,
// or executed when the user presses enter.
Model FocusModel
// Preview suggests that the Model should attempt to show the preview
// of this item.
Preview bool
// Validate determines whether the item is disabled or not. It should
// complete in reasonable time, as it is called on every render. The
// return error is used in the description for the item.
Expand Down
6 changes: 3 additions & 3 deletions cmd/slackdump/internal/ui/bubbles/menu/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ func (m *Model) View() string {
if m.finishing {
return ""
}
if m.items[m.cursor].Model != nil {
if item := m.items[m.cursor]; item.Model != nil {
if m.focused {
if m.preview {
return lipgloss.JoinHorizontal(lipgloss.Top, m.view(), m.items[m.cursor].Model.View())
if item.Preview && m.preview {
return lipgloss.JoinHorizontal(lipgloss.Top, m.view(), item.Model.View())
} else {
return m.view()
}
Expand Down
11 changes: 6 additions & 5 deletions cmd/slackdump/internal/ui/dumpui/dumpui.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ func (w *Wizard) Run(ctx context.Context) error {
var items []menu.MenuItem
if w.LocalConfig != nil {
items = append(items, menu.MenuItem{
ID: actLocalConfig,
Name: "Configure " + w.Name + "...",
Help: description[actLocalConfig],
Model: cfgui.NewConfigUI(cfgui.DefaultStyle(), w.LocalConfig),
ID: actLocalConfig,
Name: w.Name + " Options...",
Help: description[actLocalConfig],
Preview: true,
Model: cfgui.NewConfigUI(cfgui.DefaultStyle(), w.LocalConfig),
})
}

Expand Down Expand Up @@ -88,7 +89,7 @@ func (w *Wizard) Run(ctx context.Context) error {
menu.MenuItem{ID: actExit, Name: "Exit", Help: description[actExit]},
)

return menu.New(w.Title, items, false)
return menu.New(w.Title, items, true)
}

LOOP:
Expand Down
16 changes: 16 additions & 0 deletions doc/tapes/browser_select.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Set Shell zsh
Sleep 1s
Type@50ms "slackdump workspace new"
Sleep 4s
Enter
Sleep 3s
Type@50ms "ora600"
Sleep 3s
Enter
Down@250ms 2
Sleep 4s
Enter
Sleep 5s
Enter
Sleep 12s

Binary file added doc/tapes/out.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d243915

Please sign in to comment.