mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-15 18:16:25 -04:00
Constructing a menu item key from a literal character requires
gocui.NewKeyRune('r'), which is a bit noisy. Add a private menuKey helper in
both the controllers and helpers packages so the common case in either reads as
menuKey('r'). Duplicating the one-liner is cheaper than a cross-package import
dependency and avoids forcing every controller file to qualify the call.
The reason for doing this now is that we are going to change MenuItem.Key to a
slice of keys later in the branch, which means we'd have to add `[]gocui.Key{`
at each call site, making them even more noisy. With the menuKey helper we can
just change its signature and leave all clients unchanged.
12 lines
441 B
Go
12 lines
441 B
Go
package controllers
|
|
|
|
import "github.com/jesseduffield/lazygit/pkg/gocui"
|
|
|
|
// menuKey is a shorthand for constructing a key value for a menu item from a single rune literal,
|
|
// avoiding the noise of `gocui.NewKeyRune('a')` at every call site. There is an intentionally
|
|
// identical helper in the helpers package so that callers in either package can use the unqualified
|
|
// form.
|
|
func menuKey(r rune) gocui.Key {
|
|
return gocui.NewKeyRune(r)
|
|
}
|