diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-26 20:32:19 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-27 09:49:30 +1000 |
commit | 7d39cc75b2f0b5e4feb4ee8c66f851dfc6aeb709 (patch) | |
tree | 5fed46bb5d77db0cbb1e91866a83c18fd13f249e /pkg/gui | |
parent | b5066f1d8e6b00113b35fb7b0ca43633f4f95921 (diff) |
support menus in custom commands
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/custom_commands.go | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go index 8af82e123..d74a721e0 100644 --- a/pkg/gui/custom_commands.go +++ b/pkg/gui/custom_commands.go @@ -88,29 +88,63 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand CustomCommand) func( // going backwards so the outermost prompt is the first one prompt := customCommand.Prompts[idx] - gui.Log.Warn(prompt.Title) - wrappedF := f // need to do this because f's value will change with each iteration - f = func() error { - return gui.prompt( - prompt.Title, - prompt.InitialValue, - func(str string) error { - promptResponses[idx] = str - - return wrappedF() - }, - ) + switch prompt.Type { + case "prompt": + f = func() error { + return gui.prompt( + prompt.Title, + prompt.InitialValue, + func(str string) error { + promptResponses[idx] = str + + return wrappedF() + }, + ) + } + case "menu": + // need to make a menu here some how + menuItems := make([]*menuItem, len(prompt.Options)) + for i, option := range prompt.Options { + option := option + menuItems[i] = &menuItem{ + displayStrings: []string{option.Name, option.Description}, + onPress: func() error { + promptResponses[idx] = option.Value + + return wrappedF() + }, + } + } + + f = func() error { + return gui.createMenu(prompt.Title, menuItems, createMenuOptions{showCancel: true}) + } + default: + return gui.createErrorPanel("custom command prompt must have a type of 'prompt' or 'menu'") } + } return f() } } +type CustomCommandMenuOption struct { + Name string `yaml:"name"` + Description string `yaml:"description"` + Value string `yaml:"value"` +} + type CustomCommandPrompt struct { - Title string `yaml:"title"` + Type string `yaml:"type"` // one of 'prompt' and 'menu' + Title string `yaml:"title"` + + // this only apply to prompts InitialValue string `yaml:"initialValue"` + + // this only applies to menus + Options []CustomCommandMenuOption } type CustomCommand struct { |