1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

introduce gui adapter

This commit is contained in:
Jesse Duffield
2022-08-09 20:27:44 +10:00
parent 225c563c63
commit 46ae55f91e
20 changed files with 763 additions and 297 deletions

View File

@ -1,6 +1,10 @@
package custom_commands
import (
"bytes"
"fmt"
"text/template"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/config"
)
@ -101,3 +105,30 @@ func (self *Resolver) resolveMenuOption(option *config.CustomCommandMenuOption,
Value: value,
}, nil
}
func main() {
fmt.Println(ResolveTemplate("old approach: {{index .PromptResponses 0}}, new approach: {{ .Form.a }}", CustomCommandObject{
PromptResponses: []string{"a"},
Form: map[string]string{"a": "B"},
}))
}
type CustomCommandObject struct {
// deprecated. Use Responses instead
PromptResponses []string
Form map[string]string
}
func ResolveTemplate(templateStr string, object interface{}) (string, error) {
tmpl, err := template.New("template").Parse(templateStr)
if err != nil {
return "", err
}
var buf bytes.Buffer
if err := tmpl.Execute(&buf, object); err != nil {
return "", err
}
return buf.String(), nil
}