mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-10 11:10:18 +02:00
add better support for OpensMenu option when creating a menu
This commit is contained in:
parent
95678b1b43
commit
ab5a8091f5
@ -4,7 +4,6 @@ import (
|
||||
"github.com/jesseduffield/generics/slices"
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
@ -87,7 +86,7 @@ func (self *MenuViewModel) GetDisplayStrings(_startIdx int, _length int) [][]str
|
||||
})
|
||||
|
||||
return slices.Map(self.menuItems, func(item *types.MenuItem) []string {
|
||||
displayStrings := getItemDisplayStrings(item)
|
||||
displayStrings := item.LabelColumns
|
||||
if showKeys {
|
||||
displayStrings = slices.Prepend(displayStrings, style.FgCyan.Sprint(keybindings.GetKeyDisplay(item.Key)))
|
||||
}
|
||||
@ -95,18 +94,6 @@ func (self *MenuViewModel) GetDisplayStrings(_startIdx int, _length int) [][]str
|
||||
})
|
||||
}
|
||||
|
||||
func getItemDisplayStrings(item *types.MenuItem) []string {
|
||||
if item.LabelColumns != nil {
|
||||
return item.LabelColumns
|
||||
}
|
||||
|
||||
styledStr := item.Label
|
||||
if item.OpensMenu {
|
||||
styledStr = presentation.OpensMenuStyle(styledStr)
|
||||
}
|
||||
return []string{styledStr}
|
||||
}
|
||||
|
||||
func (self *MenuContext) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
basicBindings := self.ListContextTrait.GetKeybindings(opts)
|
||||
menuItemsWithKeys := slices.Filter(self.menuItems, func(item *types.MenuItem) bool {
|
||||
|
@ -1,11 +1,12 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
func (gui *Gui) getMenuOptions() map[string]string {
|
||||
@ -30,9 +31,25 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
|
||||
})
|
||||
}
|
||||
|
||||
maxColumnSize := 1
|
||||
|
||||
for _, item := range opts.Items {
|
||||
if item.OpensMenu && item.LabelColumns != nil {
|
||||
return errors.New("Message for the developer of this app: you've set opensMenu with displaystrings on the menu panel. Bad developer!. Apologies, user")
|
||||
if item.LabelColumns == nil {
|
||||
item.LabelColumns = []string{item.Label}
|
||||
}
|
||||
|
||||
if item.OpensMenu {
|
||||
item.LabelColumns[0] = presentation.OpensMenuStyle(item.LabelColumns[0])
|
||||
}
|
||||
|
||||
maxColumnSize = utils.Max(maxColumnSize, len(item.LabelColumns))
|
||||
}
|
||||
|
||||
for _, item := range opts.Items {
|
||||
if len(item.LabelColumns) < maxColumnSize {
|
||||
// we require that each item has the same number of columns so we're padding out with blank strings
|
||||
// if this item has too few
|
||||
item.LabelColumns = append(item.LabelColumns, make([]string, maxColumnSize-len(item.LabelColumns))...)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/jesseduffield/generics/slices"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
@ -50,21 +49,14 @@ func uniqueBindings(bindings []*types.Binding) []*types.Binding {
|
||||
})
|
||||
}
|
||||
|
||||
func (gui *Gui) displayDescription(binding *types.Binding) string {
|
||||
if binding.OpensMenu {
|
||||
return presentation.OpensMenuStyle(binding.Description)
|
||||
}
|
||||
|
||||
return binding.Description
|
||||
}
|
||||
|
||||
func (gui *Gui) handleCreateOptionsMenu() error {
|
||||
context := gui.currentContext()
|
||||
bindings := gui.getBindings(context)
|
||||
|
||||
menuItems := slices.Map(bindings, func(binding *types.Binding) *types.MenuItem {
|
||||
return &types.MenuItem{
|
||||
Label: gui.displayDescription(binding),
|
||||
OpensMenu: binding.OpensMenu,
|
||||
Label: binding.Description,
|
||||
OnPress: func() error {
|
||||
if binding.Key == nil {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user