1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-24 05:36:19 +02:00

add colors to differentiate action and menu commands

This commit is contained in:
1jz 2021-02-11 22:51:57 -05:00 committed by Jesse Duffield
parent ccbd2c924b
commit 50dd7b00c3
2 changed files with 32 additions and 1 deletions

View File

@ -22,6 +22,7 @@ type Binding struct {
Description string Description string
Alternative string Alternative string
Tag string // e.g. 'navigation'. Used for grouping things in the cheatsheet Tag string // e.g. 'navigation'. Used for grouping things in the cheatsheet
OpensMenu bool
} }
// GetDisplayStrings returns the display string of a file // GetDisplayStrings returns the display string of a file
@ -268,12 +269,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Universal.CreateRebaseOptionsMenu), Key: gui.getKey(config.Universal.CreateRebaseOptionsMenu),
Handler: gui.wrappedHandler(gui.handleCreateRebaseOptionsMenu), Handler: gui.wrappedHandler(gui.handleCreateRebaseOptionsMenu),
Description: gui.Tr.ViewMergeRebaseOptions, Description: gui.Tr.ViewMergeRebaseOptions,
OpensMenu: true,
}, },
{ {
ViewName: "", ViewName: "",
Key: gui.getKey(config.Universal.CreatePatchOptionsMenu), Key: gui.getKey(config.Universal.CreatePatchOptionsMenu),
Handler: gui.handleCreatePatchOptionsMenu, Handler: gui.handleCreatePatchOptionsMenu,
Description: gui.Tr.ViewPatchOptions, Description: gui.Tr.ViewPatchOptions,
OpensMenu: true,
}, },
{ {
ViewName: "", ViewName: "",
@ -298,6 +301,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Universal.OptionMenu), Key: gui.getKey(config.Universal.OptionMenu),
Handler: gui.handleCreateOptionsMenu, Handler: gui.handleCreateOptionsMenu,
Description: gui.Tr.LcOpenMenu, Description: gui.Tr.LcOpenMenu,
OpensMenu: true,
}, },
{ {
ViewName: "", ViewName: "",
@ -406,6 +410,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Universal.Remove), Key: gui.getKey(config.Universal.Remove),
Handler: gui.handleCreateDiscardMenu, Handler: gui.handleCreateDiscardMenu,
Description: gui.Tr.LcViewDiscardOptions, Description: gui.Tr.LcViewDiscardOptions,
OpensMenu: true,
}, },
{ {
ViewName: "files", ViewName: "files",
@ -448,6 +453,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Files.ViewStashOptions), Key: gui.getKey(config.Files.ViewStashOptions),
Handler: gui.handleCreateStashMenu, Handler: gui.handleCreateStashMenu,
Description: gui.Tr.LcViewStashOptions, Description: gui.Tr.LcViewStashOptions,
OpensMenu: true,
}, },
{ {
ViewName: "files", ViewName: "files",
@ -462,6 +468,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Files.ViewResetOptions), Key: gui.getKey(config.Files.ViewResetOptions),
Handler: gui.handleCreateResetMenu, Handler: gui.handleCreateResetMenu,
Description: gui.Tr.LcViewResetOptions, Description: gui.Tr.LcViewResetOptions,
OpensMenu: true,
}, },
{ {
ViewName: "files", ViewName: "files",
@ -496,6 +503,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Commits.ViewResetOptions), Key: gui.getKey(config.Commits.ViewResetOptions),
Handler: gui.handleCreateResetToUpstreamMenu, Handler: gui.handleCreateResetToUpstreamMenu,
Description: gui.Tr.LcViewResetToUpstreamOptions, Description: gui.Tr.LcViewResetToUpstreamOptions,
OpensMenu: true,
}, },
{ {
ViewName: "branches", ViewName: "branches",
@ -566,6 +574,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Branches.ViewGitFlowOptions), Key: gui.getKey(config.Branches.ViewGitFlowOptions),
Handler: gui.handleCreateGitFlowMenu, Handler: gui.handleCreateGitFlowMenu,
Description: gui.Tr.LcGitFlowOptions, Description: gui.Tr.LcGitFlowOptions,
OpensMenu: true,
}, },
{ {
ViewName: "branches", ViewName: "branches",
@ -580,6 +589,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Commits.ViewResetOptions), Key: gui.getKey(config.Commits.ViewResetOptions),
Handler: gui.handleCreateResetToBranchMenu, Handler: gui.handleCreateResetToBranchMenu,
Description: gui.Tr.LcViewResetOptions, Description: gui.Tr.LcViewResetOptions,
OpensMenu: true,
}, },
{ {
ViewName: "branches", ViewName: "branches",
@ -636,6 +646,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Commits.ViewResetOptions), Key: gui.getKey(config.Commits.ViewResetOptions),
Handler: gui.handleCreateResetToTagMenu, Handler: gui.handleCreateResetToTagMenu,
Description: gui.Tr.LcViewResetOptions, Description: gui.Tr.LcViewResetOptions,
OpensMenu: true,
}, },
{ {
ViewName: "branches", ViewName: "branches",
@ -657,6 +668,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Commits.ViewResetOptions), Key: gui.getKey(config.Commits.ViewResetOptions),
Handler: gui.handleCreateResetToRemoteBranchMenu, Handler: gui.handleCreateResetToRemoteBranchMenu,
Description: gui.Tr.LcViewResetOptions, Description: gui.Tr.LcViewResetOptions,
OpensMenu: true,
}, },
{ {
ViewName: "branches", ViewName: "branches",
@ -861,6 +873,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Commits.ViewResetOptions), Key: gui.getKey(config.Commits.ViewResetOptions),
Handler: gui.handleCreateReflogResetMenu, Handler: gui.handleCreateReflogResetMenu,
Description: gui.Tr.LcViewResetOptions, Description: gui.Tr.LcViewResetOptions,
OpensMenu: true,
}, },
{ {
ViewName: "commits", ViewName: "commits",
@ -916,6 +929,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Commits.ViewResetOptions), Key: gui.getKey(config.Commits.ViewResetOptions),
Handler: gui.wrappedHandler(gui.handleCreateSubCommitResetMenu), Handler: gui.wrappedHandler(gui.handleCreateSubCommitResetMenu),
Description: gui.Tr.LcViewResetOptions, Description: gui.Tr.LcViewResetOptions,
OpensMenu: true,
}, },
{ {
ViewName: "branches", ViewName: "branches",
@ -1059,18 +1073,21 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Universal.FilteringMenu), Key: gui.getKey(config.Universal.FilteringMenu),
Handler: gui.handleCreateFilteringMenuPanel, Handler: gui.handleCreateFilteringMenuPanel,
Description: gui.Tr.LcOpenScopingMenu, Description: gui.Tr.LcOpenScopingMenu,
OpensMenu: true,
}, },
{ {
ViewName: "", ViewName: "",
Key: gui.getKey(config.Universal.DiffingMenu), Key: gui.getKey(config.Universal.DiffingMenu),
Handler: gui.handleCreateDiffingMenuPanel, Handler: gui.handleCreateDiffingMenuPanel,
Description: gui.Tr.LcOpenDiffingMenu, Description: gui.Tr.LcOpenDiffingMenu,
OpensMenu: true,
}, },
{ {
ViewName: "", ViewName: "",
Key: gui.getKey(config.Universal.DiffingMenuAlt), Key: gui.getKey(config.Universal.DiffingMenuAlt),
Handler: gui.handleCreateDiffingMenuPanel, Handler: gui.handleCreateDiffingMenuPanel,
Description: gui.Tr.LcOpenDiffingMenu, Description: gui.Tr.LcOpenDiffingMenu,
OpensMenu: true,
}, },
{ {
ViewName: "secondary", ViewName: "secondary",
@ -1618,6 +1635,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Universal.Remove), Key: gui.getKey(config.Universal.Remove),
Handler: gui.forSubmodule(gui.handleResetRemoveSubmodule), Handler: gui.forSubmodule(gui.handleResetRemoveSubmodule),
Description: gui.Tr.LcViewResetAndRemoveOptions, Description: gui.Tr.LcViewResetAndRemoveOptions,
OpensMenu: true,
}, },
{ {
ViewName: "files", ViewName: "files",
@ -1653,6 +1671,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gui.getKey(config.Submodules.BulkMenu), Key: gui.getKey(config.Submodules.BulkMenu),
Handler: gui.wrappedHandler(gui.handleBulkSubmoduleActionsMenu), Handler: gui.wrappedHandler(gui.handleBulkSubmoduleActionsMenu),
Description: gui.Tr.LcViewBulkSubmoduleOptions, Description: gui.Tr.LcViewBulkSubmoduleOptions,
OpensMenu: true,
}, },
} }

View File

@ -3,6 +3,7 @@ package gui
import ( import (
"strings" "strings"
"github.com/fatih/color"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
@ -33,6 +34,17 @@ func (gui *Gui) getBindings(v *gocui.View) []*Binding {
return append(bindingsPanel, bindingsGlobal...) return append(bindingsPanel, bindingsGlobal...)
} }
func (gui *Gui) displayDescription(binding *Binding) string {
commandColor := color.New(color.FgCyan)
menuColor := color.New(color.FgMagenta)
if binding.OpensMenu {
return menuColor.Sprintf("%s...", binding.Description)
}
return commandColor.Sprint(binding.Description)
}
func (gui *Gui) handleCreateOptionsMenu(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCreateOptionsMenu(g *gocui.Gui, v *gocui.View) error {
bindings := gui.getBindings(v) bindings := gui.getBindings(v)
@ -41,7 +53,7 @@ func (gui *Gui) handleCreateOptionsMenu(g *gocui.Gui, v *gocui.View) error {
for i, binding := range bindings { for i, binding := range bindings {
binding := binding // note to self, never close over loop variables binding := binding // note to self, never close over loop variables
menuItems[i] = &menuItem{ menuItems[i] = &menuItem{
displayStrings: []string{GetKeyDisplay(binding.Key), binding.Description}, displayStrings: []string{GetKeyDisplay(binding.Key), gui.displayDescription(binding)},
onPress: func() error { onPress: func() error {
if binding.Key == nil { if binding.Key == nil {
return nil return nil