mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
better template support for menus and prompts
This commit is contained in:
@ -88,13 +88,25 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand CustomCommand) func(
|
|||||||
// going backwards so the outermost prompt is the first one
|
// going backwards so the outermost prompt is the first one
|
||||||
prompt := customCommand.Prompts[idx]
|
prompt := customCommand.Prompts[idx]
|
||||||
|
|
||||||
wrappedF := f // need to do this because f's value will change with each iteration
|
// need to do this because f's value will change with each iteration
|
||||||
|
wrappedF := f
|
||||||
|
|
||||||
switch prompt.Type {
|
switch prompt.Type {
|
||||||
case "prompt":
|
case "prompt":
|
||||||
f = func() error {
|
f = func() error {
|
||||||
|
title, err := gui.resolveTemplate(prompt.Title, promptResponses)
|
||||||
|
if err != nil {
|
||||||
|
return gui.surfaceError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
initialValue, err := gui.resolveTemplate(prompt.InitialValue, promptResponses)
|
||||||
|
if err != nil {
|
||||||
|
return gui.surfaceError(err)
|
||||||
|
}
|
||||||
|
|
||||||
return gui.prompt(
|
return gui.prompt(
|
||||||
prompt.Title,
|
title,
|
||||||
prompt.InitialValue,
|
initialValue,
|
||||||
func(str string) error {
|
func(str string) error {
|
||||||
promptResponses[idx] = str
|
promptResponses[idx] = str
|
||||||
|
|
||||||
@ -103,22 +115,43 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand CustomCommand) func(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
case "menu":
|
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 {
|
f = func() error {
|
||||||
return gui.createMenu(prompt.Title, menuItems, createMenuOptions{showCancel: true})
|
// need to make a menu here some how
|
||||||
|
menuItems := make([]*menuItem, len(prompt.Options))
|
||||||
|
for i, option := range prompt.Options {
|
||||||
|
option := option
|
||||||
|
|
||||||
|
name, err := gui.resolveTemplate(option.Name, promptResponses)
|
||||||
|
if err != nil {
|
||||||
|
return gui.surfaceError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
description, err := gui.resolveTemplate(option.Description, promptResponses)
|
||||||
|
if err != nil {
|
||||||
|
return gui.surfaceError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err := gui.resolveTemplate(option.Value, promptResponses)
|
||||||
|
if err != nil {
|
||||||
|
return gui.surfaceError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
menuItems[i] = &menuItem{
|
||||||
|
displayStrings: []string{name, description},
|
||||||
|
onPress: func() error {
|
||||||
|
promptResponses[idx] = value
|
||||||
|
|
||||||
|
return wrappedF()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
title, err := gui.resolveTemplate(prompt.Title, promptResponses)
|
||||||
|
if err != nil {
|
||||||
|
return gui.surfaceError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.createMenu(title, menuItems, createMenuOptions{showCancel: true})
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return gui.createErrorPanel("custom command prompt must have a type of 'prompt' or 'menu'")
|
return gui.createErrorPanel("custom command prompt must have a type of 'prompt' or 'menu'")
|
||||||
|
Reference in New Issue
Block a user