1
0
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:
Stefan Haller
2025-07-28 14:53:49 +02:00
parent 9eb1e3a729
commit 75afa099e9
2 changed files with 25 additions and 7 deletions

View File

@ -16,12 +16,20 @@ 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
Alternative string
Tag string // e.g. 'navigation'. Used for grouping things in the cheatsheet
OpensMenu bool
// 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
// If true, the keybinding will appear at the bottom of the screen.
// Even if set to true, the keybinding will not be displayed if it is currently
@ -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