diff options
author | Dawid Dziurla <dawidd0811@gmail.com> | 2018-09-01 16:50:22 +0200 |
---|---|---|
committer | Dawid Dziurla <dawidd0811@gmail.com> | 2018-09-03 17:54:06 +0200 |
commit | 359636c1aa394bf8b619a7287f504e6afcf11470 (patch) | |
tree | a9ec5c0a8beba2f874d63e3ffebd64d18ee0851c /pkg/gui | |
parent | 1fa55875e2487e9b5d9ec910a1b7a5da795333d9 (diff) |
add generate_cheatsheet script
script is generating markdown document with small cheatsheet
in selected language
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/help_panel.go | 26 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 4 |
2 files changed, 17 insertions, 13 deletions
diff --git a/pkg/gui/help_panel.go b/pkg/gui/help_panel.go index 3c102f2dc..ffb0628b7 100644 --- a/pkg/gui/help_panel.go +++ b/pkg/gui/help_panel.go @@ -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) } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 34c3e0f68..034f907bf 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -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 { |