diff options
| author | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2018-12-31 17:08:58 +0300 |
|---|---|---|
| committer | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2018-12-31 17:08:58 +0300 |
| commit | f96d29826072337d7e4498e6ccea3a05e014465b (patch) | |
| tree | 1a4d1c5cb5e0753e2a99b2ac06f44dd58a8146ad | |
| parent | Merge branch 'master' into develop (diff) | |
| download | gitbatch-f96d29826072337d7e4498e6ccea3a05e014465b.tar.gz | |
switch esc keybinding to q, add home/end buttons to repository nav and fic a bug preventing app to release sysin
| -rw-r--r-- | main.go | 4 | ||||
| -rw-r--r-- | pkg/gui/gui.go | 1 | ||||
| -rw-r--r-- | pkg/gui/keybindings.go | 36 | ||||
| -rw-r--r-- | pkg/gui/mainview.go | 38 |
4 files changed, 66 insertions, 13 deletions
@@ -3,7 +3,7 @@ package main import ( "github.com/isacikgoz/gitbatch/pkg/app" log "github.com/sirupsen/logrus" - "gopkg.in/alecthomas/kingpin.v2" + kingpin "gopkg.in/alecthomas/kingpin.v2" ) var ( @@ -15,7 +15,7 @@ var ( ) func main() { - kingpin.Version("gitbatch version 0.2.1") + kingpin.Version("gitbatch version 0.2.2") // parse the command line flag and options kingpin.Parse() diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 0c050bd..b19772b 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -111,7 +111,6 @@ func (gui *Gui) Run() error { g.InputEsc = true g.SetManagerFunc(gui.layout) - defer g.Close() gui.g = g g.Highlight = true g.SelFgColor = gocui.ColorGreen diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 3c5db5f..330c67a 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -110,10 +110,10 @@ func (gui *Gui) generateKeybindings() error { statusKeybindings := []*KeyBinding{ { View: view.Name, - Key: gocui.KeyEsc, + Key: 'q', Modifier: gocui.ModNone, Handler: gui.closeStatusView, - Display: "esc", + Display: "q", Description: "Close/Cancel", Vital: true, }, { @@ -318,6 +318,22 @@ func (gui *Gui) generateKeybindings() error { Vital: false, }, { View: mainViewFeature.Name, + Key: gocui.KeyHome, + Modifier: gocui.ModNone, + Handler: gui.cursorTop, + Display: "home", + Description: "Home", + Vital: false, + }, { + View: mainViewFeature.Name, + Key: gocui.KeyEnd, + Modifier: gocui.ModNone, + Handler: gui.cursorEnd, + Display: "end", + Description: "End", + Vital: false, + }, { + View: mainViewFeature.Name, Key: gocui.KeyArrowDown, Modifier: gocui.ModNone, Handler: gui.cursorDown, @@ -440,10 +456,10 @@ func (gui *Gui) generateKeybindings() error { // upstream confirmation { View: confirmationViewFeature.Name, - Key: gocui.KeyEsc, + Key: 'q', Modifier: gocui.ModNone, Handler: gui.closeConfirmationView, - Display: "esc", + Display: "q", Description: "Close/Cancel", Vital: true, }, { @@ -458,10 +474,10 @@ func (gui *Gui) generateKeybindings() error { // Diff View Controls { View: diffViewFeature.Name, - Key: gocui.KeyEsc, + Key: 'q', Modifier: gocui.ModNone, Handler: gui.closeCommitDiffView, - Display: "esc", + Display: "q", Description: "Close/Cancel", Vital: true, }, { @@ -500,10 +516,10 @@ func (gui *Gui) generateKeybindings() error { // Application Controls { View: cheatSheetViewFeature.Name, - Key: gocui.KeyEsc, + Key: 'q', Modifier: gocui.ModNone, Handler: gui.closeCheatSheetView, - Display: "esc", + Display: "q", Description: "Close/Cancel", Vital: true, }, { @@ -542,10 +558,10 @@ func (gui *Gui) generateKeybindings() error { // Error View { View: errorViewFeature.Name, - Key: gocui.KeyEsc, + Key: 'q', Modifier: gocui.ModNone, Handler: gui.closeErrorView, - Display: "esc", + Display: "q", Description: "Close/Cancel", Vital: true, }, { diff --git a/pkg/gui/mainview.go b/pkg/gui/mainview.go index d07a742..109d066 100644 --- a/pkg/gui/mainview.go +++ b/pkg/gui/mainview.go @@ -94,6 +94,44 @@ func (gui *Gui) cursorUp(g *gocui.Gui, v *gocui.View) error { return gui.renderMain() } +// moves cursor to the top +func (gui *Gui) cursorTop(g *gocui.Gui, v *gocui.View) error { + if v != nil { + ox, _ := v.Origin() + cx, _ := v.Cursor() + if err := v.SetOrigin(ox, 0); err != nil { + return err + } + if err := v.SetCursor(cx, 0); err != nil { + return err + } + } + return gui.renderMain() +} + +// moves cursor to the end +func (gui *Gui) cursorEnd(g *gocui.Gui, v *gocui.View) error { + if v != nil { + ox, _ := v.Origin() + cx, _ := v.Cursor() + _, vy := v.Size() + lr := len(gui.State.Repositories) + if lr <= vy { + if err := v.SetCursor(cx, lr-1); err != nil { + return err + } + return gui.renderMain() + } + if err := v.SetOrigin(ox, lr-vy); err != nil { + return err + } + if err := v.SetCursor(cx, vy-1); err != nil { + return err + } + } + return gui.renderMain() +} + // returns the entity at cursors position by taking its position in the gui's // slice of repositories. Since it is not a %100 percent safe methodology it may // rrequire a better implementation or the slice's order must be synchronized |
