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

add generate_cheatsheet script

script is generating markdown document with small cheatsheet
in selected language
This commit is contained in:
Dawid Dziurla 2018-09-01 16:50:22 +02:00
parent 1fa55875e2
commit 359636c1aa
No known key found for this signature in database
GPG Key ID: 7B6D8368172E9B0B
3 changed files with 58 additions and 13 deletions

View File

@ -47,23 +47,27 @@ func (gui *Gui) handleHelpClose(g *gocui.Gui, v *gocui.View) error {
return gui.returnFocus(g, v)
}
func (gui *Gui) GetKey(binding Binding) string {
r, ok := binding.Key.(rune)
key := ""
if ok {
key = string(r)
} else if binding.KeyReadable != "" {
key = binding.KeyReadable
}
return key
}
func (gui *Gui) handleHelp(g *gocui.Gui, v *gocui.View) error {
// clear keys slice, so we don't have ghost elements
keys = keys[:0]
content := ""
bindings := gui.getKeybindings()
bindings := gui.GetKeybindings()
for _, binding := range bindings {
r, ok := binding.Key.(rune)
key := ""
if ok {
key = string(r)
} else if binding.KeyReadable != "" {
key = binding.KeyReadable
}
if key != "" && binding.ViewName == v.Name() && binding.Description != "" {
if key := gui.GetKey(binding); key != "" && binding.ViewName == v.Name() && binding.Description != "" {
content += fmt.Sprintf(" %s - %s\n", key, binding.Description)
keys = append(keys, binding)
}

View File

@ -14,7 +14,7 @@ type Binding struct {
Description string
}
func (gui *Gui) getKeybindings() []Binding {
func (gui *Gui) GetKeybindings() []Binding {
bindings := []Binding{
{
ViewName: "",
@ -379,7 +379,7 @@ func (gui *Gui) getKeybindings() []Binding {
}
func (gui *Gui) keybindings(g *gocui.Gui) error {
bindings := gui.getKeybindings()
bindings := gui.GetKeybindings()
for _, binding := range bindings {
if err := g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil {

View File

@ -0,0 +1,41 @@
// run:
// LANG=en go run generate_cheatsheet.go
// to generate Keybindings_en.md file in current directory
// change LANG to generate cheatsheet in different language (if supported)
package main
import (
"os"
"fmt"
"strings"
"github.com/jesseduffield/lazygit/pkg/app"
"github.com/jesseduffield/lazygit/pkg/config"
)
func main() {
appConfig, _ := config.NewAppConfig("", "", "", "", "", new(bool))
a, _ := app.NewApp(appConfig)
lang := a.Tr.GetLanguage()
name := "Keybindings_" + lang + ".md"
bindings := a.Gui.GetKeybindings()
file, _ := os.Create(name)
current := ""
content := ""
file.WriteString("# Lazygit " + a.Tr.SLocalize("help"))
for _, binding := range bindings {
if key := a.Gui.GetKey(binding); key != "" && binding.Description != "" {
if binding.ViewName != current {
current = binding.ViewName
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)
file.WriteString(content)
}
}
}