summaryrefslogtreecommitdiffstats
path: root/pkg/gui/types
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-12-30 23:24:24 +1100
committerJesse Duffield <jessedduffield@gmail.com>2023-04-30 13:19:52 +1000
commit8edad826caf2fa48bfad33f9f8c4f3ba49a052da (patch)
tree0b49145e4f656e72441199b5a5c30176c898d7a7 /pkg/gui/types
parent826128a8e03fb50f7287029ebac93c85712faecb (diff)
Begin refactoring gui
This begins a big refactor of moving more code out of the Gui struct into contexts, controllers, and helpers. We also move some code into structs in the gui package purely for the sake of better encapsulation
Diffstat (limited to 'pkg/gui/types')
-rw-r--r--pkg/gui/types/common.go60
-rw-r--r--pkg/gui/types/context.go17
-rw-r--r--pkg/gui/types/refresh.go3
-rw-r--r--pkg/gui/types/views.go42
4 files changed, 121 insertions, 1 deletions
diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go
index aeb1da4c0..a92efb801 100644
--- a/pkg/gui/types/common.go
+++ b/pkg/gui/types/common.go
@@ -1,12 +1,15 @@
package types
import (
+ "github.com/jesseduffield/gocui"
+ "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/config"
+ "github.com/jesseduffield/lazygit/pkg/utils"
"github.com/sasha-s/go-deadlock"
"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"
)
@@ -27,6 +30,12 @@ type IGuiCommon interface {
// e.g. expanding or collapsing a folder in a file view. Calling 'Refresh' in this
// case would be overkill, although refresh will internally call 'PostRefreshUpdate'
PostRefreshUpdate(Context) error
+
+ // renders string to a view without resetting its origin
+ SetViewContent(view *gocui.View, content string)
+ // resets cursor and origin of view. Often used before calling SetViewContent
+ ResetViewOrigin(view *gocui.View)
+
// this just re-renders the screen
Render()
// allows rendering to main views (i.e. the ones to the right of the side panel)
@@ -42,12 +51,15 @@ type IGuiCommon interface {
PushContext(context Context, opts ...OnFocusOpts) error
PopContext() error
+ ReplaceContext(context Context) error
CurrentContext() Context
CurrentStaticContext() Context
+ CurrentSideContext() Context
IsCurrentContext(Context) bool
// enters search mode for the current view
OpenSearch()
+ GetConfig() config.AppConfigurer
GetAppState() *config.AppState
SaveAppState() error
@@ -55,6 +67,21 @@ type IGuiCommon interface {
// Only necessary to call if you're not already on the UI thread i.e. you're inside a goroutine.
// All controller handlers are executed on the UI thread.
OnUIThread(f func() error)
+
+ // returns the gocui Gui struct. There is a good chance you don't actually want to use
+ // this struct and instead want to use another method above
+ GocuiGui() *gocui.Gui
+
+ Views() Views
+
+ Git() *commands.GitCommand
+ OS() *oscommands.OSCommand
+ Model() *Model
+ Modes() *Modes
+
+ Mutexes() Mutexes
+
+ State() IStateAccessor
}
type IPopupHandler interface {
@@ -176,3 +203,36 @@ type Mutexes struct {
PopupMutex *deadlock.Mutex
PtyMutex *deadlock.Mutex
}
+
+type IStateAccessor interface {
+ GetIgnoreWhitespaceInDiffView() bool
+ SetIgnoreWhitespaceInDiffView(value bool)
+ GetRepoPathStack() *utils.StringStack
+ GetRepoState() IRepoStateAccessor
+ // tells us whether we're currently updating lazygit
+ GetUpdating() bool
+ SetUpdating(bool)
+ SetIsRefreshingFiles(bool)
+ GetIsRefreshingFiles() bool
+}
+
+type IRepoStateAccessor interface {
+ GetViewsSetup() bool
+ GetWindowViewNameMap() *utils.ThreadSafeMap[string, string]
+ GetStartupStage() StartupStage
+ SetStartupStage(stage StartupStage)
+ GetCurrentPopupOpts() *CreatePopupPanelOpts
+ SetCurrentPopupOpts(*CreatePopupPanelOpts)
+}
+
+// startup stages so we don't need to load everything at once
+type StartupStage int
+
+const (
+ INITIAL StartupStage = iota
+ COMPLETE
+)
+
+type IFileWatcher interface {
+ AddFilesToFileWatcher(files []*models.File) error
+}
diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go
index e88d0d0f9..ef57e06bc 100644
--- a/pkg/gui/types/context.go
+++ b/pkg/gui/types/context.go
@@ -72,6 +72,10 @@ type IBaseContext interface {
// our list controller can come along and wrap it in a list-specific click handler.
// We'll need to think of a better way to do this.
AddOnClickFn(func() error)
+
+ AddOnRenderToMainFn(func() error)
+ AddOnFocusFn(func(OnFocusOpts) error)
+ AddOnFocusLostFn(func(OnFocusLostOpts) error)
}
type Context interface {
@@ -83,6 +87,16 @@ type Context interface {
HandleRenderToMain() error
}
+type DiffableContext interface {
+ Context
+
+ // Returns the current diff terminals of the currently selected item.
+ // in the case of a branch it returns both the branch and it's upstream name,
+ // which becomes an option when you bring up the diff menu, but when you're just
+ // flicking through branches it will be using the local branch name.
+ GetDiffTerminals() []string
+}
+
type IListContext interface {
Context
@@ -150,6 +164,9 @@ type HasKeybindings interface {
GetKeybindings(opts KeybindingsOpts) []*Binding
GetMouseKeybindings(opts KeybindingsOpts) []*gocui.ViewMouseBinding
GetOnClick() func() error
+ GetOnRenderToMain() func() error
+ GetOnFocus() func(OnFocusOpts) error
+ GetOnFocusLost() func(OnFocusLostOpts) error
}
type IController interface {
diff --git a/pkg/gui/types/refresh.go b/pkg/gui/types/refresh.go
index 475b90942..6d6c6f8a4 100644
--- a/pkg/gui/types/refresh.go
+++ b/pkg/gui/types/refresh.go
@@ -6,6 +6,7 @@ type RefreshableView int
const (
COMMITS RefreshableView = iota
REBASE_COMMITS
+ SUB_COMMITS
BRANCHES
FILES
STASH
@@ -32,6 +33,6 @@ const (
type RefreshOptions struct {
Then func()
- Scope []RefreshableView // e.g. []int{COMMITS, BRANCHES}. Leave empty to refresh everything
+ Scope []RefreshableView // e.g. []RefreshableView{COMMITS, BRANCHES}. Leave empty to refresh everything
Mode RefreshMode // one of SYNC (default), ASYNC, and BLOCK_UI
}
diff --git a/pkg/gui/types/views.go b/pkg/gui/types/views.go
new file mode 100644
index 000000000..ee45cf7b6
--- /dev/null
+++ b/pkg/gui/types/views.go
@@ -0,0 +1,42 @@
+package types
+
+import "github.com/jesseduffield/gocui"
+
+type Views struct {
+ Status *gocui.View
+ Submodules *gocui.View
+ Files *gocui.View
+ Branches *gocui.View
+ Remotes *gocui.View
+ Tags *gocui.View
+ RemoteBranches *gocui.View
+ ReflogCommits *gocui.View
+ Commits *gocui.View
+ Stash *gocui.View
+
+ Main *gocui.View
+ Secondary *gocui.View
+ Staging *gocui.View
+ StagingSecondary *gocui.View
+ PatchBuilding *gocui.View
+ PatchBuildingSecondary *gocui.View
+ MergeConflicts *gocui.View
+
+ Options *gocui.View
+ Confirmation *gocui.View
+ Menu *gocui.View
+ CommitMessage *gocui.View
+ CommitFiles *gocui.View
+ SubCommits *gocui.View
+ Information *gocui.View
+ AppStatus *gocui.View
+ Search *gocui.View
+ SearchPrefix *gocui.View
+ Limit *gocui.View
+ Suggestions *gocui.View
+ Tooltip *gocui.View
+ Extras *gocui.View
+
+ // for playing the easter egg snake game
+ Snake *gocui.View
+}