1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

support menus in custom commands

This commit is contained in:
Jesse Duffield
2020-09-26 20:32:19 +10:00
parent b5066f1d8e
commit 7d39cc75b2

View File

@ -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
switch prompt.Type {
case "prompt":
f = func() error {
return gui.prompt(
prompt.Title,
prompt.InitialValue,
func(str string) error {
promptResponses[idx] = str
return wrappedF()
},
)
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 {