aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bug/bug.go7
-rw-r--r--cache/cache.go8
-rw-r--r--termui/show_bug.go10
-rw-r--r--util/colors.go1
4 files changed, 22 insertions, 4 deletions
diff --git a/bug/bug.go b/bug/bug.go
index b90beaa7..3c52adc8 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -299,11 +299,16 @@ func (bug *Bug) IsValid() bool {
return true
}
-// Append an operation into the staging area, to be commited later
+// Append an operation into the staging area, to be committed later
func (bug *Bug) Append(op Operation) {
bug.staging.Append(op)
}
+// Return if the bug need to be committed
+func (bug *Bug) HasPendingOp() bool {
+ return !bug.staging.IsEmpty()
+}
+
// Write the staging area in Git and move the operations to the packs
func (bug *Bug) Commit(repo repository.Repo) error {
if bug.staging.IsEmpty() {
diff --git a/cache/cache.go b/cache/cache.go
index b6f47c6d..da0a2681 100644
--- a/cache/cache.go
+++ b/cache/cache.go
@@ -43,6 +43,7 @@ type BugCacher interface {
SetTitle(title string) error
Commit() error
+ CommitAsNeeded() error
}
// Cacher ------------------------
@@ -294,3 +295,10 @@ func (c *BugCache) SetTitle(title string) error {
func (c *BugCache) Commit() error {
return c.bug.Commit(c.repo)
}
+
+func (c *BugCache) CommitAsNeeded() error {
+ if c.bug.HasPendingOp() {
+ return c.bug.Commit(c.repo)
+ }
+ return nil
+}
diff --git a/termui/show_bug.go b/termui/show_bug.go
index 0189b2b3..aecdce4b 100644
--- a/termui/show_bug.go
+++ b/termui/show_bug.go
@@ -76,7 +76,7 @@ func (sb *showBug) layout(g *gocui.Gui) error {
v.Frame = false
v.BgColor = gocui.ColorBlue
- fmt.Fprintf(v, "[q] Return [c] Comment [t] Change title [↓,j] Down [↑,k] Up")
+ fmt.Fprintf(v, "[q] Save and return [c] Comment [t] Change title [↓,j] Down [↑,k] Up")
}
_, err = g.SetCurrentView(showBugView)
@@ -85,7 +85,7 @@ func (sb *showBug) layout(g *gocui.Gui) error {
func (sb *showBug) keybindings(g *gocui.Gui) error {
// Return
- if err := g.SetKeybinding(showBugView, 'q', gocui.ModNone, sb.back); err != nil {
+ if err := g.SetKeybinding(showBugView, 'q', gocui.ModNone, sb.saveAndBack); err != nil {
return err
}
@@ -263,7 +263,11 @@ func (sb *showBug) renderSidebar(v *gocui.View) {
}
}
-func (sb *showBug) back(g *gocui.Gui, v *gocui.View) error {
+func (sb *showBug) saveAndBack(g *gocui.Gui, v *gocui.View) error {
+ err := sb.bug.CommitAsNeeded()
+ if err != nil {
+ return err
+ }
ui.activateWindow(ui.bugTable)
return nil
}
diff --git a/util/colors.go b/util/colors.go
index 5169bef1..5aa34363 100644
--- a/util/colors.go
+++ b/util/colors.go
@@ -3,6 +3,7 @@ package util
import "github.com/fatih/color"
var (
+ Bold = color.New(color.Bold).SprintFunc()
Black = color.New(color.FgBlack).SprintFunc()
BlackBg = color.New(color.BgBlack, color.FgWhite).SprintFunc()
White = color.New(color.FgWhite).SprintFunc()