2022-12-30 14:24:24 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2023-03-23 03:35:07 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
2022-12-30 14:24:24 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
2023-03-21 11:57:52 +02:00
|
|
|
"github.com/samber/lo"
|
2022-12-30 14:24:24 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type OptionsMapMgr struct {
|
2023-03-23 03:35:07 +02:00
|
|
|
c *helpers.HelperCommon
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) renderContextOptionsMap(c types.Context) {
|
2023-07-31 10:32:38 +02:00
|
|
|
// In demos, we render our own content to this view
|
|
|
|
if gui.integrationTest != nil && gui.integrationTest.IsDemo() {
|
|
|
|
return
|
|
|
|
}
|
2022-12-30 14:24:24 +02:00
|
|
|
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) {
|
2023-03-21 11:57:52 +02:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
})
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
2023-03-21 11:57:52 +02:00
|
|
|
self.renderOptions(self.formatBindingInfos(optionsMap))
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
2023-03-21 11:57:52 +02:00
|
|
|
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)
|
|
|
|
}),
|
|
|
|
", ")
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *OptionsMapMgr) renderOptions(options string) {
|
|
|
|
self.c.SetViewContent(self.c.Views().Options, options)
|
|
|
|
}
|
|
|
|
|
2023-03-21 11:57:52 +02:00
|
|
|
func (self *OptionsMapMgr) globalOptions() []bindingInfo {
|
2022-12-30 14:24:24 +02:00
|
|
|
keybindingConfig := self.c.UserConfig.Keybinding
|
|
|
|
|
2023-03-21 11:57:52 +02:00
|
|
|
return []bindingInfo{
|
|
|
|
{
|
|
|
|
key: fmt.Sprintf("%s/%s", keybindings.Label(keybindingConfig.Universal.ScrollUpMain), keybindings.Label(keybindingConfig.Universal.ScrollDownMain)),
|
2023-05-25 13:11:51 +02:00
|
|
|
description: self.c.Tr.Scroll,
|
2023-03-21 11:57:52 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: keybindings.Label(keybindingConfig.Universal.Return),
|
2023-05-25 13:11:51 +02:00
|
|
|
description: self.c.Tr.Cancel,
|
2023-03-21 11:57:52 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: keybindings.Label(keybindingConfig.Universal.Quit),
|
2023-05-25 13:11:51 +02:00
|
|
|
description: self.c.Tr.Quit,
|
2023-03-21 11:57:52 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: keybindings.Label(keybindingConfig.Universal.OptionMenuAlt1),
|
2023-05-25 13:11:51 +02:00
|
|
|
description: self.c.Tr.Keybindings,
|
2023-03-21 11:57:52 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: fmt.Sprintf("%s-%s", keybindings.Label(keybindingConfig.Universal.JumpToBlock[0]), keybindings.Label(keybindingConfig.Universal.JumpToBlock[len(keybindingConfig.Universal.JumpToBlock)-1])),
|
2023-05-25 13:11:51 +02:00
|
|
|
description: self.c.Tr.Jump,
|
2023-03-21 11:57:52 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: fmt.Sprintf("%s/%s", keybindings.Label(keybindingConfig.Universal.ScrollLeft), keybindings.Label(keybindingConfig.Universal.ScrollRight)),
|
2023-05-25 13:11:51 +02:00
|
|
|
description: self.c.Tr.ScrollLeftRight,
|
2023-03-21 11:57:52 +02:00
|
|
|
},
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-21 11:57:52 +02:00
|
|
|
|
|
|
|
type bindingInfo struct {
|
|
|
|
key string
|
|
|
|
description string
|
|
|
|
}
|