1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-24 19:39:16 +02:00

Show context-specific labels for the global <esc> binding

WHen several modes are active at the same time, it isn't totally obvious which
one will be cancelled first, so show this in the status bar.
This commit is contained in:
Stefan Haller
2025-08-12 17:10:34 +02:00
parent d8ea83704f
commit a8e44dcea6
4 changed files with 81 additions and 4 deletions

View File

@@ -119,6 +119,7 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: self.escape, Handler: self.escape,
Description: self.c.Tr.Cancel, Description: self.c.Tr.Cancel,
DescriptionFunc: self.escapeDescription,
GetDisabledReason: self.escapeEnabled, GetDisabledReason: self.escapeEnabled,
DisplayOnScreen: true, DisplayOnScreen: true,
}, },
@@ -191,6 +192,10 @@ func (self *GlobalController) escape() error {
return (&QuitActions{c: self.c}).Escape() return (&QuitActions{c: self.c}).Escape()
} }
func (self *GlobalController) escapeDescription() string {
return (&QuitActions{c: self.c}).EscapeDescription()
}
func (self *GlobalController) escapeEnabled() *types.DisabledReason { func (self *GlobalController) escapeEnabled() *types.DisabledReason {
if (&QuitActions{c: self.c}).EscapeEnabled() { if (&QuitActions{c: self.c}).EscapeEnabled() {
return nil return nil

View File

@@ -39,9 +39,10 @@ func NewModeHelper(
} }
type ModeStatus struct { type ModeStatus struct {
IsActive func() bool IsActive func() bool
InfoLabel func() string InfoLabel func() string
Reset func() error CancelLabel func() string
Reset func() error
} }
func (self *ModeHelper) Statuses() []ModeStatus { func (self *ModeHelper) Statuses() []ModeStatus {
@@ -58,6 +59,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
style.FgMagenta, style.FgMagenta,
) )
}, },
CancelLabel: func() string {
return self.c.Tr.CancelDiffingMode
},
Reset: self.diffHelper.ExitDiffMode, Reset: self.diffHelper.ExitDiffMode,
}, },
{ {
@@ -65,6 +69,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
InfoLabel: func() string { InfoLabel: func() string {
return self.withResetButton(self.c.Tr.BuildingPatch, style.FgYellow.SetBold()) return self.withResetButton(self.c.Tr.BuildingPatch, style.FgYellow.SetBold())
}, },
CancelLabel: func() string {
return self.c.Tr.ExitCustomPatchBuilder
},
Reset: self.patchBuildingHelper.Reset, Reset: self.patchBuildingHelper.Reset,
}, },
{ {
@@ -80,6 +87,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
style.FgRed, style.FgRed,
) )
}, },
CancelLabel: func() string {
return self.c.Tr.ExitFilterMode
},
Reset: self.ExitFilterMode, Reset: self.ExitFilterMode,
}, },
{ {
@@ -90,6 +100,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
style.FgCyan, style.FgCyan,
) )
}, },
CancelLabel: func() string {
return self.c.Tr.CancelMarkedBaseCommit
},
Reset: self.mergeAndRebaseHelper.ResetMarkedBaseCommit, Reset: self.mergeAndRebaseHelper.ResetMarkedBaseCommit,
}, },
{ {
@@ -110,6 +123,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
style.FgCyan, style.FgCyan,
) )
}, },
CancelLabel: func() string {
return self.c.Tr.ResetCherryPickShort
},
Reset: self.cherryPickHelper.Reset, Reset: self.cherryPickHelper.Reset,
}, },
{ {
@@ -122,6 +138,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
workingTreeState.Title(self.c.Tr), style.FgYellow, workingTreeState.Title(self.c.Tr), style.FgYellow,
) )
}, },
CancelLabel: func() string {
return fmt.Sprintf(self.c.Tr.AbortTitle, self.c.Git().Status.WorkingTreeState().CommandName())
},
Reset: self.mergeAndRebaseHelper.AbortMergeOrRebaseWithConfirm, Reset: self.mergeAndRebaseHelper.AbortMergeOrRebaseWithConfirm,
}, },
{ {
@@ -131,6 +150,9 @@ func (self *ModeHelper) Statuses() []ModeStatus {
InfoLabel: func() string { InfoLabel: func() string {
return self.withResetButton(self.c.Tr.Bisect.Bisecting, style.FgGreen) return self.withResetButton(self.c.Tr.Bisect.Bisecting, style.FgGreen)
}, },
CancelLabel: func() string {
return self.c.Tr.Actions.ResetBisect
},
Reset: self.bisectHelper.Reset, Reset: self.bisectHelper.Reset,
}, },
} }

View File

@@ -48,7 +48,7 @@ func (self *QuitActions) confirmQuitDuringUpdate() error {
} }
func (self *QuitActions) Escape() error { func (self *QuitActions) Escape() error {
// If you make changes to this function, be sure to update EscapeEnabled accordingly. // If you make changes to this function, be sure to update EscapeEnabled and EscapeDescription accordingly.
currentContext := self.c.Context().Current() currentContext := self.c.Context().Current()
@@ -130,3 +130,41 @@ func (self *QuitActions) EscapeEnabled() bool {
return false return false
} }
func (self *QuitActions) EscapeDescription() string {
currentContext := self.c.Context().Current()
if listContext, ok := currentContext.(types.IListContext); ok {
if listContext.GetList().IsSelectingRange() {
return self.c.Tr.DismissRangeSelect
}
}
if ctx, ok := currentContext.(types.IFilterableContext); ok {
if ctx.IsFiltering() {
return self.c.Tr.ExitFilterMode
}
}
parentContext := currentContext.GetParentContext()
if parentContext != nil {
return self.c.Tr.ExitSubview
}
for _, mode := range self.c.Helpers().Mode.Statuses() {
if mode.IsActive() {
return mode.CancelLabel()
}
}
repoPathStack := self.c.State().GetRepoPathStack()
if !repoPathStack.IsEmpty() {
return self.c.Tr.BackToParentRepo
}
if self.c.UserConfig().QuitOnTopLevelReturn {
return self.c.Tr.Quit
}
return self.c.Tr.Cancel
}

View File

@@ -601,6 +601,7 @@ type TranslationSet struct {
RenameBranchWarning string RenameBranchWarning string
OpenKeybindingsMenu string OpenKeybindingsMenu string
ResetCherryPick string ResetCherryPick string
ResetCherryPickShort string
NextTab string NextTab string
PrevTab string PrevTab string
CantUndoWhileRebasing string CantUndoWhileRebasing string
@@ -634,6 +635,7 @@ type TranslationSet struct {
SwapDiff string SwapDiff string
ViewDiffingOptions string ViewDiffingOptions string
ViewDiffingOptionsTooltip string ViewDiffingOptionsTooltip string
CancelDiffingMode string
OpenCommandLogMenu string OpenCommandLogMenu string
OpenCommandLogMenuTooltip string OpenCommandLogMenuTooltip string
ShowingGitDiff string ShowingGitDiff string
@@ -671,6 +673,7 @@ type TranslationSet struct {
SubmoduleStashAndReset string SubmoduleStashAndReset string
AndResetSubmodules string AndResetSubmodules string
EnterSubmoduleTooltip string EnterSubmoduleTooltip string
BackToParentRepo string
Enter string Enter string
CopySubmoduleNameToClipboard string CopySubmoduleNameToClipboard string
RemoveSubmodule string RemoveSubmodule string
@@ -699,6 +702,7 @@ type TranslationSet struct {
BulkSubmoduleOptions string BulkSubmoduleOptions string
RunningCommand string RunningCommand string
SubCommitsTitle string SubCommitsTitle string
ExitSubview string
SubmodulesTitle string SubmodulesTitle string
NavigationTitle string NavigationTitle string
SuggestionsCheatsheetTitle string SuggestionsCheatsheetTitle string
@@ -861,6 +865,7 @@ type TranslationSet struct {
MarkedBaseCommitStatus string MarkedBaseCommitStatus string
MarkAsBaseCommit string MarkAsBaseCommit string
MarkAsBaseCommitTooltip string MarkAsBaseCommitTooltip string
CancelMarkedBaseCommit string
MarkedCommitMarker string MarkedCommitMarker string
FailedToOpenURL string FailedToOpenURL string
InvalidLazygitEditURL string InvalidLazygitEditURL string
@@ -870,6 +875,7 @@ type TranslationSet struct {
QuickStartInteractiveRebaseTooltip string QuickStartInteractiveRebaseTooltip string
CannotQuickStartInteractiveRebase string CannotQuickStartInteractiveRebase string
ToggleRangeSelect string ToggleRangeSelect string
DismissRangeSelect string
RangeSelectUp string RangeSelectUp string
RangeSelectDown string RangeSelectDown string
RangeSelectNotSupported string RangeSelectNotSupported string
@@ -1349,6 +1355,7 @@ func EnglishTranslationSet() *TranslationSet {
DiscardSelection: `Discard`, DiscardSelection: `Discard`,
DiscardSelectionTooltip: "When unstaged change is selected, discard the change using `git reset`. When staged change is selected, unstage the change.", DiscardSelectionTooltip: "When unstaged change is selected, discard the change using `git reset`. When staged change is selected, unstage the change.",
ToggleRangeSelect: "Toggle range select", ToggleRangeSelect: "Toggle range select",
DismissRangeSelect: "Dismiss range select",
ToggleSelectHunk: "Toggle hunk selection", ToggleSelectHunk: "Toggle hunk selection",
SelectHunk: "Select hunks", SelectHunk: "Select hunks",
SelectLineByLine: "Select line-by-line", SelectLineByLine: "Select line-by-line",
@@ -1667,6 +1674,7 @@ func EnglishTranslationSet() *TranslationSet {
RenameBranchWarning: "This branch is tracking a remote. This action will only rename the local branch name, not the name of the remote branch. Continue?", RenameBranchWarning: "This branch is tracking a remote. This action will only rename the local branch name, not the name of the remote branch. Continue?",
OpenKeybindingsMenu: "Open keybindings menu", OpenKeybindingsMenu: "Open keybindings menu",
ResetCherryPick: "Reset copied (cherry-picked) commits selection", ResetCherryPick: "Reset copied (cherry-picked) commits selection",
ResetCherryPickShort: "Reset copied commits",
NextTab: "Next tab", NextTab: "Next tab",
PrevTab: "Previous tab", PrevTab: "Previous tab",
CantUndoWhileRebasing: "Can't undo while rebasing", CantUndoWhileRebasing: "Can't undo while rebasing",
@@ -1700,6 +1708,7 @@ func EnglishTranslationSet() *TranslationSet {
SwapDiff: "Reverse diff direction", SwapDiff: "Reverse diff direction",
ViewDiffingOptions: "View diffing options", ViewDiffingOptions: "View diffing options",
ViewDiffingOptionsTooltip: "View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction.", ViewDiffingOptionsTooltip: "View options relating to diffing two refs e.g. diffing against selected ref, entering ref to diff against, and reversing the diff direction.",
CancelDiffingMode: "Cancel diffing mode",
// the actual view is the extras view which I intend to give more tabs in future but for now we'll only mention the command log part // the actual view is the extras view which I intend to give more tabs in future but for now we'll only mention the command log part
OpenCommandLogMenu: "View command log options", OpenCommandLogMenu: "View command log options",
OpenCommandLogMenuTooltip: "View options for the command log e.g. show/hide the command log and focus the command log.", OpenCommandLogMenuTooltip: "View options for the command log e.g. show/hide the command log and focus the command log.",
@@ -1739,6 +1748,7 @@ func EnglishTranslationSet() *TranslationSet {
AndResetSubmodules: "And reset submodules", AndResetSubmodules: "And reset submodules",
Enter: "Enter", Enter: "Enter",
EnterSubmoduleTooltip: "Enter submodule. After entering the submodule, you can press `{{.escape}}` to escape back to the parent repo.", EnterSubmoduleTooltip: "Enter submodule. After entering the submodule, you can press `{{.escape}}` to escape back to the parent repo.",
BackToParentRepo: "Back to parent repo",
CopySubmoduleNameToClipboard: "Copy submodule name to clipboard", CopySubmoduleNameToClipboard: "Copy submodule name to clipboard",
RemoveSubmodule: "Remove submodule", RemoveSubmodule: "Remove submodule",
RemoveSubmodulePrompt: "Are you sure you want to remove submodule '%s' and its corresponding directory? This is irreversible.", RemoveSubmodulePrompt: "Are you sure you want to remove submodule '%s' and its corresponding directory? This is irreversible.",
@@ -1766,6 +1776,7 @@ func EnglishTranslationSet() *TranslationSet {
BulkSubmoduleOptions: "Bulk submodule options", BulkSubmoduleOptions: "Bulk submodule options",
RunningCommand: "Running command", RunningCommand: "Running command",
SubCommitsTitle: "Sub-commits", SubCommitsTitle: "Sub-commits",
ExitSubview: "Exit subview",
SubmodulesTitle: "Submodules", SubmodulesTitle: "Submodules",
NavigationTitle: "List panel navigation", NavigationTitle: "List panel navigation",
SuggestionsCheatsheetTitle: "Suggestions", SuggestionsCheatsheetTitle: "Suggestions",
@@ -1925,6 +1936,7 @@ func EnglishTranslationSet() *TranslationSet {
MarkedBaseCommitStatus: "Marked a base commit for rebase", MarkedBaseCommitStatus: "Marked a base commit for rebase",
MarkAsBaseCommit: "Mark as base commit for rebase", MarkAsBaseCommit: "Mark as base commit for rebase",
MarkAsBaseCommitTooltip: "Select a base commit for the next rebase. When you rebase onto a branch, only commits above the base commit will be brought across. This uses the `git rebase --onto` command.", MarkAsBaseCommitTooltip: "Select a base commit for the next rebase. When you rebase onto a branch, only commits above the base commit will be brought across. This uses the `git rebase --onto` command.",
CancelMarkedBaseCommit: "Cancel marked base commit",
MarkedCommitMarker: "↑↑↑ Will rebase from here ↑↑↑", MarkedCommitMarker: "↑↑↑ Will rebase from here ↑↑↑",
FailedToOpenURL: "Failed to open URL %s\n\nError: %v", FailedToOpenURL: "Failed to open URL %s\n\nError: %v",
InvalidLazygitEditURL: "Invalid lazygit-edit URL format: %s", InvalidLazygitEditURL: "Invalid lazygit-edit URL format: %s",