2018-08-12 11:31:27 +02:00
|
|
|
package gui
|
2018-05-19 03:16:34 +02:00
|
|
|
|
|
|
|
import (
|
2023-03-21 11:57:52 +02:00
|
|
|
goContext "context"
|
2019-05-26 03:24:01 +02:00
|
|
|
"fmt"
|
2022-09-13 12:11:03 +02:00
|
|
|
"io"
|
2019-05-18 03:28:07 +02:00
|
|
|
"os"
|
2018-07-21 10:37:00 +02:00
|
|
|
"strings"
|
2022-03-19 00:38:49 +02:00
|
|
|
"sync"
|
2018-07-21 07:51:18 +02:00
|
|
|
|
|
|
|
"github.com/jesseduffield/gocui"
|
2022-12-30 14:24:24 +02:00
|
|
|
"github.com/jesseduffield/lazycore/pkg/boxlayout"
|
2022-08-09 13:27:12 +02:00
|
|
|
appTypes "github.com/jesseduffield/lazygit/pkg/app/types"
|
2018-08-13 12:26:02 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
2022-01-19 09:32:27 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
2022-01-02 01:34:33 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
2020-09-29 12:28:39 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
2020-09-29 11:10:57 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
2021-12-29 02:37:15 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/common"
|
2018-08-18 05:22:05 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/config"
|
2022-01-16 05:46:53 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
2022-02-06 06:54:26 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
2022-08-06 10:50:52 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
2021-06-05 07:08:36 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
|
2021-04-03 02:32:14 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/modes/filtering"
|
2022-01-16 05:46:53 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/popup"
|
2022-01-29 07:23:57 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
2022-02-01 07:23:55 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation/authors"
|
2021-11-02 23:23:47 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation/graph"
|
2022-04-23 03:41:40 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
|
2022-02-24 04:29:48 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/services/custom_commands"
|
2023-03-23 09:47:29 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/status"
|
2021-07-27 15:00:37 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
2020-11-28 10:53:39 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
2022-12-20 14:07:43 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/integration/components"
|
2022-08-09 13:27:12 +02:00
|
|
|
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
allow fast flicking through any list panel
Up till now our approach to rendering things like file diffs, branch logs, and
commit patches, has been to run a command on the command line, wait for it to
complete, take its output as a string, and then write that string to the main
view (or secondary view e.g. when showing both staged and unstaged changes of a
file).
This has caused various issues. For once, if you are flicking through a list of
files and an untracked file is particularly large, not only will this require
lazygit to load that whole file into memory (or more accurately it's equally
large diff), it also will slow down the UI thread while loading that file, and
if the user continued down the list, the original command might eventually
resolve and replace whatever the diff is for the newly selected file.
Following what we've done in lazydocker, I've added a tasks package for when you
need something done but you want it to cancel as soon as something newer comes
up. Given this typically involves running a command to display to a view, I've
added a viewBufferManagerMap struct to the Gui struct which allows you to define
these tasks on a per-view basis.
viewBufferManagers can run files and directly write the output to their view,
meaning we no longer need to use so much memory.
In the tasks package there is a helper method called NewCmdTask which takes a
command, an initial amount of lines to read, and then runs that command, reads
that number of lines, and allows for a readLines channel to tell it to read more
lines. We read more lines when we scroll or resize the window.
There is an adapter for the tasks package in a file called tasks_adapter which
wraps the functions from the tasks package in gui-specific stuff like clearing
the main view before starting the next task that wants to write to the main
view.
I've removed some small features as part of this work, namely the little headers
that were at the top of the main view for some situations. For example, we no
longer show the upstream of a selected branch. I want to re-introduce this in
the future, but I didn't want to make this tasks system too complicated, and in
order to facilitate a header section in the main view we'd need to have a task
that gets the upstream for the current branch, writes it to the header, then
tells another task to write the branch log to the main view, but without
clearing inbetween. So it would get messy. I'm thinking instead of having a
separate 'header' view atop the main view to render that kind of thing (which
can happen in another PR)
I've also simplified the 'git show' to just call 'git show' and not do anything
fancy when it comes to merge commits.
I considered using this tasks approach whenever we write to a view. The only
thing is that the renderString method currently resets the origin of a view and
I don't want to lose that. So I've left some in there that I consider harmless,
but we should probably be just using tasks now for all rendering, even if it's
just strings we can instantly make.
2020-01-11 05:54:59 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/tasks"
|
2019-10-18 09:48:37 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
2018-08-19 15:28:29 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/updates"
|
2019-02-25 13:11:35 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
2022-08-07 01:44:50 +02:00
|
|
|
"github.com/sasha-s/go-deadlock"
|
2021-10-18 10:00:03 +02:00
|
|
|
"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"
|
2018-05-19 03:16:34 +02:00
|
|
|
)
|
|
|
|
|
2021-04-20 10:34:47 +02:00
|
|
|
const StartupPopupVersion = 5
|
2019-11-10 13:07:45 +02:00
|
|
|
|
2018-08-05 14:18:59 +02:00
|
|
|
// OverlappingEdges determines if panel edges overlap
|
|
|
|
var OverlappingEdges = false
|
2018-08-05 14:02:19 +02:00
|
|
|
|
2021-04-03 05:36:22 +02:00
|
|
|
type Repo string
|
|
|
|
|
2018-08-13 12:26:02 +02:00
|
|
|
// Gui wraps the gocui Gui object which handles rendering and events
|
|
|
|
type Gui struct {
|
2021-12-29 02:37:15 +02:00
|
|
|
*common.Common
|
2022-12-26 16:43:08 +02:00
|
|
|
g *gocui.Gui
|
|
|
|
gitVersion *git_commands.GitVersion
|
|
|
|
git *commands.GitCommand
|
|
|
|
os *oscommands.OSCommand
|
2021-04-03 06:56:11 +02:00
|
|
|
|
|
|
|
// this is the state of the GUI for the current repo
|
2022-01-28 11:44:36 +02:00
|
|
|
State *GuiRepoState
|
2021-04-03 06:56:11 +02:00
|
|
|
|
2022-02-24 04:29:48 +02:00
|
|
|
CustomCommandsClient *custom_commands.Client
|
|
|
|
|
2021-04-03 06:56:11 +02:00
|
|
|
// this is a mapping of repos to gui states, so that we can restore the original
|
|
|
|
// gui state when returning from a subrepo
|
2022-01-28 11:44:36 +02:00
|
|
|
RepoStateMap map[Repo]*GuiRepoState
|
allow fast flicking through any list panel
Up till now our approach to rendering things like file diffs, branch logs, and
commit patches, has been to run a command on the command line, wait for it to
complete, take its output as a string, and then write that string to the main
view (or secondary view e.g. when showing both staged and unstaged changes of a
file).
This has caused various issues. For once, if you are flicking through a list of
files and an untracked file is particularly large, not only will this require
lazygit to load that whole file into memory (or more accurately it's equally
large diff), it also will slow down the UI thread while loading that file, and
if the user continued down the list, the original command might eventually
resolve and replace whatever the diff is for the newly selected file.
Following what we've done in lazydocker, I've added a tasks package for when you
need something done but you want it to cancel as soon as something newer comes
up. Given this typically involves running a command to display to a view, I've
added a viewBufferManagerMap struct to the Gui struct which allows you to define
these tasks on a per-view basis.
viewBufferManagers can run files and directly write the output to their view,
meaning we no longer need to use so much memory.
In the tasks package there is a helper method called NewCmdTask which takes a
command, an initial amount of lines to read, and then runs that command, reads
that number of lines, and allows for a readLines channel to tell it to read more
lines. We read more lines when we scroll or resize the window.
There is an adapter for the tasks package in a file called tasks_adapter which
wraps the functions from the tasks package in gui-specific stuff like clearing
the main view before starting the next task that wants to write to the main
view.
I've removed some small features as part of this work, namely the little headers
that were at the top of the main view for some situations. For example, we no
longer show the upstream of a selected branch. I want to re-introduce this in
the future, but I didn't want to make this tasks system too complicated, and in
order to facilitate a header section in the main view we'd need to have a task
that gets the upstream for the current branch, writes it to the header, then
tells another task to write the branch log to the main view, but without
clearing inbetween. So it would get messy. I'm thinking instead of having a
separate 'header' view atop the main view to render that kind of thing (which
can happen in another PR)
I've also simplified the 'git show' to just call 'git show' and not do anything
fancy when it comes to merge commits.
I considered using this tasks approach whenever we write to a view. The only
thing is that the renderString method currently resets the origin of a view and
I don't want to lose that. So I've left some in there that I consider harmless,
but we should probably be just using tasks now for all rendering, even if it's
just strings we can instantly make.
2020-01-11 05:54:59 +02:00
|
|
|
Config config.AppConfigurer
|
|
|
|
Updater *updates.Updater
|
2023-03-23 09:47:29 +02:00
|
|
|
statusManager *status.StatusManager
|
allow fast flicking through any list panel
Up till now our approach to rendering things like file diffs, branch logs, and
commit patches, has been to run a command on the command line, wait for it to
complete, take its output as a string, and then write that string to the main
view (or secondary view e.g. when showing both staged and unstaged changes of a
file).
This has caused various issues. For once, if you are flicking through a list of
files and an untracked file is particularly large, not only will this require
lazygit to load that whole file into memory (or more accurately it's equally
large diff), it also will slow down the UI thread while loading that file, and
if the user continued down the list, the original command might eventually
resolve and replace whatever the diff is for the newly selected file.
Following what we've done in lazydocker, I've added a tasks package for when you
need something done but you want it to cancel as soon as something newer comes
up. Given this typically involves running a command to display to a view, I've
added a viewBufferManagerMap struct to the Gui struct which allows you to define
these tasks on a per-view basis.
viewBufferManagers can run files and directly write the output to their view,
meaning we no longer need to use so much memory.
In the tasks package there is a helper method called NewCmdTask which takes a
command, an initial amount of lines to read, and then runs that command, reads
that number of lines, and allows for a readLines channel to tell it to read more
lines. We read more lines when we scroll or resize the window.
There is an adapter for the tasks package in a file called tasks_adapter which
wraps the functions from the tasks package in gui-specific stuff like clearing
the main view before starting the next task that wants to write to the main
view.
I've removed some small features as part of this work, namely the little headers
that were at the top of the main view for some situations. For example, we no
longer show the upstream of a selected branch. I want to re-introduce this in
the future, but I didn't want to make this tasks system too complicated, and in
order to facilitate a header section in the main view we'd need to have a task
that gets the upstream for the current branch, writes it to the header, then
tells another task to write the branch log to the main view, but without
clearing inbetween. So it would get messy. I'm thinking instead of having a
separate 'header' view atop the main view to render that kind of thing (which
can happen in another PR)
I've also simplified the 'git show' to just call 'git show' and not do anything
fancy when it comes to merge commits.
I considered using this tasks approach whenever we write to a view. The only
thing is that the renderString method currently resets the origin of a view and
I don't want to lose that. So I've left some in there that I consider harmless,
but we should probably be just using tasks now for all rendering, even if it's
just strings we can instantly make.
2020-01-11 05:54:59 +02:00
|
|
|
waitForIntro sync.WaitGroup
|
|
|
|
fileWatcher *fileWatcher
|
|
|
|
viewBufferManagerMap map[string]*tasks.ViewBufferManager
|
2022-08-06 03:48:08 +02:00
|
|
|
// holds a mapping of view names to ptmx's. This is for rendering command outputs
|
|
|
|
// from within a pty. The point of keeping track of them is so that if we re-size
|
|
|
|
// the window, we can tell the pty it needs to resize accordingly.
|
|
|
|
viewPtmxMap map[string]*os.File
|
|
|
|
stopChan chan struct{}
|
2020-08-16 14:49:37 +02:00
|
|
|
|
|
|
|
// when lazygit is opened outside a git directory we want to open to the most
|
|
|
|
// recent repo with the recent repos popup showing
|
2021-04-03 05:36:22 +02:00
|
|
|
showRecentRepos bool
|
2020-10-04 08:41:21 +02:00
|
|
|
|
2022-07-31 05:52:56 +02:00
|
|
|
Mutexes types.Mutexes
|
2020-11-28 11:01:45 +02:00
|
|
|
|
2021-04-03 04:43:43 +02:00
|
|
|
// when you enter into a submodule we'll append the superproject's path to this array
|
|
|
|
// so that you can return to the superproject
|
2022-01-28 11:44:36 +02:00
|
|
|
RepoPathStack *utils.StringStack
|
2021-04-03 06:56:11 +02:00
|
|
|
|
|
|
|
// this tells us whether our views have been initially set up
|
|
|
|
ViewsSetup bool
|
2021-04-04 15:51:59 +02:00
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
Views types.Views
|
2021-04-10 05:08:51 +02:00
|
|
|
|
2023-05-13 12:43:26 +02:00
|
|
|
// Log of the commands/actions logged in the Command Log panel.
|
|
|
|
GuiLog []string
|
2021-04-11 04:12:54 +02:00
|
|
|
|
|
|
|
// the extras window contains things like the command log
|
|
|
|
ShowExtrasWindow bool
|
2021-10-18 10:00:03 +02:00
|
|
|
|
2022-01-29 10:09:20 +02:00
|
|
|
PopupHandler types.IPopupHandler
|
2021-12-29 02:50:20 +02:00
|
|
|
|
|
|
|
IsNewRepo bool
|
2022-03-15 15:12:26 +02:00
|
|
|
|
2022-01-28 11:44:36 +02:00
|
|
|
// flag as to whether or not the diff view should ignore whitespace
|
|
|
|
IgnoreWhitespaceInDiffView bool
|
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
IsRefreshingFiles bool
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
// we use this to decide whether we'll return to the original directory that
|
|
|
|
// lazygit was opened in, or if we'll retain the one we're currently in.
|
2022-01-28 11:44:36 +02:00
|
|
|
RetainOriginalDir bool
|
|
|
|
|
|
|
|
PrevLayout PrevLayout
|
|
|
|
|
2022-03-17 09:42:44 +02:00
|
|
|
// this is the initial dir we are in upon opening lazygit. We hold onto this
|
|
|
|
// in case we want to restore it before quitting for users who have set up
|
|
|
|
// the feature for changing directory upon quit.
|
|
|
|
// The reason we don't just wait until quit time to handle changing directories
|
|
|
|
// is because some users want to keep track of the current lazygit directory in an outside
|
|
|
|
// process
|
|
|
|
InitialDir string
|
2022-01-30 01:40:48 +02:00
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
BackgroundRoutineMgr *BackgroundRoutineMgr
|
|
|
|
// for accessing the gui's state from outside this package
|
|
|
|
stateAccessor *StateAccessor
|
|
|
|
|
|
|
|
Updating bool
|
|
|
|
|
2023-03-23 09:47:29 +02:00
|
|
|
c *helpers.HelperCommon
|
|
|
|
helpers *helpers.Helpers
|
2023-07-03 06:16:43 +02:00
|
|
|
|
|
|
|
integrationTest integrationTypes.IntegrationTest
|
2023-07-19 13:16:27 +02:00
|
|
|
|
|
|
|
afterLayoutFuncs chan func() error
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type StateAccessor struct {
|
|
|
|
gui *Gui
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ types.IStateAccessor = new(StateAccessor)
|
|
|
|
|
|
|
|
func (self *StateAccessor) GetIgnoreWhitespaceInDiffView() bool {
|
|
|
|
return self.gui.IgnoreWhitespaceInDiffView
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *StateAccessor) SetIgnoreWhitespaceInDiffView(value bool) {
|
|
|
|
self.gui.IgnoreWhitespaceInDiffView = value
|
|
|
|
}
|
2022-12-30 02:34:01 +02:00
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
func (self *StateAccessor) GetRepoPathStack() *utils.StringStack {
|
|
|
|
return self.gui.RepoPathStack
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *StateAccessor) GetUpdating() bool {
|
|
|
|
return self.gui.Updating
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *StateAccessor) SetUpdating(value bool) {
|
|
|
|
self.gui.Updating = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *StateAccessor) GetRepoState() types.IRepoStateAccessor {
|
|
|
|
return self.gui.State
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *StateAccessor) GetIsRefreshingFiles() bool {
|
|
|
|
return self.gui.IsRefreshingFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *StateAccessor) SetIsRefreshingFiles(value bool) {
|
|
|
|
self.gui.IsRefreshingFiles = value
|
2020-10-04 08:41:21 +02:00
|
|
|
}
|
|
|
|
|
2023-03-23 09:47:29 +02:00
|
|
|
func (self *StateAccessor) GetShowExtrasWindow() bool {
|
|
|
|
return self.gui.ShowExtrasWindow
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *StateAccessor) SetShowExtrasWindow(value bool) {
|
|
|
|
self.gui.ShowExtrasWindow = value
|
|
|
|
}
|
|
|
|
|
2023-03-26 06:38:18 +02:00
|
|
|
func (self *StateAccessor) GetRetainOriginalDir() bool {
|
|
|
|
return self.gui.RetainOriginalDir
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *StateAccessor) SetRetainOriginalDir(value bool) {
|
|
|
|
self.gui.RetainOriginalDir = value
|
|
|
|
}
|
|
|
|
|
2022-01-28 11:44:36 +02:00
|
|
|
// we keep track of some stuff from one render to the next to see if certain
|
|
|
|
// things have changed
|
|
|
|
type PrevLayout struct {
|
|
|
|
Information string
|
|
|
|
MainWidth int
|
|
|
|
MainHeight int
|
|
|
|
}
|
|
|
|
|
|
|
|
type GuiRepoState struct {
|
2022-01-31 13:11:34 +02:00
|
|
|
Model *types.Model
|
2022-02-06 05:37:16 +02:00
|
|
|
Modes *types.Modes
|
2022-01-28 11:44:36 +02:00
|
|
|
|
|
|
|
SplitMainPanel bool
|
2022-02-05 08:04:10 +02:00
|
|
|
LimitCommits bool
|
2022-01-28 11:44:36 +02:00
|
|
|
|
2023-05-27 06:14:43 +02:00
|
|
|
SearchState *types.SearchState
|
2022-12-30 14:24:24 +02:00
|
|
|
StartupStage types.StartupStage // Allows us to not load everything at once
|
2022-01-28 11:44:36 +02:00
|
|
|
|
2023-03-23 09:47:29 +02:00
|
|
|
ContextMgr *ContextMgr
|
2022-12-30 14:24:24 +02:00
|
|
|
Contexts *context.ContextTree
|
2022-01-28 11:44:36 +02:00
|
|
|
|
|
|
|
// WindowViewNameMap is a mapping of windows to the current view of that window.
|
|
|
|
// Some views move between windows for example the commitFiles view and when cycling through
|
|
|
|
// side windows we need to know which view to give focus to for a given window
|
2022-10-03 05:57:44 +02:00
|
|
|
WindowViewNameMap *utils.ThreadSafeMap[string, string]
|
2022-01-28 11:44:36 +02:00
|
|
|
|
|
|
|
// tells us whether we've set up our views for the current repo. We'll need to
|
|
|
|
// do this whenever we switch back and forth between repos to get the views
|
|
|
|
// back in sync with the repo state
|
|
|
|
ViewsSetup bool
|
|
|
|
|
2023-03-21 12:38:37 +02:00
|
|
|
ScreenMode types.WindowMaximisation
|
2022-02-23 11:02:40 +02:00
|
|
|
|
|
|
|
CurrentPopupOpts *types.CreatePopupPanelOpts
|
2022-01-28 11:44:36 +02:00
|
|
|
}
|
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
var _ types.IRepoStateAccessor = new(GuiRepoState)
|
|
|
|
|
|
|
|
func (self *GuiRepoState) GetViewsSetup() bool {
|
|
|
|
return self.ViewsSetup
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GuiRepoState) GetWindowViewNameMap() *utils.ThreadSafeMap[string, string] {
|
|
|
|
return self.WindowViewNameMap
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GuiRepoState) GetStartupStage() types.StartupStage {
|
|
|
|
return self.StartupStage
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GuiRepoState) SetStartupStage(value types.StartupStage) {
|
|
|
|
self.StartupStage = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GuiRepoState) GetCurrentPopupOpts() *types.CreatePopupPanelOpts {
|
|
|
|
return self.CurrentPopupOpts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GuiRepoState) SetCurrentPopupOpts(value *types.CreatePopupPanelOpts) {
|
|
|
|
self.CurrentPopupOpts = value
|
|
|
|
}
|
|
|
|
|
2023-03-21 12:38:37 +02:00
|
|
|
func (self *GuiRepoState) GetScreenMode() types.WindowMaximisation {
|
|
|
|
return self.ScreenMode
|
|
|
|
}
|
|
|
|
|
2023-03-23 09:47:29 +02:00
|
|
|
func (self *GuiRepoState) SetScreenMode(value types.WindowMaximisation) {
|
|
|
|
self.ScreenMode = value
|
|
|
|
}
|
|
|
|
|
2023-05-27 06:14:43 +02:00
|
|
|
func (self *GuiRepoState) InSearchPrompt() bool {
|
|
|
|
return self.SearchState.SearchType() != types.SearchTypeNone
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GuiRepoState) GetSearchState() *types.SearchState {
|
|
|
|
return self.SearchState
|
2023-03-23 09:47:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GuiRepoState) SetSplitMainPanel(value bool) {
|
|
|
|
self.SplitMainPanel = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *GuiRepoState) GetSplitMainPanel() bool {
|
|
|
|
return self.SplitMainPanel
|
|
|
|
}
|
|
|
|
|
2023-07-16 06:37:49 +02:00
|
|
|
func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, reuseState bool, contextKey types.ContextKey) error {
|
2022-01-31 13:11:34 +02:00
|
|
|
var err error
|
|
|
|
gui.git, err = commands.NewGitCommand(
|
|
|
|
gui.Common,
|
2022-12-26 16:43:08 +02:00
|
|
|
gui.gitVersion,
|
2022-02-06 04:42:17 +02:00
|
|
|
gui.os,
|
2022-01-31 13:11:34 +02:00
|
|
|
git_config.NewStdCachedGitConfig(gui.Log),
|
|
|
|
gui.Mutexes.SyncMutex,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-04-15 06:51:11 +02:00
|
|
|
contextToPush := gui.resetState(startArgs, reuseState)
|
2022-01-31 13:11:34 +02:00
|
|
|
|
2023-04-15 06:51:11 +02:00
|
|
|
gui.resetHelpersAndControllers()
|
2022-01-31 13:11:34 +02:00
|
|
|
|
|
|
|
if err := gui.resetKeybindings(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-07-16 06:37:49 +02:00
|
|
|
// if a context key has been given, push that instead, and set its index to 0
|
|
|
|
if contextKey != context.NO_CONTEXT {
|
|
|
|
contextToPush = gui.c.ContextForKey(contextKey)
|
|
|
|
// when we pass a list context, the expectation is that our cursor goes to the top,
|
|
|
|
// because e.g. with worktrees, we'll show the current worktree at the top of the list.
|
|
|
|
listContext, ok := contextToPush.(types.IListContext)
|
|
|
|
if ok {
|
|
|
|
listContext.GetList().SetSelectedLineIdx(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-15 06:51:11 +02:00
|
|
|
if err := gui.c.PushContext(contextToPush); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-05 05:22:03 +02:00
|
|
|
// reuseState determines if we pull the repo state from our repo state map or
|
|
|
|
// just re-initialize it. For now we're only re-using state when we're going
|
|
|
|
// in and out of submodules, for the sake of having the cursor back on the submodule
|
|
|
|
// when we return.
|
|
|
|
//
|
|
|
|
// I tried out always reverting to the repo's original state but found that in fact
|
|
|
|
// it gets a bit confusing to land back in the status panel when visiting a repo
|
|
|
|
// you've already switched from. There's no doubt some easy way to make the UX
|
|
|
|
// optimal for all cases but I'm too lazy to think about what that is right now
|
2023-04-15 06:51:11 +02:00
|
|
|
func (gui *Gui) resetState(startArgs appTypes.StartArgs, reuseState bool) types.Context {
|
2021-04-03 05:36:22 +02:00
|
|
|
currentDir, err := os.Getwd()
|
2021-04-05 05:22:03 +02:00
|
|
|
|
|
|
|
if reuseState {
|
|
|
|
if err == nil {
|
|
|
|
if state := gui.RepoStateMap[Repo(currentDir)]; state != nil {
|
|
|
|
gui.State = state
|
|
|
|
gui.State.ViewsSetup = false
|
2022-02-23 11:02:40 +02:00
|
|
|
|
|
|
|
// setting this to nil so we don't get stuck based on a popup that was
|
|
|
|
// previously opened
|
|
|
|
gui.Mutexes.PopupMutex.Lock()
|
|
|
|
gui.State.CurrentPopupOpts = nil
|
|
|
|
gui.Mutexes.PopupMutex.Unlock()
|
|
|
|
|
2023-04-15 06:51:11 +02:00
|
|
|
return gui.c.CurrentContext()
|
2021-04-05 05:22:03 +02:00
|
|
|
}
|
|
|
|
} else {
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.Log.Error(err)
|
2021-04-03 05:36:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 07:56:36 +02:00
|
|
|
contextTree := gui.contextTree()
|
2021-04-05 05:07:44 +02:00
|
|
|
|
2023-01-11 13:21:46 +02:00
|
|
|
initialScreenMode := initialScreenMode(startArgs, gui.Config)
|
2022-02-05 07:56:36 +02:00
|
|
|
|
2022-01-28 11:44:36 +02:00
|
|
|
gui.State = &GuiRepoState{
|
2022-01-31 13:11:34 +02:00
|
|
|
Model: &types.Model{
|
|
|
|
CommitFiles: nil,
|
|
|
|
Files: make([]*models.File, 0),
|
|
|
|
Commits: make([]*models.Commit, 0),
|
|
|
|
StashEntries: make([]*models.StashEntry, 0),
|
|
|
|
FilteredReflogCommits: make([]*models.Commit, 0),
|
|
|
|
ReflogCommits: make([]*models.Commit, 0),
|
|
|
|
BisectInfo: git_commands.NewNullBisectInfo(),
|
|
|
|
FilesTrie: patricia.NewTrie(),
|
2023-07-22 02:33:40 +02:00
|
|
|
Authors: map[string]*models.Author{},
|
2022-01-31 13:11:34 +02:00
|
|
|
},
|
2022-02-06 05:37:16 +02:00
|
|
|
Modes: &types.Modes{
|
2022-06-09 11:52:08 +02:00
|
|
|
Filtering: filtering.New(startArgs.FilterPath),
|
2021-06-05 07:08:36 +02:00
|
|
|
CherryPicking: cherrypicking.New(),
|
|
|
|
Diffing: diffing.New(),
|
2021-04-03 04:43:43 +02:00
|
|
|
},
|
2022-06-13 03:01:26 +02:00
|
|
|
ScreenMode: initialScreenMode,
|
2023-03-23 13:05:25 +02:00
|
|
|
// TODO: only use contexts from context manager
|
2023-04-15 06:51:11 +02:00
|
|
|
ContextMgr: NewContextMgr(gui, contextTree),
|
2022-06-13 03:01:26 +02:00
|
|
|
Contexts: contextTree,
|
2022-12-30 14:24:24 +02:00
|
|
|
WindowViewNameMap: initialWindowViewNameMap(contextTree),
|
2023-05-27 06:14:43 +02:00
|
|
|
SearchState: types.NewSearchState(),
|
2018-08-13 12:26:02 +02:00
|
|
|
}
|
2021-04-03 02:32:14 +02:00
|
|
|
|
2021-04-03 06:56:11 +02:00
|
|
|
gui.RepoStateMap[Repo(currentDir)] = gui.State
|
2023-04-15 06:51:11 +02:00
|
|
|
|
|
|
|
return initialContext(contextTree, startArgs)
|
2020-03-29 01:20:57 +02:00
|
|
|
}
|
2018-08-13 12:26:02 +02:00
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
func initialWindowViewNameMap(contextTree *context.ContextTree) *utils.ThreadSafeMap[string, string] {
|
|
|
|
result := utils.NewThreadSafeMap[string, string]()
|
|
|
|
|
|
|
|
for _, context := range contextTree.Flatten() {
|
|
|
|
result.Set(context.GetWindowName(), context.GetViewName())
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2023-03-21 12:38:37 +02:00
|
|
|
func initialScreenMode(startArgs appTypes.StartArgs, config config.AppConfigurer) types.WindowMaximisation {
|
2022-08-09 13:27:12 +02:00
|
|
|
if startArgs.FilterPath != "" || startArgs.GitArg != appTypes.GitArgNone {
|
2023-03-21 12:38:37 +02:00
|
|
|
return types.SCREEN_HALF
|
2022-06-09 11:52:08 +02:00
|
|
|
} else {
|
2023-01-16 16:37:21 +02:00
|
|
|
defaultWindowSize := config.GetUserConfig().Gui.WindowSize
|
2023-01-11 13:21:46 +02:00
|
|
|
|
2023-01-16 16:37:21 +02:00
|
|
|
switch defaultWindowSize {
|
2023-01-11 13:21:46 +02:00
|
|
|
case "half":
|
2023-03-21 12:38:37 +02:00
|
|
|
return types.SCREEN_HALF
|
2023-01-11 13:21:46 +02:00
|
|
|
case "full":
|
2023-03-21 12:38:37 +02:00
|
|
|
return types.SCREEN_FULL
|
2023-01-11 13:21:46 +02:00
|
|
|
default:
|
2023-03-21 12:38:37 +02:00
|
|
|
return types.SCREEN_NORMAL
|
2023-01-11 13:21:46 +02:00
|
|
|
}
|
2022-06-09 11:52:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-09 13:27:12 +02:00
|
|
|
func initialContext(contextTree *context.ContextTree, startArgs appTypes.StartArgs) types.IListContext {
|
2022-06-09 11:52:08 +02:00
|
|
|
var initialContext types.IListContext = contextTree.Files
|
|
|
|
|
|
|
|
if startArgs.FilterPath != "" {
|
|
|
|
initialContext = contextTree.LocalCommits
|
2022-08-09 13:27:12 +02:00
|
|
|
} else if startArgs.GitArg != appTypes.GitArgNone {
|
2022-06-09 11:52:08 +02:00
|
|
|
switch startArgs.GitArg {
|
2022-08-09 13:27:12 +02:00
|
|
|
case appTypes.GitArgStatus:
|
2022-06-09 11:52:08 +02:00
|
|
|
initialContext = contextTree.Files
|
2022-08-09 13:27:12 +02:00
|
|
|
case appTypes.GitArgBranch:
|
2022-06-09 11:52:08 +02:00
|
|
|
initialContext = contextTree.Branches
|
2022-08-09 13:27:12 +02:00
|
|
|
case appTypes.GitArgLog:
|
2022-06-09 11:52:08 +02:00
|
|
|
initialContext = contextTree.LocalCommits
|
2022-08-09 13:27:12 +02:00
|
|
|
case appTypes.GitArgStash:
|
2022-06-09 11:52:08 +02:00
|
|
|
initialContext = contextTree.Stash
|
|
|
|
default:
|
|
|
|
panic("unhandled git arg")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return initialContext
|
|
|
|
}
|
|
|
|
|
2023-03-23 03:35:07 +02:00
|
|
|
func (gui *Gui) Contexts() *context.ContextTree {
|
|
|
|
return gui.State.Contexts
|
|
|
|
}
|
|
|
|
|
2020-03-29 01:20:57 +02:00
|
|
|
// for now the split view will always be on
|
|
|
|
// NewGui builds a new gui handler
|
2022-01-02 01:34:33 +02:00
|
|
|
func NewGui(
|
|
|
|
cmn *common.Common,
|
|
|
|
config config.AppConfigurer,
|
2022-12-26 16:43:08 +02:00
|
|
|
gitVersion *git_commands.GitVersion,
|
2022-01-02 01:34:33 +02:00
|
|
|
updater *updates.Updater,
|
|
|
|
showRecentRepos bool,
|
2022-03-17 09:42:44 +02:00
|
|
|
initialDir string,
|
2022-01-02 01:34:33 +02:00
|
|
|
) (*Gui, error) {
|
2018-08-14 15:47:14 +02:00
|
|
|
gui := &Gui{
|
2023-03-21 11:57:52 +02:00
|
|
|
Common: cmn,
|
|
|
|
gitVersion: gitVersion,
|
|
|
|
Config: config,
|
|
|
|
Updater: updater,
|
2023-03-23 09:47:29 +02:00
|
|
|
statusManager: status.NewStatusManager(),
|
2023-03-21 11:57:52 +02:00
|
|
|
viewBufferManagerMap: map[string]*tasks.ViewBufferManager{},
|
|
|
|
viewPtmxMap: map[string]*os.File{},
|
|
|
|
showRecentRepos: showRecentRepos,
|
|
|
|
RepoPathStack: &utils.StringStack{},
|
|
|
|
RepoStateMap: map[Repo]*GuiRepoState{},
|
2023-05-13 12:43:26 +02:00
|
|
|
GuiLog: []string{},
|
2021-12-29 03:03:35 +02:00
|
|
|
|
|
|
|
// originally we could only hide the command log permanently via the config
|
|
|
|
// but now we do it via state. So we need to still support the config for the
|
|
|
|
// sake of backwards compatibility. We're making use of short circuiting here
|
|
|
|
ShowExtrasWindow: cmn.UserConfig.Gui.ShowCommandLog && !config.GetAppState().HideCommandLog,
|
2022-07-31 05:52:56 +02:00
|
|
|
Mutexes: types.Mutexes{
|
2023-07-08 12:47:16 +02:00
|
|
|
RefreshingFilesMutex: &deadlock.Mutex{},
|
|
|
|
RefreshingBranchesMutex: &deadlock.Mutex{},
|
|
|
|
RefreshingStatusMutex: &deadlock.Mutex{},
|
|
|
|
SyncMutex: &deadlock.Mutex{},
|
|
|
|
LocalCommitsMutex: &deadlock.Mutex{},
|
|
|
|
SubCommitsMutex: &deadlock.Mutex{},
|
2023-07-22 02:33:40 +02:00
|
|
|
AuthorsMutex: &deadlock.Mutex{},
|
2023-07-08 12:47:16 +02:00
|
|
|
SubprocessMutex: &deadlock.Mutex{},
|
|
|
|
PopupMutex: &deadlock.Mutex{},
|
|
|
|
PtyMutex: &deadlock.Mutex{},
|
2022-01-16 05:46:53 +02:00
|
|
|
},
|
2023-07-19 13:16:27 +02:00
|
|
|
InitialDir: initialDir,
|
|
|
|
afterLayoutFuncs: make(chan func() error, 1000),
|
2018-08-14 15:47:14 +02:00
|
|
|
}
|
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
gui.WatchFilesForChanges()
|
2019-11-12 13:19:20 +02:00
|
|
|
|
2022-01-28 11:44:36 +02:00
|
|
|
gui.PopupHandler = popup.NewPopupHandler(
|
|
|
|
cmn,
|
2023-03-21 11:57:52 +02:00
|
|
|
func(ctx goContext.Context, opts types.CreatePopupPanelOpts) error {
|
|
|
|
return gui.helpers.Confirmation.CreatePopupPanel(ctx, opts)
|
|
|
|
},
|
2022-01-16 05:46:53 +02:00
|
|
|
func() error { return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) },
|
2023-03-23 09:47:29 +02:00
|
|
|
func() error { return gui.State.ContextMgr.Pop() },
|
|
|
|
func() types.Context { return gui.State.ContextMgr.Current() },
|
2022-01-28 11:44:36 +02:00
|
|
|
gui.createMenu,
|
2023-07-09 13:09:52 +02:00
|
|
|
func(message string, f func(gocui.Task) error) { gui.helpers.AppStatus.WithWaitingStatus(message, f) },
|
2023-03-23 09:47:29 +02:00
|
|
|
func(message string) { gui.helpers.AppStatus.Toast(message) },
|
2022-01-16 05:46:53 +02:00
|
|
|
func() string { return gui.Views.Confirmation.TextArea.GetContent() },
|
2023-07-09 13:09:52 +02:00
|
|
|
func(f func(gocui.Task)) { gui.c.OnWorker(f) },
|
2022-01-28 11:44:36 +02:00
|
|
|
)
|
2021-04-10 08:01:46 +02:00
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
guiCommon := &guiCommon{gui: gui, IPopupHandler: gui.PopupHandler}
|
2023-03-23 03:35:07 +02:00
|
|
|
helperCommon := &helpers.HelperCommon{IGuiCommon: guiCommon, Common: cmn, IGetContexts: gui}
|
2022-01-16 05:46:53 +02:00
|
|
|
|
2022-02-23 10:44:48 +02:00
|
|
|
credentialsHelper := helpers.NewCredentialsHelper(helperCommon)
|
|
|
|
|
|
|
|
guiIO := oscommands.NewGuiIO(
|
|
|
|
cmn.Log,
|
|
|
|
gui.LogCommand,
|
|
|
|
gui.getCmdWriter,
|
|
|
|
credentialsHelper.PromptUserForCredential,
|
|
|
|
)
|
|
|
|
|
2022-04-01 16:38:41 +02:00
|
|
|
osCommand := oscommands.NewOSCommand(cmn, config, oscommands.GetPlatform(), guiIO)
|
2022-02-23 10:44:48 +02:00
|
|
|
|
|
|
|
gui.os = osCommand
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
// storing this stuff on the gui for now to ease refactoring
|
|
|
|
// TODO: reset these controllers upon changing repos due to state changing
|
2022-02-06 06:54:26 +02:00
|
|
|
gui.c = helperCommon
|
2022-01-16 05:46:53 +02:00
|
|
|
|
2021-12-29 02:50:20 +02:00
|
|
|
authors.SetCustomAuthors(gui.UserConfig.Gui.AuthorColors)
|
2023-06-15 13:39:11 +02:00
|
|
|
if gui.UserConfig.Gui.NerdFontsVersion != "" {
|
|
|
|
icons.SetNerdFontsVersion(gui.UserConfig.Gui.NerdFontsVersion)
|
|
|
|
} else if gui.UserConfig.Gui.ShowIcons {
|
|
|
|
icons.SetNerdFontsVersion("2")
|
|
|
|
}
|
2022-02-01 07:23:55 +02:00
|
|
|
presentation.SetCustomBranches(gui.UserConfig.Gui.BranchColors)
|
2021-10-30 09:00:28 +02:00
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
gui.BackgroundRoutineMgr = &BackgroundRoutineMgr{gui: gui}
|
|
|
|
gui.stateAccessor = &StateAccessor{gui: gui}
|
|
|
|
|
2022-01-23 05:40:28 +02:00
|
|
|
return gui, nil
|
|
|
|
}
|
|
|
|
|
2021-11-01 00:35:54 +02:00
|
|
|
var RuneReplacements = map[rune]string{
|
|
|
|
// for the commit graph
|
2021-11-02 23:23:47 +02:00
|
|
|
graph.MergeSymbol: "M",
|
|
|
|
graph.CommitSymbol: "o",
|
2021-11-01 00:35:54 +02:00
|
|
|
}
|
|
|
|
|
2022-08-09 13:27:12 +02:00
|
|
|
func (gui *Gui) initGocui(headless bool, test integrationTypes.IntegrationTest) (*gocui.Gui, error) {
|
2023-07-19 14:02:43 +02:00
|
|
|
runInSandbox := os.Getenv(components.SANDBOX_ENV_VAR) == "true"
|
|
|
|
playRecording := test != nil && !runInSandbox
|
|
|
|
|
|
|
|
width, height := 0, 0
|
|
|
|
if test != nil {
|
|
|
|
if test.RequiresHeadless() {
|
|
|
|
if runInSandbox {
|
|
|
|
panic("Test requires headless, can't run in sandbox")
|
|
|
|
}
|
|
|
|
headless = true
|
|
|
|
}
|
|
|
|
width, height = test.HeadlessDimensions()
|
|
|
|
}
|
2020-10-04 08:41:21 +02:00
|
|
|
|
2023-07-19 14:02:43 +02:00
|
|
|
g, err := gocui.NewGui(gocui.NewGuiOpts{
|
|
|
|
OutputMode: gocui.OutputTrue,
|
|
|
|
SupportOverlaps: OverlappingEdges,
|
|
|
|
PlayRecording: playRecording,
|
|
|
|
Headless: headless,
|
|
|
|
RuneReplacements: RuneReplacements,
|
|
|
|
Width: width,
|
|
|
|
Height: height,
|
|
|
|
})
|
2022-01-31 13:11:34 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return g, nil
|
|
|
|
}
|
|
|
|
|
2022-06-13 03:01:26 +02:00
|
|
|
func (gui *Gui) viewTabMap() map[string][]context.TabView {
|
2023-07-17 08:29:55 +02:00
|
|
|
result := map[string][]context.TabView{
|
|
|
|
"branches": {
|
|
|
|
{
|
|
|
|
Tab: gui.c.Tr.LocalBranchesTitle,
|
|
|
|
ViewName: "localBranches",
|
2022-09-01 20:25:41 +02:00
|
|
|
},
|
2023-07-17 08:29:55 +02:00
|
|
|
{
|
|
|
|
Tab: gui.c.Tr.RemotesTitle,
|
|
|
|
ViewName: "remotes",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Tab: gui.c.Tr.TagsTitle,
|
|
|
|
ViewName: "tags",
|
|
|
|
},
|
|
|
|
},
|
2022-05-18 14:09:48 +02:00
|
|
|
"commits": {
|
|
|
|
{
|
2022-06-13 03:01:26 +02:00
|
|
|
Tab: gui.c.Tr.CommitsTitle,
|
|
|
|
ViewName: "commits",
|
2022-05-18 14:09:48 +02:00
|
|
|
},
|
|
|
|
{
|
2022-06-13 03:01:26 +02:00
|
|
|
Tab: gui.c.Tr.ReflogCommitsTitle,
|
|
|
|
ViewName: "reflogCommits",
|
2022-05-18 14:09:48 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"files": {
|
|
|
|
{
|
2022-06-13 03:01:26 +02:00
|
|
|
Tab: gui.c.Tr.FilesTitle,
|
|
|
|
ViewName: "files",
|
2022-05-18 14:09:48 +02:00
|
|
|
},
|
2023-07-17 11:59:51 +02:00
|
|
|
context.TabView{
|
|
|
|
Tab: gui.c.Tr.WorktreesTitle,
|
|
|
|
ViewName: "worktrees",
|
|
|
|
},
|
2022-05-18 14:09:48 +02:00
|
|
|
{
|
2022-06-13 03:01:26 +02:00
|
|
|
Tab: gui.c.Tr.SubmodulesTitle,
|
|
|
|
ViewName: "submodules",
|
2022-05-18 14:09:48 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-07-17 08:29:55 +02:00
|
|
|
|
|
|
|
return result
|
2022-05-18 14:09:48 +02:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
// Run: setup the gui with keybindings and start the mainloop
|
2022-08-09 13:27:12 +02:00
|
|
|
func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
|
|
|
|
g, err := gui.initGocui(Headless(), startArgs.IntegrationTest)
|
2018-07-21 07:51:18 +02:00
|
|
|
if err != nil {
|
2018-08-13 13:16:21 +02:00
|
|
|
return err
|
2018-07-21 07:51:18 +02:00
|
|
|
}
|
2021-04-10 03:40:42 +02:00
|
|
|
|
2023-04-02 15:01:04 +02:00
|
|
|
defer gui.checkForDeprecatedEditConfigs()
|
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
gui.g = g
|
|
|
|
defer gui.g.Close()
|
2020-02-23 12:53:30 +02:00
|
|
|
|
2022-08-06 10:50:52 +02:00
|
|
|
// if the deadlock package wants to report a deadlock, we first need to
|
|
|
|
// close the gui so that we can actually read what it prints.
|
|
|
|
deadlock.Opts.LogBuf = utils.NewOnceWriter(os.Stderr, func() {
|
|
|
|
gui.g.Close()
|
|
|
|
})
|
|
|
|
deadlock.Opts.Disable = !gui.Debug
|
|
|
|
|
2021-02-23 14:01:45 +02:00
|
|
|
if err := gui.Config.ReloadUserConfig(); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2021-12-29 02:50:20 +02:00
|
|
|
userConfig := gui.UserConfig
|
2023-05-27 06:14:43 +02:00
|
|
|
|
|
|
|
gui.g.OnSearchEscape = func() error { gui.helpers.Search.Cancel(); return nil }
|
2022-08-06 10:50:52 +02:00
|
|
|
gui.g.SearchEscapeKey = keybindings.GetKey(userConfig.Keybinding.Universal.Return)
|
|
|
|
gui.g.NextSearchMatchKey = keybindings.GetKey(userConfig.Keybinding.Universal.NextMatch)
|
|
|
|
gui.g.PrevSearchMatchKey = keybindings.GetKey(userConfig.Keybinding.Universal.PrevMatch)
|
2020-02-23 12:53:30 +02:00
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
gui.g.ShowListFooter = userConfig.Gui.ShowListFooter
|
2021-06-10 10:26:29 +02:00
|
|
|
|
2020-10-03 06:54:55 +02:00
|
|
|
if userConfig.Gui.MouseEvents {
|
2022-01-31 13:11:34 +02:00
|
|
|
gui.g.Mouse = true
|
2019-03-03 07:15:20 +02:00
|
|
|
}
|
2019-02-25 13:11:35 +02:00
|
|
|
|
2019-10-19 11:39:18 +02:00
|
|
|
if err := gui.setColorScheme(); err != nil {
|
2018-08-18 05:53:58 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-08-11 07:09:37 +02:00
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
gui.g.SetManager(gocui.ManagerFunc(gui.layout), gocui.ManagerFunc(gui.getFocusLayout()))
|
|
|
|
|
2022-02-05 07:56:36 +02:00
|
|
|
if err := gui.createAllViews(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
// onNewRepo must be called after g.SetManager because SetManager deletes keybindings
|
2023-07-16 06:37:49 +02:00
|
|
|
if err := gui.onNewRepo(startArgs, false, context.NO_CONTEXT); err != nil {
|
2022-01-31 13:11:34 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-10 13:07:45 +02:00
|
|
|
gui.waitForIntro.Add(1)
|
2022-03-26 19:24:36 +02:00
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
gui.BackgroundRoutineMgr.startBackgroundRoutines()
|
2018-07-21 10:37:00 +02:00
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.Log.Info("starting main loop")
|
2019-11-10 13:07:45 +02:00
|
|
|
|
2023-07-03 06:16:43 +02:00
|
|
|
// setting here so we can use it in layout.go
|
|
|
|
gui.integrationTest = startArgs.IntegrationTest
|
2022-09-10 06:11:05 +02:00
|
|
|
|
2022-01-31 13:11:34 +02:00
|
|
|
return gui.g.MainLoop()
|
2018-08-13 12:26:02 +02:00
|
|
|
}
|
|
|
|
|
2022-08-09 13:27:12 +02:00
|
|
|
func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error {
|
2021-04-03 04:43:43 +02:00
|
|
|
gui.stopChan = make(chan struct{})
|
|
|
|
return utils.SafeWithError(func() error {
|
2022-06-09 11:52:08 +02:00
|
|
|
if err := gui.Run(startArgs); err != nil {
|
allow fast flicking through any list panel
Up till now our approach to rendering things like file diffs, branch logs, and
commit patches, has been to run a command on the command line, wait for it to
complete, take its output as a string, and then write that string to the main
view (or secondary view e.g. when showing both staged and unstaged changes of a
file).
This has caused various issues. For once, if you are flicking through a list of
files and an untracked file is particularly large, not only will this require
lazygit to load that whole file into memory (or more accurately it's equally
large diff), it also will slow down the UI thread while loading that file, and
if the user continued down the list, the original command might eventually
resolve and replace whatever the diff is for the newly selected file.
Following what we've done in lazydocker, I've added a tasks package for when you
need something done but you want it to cancel as soon as something newer comes
up. Given this typically involves running a command to display to a view, I've
added a viewBufferManagerMap struct to the Gui struct which allows you to define
these tasks on a per-view basis.
viewBufferManagers can run files and directly write the output to their view,
meaning we no longer need to use so much memory.
In the tasks package there is a helper method called NewCmdTask which takes a
command, an initial amount of lines to read, and then runs that command, reads
that number of lines, and allows for a readLines channel to tell it to read more
lines. We read more lines when we scroll or resize the window.
There is an adapter for the tasks package in a file called tasks_adapter which
wraps the functions from the tasks package in gui-specific stuff like clearing
the main view before starting the next task that wants to write to the main
view.
I've removed some small features as part of this work, namely the little headers
that were at the top of the main view for some situations. For example, we no
longer show the upstream of a selected branch. I want to re-introduce this in
the future, but I didn't want to make this tasks system too complicated, and in
order to facilitate a header section in the main view we'd need to have a task
that gets the upstream for the current branch, writes it to the header, then
tells another task to write the branch log to the main view, but without
clearing inbetween. So it would get messy. I'm thinking instead of having a
separate 'header' view atop the main view to render that kind of thing (which
can happen in another PR)
I've also simplified the 'git show' to just call 'git show' and not do anything
fancy when it comes to merge commits.
I considered using this tasks approach whenever we write to a view. The only
thing is that the renderString method currently resets the origin of a view and
I don't want to lose that. So I've left some in there that I consider harmless,
but we should probably be just using tasks now for all rendering, even if it's
just strings we can instantly make.
2020-01-11 05:54:59 +02:00
|
|
|
for _, manager := range gui.viewBufferManagerMap {
|
|
|
|
manager.Close()
|
|
|
|
}
|
|
|
|
|
2020-01-31 10:46:29 +02:00
|
|
|
if !gui.fileWatcher.Disabled {
|
|
|
|
gui.fileWatcher.Watcher.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
close(gui.stopChan)
|
|
|
|
|
2020-08-23 12:20:05 +02:00
|
|
|
switch err {
|
|
|
|
case gocui.ErrQuit:
|
2023-03-26 06:38:18 +02:00
|
|
|
if gui.c.State().GetRetainOriginalDir() {
|
2022-12-30 14:24:24 +02:00
|
|
|
if err := gui.helpers.RecordDirectory.RecordDirectory(gui.InitialDir); err != nil {
|
2022-03-15 15:12:26 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2022-12-30 14:24:24 +02:00
|
|
|
if err := gui.helpers.RecordDirectory.RecordCurrentDirectory(); err != nil {
|
2019-10-07 03:34:12 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-23 12:20:05 +02:00
|
|
|
return nil
|
2021-04-03 04:43:43 +02:00
|
|
|
|
2020-08-23 12:20:05 +02:00
|
|
|
default:
|
2019-02-18 10:42:23 +02:00
|
|
|
return err
|
2018-08-13 12:26:02 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-03 04:43:43 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2018-05-19 09:04:33 +02:00
|
|
|
}
|
|
|
|
|
2023-04-02 15:01:04 +02:00
|
|
|
func (gui *Gui) checkForDeprecatedEditConfigs() {
|
|
|
|
osConfig := &gui.UserConfig.OS
|
|
|
|
deprecatedConfigs := []struct {
|
|
|
|
config string
|
|
|
|
oldName string
|
|
|
|
newName string
|
|
|
|
}{
|
|
|
|
{osConfig.EditCommand, "EditCommand", "Edit"},
|
|
|
|
{osConfig.EditCommandTemplate, "EditCommandTemplate", "Edit,EditAtLine"},
|
|
|
|
{osConfig.OpenCommand, "OpenCommand", "Open"},
|
|
|
|
{osConfig.OpenLinkCommand, "OpenLinkCommand", "OpenLink"},
|
|
|
|
}
|
|
|
|
deprecatedConfigStrings := []string{}
|
|
|
|
|
|
|
|
for _, dc := range deprecatedConfigs {
|
|
|
|
if dc.config != "" {
|
|
|
|
deprecatedConfigStrings = append(deprecatedConfigStrings, fmt.Sprintf(" OS.%s -> OS.%s", dc.oldName, dc.newName))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(deprecatedConfigStrings) != 0 {
|
|
|
|
warningMessage := utils.ResolvePlaceholderString(
|
|
|
|
gui.c.Tr.DeprecatedEditConfigWarning,
|
|
|
|
map[string]string{
|
|
|
|
"configs": strings.Join(deprecatedConfigStrings, "\n"),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
os.Stdout.Write([]byte(warningMessage))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-10 03:40:42 +02:00
|
|
|
// returns whether command exited without error or not
|
2021-12-07 12:59:36 +02:00
|
|
|
func (gui *Gui) runSubprocessWithSuspenseAndRefresh(subprocess oscommands.ICmdObj) error {
|
2021-04-10 03:40:42 +02:00
|
|
|
_, err := gui.runSubprocessWithSuspense(subprocess)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
if err := gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}); err != nil {
|
2021-04-10 03:40:42 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns whether command exited without error or not
|
2021-12-07 12:59:36 +02:00
|
|
|
func (gui *Gui) runSubprocessWithSuspense(subprocess oscommands.ICmdObj) (bool, error) {
|
2021-04-10 03:40:42 +02:00
|
|
|
gui.Mutexes.SubprocessMutex.Lock()
|
|
|
|
defer gui.Mutexes.SubprocessMutex.Unlock()
|
|
|
|
|
|
|
|
if err := gui.g.Suspend(); err != nil {
|
2022-01-16 05:46:53 +02:00
|
|
|
return false, gui.c.Error(err)
|
2021-04-02 12:30:39 +02:00
|
|
|
}
|
|
|
|
|
2023-07-08 07:23:15 +02:00
|
|
|
gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(true)
|
|
|
|
defer gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(false)
|
2021-04-10 04:07:52 +02:00
|
|
|
|
2021-04-02 12:30:39 +02:00
|
|
|
cmdErr := gui.runSubprocess(subprocess)
|
|
|
|
|
2021-04-10 03:40:42 +02:00
|
|
|
if err := gui.g.Resume(); err != nil {
|
2021-04-10 04:07:52 +02:00
|
|
|
return false, err
|
2021-04-02 12:30:39 +02:00
|
|
|
}
|
|
|
|
|
2022-01-16 05:31:28 +02:00
|
|
|
if cmdErr != nil {
|
2022-01-16 05:46:53 +02:00
|
|
|
return false, gui.c.Error(cmdErr)
|
2022-01-16 05:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
2021-04-02 12:30:39 +02:00
|
|
|
}
|
|
|
|
|
2022-01-08 06:46:35 +02:00
|
|
|
func (gui *Gui) runSubprocess(cmdObj oscommands.ICmdObj) error { //nolint:unparam
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.LogCommand(cmdObj.ToString(), true)
|
2022-01-05 03:01:59 +02:00
|
|
|
|
2021-12-07 12:59:36 +02:00
|
|
|
subprocess := cmdObj.GetCmd()
|
2021-04-02 12:30:39 +02:00
|
|
|
subprocess.Stdout = os.Stdout
|
|
|
|
subprocess.Stderr = os.Stdout
|
|
|
|
subprocess.Stdin = os.Stdin
|
2019-03-12 12:43:56 +02:00
|
|
|
|
2021-07-27 15:00:37 +02:00
|
|
|
fmt.Fprintf(os.Stdout, "\n%s\n\n", style.FgBlue.Sprint("+ "+strings.Join(subprocess.Args, " ")))
|
2019-05-26 03:24:01 +02:00
|
|
|
|
2021-12-05 23:33:26 +02:00
|
|
|
err := subprocess.Run()
|
2019-03-12 12:43:56 +02:00
|
|
|
|
2022-09-13 12:11:03 +02:00
|
|
|
subprocess.Stdout = io.Discard
|
|
|
|
subprocess.Stderr = io.Discard
|
2021-04-02 12:30:39 +02:00
|
|
|
subprocess.Stdin = nil
|
2019-05-26 03:24:01 +02:00
|
|
|
|
2022-03-17 08:43:03 +02:00
|
|
|
if gui.Config.GetUserConfig().PromptToReturnFromSubprocess {
|
|
|
|
fmt.Fprintf(os.Stdout, "\n%s", style.FgGreen.Sprint(gui.Tr.PressEnterToReturn))
|
2021-12-25 21:35:04 +02:00
|
|
|
|
|
|
|
// scan to buffer to prevent run unintentional operations when TUI resumes.
|
|
|
|
var buffer string
|
|
|
|
fmt.Scanln(&buffer) // wait for enter press
|
2022-03-17 08:43:03 +02:00
|
|
|
}
|
2019-05-26 03:24:01 +02:00
|
|
|
|
2021-12-05 23:33:26 +02:00
|
|
|
return err
|
2019-03-12 12:43:56 +02:00
|
|
|
}
|
|
|
|
|
2020-03-29 01:31:34 +02:00
|
|
|
func (gui *Gui) loadNewRepo() error {
|
|
|
|
if err := gui.updateRecentRepoList(); err != nil {
|
|
|
|
return err
|
2019-03-03 05:28:16 +02:00
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
if err := gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}); err != nil {
|
2020-03-29 01:31:34 +02:00
|
|
|
return err
|
2020-03-28 07:28:35 +02:00
|
|
|
}
|
|
|
|
|
2022-02-06 04:42:17 +02:00
|
|
|
if err := gui.os.UpdateWindowTitle(); err != nil {
|
2022-01-20 17:02:03 +02:00
|
|
|
return err
|
|
|
|
}
|
2022-01-19 11:42:32 +02:00
|
|
|
|
2020-03-28 07:28:35 +02:00
|
|
|
return nil
|
2019-02-25 13:11:35 +02:00
|
|
|
}
|
2019-10-19 11:39:18 +02:00
|
|
|
|
2023-07-10 05:05:49 +02:00
|
|
|
func (gui *Gui) showIntroPopupMessage() {
|
|
|
|
gui.waitForIntro.Add(1)
|
2019-10-19 11:39:18 +02:00
|
|
|
|
2023-07-10 05:05:49 +02:00
|
|
|
gui.c.OnUIThread(func() error {
|
|
|
|
onConfirm := func() error {
|
|
|
|
gui.c.GetAppState().StartupPopupVersion = StartupPopupVersion
|
|
|
|
err := gui.c.SaveAppState()
|
2020-03-29 01:31:34 +02:00
|
|
|
gui.waitForIntro.Done()
|
2023-07-10 05:05:49 +02:00
|
|
|
return err
|
2020-03-29 01:31:34 +02:00
|
|
|
}
|
2019-11-10 07:20:35 +02:00
|
|
|
|
2023-07-10 05:05:49 +02:00
|
|
|
return gui.c.Confirm(types.ConfirmOpts{
|
|
|
|
Title: "",
|
|
|
|
Prompt: gui.c.Tr.IntroPopupMessage,
|
|
|
|
HandleConfirm: onConfirm,
|
|
|
|
HandleClose: onConfirm,
|
|
|
|
})
|
2020-08-15 08:36:39 +02:00
|
|
|
})
|
2019-11-10 07:20:35 +02:00
|
|
|
}
|
|
|
|
|
2020-03-29 01:31:34 +02:00
|
|
|
// setColorScheme sets the color scheme for the app based on the user config
|
|
|
|
func (gui *Gui) setColorScheme() error {
|
2021-12-29 02:50:20 +02:00
|
|
|
userConfig := gui.UserConfig
|
2020-10-03 06:54:55 +02:00
|
|
|
theme.UpdateTheme(userConfig.Gui.Theme)
|
2020-03-29 01:31:34 +02:00
|
|
|
|
|
|
|
gui.g.FgColor = theme.InactiveBorderColor
|
|
|
|
gui.g.SelFgColor = theme.ActiveBorderColor
|
2020-12-24 05:45:59 +02:00
|
|
|
gui.g.FrameColor = theme.InactiveBorderColor
|
|
|
|
gui.g.SelFrameColor = theme.ActiveBorderColor
|
2020-03-29 01:31:34 +02:00
|
|
|
|
|
|
|
return nil
|
2020-03-29 01:11:15 +02:00
|
|
|
}
|
2022-01-15 03:04:00 +02:00
|
|
|
|
2022-08-06 10:50:52 +02:00
|
|
|
func (gui *Gui) onUIThread(f func() error) {
|
2022-01-15 03:04:00 +02:00
|
|
|
gui.g.Update(func(*gocui.Gui) error {
|
|
|
|
return f()
|
|
|
|
})
|
|
|
|
}
|
2022-12-30 14:24:24 +02:00
|
|
|
|
2023-07-09 13:09:52 +02:00
|
|
|
func (gui *Gui) onWorker(f func(gocui.Task)) {
|
2023-07-03 06:16:43 +02:00
|
|
|
gui.g.OnWorker(f)
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:24:24 +02:00
|
|
|
func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map[string]boxlayout.Dimensions {
|
2023-03-23 09:55:41 +02:00
|
|
|
return gui.helpers.WindowArrangement.GetWindowDimensions(informationStr, appStatus)
|
2022-12-30 14:24:24 +02:00
|
|
|
}
|