1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/credentials_panel.go

73 lines
2.0 KiB
Go
Raw Normal View History

package gui
import (
"strings"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
2022-01-28 11:44:36 +02:00
"github.com/jesseduffield/lazygit/pkg/gui/types"
2020-10-04 02:00:48 +02:00
"github.com/jesseduffield/lazygit/pkg/utils"
)
type credentials chan string
// promptUserForCredential wait for a username, password or passphrase input from the credentials popup
2022-01-08 06:46:35 +02:00
func (gui *Gui) promptUserForCredential(passOrUname oscommands.CredentialType) string {
gui.credentials = make(chan string)
2022-01-15 03:04:00 +02:00
gui.OnUIThread(func() error {
2021-04-04 16:31:52 +02:00
credentialsView := gui.Views.Credentials
2020-11-16 11:38:26 +02:00
switch passOrUname {
2022-01-08 06:46:35 +02:00
case oscommands.Username:
credentialsView.Title = gui.c.Tr.CredentialsUsername
credentialsView.Mask = 0
2022-01-08 06:46:35 +02:00
case oscommands.Password:
credentialsView.Title = gui.c.Tr.CredentialsPassword
credentialsView.Mask = '*'
2022-01-08 06:46:35 +02:00
case oscommands.Passphrase:
credentialsView.Title = gui.c.Tr.CredentialsPassphrase
credentialsView.Mask = '*'
}
2020-08-16 05:58:29 +02:00
if err := gui.c.PushContext(gui.State.Contexts.Credentials); err != nil {
return err
}
2020-08-16 05:58:29 +02:00
return nil
})
// wait for username/passwords/passphrase input
userInput := <-gui.credentials
return userInput + "\n"
}
func (gui *Gui) handleSubmitCredential() error {
2021-04-04 15:51:59 +02:00
credentialsView := gui.Views.Credentials
2021-10-17 04:00:44 +02:00
message := strings.TrimSpace(credentialsView.TextArea.GetContent())
gui.credentials <- message
2021-10-17 08:38:59 +02:00
credentialsView.ClearTextArea()
2022-02-22 11:17:26 +02:00
if err := gui.c.PopContext(); err != nil {
return err
}
2020-08-16 05:58:29 +02:00
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
}
func (gui *Gui) handleCloseCredentialsView() error {
2022-01-28 11:44:36 +02:00
gui.Views.Credentials.ClearTextArea()
gui.credentials <- ""
2022-02-22 11:17:26 +02:00
return gui.c.PopContext()
}
2022-01-28 11:44:36 +02:00
func (gui *Gui) handleAskFocused() error {
keybindingConfig := gui.c.UserConfig.Keybinding
2020-10-03 06:54:55 +02:00
2020-10-04 02:00:48 +02:00
message := utils.ResolvePlaceholderString(
gui.c.Tr.CloseConfirm,
2020-10-04 02:00:48 +02:00
map[string]string{
2020-10-03 06:54:55 +02:00
"keyBindClose": gui.getKeyDisplay(keybindingConfig.Universal.Return),
"keyBindConfirm": gui.getKeyDisplay(keybindingConfig.Universal.Confirm),
},
)
2020-10-04 02:00:48 +02:00
2022-01-15 03:04:00 +02:00
return gui.renderString(gui.Views.Options, message)
}