2018-12-18 13:19:32 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2018-12-19 11:06:58 +02:00
|
|
|
"strings"
|
|
|
|
|
2022-01-08 05:41:30 +02:00
|
|
|
"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"
|
2018-12-18 13:19:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type credentials chan string
|
|
|
|
|
2020-10-10 02:43:59 +02:00
|
|
|
// 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 {
|
2018-12-18 13:19:32 +02:00
|
|
|
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:
|
2020-10-04 02:00:48 +02:00
|
|
|
credentialsView.Title = gui.Tr.CredentialsUsername
|
2018-12-18 13:19:32 +02:00
|
|
|
credentialsView.Mask = 0
|
2022-01-08 06:46:35 +02:00
|
|
|
case oscommands.Password:
|
2020-10-04 02:00:48 +02:00
|
|
|
credentialsView.Title = gui.Tr.CredentialsPassword
|
2018-12-18 13:19:32 +02:00
|
|
|
credentialsView.Mask = '*'
|
2022-01-08 06:46:35 +02:00
|
|
|
case oscommands.Passphrase:
|
2020-10-10 02:43:59 +02:00
|
|
|
credentialsView.Title = gui.Tr.CredentialsPassphrase
|
|
|
|
credentialsView.Mask = '*'
|
2018-12-18 13:19:32 +02:00
|
|
|
}
|
2020-08-16 05:58:29 +02:00
|
|
|
|
2021-04-03 06:56:11 +02:00
|
|
|
if err := gui.pushContext(gui.State.Contexts.Credentials); err != nil {
|
2018-12-18 13:19:32 +02:00
|
|
|
return err
|
|
|
|
}
|
2020-08-16 05:58:29 +02:00
|
|
|
|
2018-12-18 13:19:32 +02:00
|
|
|
gui.RenderCommitLength()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2020-10-10 02:43:59 +02:00
|
|
|
// wait for username/passwords/passphrase input
|
2018-12-18 13:19:32 +02:00
|
|
|
userInput := <-gui.credentials
|
2018-12-18 13:23:17 +02:00
|
|
|
return userInput + "\n"
|
2018-12-18 13:19:32 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
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())
|
2018-12-18 13:19:32 +02:00
|
|
|
gui.credentials <- message
|
2021-10-17 08:38:59 +02:00
|
|
|
credentialsView.ClearTextArea()
|
2020-08-16 05:58:29 +02:00
|
|
|
if err := gui.returnFromContext(); err != nil {
|
2018-12-18 13:19:32 +02:00
|
|
|
return err
|
|
|
|
}
|
2020-08-16 05:58:29 +02:00
|
|
|
|
2022-01-28 11:44:36 +02:00
|
|
|
return gui.refreshSidePanels(types.RefreshOptions{Mode: types.ASYNC})
|
2018-12-18 13:19:32 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCloseCredentialsView() error {
|
2022-01-28 11:44:36 +02:00
|
|
|
gui.Views.Credentials.ClearTextArea()
|
2018-12-18 13:23:17 +02:00
|
|
|
gui.credentials <- ""
|
2020-08-16 05:58:29 +02:00
|
|
|
return gui.returnFromContext()
|
2018-12-18 13:19:32 +02:00
|
|
|
}
|
|
|
|
|
2022-01-28 11:44:36 +02:00
|
|
|
func (gui *Gui) handleAskFocused() error {
|
2021-12-29 02:50:20 +02:00
|
|
|
keybindingConfig := gui.UserConfig.Keybinding
|
2020-10-03 06:54:55 +02:00
|
|
|
|
2020-10-04 02:00:48 +02:00
|
|
|
message := utils.ResolvePlaceholderString(
|
|
|
|
gui.Tr.CloseConfirm,
|
|
|
|
map[string]string{
|
2020-10-03 06:54:55 +02:00
|
|
|
"keyBindClose": gui.getKeyDisplay(keybindingConfig.Universal.Return),
|
|
|
|
"keyBindConfirm": gui.getKeyDisplay(keybindingConfig.Universal.Confirm),
|
2018-12-18 13:19:32 +02:00
|
|
|
},
|
|
|
|
)
|
2020-10-04 02:00:48 +02:00
|
|
|
|
2022-01-15 03:04:00 +02:00
|
|
|
return gui.renderString(gui.Views.Options, message)
|
2018-12-18 13:19:32 +02:00
|
|
|
}
|