1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/options_map.go
Jesse Duffield 460a166e16 Stop displaying navigation keybinding at bottom of screen
The reason for this is that now our labels for navigation keybindings are larger so they
take up more realestate. It's not the kind of thing a user needs to be told anyway,
anybody is going to try out hjkl and the arrow keys when a TUI opens up.

We could map from <up> to the single character up unicode rune but given you can rebind this stuff
I'd rather keep it simple
2023-05-21 11:01:15 +10:00

90 lines
2.7 KiB
Go

package gui
import (
"fmt"
"strings"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo"
)
type OptionsMapMgr struct {
c *helpers.HelperCommon
}
func (gui *Gui) renderContextOptionsMap(c types.Context) {
mgr := OptionsMapMgr{c: gui.c}
mgr.renderContextOptionsMap(c)
}
// render the options available for the current context at the bottom of the screen
func (self *OptionsMapMgr) renderContextOptionsMap(c types.Context) {
bindingsToDisplay := lo.Filter(c.GetKeybindings(self.c.KeybindingsOpts()), func(binding *types.Binding, _ int) bool {
return binding.Display
})
var optionsMap []bindingInfo
if len(bindingsToDisplay) == 0 {
optionsMap = self.globalOptions()
} else {
optionsMap = lo.Map(bindingsToDisplay, func(binding *types.Binding, _ int) bindingInfo {
return bindingInfo{
key: keybindings.LabelFromKey(binding.Key),
description: binding.Description,
}
})
}
self.renderOptions(self.formatBindingInfos(optionsMap))
}
func (self *OptionsMapMgr) formatBindingInfos(bindingInfos []bindingInfo) string {
return strings.Join(
lo.Map(bindingInfos, func(bindingInfo bindingInfo, _ int) string {
return fmt.Sprintf("%s: %s", bindingInfo.key, bindingInfo.description)
}),
", ")
}
func (self *OptionsMapMgr) renderOptions(options string) {
self.c.SetViewContent(self.c.Views().Options, options)
}
func (self *OptionsMapMgr) globalOptions() []bindingInfo {
keybindingConfig := self.c.UserConfig.Keybinding
return []bindingInfo{
{
key: fmt.Sprintf("%s/%s", keybindings.Label(keybindingConfig.Universal.ScrollUpMain), keybindings.Label(keybindingConfig.Universal.ScrollDownMain)),
description: self.c.Tr.LcScroll,
},
{
key: keybindings.Label(keybindingConfig.Universal.Return),
description: self.c.Tr.LcCancel,
},
{
key: keybindings.Label(keybindingConfig.Universal.Quit),
description: self.c.Tr.LcQuit,
},
{
key: keybindings.Label(keybindingConfig.Universal.OptionMenuAlt1),
description: self.c.Tr.LcMenu,
},
{
key: fmt.Sprintf("%s-%s", keybindings.Label(keybindingConfig.Universal.JumpToBlock[0]), keybindings.Label(keybindingConfig.Universal.JumpToBlock[len(keybindingConfig.Universal.JumpToBlock)-1])),
description: self.c.Tr.LcJump,
},
{
key: fmt.Sprintf("%s/%s", keybindings.Label(keybindingConfig.Universal.ScrollLeft), keybindings.Label(keybindingConfig.Universal.ScrollRight)),
description: self.c.Tr.LcScrollLeftRight,
},
}
}
type bindingInfo struct {
key string
description string
}