2022-12-26 11:12:56 +11:00
|
|
|
package components
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-02-24 21:42:27 +11:00
|
|
|
"strings"
|
2022-12-26 11:12:56 +11:00
|
|
|
|
2023-02-24 21:42:27 +11:00
|
|
|
"github.com/go-errors/errors"
|
2022-12-26 11:12:56 +11:00
|
|
|
"github.com/jesseduffield/gocui"
|
2023-02-24 21:42:27 +11:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
2022-12-26 11:12:56 +11:00
|
|
|
)
|
|
|
|
|
2022-12-27 15:22:31 +11:00
|
|
|
type Views struct {
|
2022-12-27 21:35:36 +11:00
|
|
|
t *TestDriver
|
2022-12-27 15:56:02 +11:00
|
|
|
}
|
|
|
|
|
2022-12-27 16:27:36 +11:00
|
|
|
// not exporting this because I want the test to always be explicit about what
|
|
|
|
// view it's dealing with.
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) current() *ViewDriver {
|
|
|
|
return &ViewDriver{
|
2022-12-27 15:56:02 +11:00
|
|
|
context: "current view",
|
2022-12-27 21:35:36 +11:00
|
|
|
getView: func() *gocui.View { return self.t.gui.CurrentContext().GetView() },
|
|
|
|
t: self.t,
|
2022-12-27 15:56:02 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Main() *ViewDriver {
|
|
|
|
return &ViewDriver{
|
2022-12-27 15:56:02 +11:00
|
|
|
context: "main view",
|
2022-12-27 21:35:36 +11:00
|
|
|
getView: func() *gocui.View { return self.t.gui.MainView() },
|
|
|
|
t: self.t,
|
2022-12-27 15:56:02 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Secondary() *ViewDriver {
|
|
|
|
return &ViewDriver{
|
2022-12-27 15:56:02 +11:00
|
|
|
context: "secondary view",
|
2022-12-27 21:35:36 +11:00
|
|
|
getView: func() *gocui.View { return self.t.gui.SecondaryView() },
|
|
|
|
t: self.t,
|
2022-12-27 15:56:02 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-24 21:42:27 +11:00
|
|
|
func (self *Views) regularView(viewName string) *ViewDriver {
|
|
|
|
return self.newStaticViewDriver(viewName, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Views) patchExplorerViewByName(viewName string) *ViewDriver {
|
|
|
|
return self.newStaticViewDriver(viewName, func() ([]string, error) {
|
|
|
|
ctx := self.t.gui.ContextForView(viewName).(*context.PatchExplorerContext)
|
|
|
|
state := ctx.GetState()
|
|
|
|
if state == nil {
|
|
|
|
return nil, errors.New("Expected patch explorer to be activated")
|
|
|
|
}
|
|
|
|
selectedContent := state.PlainRenderSelected()
|
|
|
|
// the above method returns a string with a trailing newline so we need to remove that before splitting
|
|
|
|
selectedLines := strings.Split(strings.TrimSuffix(selectedContent, "\n"), "\n")
|
|
|
|
return selectedLines, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 'static' because it'll always refer to the same view, as opposed to the 'main' view which could actually be
|
|
|
|
// one of several views, or the 'current' view which depends on focus.
|
|
|
|
func (self *Views) newStaticViewDriver(viewName string, getSelectedLinesFn func() ([]string, error)) *ViewDriver {
|
2022-12-28 11:27:48 +11:00
|
|
|
return &ViewDriver{
|
2023-02-24 21:42:27 +11:00
|
|
|
context: fmt.Sprintf("%s view", viewName),
|
|
|
|
getView: func() *gocui.View { return self.t.gui.View(viewName) },
|
|
|
|
getSelectedLinesFn: getSelectedLinesFn,
|
|
|
|
t: self.t,
|
2022-12-27 15:56:02 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Commits() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("commits")
|
2022-12-26 11:12:56 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Files() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("files")
|
2022-12-26 11:12:56 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Status() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("status")
|
2022-12-26 11:12:56 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Submodules() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("submodules")
|
2022-12-26 11:12:56 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Information() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("information")
|
2022-12-26 17:37:41 +11:00
|
|
|
}
|
|
|
|
|
2023-01-26 13:25:56 +11:00
|
|
|
func (self *Views) AppStatus() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("appStatus")
|
2023-01-26 13:25:56 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Branches() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("localBranches")
|
2022-12-27 16:27:36 +11:00
|
|
|
}
|
2022-12-26 11:12:56 +11:00
|
|
|
|
2023-02-19 13:38:15 +11:00
|
|
|
func (self *Views) Remotes() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("remotes")
|
2023-02-19 13:38:15 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) RemoteBranches() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("remoteBranches")
|
2022-12-26 11:12:56 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Tags() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("tags")
|
2022-12-27 16:27:36 +11:00
|
|
|
}
|
2022-12-26 11:12:56 +11:00
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) ReflogCommits() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("reflogCommits")
|
2022-12-26 11:12:56 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) SubCommits() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("subCommits")
|
2022-12-27 16:27:36 +11:00
|
|
|
}
|
2022-12-26 11:12:56 +11:00
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) CommitFiles() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("commitFiles")
|
2022-12-26 11:12:56 +11:00
|
|
|
}
|
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Stash() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("stash")
|
2022-12-27 16:27:36 +11:00
|
|
|
}
|
2022-12-26 11:12:56 +11:00
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Staging() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.patchExplorerViewByName("staging")
|
2022-12-26 11:12:56 +11:00
|
|
|
}
|
2022-12-27 15:22:31 +11:00
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) StagingSecondary() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.patchExplorerViewByName("stagingSecondary")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Views) PatchBuilding() *ViewDriver {
|
|
|
|
return self.patchExplorerViewByName("patchBuilding")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Views) PatchBuildingSecondary() *ViewDriver {
|
|
|
|
// this is not a patch explorer view because you can't actually focus it: it
|
|
|
|
// just renders content
|
|
|
|
return self.regularView("patchBuildingSecondary")
|
2022-12-27 16:27:36 +11:00
|
|
|
}
|
2022-12-27 15:22:31 +11:00
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Menu() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("menu")
|
2022-12-27 16:27:36 +11:00
|
|
|
}
|
2022-12-27 15:22:31 +11:00
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Confirmation() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("confirmation")
|
2022-12-27 16:27:36 +11:00
|
|
|
}
|
2022-12-27 15:22:31 +11:00
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) CommitMessage() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("commitMessage")
|
2022-12-27 16:27:36 +11:00
|
|
|
}
|
2022-12-27 15:22:31 +11:00
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) Suggestions() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("suggestions")
|
2022-12-27 16:27:36 +11:00
|
|
|
}
|
2022-12-27 15:56:02 +11:00
|
|
|
|
2022-12-28 11:27:48 +11:00
|
|
|
func (self *Views) MergeConflicts() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("mergeConflicts")
|
2022-12-27 16:27:36 +11:00
|
|
|
}
|
2023-02-22 21:57:32 +11:00
|
|
|
|
|
|
|
func (self *Views) Search() *ViewDriver {
|
2023-02-24 21:42:27 +11:00
|
|
|
return self.regularView("search")
|
2023-02-22 21:57:32 +11:00
|
|
|
}
|