1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-07 13:42:01 +02:00

include global keybindings in menu

This commit is contained in:
Dawid Dziurla 2018-09-05 13:01:21 +02:00
parent 557009e660
commit 906f8e252e
No known key found for this signature in database
GPG Key ID: 7B6D8368172E9B0B
7 changed files with 34 additions and 9 deletions

View File

@ -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"),

View File

@ -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: '?',

View File

@ -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)
}

View File

@ -40,6 +40,9 @@ func addDutch(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "StatusTitle",
Other: "Status",
}, &i18n.Message{
ID: "GlobalTitle",
Other: "Global",
}, &i18n.Message{
ID: "navigate",
Other: "navigeer",

View File

@ -48,6 +48,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "StatusTitle",
Other: "Status",
}, &i18n.Message{
ID: "GlobalTitle",
Other: "Global",
}, &i18n.Message{
ID: "navigate",
Other: "navigate",

View File

@ -38,6 +38,9 @@ func addPolish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "StatusTitle",
Other: "Status",
}, &i18n.Message{
ID: "GlobalTitle",
Other: "Globalne",
}, &i18n.Message{
ID: "navigate",
Other: "nawiguj",

View File

@ -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)
}
}