mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-25 12:24:47 +02:00
good progress
This commit is contained in:
parent
a32947e7a7
commit
2f5d5034db
@ -76,9 +76,8 @@ func (gui *Gui) refreshBranches() {
|
|||||||
}
|
}
|
||||||
gui.State.Branches = builder.Build()
|
gui.State.Branches = builder.Build()
|
||||||
|
|
||||||
// TODO: if we're in the remotes view and we've just deleted a remote we need to refresh accordingly
|
if err := gui.rerenderIfVisible(gui.Contexts.Branches.Context); err != nil {
|
||||||
if gui.getBranchesView().Context == "local-branches" {
|
gui.Log.Error(err)
|
||||||
_ = gui.renderLocalBranchesWithSelection()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.refreshStatus()
|
gui.refreshStatus()
|
||||||
@ -90,11 +89,11 @@ func (gui *Gui) renderLocalBranchesWithSelection() error {
|
|||||||
gui.refreshSelectedLine(&gui.State.Panels.Branches.SelectedLine, len(gui.State.Branches))
|
gui.refreshSelectedLine(&gui.State.Panels.Branches.SelectedLine, len(gui.State.Branches))
|
||||||
displayStrings := presentation.GetBranchListDisplayStrings(gui.State.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
|
displayStrings := presentation.GetBranchListDisplayStrings(gui.State.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
|
||||||
gui.renderDisplayStrings(branchesView, displayStrings)
|
gui.renderDisplayStrings(branchesView, displayStrings)
|
||||||
if gui.g.CurrentView() == branchesView {
|
// if gui.g.CurrentView() == branchesView {
|
||||||
if err := gui.handleBranchSelect(); err != nil {
|
// if err := gui.handleBranchSelect(); err != nil {
|
||||||
return gui.surfaceError(err)
|
// return gui.surfaceError(err)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -102,13 +102,21 @@ func (gui *Gui) refreshCommitFilesView() error {
|
|||||||
}
|
}
|
||||||
gui.State.CommitFiles = files
|
gui.State.CommitFiles = files
|
||||||
|
|
||||||
|
if err := gui.renderCommitFiles(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.handleCommitFileSelect()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) renderCommitFiles() error {
|
||||||
gui.refreshSelectedLine(&gui.State.Panels.CommitFiles.SelectedLine, len(gui.State.CommitFiles))
|
gui.refreshSelectedLine(&gui.State.Panels.CommitFiles.SelectedLine, len(gui.State.CommitFiles))
|
||||||
|
|
||||||
commitsFileView := gui.getCommitFilesView()
|
commitsFileView := gui.getCommitFilesView()
|
||||||
displayStrings := presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Diff.Ref)
|
displayStrings := presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Diff.Ref)
|
||||||
gui.renderDisplayStrings(commitsFileView, displayStrings)
|
gui.renderDisplayStrings(commitsFileView, displayStrings)
|
||||||
|
|
||||||
return gui.handleCommitFileSelect()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleOpenOldCommitFile(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleOpenOldCommitFile(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
@ -168,18 +168,42 @@ func (gui *Gui) deactivateContext(c Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) rerenderIfVisible(c Context) error {
|
||||||
|
v, err := gui.g.View(c.GetViewName())
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.Context == c.GetKey() {
|
||||||
|
if err := c.HandleRender(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) activateContext(c Context) error {
|
func (gui *Gui) activateContext(c Context) error {
|
||||||
gui.Log.Warn(spew.Sdump(gui.renderContextStack()))
|
gui.Log.Warn(spew.Sdump(gui.renderContextStack()))
|
||||||
|
|
||||||
viewName := c.GetViewName()
|
viewName := c.GetViewName()
|
||||||
_, err := gui.g.View(viewName)
|
v, err := gui.g.View(viewName)
|
||||||
// if view no longer exists, pop again
|
// if view no longer exists, pop again
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gui.returnFromContext()
|
return gui.returnFromContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the new context's view was previously displaying another context, render the new context
|
||||||
|
if v.Context != c.GetKey() {
|
||||||
|
if err := c.HandleRender(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if viewName == "main" {
|
if viewName == "main" {
|
||||||
gui.changeMainViewsContext(c.GetKey())
|
gui.changeMainViewsContext(c.GetKey())
|
||||||
|
} else {
|
||||||
|
gui.changeMainViewsContext("normal")
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.setViewTabForContext(c)
|
gui.setViewTabForContext(c)
|
||||||
@ -421,11 +445,6 @@ func (gui *Gui) onViewFocusLost(v *gocui.View, newView *gocui.View) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.Name() == "main" {
|
|
||||||
// if we have lost focus to a first-class panel, we need to do some cleanup
|
|
||||||
gui.changeMainViewsContext("normal")
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.Log.Info(v.Name() + " focus lost")
|
gui.Log.Info(v.Name() + " focus lost")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -458,9 +477,9 @@ func (gui *Gui) changeMainViewsContext(context string) {
|
|||||||
|
|
||||||
func (gui *Gui) viewTabContextMap() map[string][]tabContext {
|
func (gui *Gui) viewTabContextMap() map[string][]tabContext {
|
||||||
return map[string][]tabContext{
|
return map[string][]tabContext{
|
||||||
"branches": []tabContext{
|
"branches": {
|
||||||
{
|
{
|
||||||
tab: "Branches",
|
tab: "Local Branches",
|
||||||
contexts: []Context{gui.Contexts.Branches.Context},
|
contexts: []Context{gui.Contexts.Branches.Context},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -475,7 +494,7 @@ func (gui *Gui) viewTabContextMap() map[string][]tabContext {
|
|||||||
contexts: []Context{gui.Contexts.Tags.Context},
|
contexts: []Context{gui.Contexts.Tags.Context},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"commits": []tabContext{
|
"commits": {
|
||||||
{
|
{
|
||||||
tab: "Commits",
|
tab: "Commits",
|
||||||
contexts: []Context{gui.Contexts.BranchCommits.Context},
|
contexts: []Context{gui.Contexts.BranchCommits.Context},
|
||||||
@ -490,6 +509,17 @@ func (gui *Gui) viewTabContextMap() map[string][]tabContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) viewTabNames(viewName string) []string {
|
||||||
|
tabContexts := gui.ViewTabContextMap[viewName]
|
||||||
|
|
||||||
|
result := make([]string, len(tabContexts))
|
||||||
|
for i, tabContext := range tabContexts {
|
||||||
|
result[i] = tabContext.tab
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) setViewTabForContext(c Context) {
|
func (gui *Gui) setViewTabForContext(c Context) {
|
||||||
gui.Log.Warnf("in set view tab: %s", c.GetKey())
|
gui.Log.Warnf("in set view tab: %s", c.GetKey())
|
||||||
|
|
||||||
@ -522,3 +552,8 @@ type tabContext struct {
|
|||||||
tab string
|
tab string
|
||||||
contexts []Context
|
contexts []Context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleContextRefresh(c Context) {
|
||||||
|
// if context is not the current context of it's view, return
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -102,8 +102,9 @@ func (gui *Gui) refreshFiles() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gui.g.Update(func(g *gocui.Gui) error {
|
gui.g.Update(func(g *gocui.Gui) error {
|
||||||
displayStrings := presentation.GetFileListDisplayStrings(gui.State.Files, gui.State.Diff.Ref)
|
if err := gui.renderFiles(); err != nil {
|
||||||
gui.renderDisplayStrings(filesView, displayStrings)
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if g.CurrentView() == filesView || (g.CurrentView() == gui.getMainView() && g.CurrentView().Context == "merging") {
|
if g.CurrentView() == filesView || (g.CurrentView() == gui.getMainView() && g.CurrentView().Context == "merging") {
|
||||||
newSelectedFile := gui.getSelectedFile()
|
newSelectedFile := gui.getSelectedFile()
|
||||||
@ -116,6 +117,18 @@ func (gui *Gui) refreshFiles() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) renderFiles() error {
|
||||||
|
filesView := gui.getFilesView()
|
||||||
|
if filesView == nil {
|
||||||
|
// if the filesView hasn't been instantiated yet we just return
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
displayStrings := presentation.GetFileListDisplayStrings(gui.State.Files, gui.State.Diff.Ref)
|
||||||
|
gui.renderDisplayStrings(filesView, displayStrings)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// specific functions
|
// specific functions
|
||||||
|
|
||||||
func (gui *Gui) stagedFiles() []*commands.File {
|
func (gui *Gui) stagedFiles() []*commands.File {
|
||||||
|
@ -147,7 +147,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
branchesView.Title = gui.Tr.SLocalize("BranchesTitle")
|
branchesView.Title = gui.Tr.SLocalize("BranchesTitle")
|
||||||
branchesView.Tabs = []string{"Local Branches", "Remotes", "Tags"}
|
branchesView.Tabs = gui.viewTabNames("branches")
|
||||||
branchesView.FgColor = textColor
|
branchesView.FgColor = textColor
|
||||||
branchesView.ContainsList = true
|
branchesView.ContainsList = true
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
|
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
|
||||||
commitsView.Tabs = []string{"Commits", "Reflog"}
|
commitsView.Tabs = gui.viewTabNames("commits")
|
||||||
commitsView.FgColor = textColor
|
commitsView.FgColor = textColor
|
||||||
commitsView.ContainsList = true
|
commitsView.ContainsList = true
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,8 @@ func (gui *Gui) menuListContext() *ListContext {
|
|||||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Menu.SelectedLine },
|
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Menu.SelectedLine },
|
||||||
OnFocus: gui.handleMenuSelect,
|
OnFocus: gui.handleMenuSelect,
|
||||||
OnItemSelect: gui.handleMenuSelect,
|
OnItemSelect: gui.handleMenuSelect,
|
||||||
|
// rendering the menu happens on creation
|
||||||
|
OnRender: func() error { return nil },
|
||||||
// need to add a layer of indirection here because the callback changes during runtime
|
// need to add a layer of indirection here because the callback changes during runtime
|
||||||
OnClickSelectedItem: func() error { return gui.State.Panels.Menu.OnPress(gui.g, nil) },
|
OnClickSelectedItem: func() error { return gui.State.Panels.Menu.OnPress(gui.g, nil) },
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
@ -180,6 +182,7 @@ func (gui *Gui) filesListContext() *ListContext {
|
|||||||
OnFocus: gui.focusAndSelectFile,
|
OnFocus: gui.focusAndSelectFile,
|
||||||
OnItemSelect: gui.focusAndSelectFile,
|
OnItemSelect: gui.focusAndSelectFile,
|
||||||
OnClickSelectedItem: gui.handleFilePress,
|
OnClickSelectedItem: gui.handleFilePress,
|
||||||
|
OnRender: gui.renderFiles,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
RendersToMainView: false,
|
RendersToMainView: false,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
@ -194,6 +197,7 @@ func (gui *Gui) branchesListContext() *ListContext {
|
|||||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Branches.SelectedLine },
|
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Branches.SelectedLine },
|
||||||
OnFocus: gui.handleBranchSelect,
|
OnFocus: gui.handleBranchSelect,
|
||||||
OnItemSelect: gui.handleBranchSelect,
|
OnItemSelect: gui.handleBranchSelect,
|
||||||
|
OnRender: gui.renderLocalBranchesWithSelection,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
@ -209,6 +213,7 @@ func (gui *Gui) remotesListContext() *ListContext {
|
|||||||
OnFocus: gui.renderRemotesWithSelection,
|
OnFocus: gui.renderRemotesWithSelection,
|
||||||
OnItemSelect: gui.handleRemoteSelect,
|
OnItemSelect: gui.handleRemoteSelect,
|
||||||
OnClickSelectedItem: gui.handleRemoteEnter,
|
OnClickSelectedItem: gui.handleRemoteEnter,
|
||||||
|
OnRender: gui.renderRemotesWithSelection,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
@ -223,6 +228,7 @@ func (gui *Gui) remoteBranchesListContext() *ListContext {
|
|||||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.RemoteBranches.SelectedLine },
|
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.RemoteBranches.SelectedLine },
|
||||||
OnFocus: gui.handleRemoteBranchSelect,
|
OnFocus: gui.handleRemoteBranchSelect,
|
||||||
OnItemSelect: gui.handleRemoteBranchSelect,
|
OnItemSelect: gui.handleRemoteBranchSelect,
|
||||||
|
OnRender: gui.renderRemoteBranchesWithSelection,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
@ -237,6 +243,7 @@ func (gui *Gui) tagsListContext() *ListContext {
|
|||||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Tags.SelectedLine },
|
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Tags.SelectedLine },
|
||||||
OnFocus: gui.handleTagSelect,
|
OnFocus: gui.handleTagSelect,
|
||||||
OnItemSelect: gui.handleTagSelect,
|
OnItemSelect: gui.handleTagSelect,
|
||||||
|
OnRender: gui.renderTagsWithSelection,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
@ -252,6 +259,7 @@ func (gui *Gui) branchCommitsListContext() *ListContext {
|
|||||||
OnFocus: gui.handleCommitSelect,
|
OnFocus: gui.handleCommitSelect,
|
||||||
OnItemSelect: gui.handleCommitSelect,
|
OnItemSelect: gui.handleCommitSelect,
|
||||||
OnClickSelectedItem: gui.handleSwitchToCommitFilesPanel,
|
OnClickSelectedItem: gui.handleSwitchToCommitFilesPanel,
|
||||||
|
OnRender: gui.renderBranchCommitsWithSelection,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
@ -266,6 +274,7 @@ func (gui *Gui) reflogCommitsListContext() *ListContext {
|
|||||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.ReflogCommits.SelectedLine },
|
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.ReflogCommits.SelectedLine },
|
||||||
OnFocus: gui.handleReflogCommitSelect,
|
OnFocus: gui.handleReflogCommitSelect,
|
||||||
OnItemSelect: gui.handleReflogCommitSelect,
|
OnItemSelect: gui.handleReflogCommitSelect,
|
||||||
|
OnRender: gui.renderReflogCommitsWithSelection,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
@ -280,6 +289,7 @@ func (gui *Gui) stashListContext() *ListContext {
|
|||||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Stash.SelectedLine },
|
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Stash.SelectedLine },
|
||||||
OnFocus: gui.handleStashEntrySelect,
|
OnFocus: gui.handleStashEntrySelect,
|
||||||
OnItemSelect: gui.handleStashEntrySelect,
|
OnItemSelect: gui.handleStashEntrySelect,
|
||||||
|
OnRender: gui.renderStash,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
@ -294,6 +304,7 @@ func (gui *Gui) commitFilesListContext() *ListContext {
|
|||||||
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.CommitFiles.SelectedLine },
|
GetSelectedLineIdxPtr: func() *int { return &gui.State.Panels.CommitFiles.SelectedLine },
|
||||||
OnFocus: gui.handleCommitFileSelect,
|
OnFocus: gui.handleCommitFileSelect,
|
||||||
OnItemSelect: gui.handleCommitFileSelect,
|
OnItemSelect: gui.handleCommitFileSelect,
|
||||||
|
OnRender: gui.renderCommitFiles,
|
||||||
Gui: gui,
|
Gui: gui,
|
||||||
RendersToMainView: true,
|
RendersToMainView: true,
|
||||||
Kind: SIDE_CONTEXT,
|
Kind: SIDE_CONTEXT,
|
||||||
|
@ -45,9 +45,13 @@ func (gui *Gui) handleStashEntrySelect() error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) refreshStashEntries(g *gocui.Gui) error {
|
func (gui *Gui) refreshStashEntries() error {
|
||||||
gui.State.StashEntries = gui.GitCommand.GetStashEntries(gui.State.FilterPath)
|
gui.State.StashEntries = gui.GitCommand.GetStashEntries(gui.State.FilterPath)
|
||||||
|
|
||||||
|
return gui.renderStash()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) renderStash() error {
|
||||||
gui.refreshSelectedLine(&gui.State.Panels.Stash.SelectedLine, len(gui.State.StashEntries))
|
gui.refreshSelectedLine(&gui.State.Panels.Stash.SelectedLine, len(gui.State.StashEntries))
|
||||||
|
|
||||||
stashView := gui.getStashView()
|
stashView := gui.getStashView()
|
||||||
|
@ -86,9 +86,9 @@ func (gui *Gui) refreshSidePanels(options refreshOptions) error {
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
func() {
|
func() {
|
||||||
if options.mode == ASYNC {
|
if options.mode == ASYNC {
|
||||||
go gui.refreshStashEntries(gui.g)
|
go gui.refreshStashEntries()
|
||||||
} else {
|
} else {
|
||||||
gui.refreshStashEntries(gui.g)
|
gui.refreshStashEntries()
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user