2022-01-16 05:46:53 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2022-12-30 14:24:24 +02:00
|
|
|
"github.com/jesseduffield/gocui"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
2022-01-16 05:46:53 +02:00
|
|
|
"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
|
2022-01-29 10:09:20 +02:00
|
|
|
types.IPopupHandler
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
var _ types.IGuiCommon = &guiCommon{}
|
2022-01-16 05:46:53 +02:00
|
|
|
|
|
|
|
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 {
|
2023-03-26 07:37:01 +02:00
|
|
|
return self.gui.helpers.Refresh.Refresh(opts)
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-02-22 12:16:00 +02:00
|
|
|
func (self *guiCommon) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) {
|
|
|
|
return self.gui.runSubprocessWithSuspense(cmdObj)
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
func (self *guiCommon) PushContext(context types.Context, opts ...types.OnFocusOpts) error {
|
2023-03-23 09:47:29 +02:00
|
|
|
return self.gui.State.ContextMgr.Push(context, opts...)
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) PopContext() error {
|
2023-03-23 09:47:29 +02:00
|
|
|
return self.gui.State.ContextMgr.Pop()
|
2022-01-16 05:46:53 +02:00
|
|
|
}
|
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
func (self *guiCommon) ReplaceContext(context types.Context) error {
|
2023-03-23 09:47:29 +02:00
|
|
|
return self.gui.State.ContextMgr.Replace(context)
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
2023-01-21 13:38:14 +02:00
|
|
|
func (self *guiCommon) RemoveContexts(contexts []types.Context) error {
|
|
|
|
return self.gui.State.ContextMgr.RemoveContexts(contexts)
|
|
|
|
}
|
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
func (self *guiCommon) CurrentContext() types.Context {
|
2023-03-23 09:47:29 +02:00
|
|
|
return self.gui.State.ContextMgr.Current()
|
2022-01-29 10:09:20 +02:00
|
|
|
}
|
|
|
|
|
2022-06-13 03:01:26 +02:00
|
|
|
func (self *guiCommon) CurrentStaticContext() types.Context {
|
2023-03-23 09:47:29 +02:00
|
|
|
return self.gui.State.ContextMgr.CurrentStatic()
|
2022-06-13 03:01:26 +02:00
|
|
|
}
|
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
func (self *guiCommon) CurrentSideContext() types.Context {
|
2023-03-23 09:47:29 +02:00
|
|
|
return self.gui.State.ContextMgr.CurrentSide()
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
2022-06-13 03:01:26 +02:00
|
|
|
func (self *guiCommon) IsCurrentContext(c types.Context) bool {
|
2023-03-23 09:47:29 +02:00
|
|
|
return self.gui.State.ContextMgr.IsCurrent(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) Context() types.IContextMgr {
|
|
|
|
return self.gui.State.ContextMgr
|
2022-06-13 03:01:26 +02:00
|
|
|
}
|
|
|
|
|
2023-05-02 11:05:42 +02:00
|
|
|
func (self *guiCommon) ActivateContext(context types.Context) error {
|
|
|
|
return self.gui.State.ContextMgr.ActivateContext(context, types.OnFocusOpts{})
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
func (self *guiCommon) GetAppState() *config.AppState {
|
|
|
|
return self.gui.Config.GetAppState()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) SaveAppState() error {
|
|
|
|
return self.gui.Config.SaveAppState()
|
|
|
|
}
|
2022-01-29 10:09:20 +02:00
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
func (self *guiCommon) GetConfig() config.AppConfigurer {
|
|
|
|
return self.gui.Config
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) ResetViewOrigin(view *gocui.View) {
|
|
|
|
self.gui.resetViewOrigin(view)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) SetViewContent(view *gocui.View, content string) {
|
|
|
|
self.gui.setViewContent(view, content)
|
|
|
|
}
|
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
func (self *guiCommon) Render() {
|
|
|
|
self.gui.render()
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
func (self *guiCommon) Views() types.Views {
|
|
|
|
return self.gui.Views
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) Git() *commands.GitCommand {
|
|
|
|
return self.gui.git
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) OS() *oscommands.OSCommand {
|
|
|
|
return self.gui.os
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) Modes() *types.Modes {
|
|
|
|
return self.gui.State.Modes
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) Model() *types.Model {
|
|
|
|
return self.gui.State.Model
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) Mutexes() types.Mutexes {
|
|
|
|
return self.gui.Mutexes
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) GocuiGui() *gocui.Gui {
|
|
|
|
return self.gui.g
|
|
|
|
}
|
|
|
|
|
2022-02-23 10:44:48 +02:00
|
|
|
func (self *guiCommon) OnUIThread(f func() error) {
|
2022-08-06 10:50:52 +02:00
|
|
|
self.gui.onUIThread(f)
|
2022-02-23 10:44:48 +02:00
|
|
|
}
|
2022-08-07 03:34:53 +02:00
|
|
|
|
2023-07-09 03:32:27 +02:00
|
|
|
func (self *guiCommon) OnWorker(f func(*gocui.Task)) {
|
2023-07-03 06:16:43 +02:00
|
|
|
self.gui.onWorker(f)
|
|
|
|
}
|
|
|
|
|
2022-08-07 03:34:53 +02:00
|
|
|
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(),
|
|
|
|
}
|
|
|
|
}
|
2022-12-30 14:24:24 +02:00
|
|
|
|
|
|
|
func (self *guiCommon) State() types.IStateAccessor {
|
|
|
|
return self.gui.stateAccessor
|
|
|
|
}
|
2023-03-21 11:57:52 +02:00
|
|
|
|
|
|
|
func (self *guiCommon) KeybindingsOpts() types.KeybindingsOpts {
|
|
|
|
return self.gui.keybindingOpts()
|
|
|
|
}
|
2023-03-23 09:47:29 +02:00
|
|
|
|
|
|
|
func (self *guiCommon) IsAnyModeActive() bool {
|
2023-03-23 13:21:42 +02:00
|
|
|
return self.gui.helpers.Mode.IsAnyModeActive()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *guiCommon) GetInitialKeybindingsWithCustomCommands() ([]*types.Binding, []*gocui.ViewMouseBinding) {
|
|
|
|
return self.gui.GetInitialKeybindingsWithCustomCommands()
|
2023-03-23 09:47:29 +02:00
|
|
|
}
|