diff options
author | Dawid Dziurla <dawidd0811@gmail.com> | 2018-09-05 13:01:21 +0200 |
---|---|---|
committer | Dawid Dziurla <dawidd0811@gmail.com> | 2018-09-05 13:16:40 +0200 |
commit | 906f8e252e43c1dbd2303fb90de660a2181e5f32 (patch) | |
tree | 25941fd431e59485485d0f6a8eef76daccf5f6db | |
parent | 557009e660e3203dce62624599c173e25f086465 (diff) |
include global keybindings in menu
-rw-r--r-- | pkg/gui/gui.go | 3 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 3 | ||||
-rw-r--r-- | pkg/gui/menu_panel.go | 15 | ||||
-rw-r--r-- | pkg/i18n/dutch.go | 3 | ||||
-rw-r--r-- | pkg/i18n/english.go | 3 | ||||
-rw-r--r-- | pkg/i18n/polish.go | 3 | ||||
-rw-r--r-- | scripts/generate_cheatsheet.go | 13 |
7 files changed, 34 insertions, 9 deletions
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index c9beb36eb..5642e0901 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -350,9 +350,6 @@ func (gui *Gui) renderAppStatus(g *gocui.Gui) error { func (gui *Gui) renderGlobalOptions(g *gocui.Gui) error { return gui.renderOptionsMap(g, map[string]string{ - "R": gui.Tr.SLocalize("refresh"), - "p": gui.Tr.SLocalize("pull"), - "P": gui.Tr.SLocalize("push"), "PgUp/PgDn": gui.Tr.SLocalize("scroll"), "← → ↑ ↓": gui.Tr.SLocalize("navigate"), "esc/q": gui.Tr.SLocalize("close"), diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 0ca82d3c6..9202d7a1d 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -56,16 +56,19 @@ func (gui *Gui) GetKeybindings() []Binding { Key: 'P', Modifier: gocui.ModNone, Handler: gui.pushFiles, + Description: gui.Tr.SLocalize("push"), }, { ViewName: "", Key: 'p', Modifier: gocui.ModNone, Handler: gui.pullFiles, + Description: gui.Tr.SLocalize("pull"), }, { ViewName: "", Key: 'R', Modifier: gocui.ModNone, Handler: gui.handleRefresh, + Description: gui.Tr.SLocalize("refresh"), }, { ViewName: "", Key: '?', diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index fa276e8c4..1bd02eeb2 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -10,6 +10,9 @@ import ( func (gui *Gui) handleMenuPress(g *gocui.Gui, v *gocui.View) error { lineNumber := gui.getItemPosition(v) + if gui.State.Keys[lineNumber].Key == nil { + return nil + } if len(gui.State.Keys) > lineNumber { err := gui.handleMenuClose(g, v) if err != nil { @@ -59,7 +62,7 @@ func (gui *Gui) GetKey(binding Binding) string { return key } -func (gui *Gui) getMaxKeyLength(bindings []Binding) int { +func (gui *Gui) GetMaxKeyLength(bindings []Binding) int { max := 0 for _, binding := range bindings { keyLength := len(gui.GetKey(binding)) @@ -74,11 +77,17 @@ func (gui *Gui) handleMenu(g *gocui.Gui, v *gocui.View) error { // clear keys slice, so we don't have ghost elements gui.State.Keys = gui.State.Keys[:0] content := "" + current := "" bindings := gui.GetKeybindings() - padWidth := gui.getMaxKeyLength(bindings) + padWidth := gui.GetMaxKeyLength(bindings) for _, binding := range bindings { - if key := gui.GetKey(binding); key != "" && binding.ViewName == v.Name() && binding.Description != "" { + if key := gui.GetKey(binding); key != "" && (binding.ViewName == v.Name() || binding.ViewName == "") && binding.Description != "" { + if binding.ViewName != current { + content += "\n" + gui.State.Keys = append(gui.State.Keys, Binding{}) + current = binding.ViewName + } content += fmt.Sprintf("%s %s\n", utils.WithPadding(key, padWidth), binding.Description) gui.State.Keys = append(gui.State.Keys, binding) } diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index cbdccbf2a..7a3ba16b0 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -41,6 +41,9 @@ func addDutch(i18nObject *i18n.Bundle) error { ID: "StatusTitle", Other: "Status", }, &i18n.Message{ + ID: "GlobalTitle", + Other: "Global", + }, &i18n.Message{ ID: "navigate", Other: "navigeer", }, &i18n.Message{ diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 471a75b6f..c92d5510a 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -49,6 +49,9 @@ func addEnglish(i18nObject *i18n.Bundle) error { ID: "StatusTitle", Other: "Status", }, &i18n.Message{ + ID: "GlobalTitle", + Other: "Global", + }, &i18n.Message{ ID: "navigate", Other: "navigate", }, &i18n.Message{ diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index f99890c15..cb190d246 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -39,6 +39,9 @@ func addPolish(i18nObject *i18n.Bundle) error { ID: "StatusTitle", Other: "Status", }, &i18n.Message{ + ID: "GlobalTitle", + Other: "Globalne", + }, &i18n.Message{ ID: "navigate", Other: "nawiguj", }, &i18n.Message{ diff --git a/scripts/generate_cheatsheet.go b/scripts/generate_cheatsheet.go index 2c18e5f03..95012e2a4 100644 --- a/scripts/generate_cheatsheet.go +++ b/scripts/generate_cheatsheet.go @@ -12,6 +12,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/app" "github.com/jesseduffield/lazygit/pkg/config" + "github.com/jesseduffield/lazygit/pkg/utils" ) func main() { @@ -20,9 +21,11 @@ func main() { lang := a.Tr.GetLanguage() name := "Keybindings_" + lang + ".md" bindings := a.Gui.GetKeybindings() + padWidth := a.Gui.GetMaxKeyLength(bindings) file, _ := os.Create(name) - current := "" + current := "v" content := "" + title := "" file.WriteString("# Lazygit " + a.Tr.SLocalize("menu")) @@ -30,11 +33,15 @@ func main() { if key := a.Gui.GetKey(binding); key != "" && binding.Description != "" { if binding.ViewName != current { current = binding.ViewName - title := a.Tr.SLocalize(strings.Title(current) + "Title") + if current == "" { + title = a.Tr.SLocalize("GlobalTitle") + } else { + title = a.Tr.SLocalize(strings.Title(current) + "Title") + } content = fmt.Sprintf("</pre>\n\n## %s\n<pre>\n", title) file.WriteString(content) } - content = fmt.Sprintf("\t<kbd>%s</kbd>:\t%s\n", key, binding.Description) + content = fmt.Sprintf("\t<kbd>%s</kbd>%s %s\n", key, strings.TrimPrefix(utils.WithPadding(key, padWidth), key), binding.Description) file.WriteString(content) } } |