mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-27 23:08:02 +02:00
some fixes for issues around the credentials panel
This commit is contained in:
parent
c71bcc64ed
commit
a26c15dafa
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user