summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-03-02 18:45:18 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-03-02 19:05:21 +1100
commit7a170bbccfb5464706694320041567fdf7cd5eff (patch)
tree800b44100d087e1f4004245e068d47b2c1540321
parent8c0ea8f45fde1dfddd23198fcb06ae77468e3a3a (diff)
extend cheatsheet generator to contain context based keybindings
-rw-r--r--Keybindings_en.md6
-rw-r--r--pkg/gui/keybindings.go5
-rw-r--r--pkg/i18n/english.go4
-rw-r--r--scripts/generate_cheatsheet.go99
4 files changed, 72 insertions, 42 deletions
diff --git a/Keybindings_en.md b/Keybindings_en.md
index ff91437df..e80ba5f95 100644
--- a/Keybindings_en.md
+++ b/Keybindings_en.md
@@ -30,8 +30,8 @@
<kbd>o</kbd>: open file
<kbd>i</kbd>: add to .gitignore
<kbd>r</kbd>: refresh files
- <kbd>s</kbd>: stash files
- <kbd>S</kbd>: soft reset to last commit
+ <kbd>S</kbd>: stash files
+ <kbd>s</kbd>: soft reset to last commit
<kbd>a</kbd>: stage/unstage all
<kbd>t</kbd>: add patch
<kbd>D</kbd>: reset hard and remove untracked files
@@ -57,7 +57,7 @@
<pre>
<kbd>s</kbd>: squash down
- <kbd>r</kbd>: rename commit
+ <kbd>r</kbd>: reword commit
<kbd>R</kbd>: rename commit with editor
<kbd>g</kbd>: reset to this commit
<kbd>f</kbd>: fixup commit
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 3e0e3b1d1..eb49fe672 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -13,7 +13,6 @@ type Binding struct {
Key interface{} // FIXME: find out how to get `gocui.Key | rune`
Modifier gocui.Modifier
Description string
- panic bool
}
// GetDisplayStrings returns the display string of a file
@@ -32,10 +31,6 @@ func (b *Binding) GetKey() string {
key = int(b.Key.(gocui.Key))
}
- if b.panic {
- panic(key)
- }
-
// special keys
switch key {
case 27:
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index 7195c5f0d..79c1e9854 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -311,10 +311,10 @@ func addEnglish(i18nObject *i18n.Bundle) error {
Other: "revert commit", // TODO: i18n
}, &i18n.Message{
ID: "OnlyRenameTopCommit",
- Other: "Can only rename topmost commit from within lazygit. Use shift+R instead",
+ Other: "Can only reword topmost commit from within lazygit. Use shift+R instead",
}, &i18n.Message{
ID: "renameCommit",
- Other: "rename commit",
+ Other: "reword commit",
}, &i18n.Message{
ID: "deleteCommit",
Other: "delete commit", // TODO: other languages
diff --git a/scripts/generate_cheatsheet.go b/scripts/generate_cheatsheet.go
index 92d5880a5..f8beaa457 100644
--- a/scripts/generate_cheatsheet.go
+++ b/scripts/generate_cheatsheet.go
@@ -19,6 +19,24 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui"
)
+type bindingSection struct {
+ title string
+ bindings []*gui.Binding
+}
+
+func main() {
+ mConfig, _ := config.NewAppConfig("", "", "", "", "", true)
+ mApp, _ := app.NewApp(mConfig)
+ lang := mApp.Tr.GetLanguage()
+ file, _ := os.Create("Keybindings_" + lang + ".md")
+
+ bindingSections := getBindingSections(mApp)
+
+ content := formatSections(mApp, bindingSections)
+
+ writeString(file, content)
+}
+
func writeString(file *os.File, str string) {
_, err := file.WriteString(str)
if err != nil {
@@ -35,24 +53,12 @@ func formatTitle(title string) string {
return fmt.Sprintf("\n## %s\n\n", title)
}
-func writeBinding(file *os.File, binding *gui.Binding) {
- info := fmt.Sprintf(" <kbd>%s</kbd>: %s\n", binding.GetKey(), binding.Description)
- writeString(file, info)
+func formatBinding(binding *gui.Binding) string {
+ return fmt.Sprintf(" <kbd>%s</kbd>: %s\n", binding.GetKey(), binding.Description)
}
-// I should really just build an array of tuples, one thing with a string and the other with a list of bindings, and then build them like that.
-
-func main() {
- mConfig, _ := config.NewAppConfig("", "", "", "", "", true)
- mApp, _ := app.NewApp(mConfig)
- lang := mApp.Tr.GetLanguage()
- file, _ := os.Create("Keybindings_" + lang + ".md")
- current := ""
-
- writeString(file, fmt.Sprintf("# Lazygit %s\n", mApp.Tr.SLocalize("menu")))
- writeString(file, formatTitle(localisedTitle(mApp, "global")))
-
- writeString(file, "<pre>\n")
+func getBindingSections(mApp *app.App) []*bindingSection {
+ bindingSections := []*bindingSection{}
// TODO: add context-based keybindings
for _, binding := range mApp.Gui.GetInitialKeybindings() {
@@ -60,32 +66,61 @@ func main() {
continue
}
- if binding.ViewName != current {
- current = binding.ViewName
- writeString(file, "</pre>\n")
- writeString(file, formatTitle(localisedTitle(mApp, current)))
- writeString(file, "<pre>\n")
+ viewName := binding.ViewName
+ if viewName == "" {
+ viewName = "global"
}
+ title := localisedTitle(mApp, viewName)
- writeBinding(file, binding)
+ bindingSections = addBinding(title, bindingSections, binding)
}
- writeString(file, "</pre>\n")
-
for view, contexts := range mApp.Gui.GetContextMap() {
for contextName, contextBindings := range contexts {
translatedView := localisedTitle(mApp, view)
translatedContextName := localisedTitle(mApp, contextName)
- writeString(file, fmt.Sprintf("\n## %s (%s)\n\n", translatedView, translatedContextName))
- writeString(file, "<pre>\n")
- for _, binding := range contextBindings {
- if binding.Description == "" {
- continue
- }
+ title := fmt.Sprintf("%s (%s)", translatedView, translatedContextName)
- writeBinding(file, binding)
+ for _, binding := range contextBindings {
+ bindingSections = addBinding(title, bindingSections, binding)
}
- writeString(file, "</pre>\n")
}
}
+
+ return bindingSections
+}
+
+func addBinding(title string, bindingSections []*bindingSection, binding *gui.Binding) []*bindingSection {
+ if binding.Description == "" {
+ return bindingSections
+ }
+
+ for _, section := range bindingSections {
+ if title == section.title {
+ section.bindings = append(section.bindings, binding)
+ return bindingSections
+ }
+ }
+
+ section := &bindingSection{
+ title: title,
+ bindings: []*gui.Binding{binding},
+ }
+
+ return append(bindingSections, section)
+}
+
+func formatSections(mApp *app.App, bindingSections []*bindingSection) string {
+ content := fmt.Sprintf("# Lazygit %s\n", mApp.Tr.SLocalize("menu"))
+
+ for _, section := range bindingSections {
+ content += formatTitle(section.title)
+ content += "<pre>\n"
+ for _, binding := range section.bindings {
+ content += formatBinding(binding)
+ }
+ content += "</pre>\n"
+ }
+
+ return content
}