summaryrefslogtreecommitdiffstats
path: root/pkg/gui/keybindings.go
diff options
context:
space:
mode:
authorDavid Chen <weichen2000121@gmail.com>2020-01-07 09:50:25 -0800
committerDavid Chen <weichen2000121@gmail.com>2020-01-07 09:50:25 -0800
commit529ba45cc74c9f777c0589fa85b4a5f3ee109402 (patch)
tree14dea64b3b3292f8093e4c184286564e9c8ee4c4 /pkg/gui/keybindings.go
parent66c7672a0cda3fa95b49d5bb2b6a0d25b4631794 (diff)
fixed keybinding display in merge_panel.go
Diffstat (limited to 'pkg/gui/keybindings.go')
-rw-r--r--pkg/gui/keybindings.go74
1 files changed, 27 insertions, 47 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 50cec5afd..032281608 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -21,7 +21,7 @@ type Binding struct {
// GetDisplayStrings returns the display string of a file
func (b *Binding) GetDisplayStrings(isFocused bool) []string {
- return []string{b.GetKey(), b.Description}
+ return []string{GetKeyDisplay(b.Key), b.Description}
}
var keyMapReversed = map[gocui.Key]string{
@@ -43,10 +43,10 @@ var keyMapReversed = map[gocui.Key]string{
gocui.KeyEnd: "end",
gocui.KeyPgup: "pgup",
gocui.KeyPgdn: "pgdown",
- gocui.KeyArrowUp: "up",
- gocui.KeyArrowDown: "down",
- gocui.KeyArrowLeft: "left",
- gocui.KeyArrowRight: "right",
+ gocui.KeyArrowUp: "▲",
+ gocui.KeyArrowDown: "▼",
+ gocui.KeyArrowLeft: "◄",
+ gocui.KeyArrowRight: "►",
gocui.KeyTab: "tab", // ctrl+i
gocui.KeyEnter: "enter", // ctrl+m
gocui.KeyEsc: "esc", // ctrl+[, ctrl+3
@@ -83,48 +83,6 @@ var keyMapReversed = map[gocui.Key]string{
gocui.KeyCtrl8: "ctrl+8",
}
-// GetKey is a function.
-func (b *Binding) GetKey() string {
- key := 0
-
- switch b.Key.(type) {
- case rune:
- key = int(b.Key.(rune))
- case gocui.Key:
- value, ok := keyMapReversed[b.Key.(gocui.Key)]
- if ok {
- return value
- }
- key = int(b.Key.(gocui.Key))
- }
-
- // special keys
- switch key {
- case 27:
- return "esc"
- case 13:
- return "enter"
- case 32:
- return "space"
- case 65514:
- return "►"
- case 65515:
- return "◄"
- case 65517:
- return "▲"
- case 65516:
- return "▼"
- case 65508:
- return "PgUp"
- case 65507:
- return "PgDn"
- case 9:
- return "tab"
- }
-
- return string(key)
-}
-
var keymap = map[string]interface{}{
"<c-a>": gocui.KeyCtrlA,
"<c-b>": gocui.KeyCtrlB,
@@ -195,6 +153,28 @@ var keymap = map[string]interface{}{
"<right>": gocui.KeyArrowRight,
}
+func (gui *Gui) getKeyDisplay(name string) string {
+ key := gui.getKey(name)
+ return GetKeyDisplay(key)
+}
+
+func GetKeyDisplay(key interface{}) string {
+ keyInt := 0
+
+ switch key.(type) {
+ case rune:
+ keyInt = int(key.(rune))
+ case gocui.Key:
+ value, ok := keyMapReversed[key.(gocui.Key)]
+ if ok {
+ return value
+ }
+ keyInt = int(key.(gocui.Key))
+ }
+
+ return string(keyInt)
+}
+
func (gui *Gui) getKey(name string) interface{} {
key := gui.Config.GetUserConfig().GetString("keybinding." + name)
if len(key) > 1 {