mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-11-24 08:52:21 +02:00
Apply suggestions from @mjarkk for menyFromCommands
This commit is contained in:
parent
9daa47fb2d
commit
77e9ee64a4
@ -1,10 +1,10 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/jesseduffield/gocui"
|
||||
@ -170,34 +170,32 @@ func (gui *Gui) handleCustomCommandKeybinding(customCommand config.CustomCommand
|
||||
}
|
||||
|
||||
// Run and save output
|
||||
message,err := gui.GitCommand.RunCommandWithOutput(cmdStr)
|
||||
message, err := gui.GitCommand.RunCommandWithOutput(cmdStr)
|
||||
if err != nil {
|
||||
return gui.surfaceError(err)
|
||||
}
|
||||
|
||||
// Need to make a menu out of what the cmd has displayed
|
||||
var candidates []string
|
||||
candidates := []string{}
|
||||
reg := regexp.MustCompile(filter)
|
||||
for _,str := range strings.Split(string(message), "\n"){
|
||||
for _, str := range strings.Split(string(message), "\n") {
|
||||
cand := ""
|
||||
if str != "" {
|
||||
for i := 1; i < (reg.NumSubexp()+1); i++ {
|
||||
keep := reg.ReplaceAllString(str, "${"+fmt.Sprint(i)+"}")
|
||||
if str == "" {
|
||||
continue
|
||||
}
|
||||
for i := 1; i < (reg.NumSubexp() + 1); i++ {
|
||||
keep := reg.ReplaceAllString(str, "${"+strconv.Itoa(i)+"}")
|
||||
cand += keep
|
||||
}
|
||||
candidates = append(candidates, cand)
|
||||
}
|
||||
}
|
||||
|
||||
menuItems := make([]*menuItem, len(candidates))
|
||||
for i, option := range candidates {
|
||||
option := option
|
||||
|
||||
for i := range candidates {
|
||||
menuItems[i] = &menuItem{
|
||||
displayStrings: []string{option},
|
||||
displayStrings: []string{candidates[i]},
|
||||
onPress: func() error {
|
||||
promptResponses[idx] = option
|
||||
|
||||
promptResponses[idx] = candidates[i]
|
||||
return wrappedF()
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user