mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-03 00:57:52 +02:00
Refresh is one of those functions that shouldn't require error handling (similar to triggering a redraw of the UI, see https://github.com/jesseduffield/lazygit/issues/3887). As far as I see, the only reason why Refresh can currently return an error is that the Then function returns one. The actual refresh errors, e.g. from the git calls that are made to fetch data, are already logged and swallowed. Most of the Then functions do only UI stuff such as selecting a list item, and always return nil; there's only one that can return an error (updating the rebase todo file in LocalCommitsController.startInteractiveRebaseWithEdit); it's not a critical error if this fails, it is only used for setting rebase todo items to "edit" when you start an interactive rebase by pressing 'e' on a range selection of commits. We simply log this error instead of returning it.
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package helpers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
type CredentialsHelper struct {
|
|
c *HelperCommon
|
|
}
|
|
|
|
func NewCredentialsHelper(
|
|
c *HelperCommon,
|
|
) *CredentialsHelper {
|
|
return &CredentialsHelper{
|
|
c: c,
|
|
}
|
|
}
|
|
|
|
// promptUserForCredential wait for a username, password or passphrase input from the credentials popup
|
|
// We return a channel rather than returning the string directly so that the calling function knows
|
|
// when the prompt has been created (before the user has entered anything) so that it can
|
|
// note that we're now waiting on user input and lazygit isn't processing anything.
|
|
func (self *CredentialsHelper) PromptUserForCredential(passOrUname oscommands.CredentialType) <-chan string {
|
|
ch := make(chan string)
|
|
|
|
self.c.OnUIThread(func() error {
|
|
title, mask := self.getTitleAndMask(passOrUname)
|
|
|
|
self.c.Prompt(types.PromptOpts{
|
|
Title: title,
|
|
Mask: mask,
|
|
HandleConfirm: func(input string) error {
|
|
ch <- input + "\n"
|
|
|
|
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
|
return nil
|
|
},
|
|
HandleClose: func() error {
|
|
ch <- "\n"
|
|
|
|
return nil
|
|
},
|
|
})
|
|
|
|
return nil
|
|
})
|
|
|
|
return ch
|
|
}
|
|
|
|
func (self *CredentialsHelper) getTitleAndMask(passOrUname oscommands.CredentialType) (string, bool) {
|
|
switch passOrUname {
|
|
case oscommands.Username:
|
|
return self.c.Tr.CredentialsUsername, false
|
|
case oscommands.Password:
|
|
return self.c.Tr.CredentialsPassword, true
|
|
case oscommands.Passphrase:
|
|
return self.c.Tr.CredentialsPassphrase, true
|
|
case oscommands.PIN:
|
|
return self.c.Tr.CredentialsPIN, true
|
|
case oscommands.Token:
|
|
return self.c.Tr.CredentialsToken, true
|
|
}
|
|
|
|
// should never land here
|
|
panic("unexpected credential request")
|
|
}
|