diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-02-16 12:03:22 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-02-16 12:03:22 +1100 |
commit | daca07eacac8bc5cb7bcf65a762ed5093f2b8a82 (patch) | |
tree | 731ef3b60a94696bff3e431205b9f1b19fb3a858 | |
parent | 34acaf7ac4bc284f511924e65522e22c18b73a2f (diff) |
add loading panel
-rw-r--r-- | pkg/gui/branches_panel.go | 4 | ||||
-rw-r--r-- | pkg/gui/confirmation_panel.go | 19 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 5 | ||||
-rw-r--r-- | pkg/gui/gui.go | 43 | ||||
-rw-r--r-- | pkg/gui/status_panel.go | 2 |
5 files changed, 32 insertions, 41 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 54fd828fd..6fc6d192c 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -162,7 +162,7 @@ func (gui *Gui) handleCreatePullRequestPress(g *gocui.Gui, v *gocui.View) error } func (gui *Gui) handleGitFetch(g *gocui.Gui, v *gocui.View) error { - if err := gui.createMessagePanel(g, v, "", gui.Tr.SLocalize("FetchWait")); err != nil { + if err := gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("FetchWait")); err != nil { return err } go func() { @@ -306,7 +306,7 @@ func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error { }, ) go func() { - _ = gui.createMessagePanel(gui.g, v, "", message) + _ = gui.createLoaderPanel(gui.g, v, message) if err := gui.GitCommand.FastForward(branch.Name); err != nil { _ = gui.createErrorPanel(gui.g, err.Error()) } else { diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index 212565895..51ad711cb 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -63,7 +63,7 @@ func (gui *Gui) getConfirmationPanelDimensions(g *gocui.Gui, wrap bool, prompt s func (gui *Gui) createPromptPanel(g *gocui.Gui, currentView *gocui.View, title string, handleConfirm func(*gocui.Gui, *gocui.View) error) error { gui.onNewPopupPanel() - confirmationView, err := gui.prepareConfirmationPanel(currentView, title, "") + confirmationView, err := gui.prepareConfirmationPanel(currentView, title, "", false) if err != nil { return err } @@ -71,13 +71,14 @@ func (gui *Gui) createPromptPanel(g *gocui.Gui, currentView *gocui.View, title s return gui.setKeyBindings(g, handleConfirm, nil) } -func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt string) (*gocui.View, error) { +func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt string, hasLoader bool) (*gocui.View, error) { x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, true, prompt) confirmationView, err := gui.g.SetView("confirmation", x0, y0, x1, y1, 0) if err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return nil, err } + confirmationView.HasLoader = hasLoader confirmationView.Title = title confirmationView.Wrap = true confirmationView.FgColor = gocui.ColorWhite @@ -97,8 +98,16 @@ func (gui *Gui) onNewPopupPanel() { } } +func (gui *Gui) createLoaderPanel(g *gocui.Gui, currentView *gocui.View, prompt string) error { + return gui.createPopupPanel(g, currentView, "", prompt, true, nil, nil) +} + // it is very important that within this function we never include the original prompt in any error messages, because it may contain e.g. a user password func (gui *Gui) createConfirmationPanel(g *gocui.Gui, currentView *gocui.View, title, prompt string, handleConfirm, handleClose func(*gocui.Gui, *gocui.View) error) error { + return gui.createPopupPanel(g, currentView, title, prompt, false, handleConfirm, handleClose) +} + +func (gui *Gui) createPopupPanel(g *gocui.Gui, currentView *gocui.View, title, prompt string, hasLoader bool, handleConfirm, handleClose func(*gocui.Gui, *gocui.View) error) error { gui.onNewPopupPanel() g.Update(func(g *gocui.Gui) error { // delete the existing confirmation panel if it exists @@ -113,7 +122,7 @@ func (gui *Gui) createConfirmationPanel(g *gocui.Gui, currentView *gocui.View, t gui.Log.Error(errMessage) } } - confirmationView, err := gui.prepareConfirmationPanel(currentView, title, prompt) + confirmationView, err := gui.prepareConfirmationPanel(currentView, title, prompt, hasLoader) if err != nil { return err } @@ -144,7 +153,7 @@ func (gui *Gui) setKeyBindings(g *gocui.Gui, handleConfirm, handleClose func(*go } func (gui *Gui) createMessagePanel(g *gocui.Gui, currentView *gocui.View, title, prompt string) error { - return gui.createConfirmationPanel(g, currentView, title, prompt, nil, nil) + return gui.createPopupPanel(g, currentView, title, prompt, false, nil, nil) } // createSpecificErrorPanel allows you to create an error popup, specifying the diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 1768451fe..a27fb7dc3 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -380,9 +380,10 @@ func (gui *Gui) catSelectedFile(g *gocui.Gui) (string, error) { } func (gui *Gui) pullFiles(g *gocui.Gui, v *gocui.View) error { - if err := gui.createMessagePanel(gui.g, v, "", gui.Tr.SLocalize("PullWait")); err != nil { + if err := gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("PullWait")); err != nil { return err } + go func() { unamePassOpend := false err := gui.GitCommand.Pull(func(passOrUname string) string { @@ -395,7 +396,7 @@ func (gui *Gui) pullFiles(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) pushWithForceFlag(g *gocui.Gui, v *gocui.View, force bool) error { - if err := gui.createMessagePanel(g, v, "", gui.Tr.SLocalize("PushWait")); err != nil { + if err := gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("PushWait")); err != nil { return err } go func() { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 70b39529b..eef5e5ab5 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -24,7 +24,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/updates" - "github.com/jesseduffield/lazygit/pkg/utils" "github.com/sirupsen/logrus" ) @@ -239,7 +238,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { if height < minimumHeight || width < minimumWidth { v, err := g.SetView("limit", 0, 0, max(width-1, 2), max(height-1, 2), 0) if err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } v.Title = gui.Tr.SLocalize("NotEnoughSpace") @@ -261,7 +260,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { v, err := g.SetView("main", leftSideWidth+panelSpacing, 0, width-1, optionsTop, gocui.LEFT) if err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } v.Title = gui.Tr.SLocalize("DiffTitle") @@ -295,7 +294,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } if v, err := g.SetView("status", 0, 0, leftSideWidth, statusFilesBoundary, gocui.BOTTOM|gocui.RIGHT); err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } v.Title = gui.Tr.SLocalize("StatusTitle") @@ -304,7 +303,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { filesView, err := g.SetView("files", 0, statusFilesBoundary+panelSpacing, leftSideWidth, filesBranchesBoundary, gocui.TOP|gocui.BOTTOM) if err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } filesView.Highlight = true @@ -314,7 +313,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { branchesView, err := g.SetView("branches", 0, filesBranchesBoundary+panelSpacing, leftSideWidth, commitsBranchesBoundary, gocui.TOP|gocui.BOTTOM) if err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } branchesView.Title = gui.Tr.SLocalize("BranchesTitle") @@ -322,7 +321,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } if v, err := g.SetView("commits", 0, commitsBranchesBoundary+panelSpacing, leftSideWidth, commitsStashBoundary, gocui.TOP|gocui.BOTTOM); err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } v.Title = gui.Tr.SLocalize("CommitsTitle") @@ -330,7 +329,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } if v, err := g.SetView("stash", 0, commitsStashBoundary+panelSpacing, leftSideWidth, optionsTop, gocui.TOP|gocui.RIGHT); err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } v.Title = gui.Tr.SLocalize("StashTitle") @@ -338,7 +337,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } if v, err := g.SetView("options", appStatusOptionsBoundary-1, optionsTop, optionsVersionBoundary-1, optionsTop+2, 0); err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } v.Frame = false @@ -350,7 +349,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { if gui.getCommitMessageView() == nil { // doesn't matter where this view starts because it will be hidden if commitMessageView, err := g.SetView("commitMessage", 0, 0, width/2, height/2, 0); err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } g.SetViewOnBottom("commitMessage") @@ -364,7 +363,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { if check, _ := g.View("credentials"); check == nil { // doesn't matter where this view starts because it will be hidden if credentialsView, err := g.SetView("credentials", 0, 0, width/2, height/2, 0); err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } _, err := g.SetViewOnBottom("credentials") @@ -379,7 +378,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } if appStatusView, err := g.SetView("appStatus", -1, optionsTop, width, optionsTop+2, 0); err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } appStatusView.BgColor = gocui.ColorDefault @@ -391,7 +390,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } if v, err := g.SetView("version", optionsVersionBoundary-1, optionsTop, width, optionsTop+2, 0); err != nil { - if err != gocui.ErrUnknownView { + if err.Error() != "unknown view" { return err } v.BgColor = gocui.ColorDefault @@ -476,23 +475,6 @@ func (gui *Gui) fetch(g *gocui.Gui, v *gocui.View, canAskForCredentials bool) (u return unamePassOpend, err } -func (gui *Gui) updateLoader() error { - 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.setViewContent(g, view, staticContent+" "+utils.Loader()); err != nil { - return err - } - } - } - return nil - }) - - return nil -} - func (gui *Gui) renderAppStatus() error { appStatus := gui.statusManager.getStatusString() if appStatus != "" { @@ -555,7 +537,6 @@ func (gui *Gui) Run() error { } }() gui.goEvery(time.Second*10, gui.refreshFiles) - gui.goEvery(time.Millisecond*50, gui.updateLoader) gui.goEvery(time.Millisecond*50, gui.renderAppStatus) g.SetManagerFunc(gui.layout) diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go index bb0ac773b..06b94d722 100644 --- a/pkg/gui/status_panel.go +++ b/pkg/gui/status_panel.go @@ -44,7 +44,7 @@ func (gui *Gui) refreshStatus(g *gocui.Gui) error { func (gui *Gui) handleCheckForUpdate(g *gocui.Gui, v *gocui.View) error { gui.Updater.CheckForNewUpdate(gui.onUserUpdateCheckFinish, true) - return gui.createMessagePanel(gui.g, v, "", gui.Tr.SLocalize("CheckingForUpdates")) + return gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("CheckingForUpdates")) } func (gui *Gui) handleStatusSelect(g *gocui.Gui, v *gocui.View) error { |