diff options
author | Dawid Dziurla <dawidd0811@gmail.com> | 2019-01-16 18:42:54 +0100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-01-17 10:11:17 +1100 |
commit | b6f8ebc0ca1c4cdaa63bfd12f5507d368171b872 (patch) | |
tree | 3726cc452f1c2fcb213566647dd2b3261301aef2 | |
parent | 3e2406972248ab824b22c7c3965b5f5aab8c9b7b (diff) |
delete KeyReadable field from Binding struct
also rewrite GetKey function
-rw-r--r-- | pkg/gui/keybindings.go | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 576fee59a..f65852a31 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -12,7 +12,6 @@ type Binding struct { Handler func(*gocui.Gui, *gocui.View) error Key interface{} // FIXME: find out how to get `gocui.Key | rune` Modifier gocui.Modifier - KeyReadable string Description string } @@ -23,16 +22,26 @@ func (b *Binding) GetDisplayStrings() []string { // GetKey is a function. func (b *Binding) GetKey() string { - r, ok := b.Key.(rune) - key := "" + key := 0 - if ok { - key = string(r) - } else if b.KeyReadable != "" { - key = b.KeyReadable + switch b.Key.(type) { + case rune: + key = int(b.Key.(rune)) + case gocui.Key: + key = int(b.Key.(gocui.Key)) } - return key + // special keys + switch key { + case 27: + return "esc" + case 13: + return "enter" + case 32: + return "space" + } + + return string(key) } // GetKeybindings is a function. @@ -144,7 +153,6 @@ func (gui *Gui) GetKeybindings() []*Binding { Key: gocui.KeySpace, Modifier: gocui.ModNone, Handler: gui.handleFilePress, - KeyReadable: "space", Description: gui.Tr.SLocalize("toggleStaged"), }, { ViewName: "files", @@ -218,7 +226,6 @@ func (gui *Gui) GetKeybindings() []*Binding { Modifier: gocui.ModNone, Handler: gui.handleSwitchToStagingPanel, Description: gui.Tr.SLocalize("StageLines"), - KeyReadable: "enter", }, { ViewName: "files", Key: 'f', @@ -290,7 +297,6 @@ func (gui *Gui) GetKeybindings() []*Binding { Key: gocui.KeySpace, Modifier: gocui.ModNone, Handler: gui.handleBranchPress, - KeyReadable: "space", Description: gui.Tr.SLocalize("checkout"), }, { ViewName: "branches", @@ -369,7 +375,6 @@ func (gui *Gui) GetKeybindings() []*Binding { Key: gocui.KeySpace, Modifier: gocui.ModNone, Handler: gui.handleStashApply, - KeyReadable: "space", Description: gui.Tr.SLocalize("apply"), }, { ViewName: "stash", @@ -418,7 +423,6 @@ func (gui *Gui) GetKeybindings() []*Binding { Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: gui.handleStagingEscape, - KeyReadable: "esc", Description: gui.Tr.SLocalize("EscapeStaging"), }, { ViewName: "staging", |