summaryrefslogtreecommitdiffstats
path: root/pkg/gui/keybindings.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-09-17 21:02:30 +1000
committerJesse Duffield <jessedduffield@gmail.com>2018-09-17 21:02:30 +1000
commitc00c834b359bc0ebcd6e940e5cb5ef6f7247a6c7 (patch)
tree67ca05580afab38e8a743d6c3fcf91caa1cf82ee /pkg/gui/keybindings.go
parent3b765e5417501a39bca5c2f0038488dbbeb6b200 (diff)
standardise rendering of lists in panels
Diffstat (limited to 'pkg/gui/keybindings.go')
-rw-r--r--pkg/gui/keybindings.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index c8ed7d3c8..e05caaec7 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -1,6 +1,8 @@
package gui
-import "github.com/jesseduffield/gocui"
+import (
+ "github.com/jesseduffield/gocui"
+)
// Binding - a keybinding mapping a key and modifier to a handler. The keypress
// is only handled if the given view has focus, or handled globally if the view
@@ -14,8 +16,26 @@ type Binding struct {
Description string
}
-func (gui *Gui) GetKeybindings() []Binding {
- bindings := []Binding{
+// GetDisplayStrings returns the display string of a file
+func (b *Binding) GetDisplayStrings() []string {
+ return []string{b.GetKey(), b.Description}
+}
+
+func (b *Binding) GetKey() string {
+ r, ok := b.Key.(rune)
+ key := ""
+
+ if ok {
+ key = string(r)
+ } else if b.KeyReadable != "" {
+ key = b.KeyReadable
+ }
+
+ return key
+}
+
+func (gui *Gui) GetKeybindings() []*Binding {
+ bindings := []*Binding{
{
ViewName: "",
Key: 'q',
@@ -360,7 +380,7 @@ func (gui *Gui) GetKeybindings() []Binding {
// Would make these keybindings global but that interferes with editing
// input in the confirmation panel
for _, viewName := range []string{"status", "files", "branches", "commits", "stash", "menu"} {
- bindings = append(bindings, []Binding{
+ bindings = append(bindings, []*Binding{
{ViewName: viewName, Key: gocui.KeyTab, Modifier: gocui.ModNone, Handler: gui.nextView},
{ViewName: viewName, Key: gocui.KeyArrowLeft, Modifier: gocui.ModNone, Handler: gui.previousView},
{ViewName: viewName, Key: gocui.KeyArrowRight, Modifier: gocui.ModNone, Handler: gui.nextView},