summaryrefslogtreecommitdiffstats
path: root/pkg/gui/modes.go
blob: 0f2af61923e2f2b12ba760d7c45ae32a47583013 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package gui

import (
	"fmt"

	"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
	"github.com/jesseduffield/lazygit/pkg/gui/style"
)

type modeStatus struct {
	isActive    func() bool
	description func() string
	reset       func() error
}

func (gui *Gui) modeStatuses() []modeStatus {
	return []modeStatus{
		{
			isActive: gui.State.Modes.Diffing.Active,
			description: func() string {
				return gui.withResetButton(
					fmt.Sprintf(
						"%s %s",
						gui.c.Tr.LcShowingGitDiff,
						"git diff "+gui.diffStr(),
					),
					style.FgMagenta,
				)
			},
			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 {
				return gui.withResetButton(
					fmt.Sprintf(
						"%s '%s'",
						gui.c.Tr.LcFilteringBy,
						gui.State.Modes.Filtering.GetPath(),
					),
					style.FgRed,
				)
			},
			reset: gui.exitFilterMode,
		},
		{
			isActive: gui.State.Modes.CherryPicking.Active,
			description: func() string {
				return gui.withResetButton(
					fmt.Sprintf(
						"%d commits copied",
						len(gui.State.Modes.CherryPicking.CherryPickedCommits),
					),
					style.FgCyan,
				)
			},
			reset: gui.exitCherryPickingMode,
		},
		{
			isActive: func() bool {
				return gui.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE
			},
			description: func() string {
				workingTreeState := gui.git.Status.WorkingTreeState()
				return gui.withResetButton(
					formatWorkingTreeState(workingTreeState), style.FgYellow,
				)
			},
			reset: gui.abortMergeOrRebaseWithConfirm,
		},
		{
			isActive: func() bool {
				return gui.State.BisectInfo.Started()
			},
			description: func() string {
				return gui.withResetButton("bisecting", style.FgGreen)
			},
			reset: gui.helpers.bisect.Reset,
		},
	}
}

func (gui *Gui) withResetButton(content string, textStyle style.TextStyle) string {
	return textStyle.Sprintf(
		"%s %s",
		content,
		style.AttrUnderline.Sprint(gui.c.Tr.ResetInParentheses),
	)
}