diff options
author | mjarkk <mkopenga@gmail.com> | 2018-10-20 17:37:55 +0200 |
---|---|---|
committer | mjarkk <mkopenga@gmail.com> | 2018-10-20 17:37:55 +0200 |
commit | 12425f0aa760759d916ef16bbd028b2c2de5577b (patch) | |
tree | 882223eb8ea4a251a7084597e71743f649da656c /pkg/gui | |
parent | 727ba9f42ec0678a7da7124f8befc81550361019 (diff) |
First good success
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/commit_message_panel.go | 66 | ||||
-rw-r--r-- | pkg/gui/confirmation_panel.go | 1 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 19 | ||||
-rw-r--r-- | pkg/gui/gui.go | 14 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 10 | ||||
-rw-r--r-- | pkg/gui/view_helpers.go | 9 |
6 files changed, 108 insertions, 11 deletions
diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index c26b5573a..329ccec62 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -3,6 +3,7 @@ package gui import ( "strconv" "strings" + "sync" "github.com/jesseduffield/gocui" ) @@ -51,6 +52,71 @@ func (gui *Gui) handleCommitFocused(g *gocui.Gui, v *gocui.View) error { return gui.renderString(g, "options", message) } +var unamePassMessage = "" +var waitForGroup sync.WaitGroup +var waitForGroupActie = false + +// waitForPassUname wait for a username or password input from the pushPassUname popup +func (gui *Gui) waitForPassUname(g *gocui.Gui, currentView *gocui.View, passOrUname string) string { + pushPassUnameView := gui.getPushPassUnameView(g) + if passOrUname == "username" { + pushPassUnameView.Title = gui.Tr.SLocalize("PushUsername") + // pushPassUnameView.Mask = 1 + } else { + pushPassUnameView.Title = gui.Tr.SLocalize("PushPassword") + pushPassUnameView.Mask = '*' + } + g.Update(func(g *gocui.Gui) error { + g.SetViewOnTop("pushPassUname") + gui.switchFocus(g, currentView, pushPassUnameView) + gui.RenderCommitLength() + return nil + }) + waitForGroupActie = true + waitForGroup.Add(1) + waitForGroup.Wait() + + return unamePassMessage +} + +func (gui *Gui) handlePushConfirm(g *gocui.Gui, v *gocui.View) error { + message := gui.trimmedContent(v) + unamePassMessage = message + if waitForGroupActie { + defer waitForGroup.Done() + } + gui.refreshFiles(g) + v.Clear() + v.SetCursor(0, 0) + g.SetViewOnBottom("pushPassUname") + gui.switchFocus(g, v, gui.getFilesView(g)) + return gui.refreshCommits(g) +} + +func (gui *Gui) handlePushClose(g *gocui.Gui, v *gocui.View) error { + g.SetViewOnBottom("pushPassUname") + unamePassMessage = "" + if waitForGroupActie { + defer waitForGroup.Done() + } + return gui.switchFocus(g, v, gui.getFilesView(g)) +} + +func (gui *Gui) handlePushFocused(g *gocui.Gui, v *gocui.View) error { + if _, err := g.SetViewOnTop("pushPassUname"); err != nil { + return err + } + + message := gui.Tr.TemplateLocalize( + "CloseConfirm", + Teml{ + "keyBindClose": "esc", + "keyBindConfirm": "enter", + }, + ) + return gui.renderString(g, "options", message) +} + func (gui *Gui) simpleEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) { switch { case key == gocui.KeyBackspace || key == gocui.KeyBackspace2: diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index 58577e430..ef7c97e6e 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -85,6 +85,7 @@ func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt func (gui *Gui) onNewPopupPanel() { gui.g.SetViewOnBottom("commitMessage") + gui.g.SetViewOnBottom("pushPassUname") } func (gui *Gui) createConfirmationPanel(g *gocui.Gui, currentView *gocui.View, title, prompt string, handleConfirm, handleClose func(*gocui.Gui, *gocui.View) error) error { diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 513aa336d..8083c0e6a 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -355,22 +355,21 @@ func (gui *Gui) pullFiles(g *gocui.Gui, v *gocui.View) error { return nil } -func (gui *Gui) pushWithForceFlag(currentView *gocui.View, force bool) error { +func (gui *Gui) pushWithForceFlag(g *gocui.Gui, currentView *gocui.View, force bool) error { if err := gui.createMessagePanel(gui.g, currentView, "", gui.Tr.SLocalize("PushWait")); err != nil { return err } go func() { branchName := gui.State.Branches[0].Name err := gui.GitCommand.Push(branchName, force, func(passOrUname string) string { - if passOrUname == "password" { - // TODO: ask for password - return "some password" - } - // TODO: ask for username - return "some username" + return gui.waitForPassUname(g, currentView, passOrUname) }) if err != nil { - _ = gui.createErrorPanel(gui.g, err.Error()) + errMessage := err.Error() + if errMessage == "exit status 128" { + errMessage = gui.Tr.SLocalize("PassUnameWrong") + } + _ = gui.createErrorPanel(gui.g, errMessage) } else { _ = gui.closeConfirmationPrompt(gui.g) _ = gui.refreshCommits(gui.g) @@ -384,10 +383,10 @@ func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error { // if we have pullables we'll ask if the user wants to force push _, pullables := gui.GitCommand.UpstreamDifferenceCount() if pullables == "?" || pullables == "0" { - return gui.pushWithForceFlag(v, false) + return gui.pushWithForceFlag(g, v, false) } err := gui.createConfirmationPanel(g, nil, gui.Tr.SLocalize("ForcePush"), gui.Tr.SLocalize("ForcePushPrompt"), func(g *gocui.Gui, v *gocui.View) error { - return gui.pushWithForceFlag(v, true) + return gui.pushWithForceFlag(g, v, true) }, nil) return err } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 7e7648cfe..2baf354c0 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -268,6 +268,20 @@ func (gui *Gui) layout(g *gocui.Gui) error { } } + if gui.getPushPassUnameView(g) == nil { + // doesn't matter where this view starts because it will be hidden + if pushPassUnameView, err := g.SetView("pushPassUname", 0, 0, width/2, height/2, 0); err != nil { + if err != gocui.ErrUnknownView { + return err + } + g.SetViewOnBottom("pushPassUname") + pushPassUnameView.Title = gui.Tr.SLocalize("PushUsername") + pushPassUnameView.FgColor = gocui.ColorWhite + pushPassUnameView.Editable = true + pushPassUnameView.Editor = gocui.EditorFunc(gui.simpleEditor) + } + } + if appStatusView, err := g.SetView("appStatus", -1, optionsTop, width, optionsTop+2, 0); err != nil { if err != gocui.ErrUnknownView { return err diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 78271a3f7..a30dba5f4 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -373,6 +373,16 @@ func (gui *Gui) GetKeybindings() []*Binding { Modifier: gocui.ModNone, Handler: gui.handleCommitClose, }, { + ViewName: "pushPassUname", + Key: gocui.KeyEnter, + Modifier: gocui.ModNone, + Handler: gui.handlePushConfirm, + }, { + ViewName: "pushPassUname", + Key: gocui.KeyEsc, + Modifier: gocui.ModNone, + Handler: gui.handlePushClose, + }, { ViewName: "menu", Key: gocui.KeyEsc, Modifier: gocui.ModNone, diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 6c3e5505c..a5414448f 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -94,6 +94,8 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error { return nil case "commitMessage": return gui.handleCommitFocused(g, v) + case "pushPassUname": + return gui.handlePushFocused(g, v) case "main": // TODO: pull this out into a 'view focused' function gui.refreshMergePanel(g) @@ -288,6 +290,11 @@ func (gui *Gui) getCommitMessageView(g *gocui.Gui) *gocui.View { return v } +func (gui *Gui) getPushPassUnameView(g *gocui.Gui) *gocui.View { + v, _ := g.View("pushPassUname") + return v +} + func (gui *Gui) getBranchesView(g *gocui.Gui) *gocui.View { v, _ := g.View("branches") return v @@ -304,7 +311,7 @@ func (gui *Gui) currentViewName(g *gocui.Gui) string { func (gui *Gui) resizeCurrentPopupPanel(g *gocui.Gui) error { v := g.CurrentView() - if v.Name() == "commitMessage" || v.Name() == "confirmation" { + if v.Name() == "commitMessage" || v.Name() == "pushPassUname" || v.Name() == "confirmation" { return gui.resizePopupPanel(g, v) } return nil |