Skip to content

Commit

Permalink
picklist conquest
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Nov 4, 2024
1 parent 8019583 commit 06152e9
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/slackdump/internal/archive/search_wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func searchCfg() cfgui.Configuration {
default:
return "undefined search action"
}
}, &action)),
}, &action).Title("Search Scope")),
},
},
},
Expand Down
1 change: 0 additions & 1 deletion cmd/slackdump/internal/export/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (fl *exportFlags) configuration() cfgui.Configuration {
Inline: false,
Updater: updaters.NewPicklist(&fl.ExportStorageType, huh.NewSelect[fileproc.StorageType]().
Title("Choose File storage type").
Description("test").
Options(
huh.NewOption("Mattermost", fileproc.STmattermost),
huh.NewOption("Standard", fileproc.STstandard),
Expand Down
10 changes: 5 additions & 5 deletions cmd/slackdump/internal/ui/dumpui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ func (m *Model) view() string {
p(sty.ItemDisabled.Render(iftrue(current, pointer, padding) + itm.Name))
continue
}
p(iftrue(
current,
sty.Cursor.Render(pointer)+sty.ItemSelected.Render(itm.Name),
sty.Item.Render(padding+itm.Name),
))
if current {
p(sty.Cursor.Render(pointer) + sty.ItemSelected.Render(itm.Name))
} else {
p(sty.Item.Render(padding + itm.Name))
}
}
p("\n" + m.footer())
return sty.Border.Render(b.String())
Expand Down
2 changes: 1 addition & 1 deletion cmd/slackdump/internal/ui/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func FileSelector(msg, descr string, opt ...Option) (string, error) {
var resp struct {
Filename string
}
q := fieldFileInput(&resp.Filename, msg, descr, *opts)
q := huh.NewForm(huh.NewGroup(fieldFileInput(&resp.Filename, msg, descr, *opts))).WithTheme(HuhTheme)

for {
if err := q.Run(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/slackdump/internal/ui/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ func Input(msg, help string, validateFn func(s string) error) (string, error) {
validateFn = NoValidation
}
var resp string
if err := huh.NewText().
if err := huh.NewForm(huh.NewGroup(huh.NewText().
Title(msg).
Description(help).
Validate(validateFn).
Value(&resp).
Value(&resp))).WithTheme(HuhTheme).
Run(); err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/slackdump/internal/ui/updaters/examples/picklist/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import (

func main() {
var result fileproc.StorageType

updaters.OnClose = tea.Quit

l := updaters.NewPicklist(&result, huh.NewSelect[fileproc.StorageType]().
Title("Title").
Description("Description").
Options(
huh.NewOption("None", fileproc.STnone),
huh.NewOption("Standard", fileproc.STstandard),
Expand All @@ -27,5 +25,6 @@ func main() {
if _, err := tea.NewProgram(l).Run(); err != nil {
log.Fatal(err)
}

fmt.Println("selected: ", result)
}
15 changes: 7 additions & 8 deletions cmd/slackdump/internal/ui/updaters/picklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ import (
)

type Model[T comparable] struct {
s *huh.Select[T]
finishing bool
s huh.Field
help help.Model
finishing bool

// value
initial T
ptr *T
}

func NewPicklist[T comparable](v *T, s *huh.Select[T]) *Model[T] {
s = s.Value(v).
WithTheme(ui.HuhTheme).
WithKeyMap(huh.NewDefaultKeyMap()).(*huh.Select[T])

m := &Model[T]{
s: s,
s: s.Value(v).
Description("Select an option").
WithTheme(ui.HuhTheme).
WithKeyMap(huh.NewDefaultKeyMap()),
help: help.New(),

initial: *v,
Expand Down Expand Up @@ -55,7 +54,7 @@ func (m *Model[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
{
// update the select control
mod, cmd := m.s.Update(msg)
if mod, ok := mod.(*huh.Select[T]); ok {
if mod, ok := mod.(huh.Field); ok {
m.s = mod
}
cmds = append(cmds, cmd)
Expand Down
4 changes: 2 additions & 2 deletions cmd/slackdump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ func init() {
loadSecrets(secretFiles)

base.Slackdump.Commands = []*base.Command{
wizard.CmdWizard,
archive.CmdArchive,
export.CmdExport,
dump.CmdDump,
archive.CmdArchive,
archive.CmdSearch,
convertcmd.CmdConvert,
list.CmdList,
Expand All @@ -53,6 +52,7 @@ func init() {
apiconfig.CmdConfig,
format.CmdFormat,
view.CmdView,
wizard.CmdWizard,
CmdVersion,

man.WhatsNew,
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQW
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
github.com/charmbracelet/bubbletea v1.1.2 h1:naQXF2laRxyLyil/i7fxdpiz1/k06IKquhm4vBfHsIc=
github.com/charmbracelet/bubbletea v1.1.2/go.mod h1:9HIU/hBV24qKjlehyj8z1r/tR9TYTQEag+cWZnuXo8E=
github.com/charmbracelet/huh v0.5.3 h1:3KLP4a/K1/S4dq4xFMTNMt3XWhgMl/yx8NYtygQ0bmg=
github.com/charmbracelet/huh v0.5.3/go.mod h1:OZC3lshuF+/y8laj//DoZdFSHxC51OrtXLJI8xWVouQ=
github.com/charmbracelet/huh v0.6.0 h1:mZM8VvZGuE0hoDXq6XLxRtgfWyTI3b2jZNKh0xWmax8=
github.com/charmbracelet/huh v0.6.0/go.mod h1:GGNKeWCeNzKpEOh/OJD8WBwTQjV3prFAtQPpLv+AVwU=
github.com/charmbracelet/huh/spinner v0.0.0-20241028115900-20a4d21717a8 h1:g+Bz64hsMLTf3lAgUqI6Rj1YEAlm/HN39IuhyneCokc=
Expand Down

0 comments on commit 06152e9

Please sign in to comment.