From dc911906b3ded868074549717bdf653dd6ddb7a8 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen Date: Tue, 21 Aug 2018 06:36:20 -0400 Subject: [PATCH 1/5] Esc will quit when not in popup, fixes #197 --- pkg/gui/gui.go | 5 ++++- pkg/gui/keybindings.go | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 66777b3a6..3e0bd9936 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -363,5 +363,8 @@ func (gui *Gui) RunWithSubprocesses() { } func (gui *Gui) quit(g *gocui.Gui, v *gocui.View) error { - return gocui.ErrQuit + if v.Name() != "commitMessage" && v.Name() != "confirmation" { + return gocui.ErrQuit + } + return nil } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 68cccda6b..d09ed64b1 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -16,6 +16,7 @@ func (gui *Gui) keybindings(g *gocui.Gui) error { bindings := []Binding{ {ViewName: "", Key: 'q', Modifier: gocui.ModNone, Handler: gui.quit}, {ViewName: "", Key: gocui.KeyCtrlC, Modifier: gocui.ModNone, Handler: gui.quit}, + {ViewName: "", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.quit}, {ViewName: "", Key: gocui.KeyPgup, Modifier: gocui.ModNone, Handler: gui.scrollUpMain}, {ViewName: "", Key: gocui.KeyPgdn, Modifier: gocui.ModNone, Handler: gui.scrollDownMain}, {ViewName: "", Key: gocui.KeyCtrlU, Modifier: gocui.ModNone, Handler: gui.scrollUpMain}, From 646c205227f1d07e098e674bfafc848800adea1c Mon Sep 17 00:00:00 2001 From: Tommy Nguyen Date: Tue, 21 Aug 2018 07:50:37 -0400 Subject: [PATCH 2/5] s/quit/escape, don't use special handling for views --- pkg/gui/gui.go | 7 ++----- pkg/gui/keybindings.go | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 3e0bd9936..d07c7afee 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -362,9 +362,6 @@ func (gui *Gui) RunWithSubprocesses() { } } -func (gui *Gui) quit(g *gocui.Gui, v *gocui.View) error { - if v.Name() != "commitMessage" && v.Name() != "confirmation" { - return gocui.ErrQuit - } - return nil +func (gui *Gui) escape(g *gocui.Gui, v *gocui.View) error { + return gocui.ErrQuit } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index d09ed64b1..f0f2538b2 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -14,9 +14,9 @@ type Binding struct { func (gui *Gui) keybindings(g *gocui.Gui) error { bindings := []Binding{ - {ViewName: "", Key: 'q', Modifier: gocui.ModNone, Handler: gui.quit}, - {ViewName: "", Key: gocui.KeyCtrlC, Modifier: gocui.ModNone, Handler: gui.quit}, - {ViewName: "", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.quit}, + {ViewName: "", Key: 'q', Modifier: gocui.ModNone, Handler: gui.escape}, + {ViewName: "", Key: gocui.KeyCtrlC, Modifier: gocui.ModNone, Handler: gui.escape}, + {ViewName: "", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.escape}, {ViewName: "", Key: gocui.KeyPgup, Modifier: gocui.ModNone, Handler: gui.scrollUpMain}, {ViewName: "", Key: gocui.KeyPgdn, Modifier: gocui.ModNone, Handler: gui.scrollDownMain}, {ViewName: "", Key: gocui.KeyCtrlU, Modifier: gocui.ModNone, Handler: gui.scrollUpMain}, From cd4063c7630395ab91d8a47ee86025dda823f6e8 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen Date: Tue, 21 Aug 2018 08:54:51 -0400 Subject: [PATCH 3/5] s/escape/quit --- pkg/commands/git.go | 4 ++-- pkg/gui/files_panel.go | 23 ++++++++++++----------- pkg/gui/gui.go | 2 +- pkg/gui/keybindings.go | 6 +++--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index bf9aa6646..65e457b6f 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -270,12 +270,12 @@ func (c *GitCommand) Pull() error { } // Push push to a branch -func (c *GitCommand) Push(branchName string, force bool) error { +func (c *GitCommand) Push(branchName string, force bool) (*exec.Cmd, error) { forceFlag := "" if force { forceFlag = "--force-with-lease " } - return c.OSCommand.RunCommand("git push " + forceFlag + "-u origin " + branchName) + return c.OSCommand.PrepareSubProcess(c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, "git push " + forceFlag + "-u origin " + branchName) } // SquashPreviousTwoCommits squashes a commit down to the one below it diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 5791a9d15..0b921ca0d 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -364,17 +364,18 @@ func (gui *Gui) pushWithForceFlag(currentView *gocui.View, force bool) error { if err := gui.createMessagePanel(gui.g, currentView, "", gui.Tr.SLocalize("PushWait")); err != nil { return err } - go func() { - branchName := gui.State.Branches[0].Name - if err := gui.GitCommand.Push(branchName, force); err != nil { - _ = gui.createErrorPanel(gui.g, err.Error()) - } else { - _ = gui.closeConfirmationPrompt(gui.g) - _ = gui.refreshCommits(gui.g) - _ = gui.refreshStatus(gui.g) - } - }() - return nil + branchName := gui.State.Branches[0].Name + sub, err := gui.GitCommand.Push(branchName, force) + if err != nil { + _ = gui.createErrorPanel(gui.g, err.Error()) + } + if sub != nil { + gui.SubProcess = sub + return gui.Errors.ErrSubProcess + } + _ = gui.closeConfirmationPrompt(gui.g) + _ = gui.refreshStatus(gui.g) + return gui.refreshCommits(gui.g) } func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index d07c7afee..66777b3a6 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -362,6 +362,6 @@ func (gui *Gui) RunWithSubprocesses() { } } -func (gui *Gui) escape(g *gocui.Gui, v *gocui.View) error { +func (gui *Gui) quit(g *gocui.Gui, v *gocui.View) error { return gocui.ErrQuit } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index f0f2538b2..d09ed64b1 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -14,9 +14,9 @@ type Binding struct { func (gui *Gui) keybindings(g *gocui.Gui) error { bindings := []Binding{ - {ViewName: "", Key: 'q', Modifier: gocui.ModNone, Handler: gui.escape}, - {ViewName: "", Key: gocui.KeyCtrlC, Modifier: gocui.ModNone, Handler: gui.escape}, - {ViewName: "", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.escape}, + {ViewName: "", Key: 'q', Modifier: gocui.ModNone, Handler: gui.quit}, + {ViewName: "", Key: gocui.KeyCtrlC, Modifier: gocui.ModNone, Handler: gui.quit}, + {ViewName: "", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.quit}, {ViewName: "", Key: gocui.KeyPgup, Modifier: gocui.ModNone, Handler: gui.scrollUpMain}, {ViewName: "", Key: gocui.KeyPgdn, Modifier: gocui.ModNone, Handler: gui.scrollDownMain}, {ViewName: "", Key: gocui.KeyCtrlU, Modifier: gocui.ModNone, Handler: gui.scrollUpMain}, From eff931a1387dc042b77701ece91e4028bb15aeda Mon Sep 17 00:00:00 2001 From: Tommy Nguyen Date: Tue, 21 Aug 2018 09:00:16 -0400 Subject: [PATCH 4/5] Update gocui fork --- Gopkg.lock | 2 +- vendor/github.com/jesseduffield/gocui/gui.go | 28 ++++++++++++++----- .../jesseduffield/gocui/keybinding.go | 3 -- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 6efc5a34e..9c715f884 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -77,7 +77,7 @@ branch = "master" name = "github.com/jesseduffield/gocui" packages = ["."] - revision = "432b7f6215f81ef1aaa1b2d9b69887822923cf79" + revision = "76a959bb4b0df223fd046b96b68f0162dd609e4b" [[projects]] name = "github.com/kevinburke/ssh_config" diff --git a/vendor/github.com/jesseduffield/gocui/gui.go b/vendor/github.com/jesseduffield/gocui/gui.go index 28a52d1cd..24ff49808 100644 --- a/vendor/github.com/jesseduffield/gocui/gui.go +++ b/vendor/github.com/jesseduffield/gocui/gui.go @@ -653,17 +653,31 @@ func (g *Gui) onKey(ev *termbox.Event) error { // execKeybindings executes the keybinding handlers that match the passed view // and event. The value of matched is true if there is a match and no errors. func (g *Gui) execKeybindings(v *View, ev *termbox.Event) (matched bool, err error) { - matched = false + var globalKb *keybinding for _, kb := range g.keybindings { if kb.handler == nil { continue } - if kb.matchKeypress(Key(ev.Key), ev.Ch, Modifier(ev.Mod)) && kb.matchView(v) { - if err := kb.handler(g, v); err != nil { - return false, err - } - matched = true + if !kb.matchKeypress(Key(ev.Key), ev.Ch, Modifier(ev.Mod)) { + continue + } + if kb.matchView(v) { + return g.execKeybinding(v, kb) + } + if kb.viewName == "" { + globalKb = kb } } - return matched, nil + if globalKb != nil { + return g.execKeybinding(v, globalKb) + } + return false, nil +} + +// execKeybinding executes a given keybinding +func (g *Gui) execKeybinding(v *View, kb *keybinding) (bool, error) { + if err := kb.handler(g, v); err != nil { + return false, err + } + return true, nil } diff --git a/vendor/github.com/jesseduffield/gocui/keybinding.go b/vendor/github.com/jesseduffield/gocui/keybinding.go index 7efdb75c6..82d1acc9f 100644 --- a/vendor/github.com/jesseduffield/gocui/keybinding.go +++ b/vendor/github.com/jesseduffield/gocui/keybinding.go @@ -38,9 +38,6 @@ func (kb *keybinding) matchView(v *View) bool { if v.Editable == true && kb.ch != 0 { return false } - if kb.viewName == "" { - return true - } return v != nil && kb.viewName == v.name } From 110ff38c0d4a40ff450086480fe8ebe0fd2ed61d Mon Sep 17 00:00:00 2001 From: Tommy Nguyen Date: Wed, 22 Aug 2018 11:34:16 -0400 Subject: [PATCH 5/5] Remove accidentally checked in code --- pkg/commands/git.go | 4 ++-- pkg/gui/files_panel.go | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 65e457b6f..bf9aa6646 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -270,12 +270,12 @@ func (c *GitCommand) Pull() error { } // Push push to a branch -func (c *GitCommand) Push(branchName string, force bool) (*exec.Cmd, error) { +func (c *GitCommand) Push(branchName string, force bool) error { forceFlag := "" if force { forceFlag = "--force-with-lease " } - return c.OSCommand.PrepareSubProcess(c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, "git push " + forceFlag + "-u origin " + branchName) + return c.OSCommand.RunCommand("git push " + forceFlag + "-u origin " + branchName) } // SquashPreviousTwoCommits squashes a commit down to the one below it diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 0b921ca0d..5791a9d15 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -364,18 +364,17 @@ func (gui *Gui) pushWithForceFlag(currentView *gocui.View, force bool) error { if err := gui.createMessagePanel(gui.g, currentView, "", gui.Tr.SLocalize("PushWait")); err != nil { return err } - branchName := gui.State.Branches[0].Name - sub, err := gui.GitCommand.Push(branchName, force) - if err != nil { - _ = gui.createErrorPanel(gui.g, err.Error()) - } - if sub != nil { - gui.SubProcess = sub - return gui.Errors.ErrSubProcess - } - _ = gui.closeConfirmationPrompt(gui.g) - _ = gui.refreshStatus(gui.g) - return gui.refreshCommits(gui.g) + go func() { + branchName := gui.State.Branches[0].Name + if err := gui.GitCommand.Push(branchName, force); err != nil { + _ = gui.createErrorPanel(gui.g, err.Error()) + } else { + _ = gui.closeConfirmationPrompt(gui.g) + _ = gui.refreshCommits(gui.g) + _ = gui.refreshStatus(gui.g) + } + }() + return nil } func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error {