summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-26 23:20:12 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-28 11:59:45 +1100
commitefb51eee96331448d0b419ff9d981f11f22f7638 (patch)
tree2d4068d3aebc66232803315e40844167f6abe427 /pkg/gui
parentfbbd16bd829d6f2a8797453f2d05856b33d34d44 (diff)
more efficient refreshing
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/branches_panel.go34
-rw-r--r--pkg/gui/commits_panel.go33
-rw-r--r--pkg/gui/gui.go11
-rw-r--r--pkg/gui/status_panel.go54
-rw-r--r--pkg/gui/view_helpers.go5
5 files changed, 54 insertions, 83 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index fe947f50f..268247630 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -53,32 +53,20 @@ func (gui *Gui) handleBranchSelect(g *gocui.Gui, v *gocui.View) error {
// gui.refreshStatus is called at the end of this because that's when we can
// be sure there is a state.Branches array to pick the current branch from
-func (gui *Gui) refreshBranches(g *gocui.Gui) error {
- if err := gui.refreshRemotes(); err != nil {
- return err
- }
+func (gui *Gui) refreshBranches() {
+ _ = gui.refreshRemotes()
+ _ = gui.refreshTags()
- if err := gui.refreshTags(); err != nil {
- return err
+ builder, err := commands.NewBranchListBuilder(gui.Log, gui.GitCommand, gui.State.ReflogCommits)
+ if err != nil {
+ _ = gui.createErrorPanel(gui.g, err.Error())
}
+ gui.State.Branches = builder.Build()
- g.Update(func(g *gocui.Gui) error {
- builder, err := commands.NewBranchListBuilder(gui.Log, gui.GitCommand, gui.State.ReflogCommits)
- if err != nil {
- return err
- }
- gui.State.Branches = builder.Build()
-
- // TODO: if we're in the remotes view and we've just deleted a remote we need to refresh accordingly
- if gui.getBranchesView().Context == "local-branches" {
- if err := gui.renderLocalBranchesWithSelection(); err != nil {
- return err
- }
- }
-
- return gui.refreshStatus(g)
- })
- return nil
+ // TODO: if we're in the remotes view and we've just deleted a remote we need to refresh accordingly
+ if gui.getBranchesView().Context == "local-branches" {
+ gui.renderLocalBranchesWithSelection()
+ }
}
func (gui *Gui) renderLocalBranchesWithSelection() error {
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index f0c391755..27f709f1e 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -71,27 +71,26 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) refreshCommits(g *gocui.Gui) error {
- g.Update(func(*gocui.Gui) error {
- // I think this is here for the sake of some kind of rebasing thing
- _ = gui.refreshStatus(g)
+ if err := gui.updateWorkTreeState(); err != nil {
+ return gui.createErrorPanel(gui.g, err.Error())
+ }
- if err := gui.refreshCommitsWithLimit(); err != nil {
- return err
- }
+ if err := gui.refreshCommitsWithLimit(); err != nil {
+ return gui.createErrorPanel(gui.g, err.Error())
+ }
- if err := gui.refreshReflogCommits(); err != nil {
- return gui.createErrorPanel(gui.g, err.Error())
- }
+ if err := gui.refreshReflogCommits(); err != nil {
+ return gui.createErrorPanel(gui.g, err.Error())
+ }
- if err := gui.refreshBranches(gui.g); err != nil {
- return gui.createErrorPanel(gui.g, err.Error())
- }
+ gui.refreshBranches()
+
+ gui.refreshStatus()
+
+ if g.CurrentView() == gui.getCommitFilesView() || (g.CurrentView() == gui.getMainView() || gui.State.MainContext == "patch-building") {
+ return gui.refreshCommitFilesView()
+ }
- if g.CurrentView() == gui.getCommitFilesView() || (g.CurrentView() == gui.getMainView() || gui.State.MainContext == "patch-building") {
- return gui.refreshCommitFilesView()
- }
- return nil
- })
return nil
}
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 62a673870..b4805b7f3 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -157,11 +157,6 @@ type commitFilesPanelState struct {
SelectedLine int
}
-type statusPanelState struct {
- pushables string
- pullables string
-}
-
type panelStates struct {
Files *filePanelState
Branches *branchPanelState
@@ -175,7 +170,6 @@ type panelStates struct {
LineByLine *lineByLinePanelState
Merging *mergingPanelState
CommitFiles *commitFilesPanelState
- Status *statusPanelState
}
type searchingState struct {
@@ -246,7 +240,6 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma
Conflicts: []commands.Conflict{},
EditHistory: stack.New(),
},
- Status: &statusPanelState{},
},
ScreenMode: SCREEN_NORMAL,
SideView: nil,
@@ -930,7 +923,9 @@ func (gui *Gui) fetch(g *gocui.Gui, v *gocui.View, canAskForCredentials bool) (u
_ = gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("Error"), coloredMessage, close, close)
}
- _ = gui.refreshStatus(g)
+ if err := gui.refreshCommits(g); err != nil {
+ return unamePassOpend, err
+ }
return unamePassOpend, err
}
diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go
index d7561d9d7..c6ebff794 100644
--- a/pkg/gui/status_panel.go
+++ b/pkg/gui/status_panel.go
@@ -10,50 +10,34 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils"
)
-func (gui *Gui) refreshStatus(g *gocui.Gui) error {
- state := gui.State.Panels.Status
-
- v, err := g.View("status")
- if err != nil {
- panic(err)
- }
- // for some reason if this isn't wrapped in an update the clear seems to
- // be applied after the other things or something like that; the panel's
- // contents end up cleared
- g.Update(func(*gocui.Gui) error {
- v.Clear()
- // TODO: base this off of the current branch
- state.pushables, state.pullables = gui.GitCommand.GetCurrentBranchUpstreamDifferenceCount()
- if err := gui.updateWorkTreeState(); err != nil {
- return err
- }
+// never call this on its own, it should only be called from within refreshCommits()
+func (gui *Gui) refreshStatus() {
+ currentBranch := gui.currentBranch()
+ status := ""
+ if currentBranch.Pushables != "" && currentBranch.Pullables != "" {
trackColor := color.FgYellow
- if state.pushables == "0" && state.pullables == "0" {
+ if currentBranch.Pushables == "0" && currentBranch.Pullables == "0" {
trackColor = color.FgGreen
- } else if state.pushables == "?" && state.pullables == "?" {
+ } else if currentBranch.Pushables == "?" && currentBranch.Pullables == "?" {
trackColor = color.FgRed
}
- status := utils.ColoredString(fmt.Sprintf("↑%s↓%s", state.pushables, state.pullables), trackColor)
- branches := gui.State.Branches
+ status = utils.ColoredString(fmt.Sprintf("↑%s↓%s ", currentBranch.Pushables, currentBranch.Pullables), trackColor)
+ }
- if gui.State.WorkingTreeState != "normal" {
- status += utils.ColoredString(fmt.Sprintf(" (%s)", gui.State.WorkingTreeState), color.FgYellow)
- }
+ if gui.State.WorkingTreeState != "normal" {
+ status += utils.ColoredString(fmt.Sprintf("(%s) ", gui.State.WorkingTreeState), color.FgYellow)
+ }
- if len(branches) > 0 {
- branch := branches[0]
- name := utils.ColoredString(branch.Name, presentation.GetBranchColor(branch.Name))
- repoName := utils.GetCurrentRepoName()
- status += fmt.Sprintf(" %s → %s", repoName, name)
- }
+ name := utils.ColoredString(currentBranch.Name, presentation.GetBranchColor(currentBranch.Name))
+ repoName := utils.GetCurrentRepoName()
+ status += fmt.Sprintf("%s → %s ", repoName, name)
- fmt.Fprint(v, status)
+ gui.g.Update(func(*gocui.Gui) error {
+ gui.setViewContent(gui.g, gui.getStatusView(), status)
return nil
})
-
- return nil
}
func runeCount(str string) int {
@@ -70,10 +54,10 @@ func (gui *Gui) handleCheckForUpdate(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) handleStatusClick(g *gocui.Gui, v *gocui.View) error {
- state := gui.State.Panels.Status
+ currentBranch := gui.currentBranch()
cx, _ := v.Cursor()
- upstreamStatus := fmt.Sprintf("↑%s↓%s", state.pushables, state.pullables)
+ upstreamStatus := fmt.Sprintf("↑%s↓%s", currentBranch.Pushables, currentBranch.Pullables)
repoName := utils.GetCurrentRepoName()
gui.Log.Warn(gui.State.WorkingTreeState)
switch gui.State.WorkingTreeState {
diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go
index 7a1285bbb..254abd044 100644
--- a/pkg/gui/view_helpers.go
+++ b/pkg/gui/view_helpers.go
@@ -309,6 +309,11 @@ func (gui *Gui) getSearchView() *gocui.View {
return v
}
+func (gui *Gui) getStatusView() *gocui.View {
+ v, _ := gui.g.View("status")
+ return v
+}
+
func (gui *Gui) trimmedContent(v *gocui.View) string {
return strings.TrimSpace(v.Buffer())
}