diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2024-01-02 12:19:31 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2024-01-28 08:33:13 +1100 |
commit | 0f9d9e13d12d37ab419efccc5c217422fb67a765 (patch) | |
tree | 35fc5bdc4473da8a6750ee621e270b9e595520c9 /pkg/gui/types | |
parent | c07b3fad64ca71bc1873bcc1bb9e2256c05d4df0 (diff) |
Show mode-specific keybinding suggestions
As part of making lazygit more discoverable, there are certain keys which you almost certainly
need to press when you're in a given mode e.g. 'v' to paste commits when cherry-picking. This
commit prominently shows these keybinding suggestions alongside the others in the option view.
I'm using the same colours for these keybindings as is associated with the mode elsewhere e.g.
yellow for rebasing and cyan for cherry-picking. The cherry-picking one is a bit weird because
we also use cyan text to show loaders and app status at the bottom left so it may be confusing,
but I haven't personally found it awkward from having tested it out myself.
Previously we would render these options whenever a new context was activated, but now that we
need to re-render options whenever a mode changes, I'm instead rendering them on each screen
re-render (i.e. in the layout function). Given how cheap it is to render this text, I think
it's fine performance-wise.
Diffstat (limited to 'pkg/gui/types')
-rw-r--r-- | pkg/gui/types/keybindings.go | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/pkg/gui/types/keybindings.go b/pkg/gui/types/keybindings.go index 7d2c19bd4..db21e7bc9 100644 --- a/pkg/gui/types/keybindings.go +++ b/pkg/gui/types/keybindings.go @@ -11,21 +11,25 @@ type Key interface{} // FIXME: find out how to get `gocui.Key | rune` // is only handled if the given view has focus, or handled globally if the view // is "" type Binding struct { - ViewName string - Handler func() error - Key Key - Modifier gocui.Modifier - Description string + ViewName string + Handler func() error + Key Key + Modifier gocui.Modifier + Description 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 - // If true, the keybinding will appear at the bottom of the screen. If - // the given view has no bindings with Display: true, the default keybindings - // will be displayed instead. - // TODO: implement this - Display 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 + // disabled. We could instead display it with a strikethrough, but there's + // limited realestate to show all the keybindings we want, so we're hiding it instead. + DisplayOnScreen bool + // if unset, the binding will be displayed in the default color. Only applies to the keybinding + // on-screen, not in the keybindings menu. DisplayStyle *style.TextStyle // to be displayed if the keybinding is highlighted from within a menu @@ -39,6 +43,10 @@ type Binding struct { GetDisabledReason func() *DisabledReason } +func (Binding *Binding) IsDisabled() bool { + return Binding.GetDisabledReason != nil && Binding.GetDisabledReason() != nil +} + // A guard is a decorator which checks something before executing a handler // and potentially early-exits if some precondition hasn't been met. type Guard func(func() error) func() error |