1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-17 21:18:31 +02:00

pass callback directly

This commit is contained in:
Jesse Duffield 2020-08-11 20:25:36 +10:00
parent 79e73d2eff
commit 1b78a42b80
3 changed files with 6 additions and 12 deletions

View File

@ -9,9 +9,9 @@ import (
type credentials chan string
// waitForPassUname wait for a username or password input from the credentials popup
func (gui *Gui) waitForPassUname(g *gocui.Gui, currentView *gocui.View, passOrUname string) string {
func (gui *Gui) waitForPassUname(passOrUname string) string {
gui.credentials = make(chan string)
g.Update(func(g *gocui.Gui) error {
gui.g.Update(func(g *gocui.Gui) error {
credentialsView, _ := g.View("credentials")
if passOrUname == "username" {
credentialsView.Title = gui.Tr.SLocalize("CredentialsUsername")
@ -20,7 +20,7 @@ func (gui *Gui) waitForPassUname(g *gocui.Gui, currentView *gocui.View, passOrUn
credentialsView.Title = gui.Tr.SLocalize("CredentialsPassword")
credentialsView.Mask = '*'
}
err := gui.switchFocus(g, currentView, credentialsView)
err := gui.switchFocus(g, gui.g.CurrentView(), credentialsView)
if err != nil {
return err
}

View File

@ -477,9 +477,7 @@ func (gui *Gui) pullFiles(v *gocui.View, args string) error {
// what if we had a struct which contained an array of functions to run, each of which return a function, or perhaps write to a channel when they're done, and if there is no error, we run the next thing. In this case we first want to fetch, potentially handling a credential popup, then we want to rebase.
go func() {
err := gui.GitCommand.Pull(args, func(passOrUname string) string {
return gui.waitForPassUname(gui.g, v, passOrUname)
})
err := gui.GitCommand.Pull(args, gui.waitForPassUname)
// gui.handleGenericMergeCommandResult(err)
gui.HandleCredentialsPopup(gui.g, err)
}()
@ -493,9 +491,7 @@ func (gui *Gui) pushWithForceFlag(g *gocui.Gui, v *gocui.View, force bool, upstr
}
go func() {
branchName := gui.getCheckedOutBranch().Name
err := gui.GitCommand.Push(branchName, force, upstream, args, func(passOrUname string) string {
return gui.waitForPassUname(g, v, passOrUname)
})
err := gui.GitCommand.Push(branchName, force, upstream, args, gui.waitForPassUname)
gui.HandleCredentialsPopup(g, err)
}()
return nil

View File

@ -167,9 +167,7 @@ func (gui *Gui) handleInfoClick(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) fetch(g *gocui.Gui, v *gocui.View, canAskForCredentials bool) (err error) {
err = gui.GitCommand.Fetch(func(passOrUname string) string {
return gui.waitForPassUname(gui.g, v, passOrUname)
}, canAskForCredentials)
err = gui.GitCommand.Fetch(gui.waitForPassUname, canAskForCredentials)
if canAskForCredentials && err != nil && strings.Contains(err.Error(), "exit status 128") {
colorFunction := color.New(color.FgRed).SprintFunc()