MCPcopy
hub / github.com/jesseduffield/lazygit / renderContextOptionsMap

Method renderContextOptionsMap

pkg/gui/options_map.go:37–106  ·  view source on GitHub ↗

Render the options available for the current context at the bottom of the screen STYLE GUIDE: we use the default options fg color for most keybindings. We can only use a different color if we're in a specific mode where the user is likely to want to press that key. For example, when in cherry-pickin

()

Source from the content-addressed store, hash-verified

35// to want to press that key. For example, when in cherry-picking mode, we
36// want to prominently show the keybinding for pasting commits.
37func (self *OptionsMapMgr) renderContextOptionsMap() {
38 currentContext := self.c.Context().Current()
39
40 currentContextBindings := currentContext.GetKeybindings(self.c.KeybindingsOpts())
41 globalBindings := self.c.Contexts().Global.GetKeybindings(self.c.KeybindingsOpts())
42
43 currentContextKeys := set.NewFromSlice(
44 lo.FlatMap(currentContextBindings, func(binding *types.Binding, _ int) []gocui.Key {
45 return binding.Keys
46 }))
47
48 allBindings := append(currentContextBindings, lo.Filter(globalBindings, func(b *types.Binding, _ int) bool {
49 return len(b.Keys) > 0 && !currentContextKeys.Includes(b.Keys[0])
50 })...)
51
52 bindingsToDisplay := lo.Filter(allBindings, func(binding *types.Binding, _ int) bool {
53 return len(binding.Keys) > 0 && binding.DisplayOnScreen && !binding.IsDisabled()
54 })
55
56 optionsMap := lo.Map(bindingsToDisplay, func(binding *types.Binding, _ int) bindingInfo {
57 displayStyle := theme.OptionsFgColor
58 if binding.DisplayStyle != nil {
59 displayStyle = *binding.DisplayStyle
60 }
61
62 return bindingInfo{
63 key: config.LabelForKey(binding.Keys[0]),
64 description: binding.GetShortDescription(),
65 style: displayStyle,
66 }
67 })
68
69 // Mode-specific local keybindings
70 if currentContext.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
71 if self.c.Modes().CherryPicking.Active() {
72 optionsMap = utils.Prepend(optionsMap, bindingInfo{
73 key: self.c.KeybindingsOpts().Config.Commits.PasteCommits.String(),
74 description: self.c.Tr.PasteCommits,
75 style: style.FgCyan,
76 })
77 }
78
79 if self.c.Model().BisectInfo.Started() {
80 optionsMap = utils.Prepend(optionsMap, bindingInfo{
81 key: self.c.KeybindingsOpts().Config.Commits.ViewBisectOptions.String(),
82 description: self.c.Tr.ViewBisectOptions,
83 style: style.FgGreen,
84 })
85 }
86 }
87
88 // Mode-specific global keybindings
89 if state := self.c.Model().WorkingTreeStateAtLastCommitRefresh; state.Any() {
90 optionsMap = utils.Prepend(optionsMap, bindingInfo{
91 key: self.c.KeybindingsOpts().Config.Universal.CreateRebaseOptionsMenu.String(),
92 description: state.OptionsMapTitle(self.c.Tr),
93 style: style.FgYellow,
94 })

Callers 1

Calls 15

renderOptionsMethod · 0.95
formatBindingInfosMethod · 0.95
LabelForKeyFunction · 0.92
PrependFunction · 0.92
FilterMethod · 0.80
IsDisabledMethod · 0.80
GetShortDescriptionMethod · 0.80
StartedMethod · 0.80
AnyMethod · 0.80
OptionsMapTitleMethod · 0.80
CurrentMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected