@@ -16,12 +16,20 @@ type Binding struct {
16
16
Key Key
17
17
Modifier gocui.Modifier
18
18
Description string
19
+ // DescriptionFunc is used instead of Description if non-nil, and is useful for dynamic
20
+ // descriptions that change depending on context. Important: this must not be an expensive call.
21
+ // Note that you should still provide a generic, non-dynamic description in the Description field,
22
+ // as this is used in the cheatsheet.
23
+ DescriptionFunc func () string
19
24
// If defined, this is used in place of Description when showing the keybinding
20
25
// in the options view at the bottom left of the screen.
21
26
ShortDescription string
22
- Alternative string
23
- Tag string // e.g. 'navigation'. Used for grouping things in the cheatsheet
24
- OpensMenu bool
27
+ // ShortDescriptionFunc is used instead of ShortDescription if non-nil, and is useful for dynamic
28
+ // descriptions that change depending on context. Important: this must not be an expensive call.
29
+ ShortDescriptionFunc func () string
30
+ Alternative string
31
+ Tag string // e.g. 'navigation'. Used for grouping things in the cheatsheet
32
+ OpensMenu bool
25
33
26
34
// If true, the keybinding will appear at the bottom of the screen.
27
35
// Even if set to true, the keybinding will not be displayed if it is currently
@@ -47,11 +55,21 @@ func (b *Binding) IsDisabled() bool {
47
55
return b .GetDisabledReason != nil && b .GetDisabledReason () != nil
48
56
}
49
57
58
+ func (b * Binding ) GetDescription () string {
59
+ if b .DescriptionFunc != nil {
60
+ return b .DescriptionFunc ()
61
+ }
62
+ return b .Description
63
+ }
64
+
50
65
func (b * Binding ) GetShortDescription () string {
66
+ if b .ShortDescriptionFunc != nil {
67
+ return b .ShortDescriptionFunc ()
68
+ }
51
69
if b .ShortDescription != "" {
52
70
return b .ShortDescription
53
71
}
54
- return b .Description
72
+ return b .GetDescription ()
55
73
}
56
74
57
75
// A guard is a decorator which checks something before executing a handler
0 commit comments