summaryrefslogtreecommitdiffstats
path: root/branches_panel.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-06-02 08:35:49 +1000
committerJesse Duffield <jessedduffield@gmail.com>2018-06-02 08:35:49 +1000
commit103a6fd21970db5590040e3eef28a2228e7279ef (patch)
treeef8f62bd7a13c879e69b632a2de5aaffc2bef02a /branches_panel.go
parenta555a75565c2737a41583063936a70ab5e07c0e4 (diff)
logging durations and more stuff
Diffstat (limited to 'branches_panel.go')
-rw-r--r--branches_panel.go50
1 files changed, 20 insertions, 30 deletions
diff --git a/branches_panel.go b/branches_panel.go
index 75408f266..3ff79afda 100644
--- a/branches_panel.go
+++ b/branches_panel.go
@@ -1,18 +1,6 @@
-// lots of this has been directly ported from one of the example files, will brush up later
-
-// Copyright 2014 The gocui Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
package main
import (
-
- // "io"
- // "io/ioutil"
-
- // "strings"
-
"fmt"
"github.com/jroimartin/gocui"
@@ -41,34 +29,36 @@ func getSelectedBranch(v *gocui.View) Branch {
return state.Branches[lineNumber]
}
+// may want to standardise how these select methods work
func handleBranchSelect(g *gocui.Gui, v *gocui.View) error {
renderString(g, "options", "space: checkout, f: force checkout")
if len(state.Branches) == 0 {
return renderString(g, "main", "No branches for this repo")
}
- // may want to standardise how these select methods work
- lineNumber := getItemPosition(v)
- branch := state.Branches[lineNumber]
- diff, _ := getBranchDiff(branch.Name, branch.BaseBranch)
- if err := renderString(g, "main", diff); err != nil {
- return err
- }
+ go func() {
+ lineNumber := getItemPosition(v)
+ branch := state.Branches[lineNumber]
+ diff, _ := getBranchDiff(branch.Name, branch.BaseBranch)
+ renderString(g, "main", diff)
+ }()
return nil
}
// 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 refreshBranches(g *gocui.Gui) error {
- v, err := g.View("branches")
- if err != nil {
- panic(err)
- }
- state.Branches = getGitBranches()
- v.Clear()
- for _, branch := range state.Branches {
- fmt.Fprintln(v, branch.DisplayString)
- }
- resetOrigin(v)
- refreshStatus(g)
+ g.Update(func(g *gocui.Gui) error {
+ v, err := g.View("branches")
+ if err != nil {
+ panic(err)
+ }
+ state.Branches = getGitBranches()
+ v.Clear()
+ for _, branch := range state.Branches {
+ fmt.Fprintln(v, branch.DisplayString)
+ }
+ resetOrigin(v)
+ return refreshStatus(g)
+ })
return nil
}