1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-10 11:10:18 +02:00
lazygit/pkg/gui/modes.go

97 lines
2.2 KiB
Go
Raw Normal View History

package gui
import (
2022-01-19 09:32:27 +02:00
"fmt"
2021-12-30 04:35:10 +02:00
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/gui/style"
)
type modeStatus struct {
isActive func() bool
description func() string
2020-08-23 01:23:59 +02:00
reset func() error
}
func (gui *Gui) modeStatuses() []modeStatus {
return []modeStatus{
{
isActive: gui.State.Modes.Diffing.Active,
description: func() string {
2022-01-19 09:32:27 +02:00
return gui.withResetButton(
fmt.Sprintf(
"%s %s",
gui.c.Tr.LcShowingGitDiff,
2022-01-19 09:32:27 +02:00
"git diff "+gui.diffStr(),
),
style.FgMagenta,
2020-08-23 01:23:59 +02:00
)
},
2020-08-23 01:23:59 +02:00
reset: gui.exitDiffMode,
},
{
isActive: gui.git.Patch.PatchManager.Active,
description: func() string {
return gui.withResetButton(gui.c.Tr.LcBuildingPatch, style.FgYellow.SetBold())
},
reset: gui.handleResetPatch,
},
{
isActive: gui.State.Modes.Filtering.Active,
description: func() string {
2022-01-19 09:32:27 +02:00
return gui.withResetButton(
fmt.Sprintf(
"%s '%s'",
gui.c.Tr.LcFilteringBy,
2022-01-19 09:32:27 +02:00
gui.State.Modes.Filtering.GetPath(),
),
style.FgRed,
2020-08-23 01:23:59 +02:00
)
},
reset: gui.exitFilterMode,
},
{
isActive: gui.State.Modes.CherryPicking.Active,
description: func() string {
2022-01-19 09:32:27 +02:00
return gui.withResetButton(
fmt.Sprintf(
"%d commits copied",
len(gui.State.Modes.CherryPicking.CherryPickedCommits),
),
style.FgCyan,
2020-08-23 01:23:59 +02:00
)
},
2022-01-31 13:11:34 +02:00
reset: gui.helpers.CherryPick.Reset,
},
{
isActive: func() bool {
return gui.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE
},
description: func() string {
workingTreeState := gui.git.Status.WorkingTreeState()
2022-01-19 09:32:27 +02:00
return gui.withResetButton(
formatWorkingTreeState(workingTreeState), style.FgYellow,
)
},
2022-01-31 13:11:34 +02:00
reset: gui.helpers.Rebase.AbortMergeOrRebaseWithConfirm,
},
2022-01-19 09:32:27 +02:00
{
isActive: func() bool {
2022-01-31 13:11:34 +02:00
return gui.State.Model.BisectInfo.Started()
2022-01-19 09:32:27 +02:00
},
description: func() string {
return gui.withResetButton("bisecting", style.FgGreen)
},
2022-01-31 13:11:34 +02:00
reset: gui.helpers.Bisect.Reset,
2022-01-19 09:32:27 +02:00
},
}
}
2022-01-19 09:32:27 +02:00
func (gui *Gui) withResetButton(content string, textStyle style.TextStyle) string {
return textStyle.Sprintf(
"%s %s",
content,
style.AttrUnderline.Sprint(gui.c.Tr.ResetInParentheses),
2022-01-19 09:32:27 +02:00
)
}