mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-06 22:33:07 +02:00
Add support for dynamic binding descriptions
This commit is contained in:
@ -25,7 +25,7 @@ func (self *OptionsMenuAction) Call() error {
|
||||
}
|
||||
return &types.MenuItem{
|
||||
OpensMenu: binding.OpensMenu,
|
||||
Label: binding.Description,
|
||||
Label: binding.GetDescription(),
|
||||
OnPress: func() error {
|
||||
if binding.Handler == nil {
|
||||
return nil
|
||||
@ -60,7 +60,7 @@ func (self *OptionsMenuAction) getBindings(context types.Context) ([]*types.Bind
|
||||
bindings, _ := self.c.GetInitialKeybindingsWithCustomCommands()
|
||||
|
||||
for _, binding := range bindings {
|
||||
if binding.Description != "" {
|
||||
if binding.GetDescription() != "" {
|
||||
if binding.ViewName == "" || binding.Tag == "global" {
|
||||
bindingsGlobal = append(bindingsGlobal, binding)
|
||||
} else if binding.ViewName == context.GetViewName() {
|
||||
@ -80,6 +80,6 @@ func (self *OptionsMenuAction) getBindings(context types.Context) ([]*types.Bind
|
||||
// handler in the keybinding struct.
|
||||
func uniqueBindings(bindings []*types.Binding) []*types.Binding {
|
||||
return lo.UniqBy(bindings, func(binding *types.Binding) string {
|
||||
return binding.Description
|
||||
return binding.GetDescription()
|
||||
})
|
||||
}
|
||||
|
@ -16,9 +16,17 @@ type Binding struct {
|
||||
Key Key
|
||||
Modifier gocui.Modifier
|
||||
Description string
|
||||
// DescriptionFunc is used instead of Description if non-nil, and is useful for dynamic
|
||||
// descriptions that change depending on context. Important: this must not be an expensive call.
|
||||
// Note that you should still provide a generic, non-dynamic description in the Description field,
|
||||
// as this is used in the cheatsheet.
|
||||
DescriptionFunc func() string
|
||||
// If defined, this is used in place of Description when showing the keybinding
|
||||
// in the options view at the bottom left of the screen.
|
||||
ShortDescription string
|
||||
// ShortDescriptionFunc is used instead of ShortDescription if non-nil, and is useful for dynamic
|
||||
// descriptions that change depending on context. Important: this must not be an expensive call.
|
||||
ShortDescriptionFunc func() string
|
||||
Alternative string
|
||||
Tag string // e.g. 'navigation'. Used for grouping things in the cheatsheet
|
||||
OpensMenu bool
|
||||
@ -47,11 +55,21 @@ func (b *Binding) IsDisabled() bool {
|
||||
return b.GetDisabledReason != nil && b.GetDisabledReason() != nil
|
||||
}
|
||||
|
||||
func (b *Binding) GetDescription() string {
|
||||
if b.DescriptionFunc != nil {
|
||||
return b.DescriptionFunc()
|
||||
}
|
||||
return b.Description
|
||||
}
|
||||
|
||||
func (b *Binding) GetShortDescription() string {
|
||||
if b.ShortDescriptionFunc != nil {
|
||||
return b.ShortDescriptionFunc()
|
||||
}
|
||||
if b.ShortDescription != "" {
|
||||
return b.ShortDescription
|
||||
}
|
||||
return b.Description
|
||||
return b.GetDescription()
|
||||
}
|
||||
|
||||
// A guard is a decorator which checks something before executing a handler
|
||||
|
Reference in New Issue
Block a user