mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
include global keybindings in menu
This commit is contained in:
parent
557009e660
commit
906f8e252e
@ -350,9 +350,6 @@ func (gui *Gui) renderAppStatus(g *gocui.Gui) error {
|
|||||||
|
|
||||||
func (gui *Gui) renderGlobalOptions(g *gocui.Gui) error {
|
func (gui *Gui) renderGlobalOptions(g *gocui.Gui) error {
|
||||||
return gui.renderOptionsMap(g, map[string]string{
|
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"),
|
"PgUp/PgDn": gui.Tr.SLocalize("scroll"),
|
||||||
"← → ↑ ↓": gui.Tr.SLocalize("navigate"),
|
"← → ↑ ↓": gui.Tr.SLocalize("navigate"),
|
||||||
"esc/q": gui.Tr.SLocalize("close"),
|
"esc/q": gui.Tr.SLocalize("close"),
|
||||||
|
@ -56,16 +56,19 @@ func (gui *Gui) GetKeybindings() []Binding {
|
|||||||
Key: 'P',
|
Key: 'P',
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.pushFiles,
|
Handler: gui.pushFiles,
|
||||||
|
Description: gui.Tr.SLocalize("push"),
|
||||||
}, {
|
}, {
|
||||||
ViewName: "",
|
ViewName: "",
|
||||||
Key: 'p',
|
Key: 'p',
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.pullFiles,
|
Handler: gui.pullFiles,
|
||||||
|
Description: gui.Tr.SLocalize("pull"),
|
||||||
}, {
|
}, {
|
||||||
ViewName: "",
|
ViewName: "",
|
||||||
Key: 'R',
|
Key: 'R',
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleRefresh,
|
Handler: gui.handleRefresh,
|
||||||
|
Description: gui.Tr.SLocalize("refresh"),
|
||||||
}, {
|
}, {
|
||||||
ViewName: "",
|
ViewName: "",
|
||||||
Key: '?',
|
Key: '?',
|
||||||
|
@ -10,6 +10,9 @@ import (
|
|||||||
|
|
||||||
func (gui *Gui) handleMenuPress(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleMenuPress(g *gocui.Gui, v *gocui.View) error {
|
||||||
lineNumber := gui.getItemPosition(v)
|
lineNumber := gui.getItemPosition(v)
|
||||||
|
if gui.State.Keys[lineNumber].Key == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if len(gui.State.Keys) > lineNumber {
|
if len(gui.State.Keys) > lineNumber {
|
||||||
err := gui.handleMenuClose(g, v)
|
err := gui.handleMenuClose(g, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -59,7 +62,7 @@ func (gui *Gui) GetKey(binding Binding) string {
|
|||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) getMaxKeyLength(bindings []Binding) int {
|
func (gui *Gui) GetMaxKeyLength(bindings []Binding) int {
|
||||||
max := 0
|
max := 0
|
||||||
for _, binding := range bindings {
|
for _, binding := range bindings {
|
||||||
keyLength := len(gui.GetKey(binding))
|
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
|
// clear keys slice, so we don't have ghost elements
|
||||||
gui.State.Keys = gui.State.Keys[:0]
|
gui.State.Keys = gui.State.Keys[:0]
|
||||||
content := ""
|
content := ""
|
||||||
|
current := ""
|
||||||
bindings := gui.GetKeybindings()
|
bindings := gui.GetKeybindings()
|
||||||
padWidth := gui.getMaxKeyLength(bindings)
|
padWidth := gui.GetMaxKeyLength(bindings)
|
||||||
|
|
||||||
for _, binding := range 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)
|
content += fmt.Sprintf("%s %s\n", utils.WithPadding(key, padWidth), binding.Description)
|
||||||
gui.State.Keys = append(gui.State.Keys, binding)
|
gui.State.Keys = append(gui.State.Keys, binding)
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,9 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StatusTitle",
|
ID: "StatusTitle",
|
||||||
Other: "Status",
|
Other: "Status",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "GlobalTitle",
|
||||||
|
Other: "Global",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "navigate",
|
ID: "navigate",
|
||||||
Other: "navigeer",
|
Other: "navigeer",
|
||||||
|
@ -48,6 +48,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StatusTitle",
|
ID: "StatusTitle",
|
||||||
Other: "Status",
|
Other: "Status",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "GlobalTitle",
|
||||||
|
Other: "Global",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "navigate",
|
ID: "navigate",
|
||||||
Other: "navigate",
|
Other: "navigate",
|
||||||
|
@ -38,6 +38,9 @@ func addPolish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "StatusTitle",
|
ID: "StatusTitle",
|
||||||
Other: "Status",
|
Other: "Status",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "GlobalTitle",
|
||||||
|
Other: "Globalne",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "navigate",
|
ID: "navigate",
|
||||||
Other: "nawiguj",
|
Other: "nawiguj",
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/app"
|
"github.com/jesseduffield/lazygit/pkg/app"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -20,9 +21,11 @@ func main() {
|
|||||||
lang := a.Tr.GetLanguage()
|
lang := a.Tr.GetLanguage()
|
||||||
name := "Keybindings_" + lang + ".md"
|
name := "Keybindings_" + lang + ".md"
|
||||||
bindings := a.Gui.GetKeybindings()
|
bindings := a.Gui.GetKeybindings()
|
||||||
|
padWidth := a.Gui.GetMaxKeyLength(bindings)
|
||||||
file, _ := os.Create(name)
|
file, _ := os.Create(name)
|
||||||
current := ""
|
current := "v"
|
||||||
content := ""
|
content := ""
|
||||||
|
title := ""
|
||||||
|
|
||||||
file.WriteString("# Lazygit " + a.Tr.SLocalize("menu"))
|
file.WriteString("# Lazygit " + a.Tr.SLocalize("menu"))
|
||||||
|
|
||||||
@ -30,11 +33,15 @@ func main() {
|
|||||||
if key := a.Gui.GetKey(binding); key != "" && binding.Description != "" {
|
if key := a.Gui.GetKey(binding); key != "" && binding.Description != "" {
|
||||||
if binding.ViewName != current {
|
if binding.ViewName != current {
|
||||||
current = binding.ViewName
|
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)
|
content = fmt.Sprintf("</pre>\n\n## %s\n<pre>\n", title)
|
||||||
file.WriteString(content)
|
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)
|
file.WriteString(content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user