aboutsummaryrefslogtreecommitdiffstats
path: root/termui/show_bug.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-08-12 02:42:03 +0200
committerMichael Muré <batolettre@gmail.com>2018-08-12 02:42:03 +0200
commit53a3d5e11355ec6bed2e27bc26459a50e435b643 (patch)
tree36fc783081f21bed66398e3f93b6c0c1b6bd1275 /termui/show_bug.go
parentf51cc4a33fcac3ebf2024e0c6cb97cb809f8db71 (diff)
downloadgit-bug-53a3d5e11355ec6bed2e27bc26459a50e435b643.tar.gz
termui: add and remove labels
Diffstat (limited to 'termui/show_bug.go')
-rw-r--r--termui/show_bug.go75
1 files changed, 74 insertions, 1 deletions
diff --git a/termui/show_bug.go b/termui/show_bug.go
index 040a7b5f..ab0fd472 100644
--- a/termui/show_bug.go
+++ b/termui/show_bug.go
@@ -90,8 +90,15 @@ func (sb *showBug) layout(g *gocui.Gui) error {
sb.childViews = append(sb.childViews, showBugInstructionView)
v.Frame = false
v.BgColor = gocui.ColorBlue
+ }
+
+ v.Clear()
+ fmt.Fprintf(v, "[q] Save and return [←,h] Left [↓,j] Down [↑,k] Up [→,l] Right ")
- fmt.Fprintf(v, "[q] Save and return [c] Comment [t] Change title [↓,j] Down [↑,k] Up")
+ if sb.isOnSide {
+ fmt.Fprint(v, "[a] Add label [r] Remove label")
+ } else {
+ fmt.Fprint(v, "[c] Comment [t] Change title")
}
_, err = g.SetViewOnTop(showBugInstructionView)
@@ -170,6 +177,14 @@ func (sb *showBug) keybindings(g *gocui.Gui) error {
}
// Labels
+ if err := g.SetKeybinding(showBugView, 'a', gocui.ModNone,
+ sb.addLabel); err != nil {
+ return err
+ }
+ if err := g.SetKeybinding(showBugView, 'r', gocui.ModNone,
+ sb.removeLabel); err != nil {
+ return err
+ }
return nil
}
@@ -563,3 +578,61 @@ func (sb *showBug) comment(g *gocui.Gui, v *gocui.View) error {
func (sb *showBug) setTitle(g *gocui.Gui, v *gocui.View) error {
return setTitleWithEditor(sb.bug)
}
+
+func (sb *showBug) addLabel(g *gocui.Gui, v *gocui.View) error {
+ c := ui.inputPopup.Activate("Add labels")
+
+ go func() {
+ input := <-c
+
+ labels := strings.FieldsFunc(input, func(r rune) bool {
+ return r == ' ' || r == ','
+ })
+
+ err := sb.bug.ChangeLabels(trimLabels(labels), nil)
+ if err != nil {
+ ui.errorPopup.Activate(err.Error())
+ }
+
+ g.Update(func(gui *gocui.Gui) error {
+ return nil
+ })
+ }()
+
+ return nil
+}
+
+func (sb *showBug) removeLabel(g *gocui.Gui, v *gocui.View) error {
+ c := ui.inputPopup.Activate("Remove labels")
+
+ go func() {
+ input := <-c
+
+ labels := strings.FieldsFunc(input, func(r rune) bool {
+ return r == ' ' || r == ','
+ })
+
+ err := sb.bug.ChangeLabels(nil, trimLabels(labels))
+ if err != nil {
+ ui.errorPopup.Activate(err.Error())
+ }
+
+ g.Update(func(gui *gocui.Gui) error {
+ return nil
+ })
+ }()
+
+ return nil
+}
+
+func trimLabels(labels []string) []string {
+ var result []string
+
+ for _, label := range labels {
+ trimmed := strings.TrimSpace(label)
+ if len(trimmed) > 0 {
+ result = append(result, trimmed)
+ }
+ }
+ return result
+}