From b6f8ebc0ca1c4cdaa63bfd12f5507d368171b872 Mon Sep 17 00:00:00 2001
From: Dawid Dziurla <dawidd0811@gmail.com>
Date: Wed, 16 Jan 2019 18:42:54 +0100
Subject: [PATCH] delete KeyReadable field from Binding struct

also rewrite GetKey function
---
 pkg/gui/keybindings.go | 30 +++++++++++++++++-------------
 1 file 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",