summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-12-12 22:34:20 +1100
committerJesse Duffield <jessedduffield@gmail.com>2018-12-12 22:34:20 +1100
commita26c15dafa7e8c80a56ce0f452137e0af16a883e (patch)
tree29f0222e1709d480fe84055e07fd1ca3c002af5f
parentc71bcc64ed7e3a5dc921b14df53dbe9d2837a20a (diff)
some fixes for issues around the credentials panel
-rw-r--r--pkg/commands/exec_live_default.go29
-rw-r--r--pkg/gui/commit_message_panel.go9
-rw-r--r--pkg/gui/gui.go18
-rw-r--r--pkg/gui/view_helpers.go41
4 files changed, 49 insertions, 48 deletions
diff --git a/pkg/commands/exec_live_default.go b/pkg/commands/exec_live_default.go
index 5fb84c81e..9f08b014b 100644
--- a/pkg/commands/exec_live_default.go
+++ b/pkg/commands/exec_live_default.go
@@ -30,42 +30,33 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
tty, err := pty.Start(cmd)
+ // go func() {
+ // _ = tty.Close()
+ // }()
+
if err != nil {
return "", err
}
- stopAsking := make(chan struct{})
-
var waitForBufio sync.WaitGroup
waitForBufio.Add(1)
- defer func() {
- _ = tty.Close()
- }()
-
go func() {
scanner := bufio.NewScanner(tty)
scanner.Split(scanWordsWithNewLines)
for scanner.Scan() {
- select {
- case <-stopAsking:
- // just do nothing
- default:
- toOutput := strings.Trim(scanner.Text(), " ")
- cmdOutput = append(cmdOutput, toOutput)
- toWrite := output(toOutput)
- if len(toWrite) > 0 {
- _, _ = tty.Write([]byte(toWrite + "\n"))
- }
+ toOutput := strings.Trim(scanner.Text(), " ")
+ cmdOutput = append(cmdOutput, toOutput)
+ toWrite := output(toOutput)
+ if len(toWrite) > 0 {
+ _, _ = tty.Write([]byte(toWrite + "\n"))
}
}
waitForBufio.Done()
}()
err = cmd.Wait()
- go func() {
- stopAsking <- struct{}{}
- }()
+ tty.Close()
if err != nil {
waitForBufio.Wait()
return strings.Join(cmdOutput, " "), err
diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go
index 4ba9a3d97..8f14cf6e1 100644
--- a/pkg/gui/commit_message_panel.go
+++ b/pkg/gui/commit_message_panel.go
@@ -103,7 +103,11 @@ func (gui *Gui) handlePushConfirm(g *gocui.Gui, v *gocui.View) error {
if err != nil {
return err
}
- err = gui.switchFocus(g, v, gui.getFilesView(g))
+ nextView, err := gui.g.View("confirmation")
+ if err != nil {
+ nextView = gui.getFilesView(g)
+ }
+ err = gui.switchFocus(g, nil, nextView)
if err != nil {
return err
}
@@ -115,8 +119,9 @@ func (gui *Gui) handlePushClose(g *gocui.Gui, v *gocui.View) error {
if err != nil {
return err
}
+
gui.credentials <- "-"
- return gui.switchFocus(g, v, gui.getFilesView(g))
+ return gui.switchFocus(g, nil, gui.getFilesView(g))
}
func (gui *Gui) handlePushFocused(g *gocui.Gui, v *gocui.View) error {
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 3345be560..b0062dba8 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -457,15 +457,19 @@ func (gui *Gui) fetch(g *gocui.Gui, v *gocui.View, canSskForCredentials bool) (u
}
func (gui *Gui) updateLoader(g *gocui.Gui) error {
- if view, _ := g.View("confirmation"); view != nil {
- content := gui.trimmedContent(view)
- if strings.Contains(content, "...") {
- staticContent := strings.Split(content, "...")[0] + "..."
- if err := gui.renderString(g, "confirmation", staticContent+" "+utils.Loader()); err != nil {
- return err
+ gui.g.Update(func(g *gocui.Gui) error {
+ if view, _ := g.View("confirmation"); view != nil {
+ content := gui.trimmedContent(view)
+ if strings.Contains(content, "...") {
+ staticContent := strings.Split(content, "...")[0] + "..."
+ if err := gui.synchronousRenderString(g, "confirmation", staticContent+" "+utils.Loader()); err != nil {
+ return err
+ }
}
}
- }
+ return nil
+ })
+
return nil
}
diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go
index 298e0be7f..fa676a47d 100644
--- a/pkg/gui/view_helpers.go
+++ b/pkg/gui/view_helpers.go
@@ -222,22 +222,26 @@ func (gui *Gui) focusPoint(cx int, cy int, v *gocui.View) error {
return nil
}
+func (gui *Gui) synchronousRenderString(g *gocui.Gui, viewName, s string) error {
+ v, err := g.View(viewName)
+ // just in case the view disappeared as this function was called, we'll
+ // silently return if it's not found
+ if err != nil {
+ return nil
+ }
+ v.Clear()
+ if err := v.SetOrigin(0, 0); err != nil {
+ return err
+ }
+ output := string(bom.Clean([]byte(s)))
+ output = utils.NormalizeLinefeeds(output)
+ fmt.Fprint(v, output)
+ return nil
+}
+
func (gui *Gui) renderString(g *gocui.Gui, viewName, s string) error {
g.Update(func(*gocui.Gui) error {
- v, err := g.View(viewName)
- // just in case the view disappeared as this function was called, we'll
- // silently return if it's not found
- if err != nil {
- return nil
- }
- v.Clear()
- if err := v.SetOrigin(0, 0); err != nil {
- return err
- }
- output := string(bom.Clean([]byte(s)))
- output = utils.NormalizeLinefeeds(output)
- fmt.Fprint(v, output)
- return nil
+ return gui.synchronousRenderString(gui.g, viewName, s)
})
return nil
}
@@ -311,19 +315,16 @@ func (gui *Gui) resizeCurrentPopupPanel(g *gocui.Gui) error {
// HandleCredentialsPopup handles the views after executing a command that might ask for credentials
func (gui *Gui) HandleCredentialsPopup(g *gocui.Gui, popupOpened bool, cmdErr error) {
+ if popupOpened {
+ _ = g.DeleteView("credentials")
+ }
if cmdErr != nil {
errMessage := cmdErr.Error()
if errMessage == "exit status 128" {
errMessage = gui.Tr.SLocalize("PassUnameWrong")
}
_ = gui.createErrorPanel(g, errMessage)
- if popupOpened {
- _ = g.DeleteView("credentials")
- }
} else {
- if popupOpened {
- _ = g.DeleteView("credentials")
- }
_ = gui.closeConfirmationPrompt(g)
_ = gui.refreshSidePanels(g)
}