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