summaryrefslogtreecommitdiffstats
path: root/pkg/gui/gui_common.go
blob: 7c306a0d54667193c146b10d77f9110736cd425d (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
97
98
99
100
101
102
103
104
105
106
107
108
package gui

import (
	"errors"

	"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
	"github.com/jesseduffield/lazygit/pkg/config"
	"github.com/jesseduffield/lazygit/pkg/gui/types"
)

// hacking this by including the gui struct for now until we split more things out
type guiCommon struct {
	gui *Gui
	types.IPopupHandler
}

var _ types.IGuiCommon = &guiCommon{}

func (self *guiCommon) LogAction(msg string) {
	self.gui.LogAction(msg)
}

func (self *guiCommon) LogCommand(cmdStr string, isCommandLine bool) {
	self.gui.LogCommand(cmdStr, isCommandLine)
}

func (self *guiCommon) Refresh(opts types.RefreshOptions) error {
	return self.gui.Refresh(opts)
}

func (self *guiCommon) PostRefreshUpdate(context types.Context) error {
	return self.gui.postRefreshUpdate(context)
}

func (self *guiCommon) RunSubprocessAndRefresh(cmdObj oscommands.ICmdObj) error {
	return self.gui.runSubprocessWithSuspenseAndRefresh(cmdObj)
}

func (self *guiCommon) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) {
	return self.gui.runSubprocessWithSuspense(cmdObj)
}

func (self *guiCommon) PushContext(context types.Context, opts ...types.OnFocusOpts) error {
	singleOpts := types.OnFocusOpts{}
	if len(opts) > 0 {
		// using triple dot but you should only ever pass one of these opt structs
		if len(opts) > 1 {
			return errors.New("cannot pass multiple opts to pushContext")
		}

		singleOpts = opts[0]
	}

	return self.gui.pushContext(context, singleOpts)
}

func (self *guiCommon) PopContext() error {
	return self.gui.popContext()
}

func (self *guiCommon) RemoveContexts(contexts []types.Context) error {
	return self.gui.removeContexts(contexts)
}

func (self *guiCommon) CurrentContext() types.Context {
	return self.gui.currentContext()
}

func (self *guiCommon) CurrentStaticContext() types.Context {
	return self.gui.currentStaticContext()
}

func (self *guiCommon) IsCurrentContext(c types.Context) bool {
	return self.CurrentContext().GetKey() == c.GetKey()
}

func (self *guiCommon) GetAppState() *config.AppState {
	return self.gui.Config.GetAppState()
}

func (self *guiCommon) SaveAppState() error {
	return self.gui.Config.SaveAppState()
}

func (self *guiCommon) Render() {
	self.gui.render()
}

func (self *guiCommon) OpenSearch() {
	_ = self.gui.handleOpenSearch(self.gui.currentViewName())
}

func (self *guiCommon) OnUIThread(f func() error) {
	self.gui.onUIThread(f)
}

func (self *guiCommon) RenderToMainViews(opts types.RefreshMainOpts) error {
	return self.gui.refreshMainViews(opts)
}

func (self *guiCommon) MainViewPairs() types.MainViewPairs {
	return types.MainViewPairs{
		Normal:         self.gui.normalMainContextPair(),
		Staging:        self.gui.stagingMainContextPair(),
		PatchBuilding:  self.gui.patchBuildingMainContextPair(),
		MergeConflicts: self.gui.mergingMainContextPair(),
	}
}