1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-21 21:47:32 +02:00

delete KeyReadable field from Binding struct

also rewrite GetKey function
This commit is contained in:
Dawid Dziurla 2019-01-16 18:42:54 +01:00 committed by Jesse Duffield
parent 3e24069722
commit b6f8ebc0ca

View File

@ -12,7 +12,6 @@ type Binding struct {
Handler func(*gocui.Gui, *gocui.View) error Handler func(*gocui.Gui, *gocui.View) error
Key interface{} // FIXME: find out how to get `gocui.Key | rune` Key interface{} // FIXME: find out how to get `gocui.Key | rune`
Modifier gocui.Modifier Modifier gocui.Modifier
KeyReadable string
Description string Description string
} }
@ -23,16 +22,26 @@ func (b *Binding) GetDisplayStrings() []string {
// GetKey is a function. // GetKey is a function.
func (b *Binding) GetKey() string { func (b *Binding) GetKey() string {
r, ok := b.Key.(rune) key := 0
key := ""
if ok { switch b.Key.(type) {
key = string(r) case rune:
} else if b.KeyReadable != "" { key = int(b.Key.(rune))
key = b.KeyReadable 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. // GetKeybindings is a function.
@ -144,7 +153,6 @@ func (gui *Gui) GetKeybindings() []*Binding {
Key: gocui.KeySpace, Key: gocui.KeySpace,
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleFilePress, Handler: gui.handleFilePress,
KeyReadable: "space",
Description: gui.Tr.SLocalize("toggleStaged"), Description: gui.Tr.SLocalize("toggleStaged"),
}, { }, {
ViewName: "files", ViewName: "files",
@ -218,7 +226,6 @@ func (gui *Gui) GetKeybindings() []*Binding {
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleSwitchToStagingPanel, Handler: gui.handleSwitchToStagingPanel,
Description: gui.Tr.SLocalize("StageLines"), Description: gui.Tr.SLocalize("StageLines"),
KeyReadable: "enter",
}, { }, {
ViewName: "files", ViewName: "files",
Key: 'f', Key: 'f',
@ -290,7 +297,6 @@ func (gui *Gui) GetKeybindings() []*Binding {
Key: gocui.KeySpace, Key: gocui.KeySpace,
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleBranchPress, Handler: gui.handleBranchPress,
KeyReadable: "space",
Description: gui.Tr.SLocalize("checkout"), Description: gui.Tr.SLocalize("checkout"),
}, { }, {
ViewName: "branches", ViewName: "branches",
@ -369,7 +375,6 @@ func (gui *Gui) GetKeybindings() []*Binding {
Key: gocui.KeySpace, Key: gocui.KeySpace,
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleStashApply, Handler: gui.handleStashApply,
KeyReadable: "space",
Description: gui.Tr.SLocalize("apply"), Description: gui.Tr.SLocalize("apply"),
}, { }, {
ViewName: "stash", ViewName: "stash",
@ -418,7 +423,6 @@ func (gui *Gui) GetKeybindings() []*Binding {
Key: gocui.KeyEsc, Key: gocui.KeyEsc,
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleStagingEscape, Handler: gui.handleStagingEscape,
KeyReadable: "esc",
Description: gui.Tr.SLocalize("EscapeStaging"), Description: gui.Tr.SLocalize("EscapeStaging"),
}, { }, {
ViewName: "staging", ViewName: "staging",