1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-27 12:32:37 +02:00

Apply suggestions from @mjarkk for menyFromCommands

This commit is contained in:
Elwardi 2021-07-18 18:38:06 +01:00
parent 9daa47fb2d
commit 77e9ee64a4
2 changed files with 36 additions and 38 deletions

View File

@ -1,10 +1,10 @@
package gui package gui
import ( import (
"fmt"
"log" "log"
"strings"
"regexp" "regexp"
"strconv"
"strings"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
@ -176,28 +176,26 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand
} }
// Need to make a menu out of what the cmd has displayed // Need to make a menu out of what the cmd has displayed
var candidates []string candidates := []string{}
reg := regexp.MustCompile(filter) reg := regexp.MustCompile(filter)
for _, str := range strings.Split(string(message), "\n") { for _, str := range strings.Split(string(message), "\n") {
cand := "" cand := ""
if str != "" { if str == "" {
continue
}
for i := 1; i < (reg.NumSubexp() + 1); i++ { for i := 1; i < (reg.NumSubexp() + 1); i++ {
keep := reg.ReplaceAllString(str, "${"+fmt.Sprint(i)+"}") keep := reg.ReplaceAllString(str, "${"+strconv.Itoa(i)+"}")
cand += keep cand += keep
} }
candidates = append(candidates, cand) candidates = append(candidates, cand)
} }
}
menuItems := make([]*menuItem, len(candidates)) menuItems := make([]*menuItem, len(candidates))
for i, option := range candidates { for i := range candidates {
option := option
menuItems[i] = &menuItem{ menuItems[i] = &menuItem{
displayStrings: []string{option}, displayStrings: []string{candidates[i]},
onPress: func() error { onPress: func() error {
promptResponses[idx] = option promptResponses[idx] = candidates[i]
return wrappedF() return wrappedF()
}, },
} }