diff options
author | Dawid Dziurla <dawidd0811@gmail.com> | 2018-09-04 15:25:02 +0200 |
---|---|---|
committer | Dawid Dziurla <dawidd0811@gmail.com> | 2018-09-04 15:25:02 +0200 |
commit | f29c81fb5c3bacb0ba3c0bf3ba090a36a2381a9c (patch) | |
tree | 94db9455416205db5b8758be79f06135c533ab07 /pkg/gui | |
parent | 67d99a24ea2686be562e8edfb650da5d90c5a68c (diff) |
add getMaxKeyLength
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/help_panel.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/pkg/gui/help_panel.go b/pkg/gui/help_panel.go index ffb0628b7..958014432 100644 --- a/pkg/gui/help_panel.go +++ b/pkg/gui/help_panel.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/jesseduffield/gocui" + "github.com/jesseduffield/lazygit/pkg/utils" ) var keys []Binding @@ -60,15 +61,27 @@ func (gui *Gui) GetKey(binding Binding) string { return key } +func (gui *Gui) getMaxKeyLength(bindings []Binding) int { + max := 0 + for _, binding := range bindings { + keyLength := len(gui.GetKey(binding)) + if keyLength > max { + max = keyLength + } + } + return max +} + 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() + padWidth := gui.getMaxKeyLength(bindings) for _, binding := range bindings { if key := gui.GetKey(binding); key != "" && binding.ViewName == v.Name() && binding.Description != "" { - content += fmt.Sprintf(" %s - %s\n", key, binding.Description) + content += fmt.Sprintf("%s %s\n", utils.WithPadding(key, padWidth), binding.Description) keys = append(keys, binding) } } |