1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-07 22:02:56 +03:00

more standardisation

This commit is contained in:
Jesse Duffield
2020-08-19 21:51:50 +10:00
parent dbf6bb5f27
commit 419cb9feb8
11 changed files with 82 additions and 141 deletions

View File

@@ -6,7 +6,6 @@ import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
) )
// list panel functions // list panel functions
@@ -82,16 +81,6 @@ func (gui *Gui) refreshBranches() {
gui.refreshStatus() gui.refreshStatus()
} }
func (gui *Gui) renderLocalBranchesContext() error {
branchesView := gui.getBranchesView()
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)
gui.renderDisplayStrings(branchesView, displayStrings)
return nil
}
// specific functions // specific functions
func (gui *Gui) handleBranchPress(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleBranchPress(g *gocui.Gui, v *gocui.View) error {

View File

@@ -4,7 +4,6 @@ import (
"github.com/go-errors/errors" "github.com/go-errors/errors"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
) )
func (gui *Gui) getSelectedCommitFile() *commands.CommitFile { func (gui *Gui) getSelectedCommitFile() *commands.CommitFile {
@@ -105,16 +104,6 @@ func (gui *Gui) refreshCommitFilesView() error {
return gui.postRefreshUpdate(gui.Contexts.BranchCommits.Files.Context) return gui.postRefreshUpdate(gui.Contexts.BranchCommits.Files.Context)
} }
func (gui *Gui) renderCommitFiles() error {
gui.refreshSelectedLine(&gui.State.Panels.CommitFiles.SelectedLine, len(gui.State.CommitFiles))
commitsFileView := gui.getCommitFilesView()
displayStrings := presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Diff.Ref)
gui.renderDisplayStrings(commitsFileView, displayStrings)
return nil
}
func (gui *Gui) handleOpenOldCommitFile(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleOpenOldCommitFile(g *gocui.Gui, v *gocui.View) error {
file := gui.getSelectedCommitFile() file := gui.getSelectedCommitFile()
if file == nil { if file == nil {

View File

@@ -6,7 +6,6 @@ import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
) )
// list panel functions // list panel functions
@@ -626,16 +625,6 @@ func (gui *Gui) handleCheckoutCommit(g *gocui.Gui, v *gocui.View) error {
}) })
} }
func (gui *Gui) renderBranchCommitsContext() error {
commitsView := gui.getCommitsView()
gui.refreshSelectedLine(&gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits))
displayStrings := presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref)
gui.renderDisplayStrings(commitsView, displayStrings)
return nil
}
func (gui *Gui) handleCreateCommitResetMenu(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCreateCommitResetMenu(g *gocui.Gui, v *gocui.View) error {
commit := gui.getSelectedCommit() commit := gui.getSelectedCommit()
if commit == nil { if commit == nil {

View File

@@ -13,7 +13,6 @@ import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
@@ -102,7 +101,7 @@ func (gui *Gui) refreshFiles() error {
} }
gui.g.Update(func(g *gocui.Gui) error { gui.g.Update(func(g *gocui.Gui) error {
if err := gui.renderFiles(); err != nil { if err := gui.Contexts.Files.Context.HandleRender(); err != nil {
return err return err
} }
@@ -117,18 +116,6 @@ 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 {

View File

@@ -101,6 +101,10 @@ type Gui struct {
ViewTabContextMap map[string][]tabContext ViewTabContextMap map[string][]tabContext
} }
type hasSelectedLine struct {
SelectedLine int
}
// for now the staging panel state, unlike the other panel states, is going to be // for now the staging panel state, unlike the other panel states, is going to be
// non-mutative, so that we don't accidentally end up // non-mutative, so that we don't accidentally end up
// with mismatches of data. We might change this in the future // with mismatches of data. We might change this in the future
@@ -126,46 +130,47 @@ type mergingPanelState struct {
} }
type filePanelState struct { type filePanelState struct {
SelectedLine int hasSelectedLine
} }
// TODO: consider splitting this out into the window and the branches view // TODO: consider splitting this out into the window and the branches view
type branchPanelState struct { type branchPanelState struct {
SelectedLine int hasSelectedLine
} }
type remotePanelState struct { type remotePanelState struct {
SelectedLine int hasSelectedLine
} }
type remoteBranchesState struct { type remoteBranchesState struct {
SelectedLine int hasSelectedLine
} }
type tagsPanelState struct { type tagsPanelState struct {
SelectedLine int hasSelectedLine
} }
type commitPanelState struct { type commitPanelState struct {
SelectedLine int hasSelectedLine
LimitCommits bool LimitCommits bool
} }
type reflogCommitPanelState struct { type reflogCommitPanelState struct {
SelectedLine int hasSelectedLine
} }
type stashPanelState struct { type stashPanelState struct {
SelectedLine int hasSelectedLine
} }
type menuPanelState struct { type menuPanelState struct {
SelectedLine int hasSelectedLine
OnPress func(g *gocui.Gui, v *gocui.View) error OnPress func(g *gocui.Gui, v *gocui.View) error
} }
type commitFilesPanelState struct { type commitFilesPanelState struct {
SelectedLine int hasSelectedLine
} }
type panelStates struct { type panelStates struct {
@@ -266,16 +271,16 @@ func (gui *Gui) resetState() {
CherryPickedCommits: make([]*commands.Commit, 0), CherryPickedCommits: make([]*commands.Commit, 0),
StashEntries: make([]*commands.StashEntry, 0), StashEntries: make([]*commands.StashEntry, 0),
Panels: &panelStates{ Panels: &panelStates{
Files: &filePanelState{SelectedLine: -1}, Files: &filePanelState{hasSelectedLine{SelectedLine: -1}},
Branches: &branchPanelState{SelectedLine: 0}, Branches: &branchPanelState{hasSelectedLine{SelectedLine: 0}},
Remotes: &remotePanelState{SelectedLine: 0}, Remotes: &remotePanelState{hasSelectedLine{SelectedLine: 0}},
RemoteBranches: &remoteBranchesState{SelectedLine: -1}, RemoteBranches: &remoteBranchesState{hasSelectedLine{SelectedLine: -1}},
Tags: &tagsPanelState{SelectedLine: -1}, Tags: &tagsPanelState{hasSelectedLine{SelectedLine: -1}},
Commits: &commitPanelState{SelectedLine: -1, LimitCommits: true}, Commits: &commitPanelState{hasSelectedLine: hasSelectedLine{SelectedLine: -1}, LimitCommits: true},
ReflogCommits: &reflogCommitPanelState{SelectedLine: 0}, // TODO: might need to make -1 ReflogCommits: &reflogCommitPanelState{hasSelectedLine{SelectedLine: 0}}, // TODO: might need to make -1
CommitFiles: &commitFilesPanelState{SelectedLine: -1}, CommitFiles: &commitFilesPanelState{hasSelectedLine{SelectedLine: -1}},
Stash: &stashPanelState{SelectedLine: -1}, Stash: &stashPanelState{hasSelectedLine{SelectedLine: -1}},
Menu: &menuPanelState{SelectedLine: 0}, Menu: &menuPanelState{hasSelectedLine: hasSelectedLine{SelectedLine: 0}, OnPress: nil},
Merging: &mergingPanelState{ Merging: &mergingPanelState{
ConflictIndex: 0, ConflictIndex: 0,
ConflictTop: true, ConflictTop: true,

View File

@@ -1,24 +1,41 @@
package gui package gui
import "github.com/jesseduffield/gocui" import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
)
type ListContext struct { type ListContext struct {
ViewName string ViewName string
ContextKey string ContextKey string
GetItemsLength func() int GetItemsLength func() int
GetSelectedLineIdxPtr func() *int GetSelectedLineIdxPtr func() *int
GetDisplayStrings func() [][]string
OnFocus func() error OnFocus func() error
OnFocusLost func() error OnFocusLost func() error
OnItemSelect func() error OnItemSelect func() error
OnClickSelectedItem func() error OnClickSelectedItem func() error
// OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view
OnRender func() error
Gui *Gui Gui *Gui
RendersToMainView bool RendersToMainView bool
Kind int Kind int
} }
// OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view
func (lc *ListContext) OnRender() error {
view, err := lc.Gui.g.View(lc.ViewName)
if err != nil {
return nil
}
if lc.GetDisplayStrings != nil {
lc.Gui.refreshSelectedLine(lc.GetSelectedLineIdxPtr(), lc.GetItemsLength())
lc.Gui.renderDisplayStrings(view, lc.GetDisplayStrings())
}
return nil
}
func (lc *ListContext) GetKey() string { func (lc *ListContext) GetKey() string {
return lc.ContextKey return lc.ContextKey
} }
@@ -163,13 +180,13 @@ 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,
RendersToMainView: false, RendersToMainView: false,
Kind: PERSISTENT_POPUP, Kind: PERSISTENT_POPUP,
// no GetDisplayStrings field because we do a custom render on menu creation
} }
} }
@@ -182,10 +199,12 @@ 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,
GetDisplayStrings: func() [][]string {
return presentation.GetFileListDisplayStrings(gui.State.Files, gui.State.Diff.Ref)
},
} }
} }
@@ -197,10 +216,12 @@ 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.renderLocalBranchesContext,
Gui: gui, Gui: gui,
RendersToMainView: true, RendersToMainView: true,
Kind: SIDE_CONTEXT, Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetBranchListDisplayStrings(gui.State.Branches, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
},
} }
} }
@@ -213,10 +234,12 @@ func (gui *Gui) remotesListContext() *ListContext {
OnFocus: gui.handleRemoteSelect, OnFocus: gui.handleRemoteSelect,
OnItemSelect: gui.handleRemoteSelect, OnItemSelect: gui.handleRemoteSelect,
OnClickSelectedItem: gui.handleRemoteEnter, OnClickSelectedItem: gui.handleRemoteEnter,
OnRender: gui.renderRemotesContext,
Gui: gui, Gui: gui,
RendersToMainView: true, RendersToMainView: true,
Kind: SIDE_CONTEXT, Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetRemoteListDisplayStrings(gui.State.Remotes, gui.State.Diff.Ref)
},
} }
} }
@@ -228,10 +251,12 @@ 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.renderRemoteBranchesContext,
Gui: gui, Gui: gui,
RendersToMainView: true, RendersToMainView: true,
Kind: SIDE_CONTEXT, Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetRemoteBranchListDisplayStrings(gui.State.RemoteBranches, gui.State.Diff.Ref)
},
} }
} }
@@ -243,10 +268,12 @@ 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.renderTagsContext,
Gui: gui, Gui: gui,
RendersToMainView: true, RendersToMainView: true,
Kind: SIDE_CONTEXT, Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetTagListDisplayStrings(gui.State.Tags, gui.State.Diff.Ref)
},
} }
} }
@@ -259,10 +286,12 @@ 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.renderBranchCommitsContext,
Gui: gui, Gui: gui,
RendersToMainView: true, RendersToMainView: true,
Kind: SIDE_CONTEXT, Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL, gui.cherryPickedCommitShaMap(), gui.State.Diff.Ref)
},
} }
} }
@@ -274,10 +303,12 @@ 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.renderReflogCommitsContext,
Gui: gui, Gui: gui,
RendersToMainView: true, RendersToMainView: true,
Kind: SIDE_CONTEXT, Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
return presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
},
} }
} }
@@ -289,10 +320,13 @@ 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,
GetDisplayStrings: func() [][]string {
// TODO :see if we still need to reset the origin here
return presentation.GetStashEntryListDisplayStrings(gui.State.StashEntries, gui.State.Diff.Ref)
},
} }
} }
@@ -304,10 +338,12 @@ 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,
GetDisplayStrings: func() [][]string {
return presentation.GetCommitFileListDisplayStrings(gui.State.CommitFiles, gui.State.Diff.Ref)
},
} }
} }

View File

@@ -3,7 +3,6 @@ package gui
import ( import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
) )
// list panel functions // list panel functions
@@ -88,16 +87,6 @@ func (gui *Gui) refreshReflogCommits() error {
return gui.postRefreshUpdate(gui.Contexts.ReflogCommits.Context) return gui.postRefreshUpdate(gui.Contexts.ReflogCommits.Context)
} }
func (gui *Gui) renderReflogCommitsContext() error {
commitsView := gui.getCommitsView()
gui.refreshSelectedLine(&gui.State.Panels.ReflogCommits.SelectedLine, len(gui.State.FilteredReflogCommits))
displayStrings := presentation.GetReflogCommitListDisplayStrings(gui.State.FilteredReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL, gui.State.Diff.Ref)
gui.renderDisplayStrings(commitsView, displayStrings)
return nil
}
func (gui *Gui) handleCheckoutReflogCommit(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCheckoutReflogCommit(g *gocui.Gui, v *gocui.View) error {
commit := gui.getSelectedReflogCommit() commit := gui.getSelectedReflogCommit()
if commit == nil { if commit == nil {

View File

@@ -5,7 +5,6 @@ import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
) )
// list panel functions // list panel functions
@@ -51,16 +50,6 @@ func (gui *Gui) handleRemoteBranchesEscape(g *gocui.Gui, v *gocui.View) error {
return gui.switchContext(gui.Contexts.Remotes.Context) return gui.switchContext(gui.Contexts.Remotes.Context)
} }
func (gui *Gui) renderRemoteBranchesContext() error {
branchesView := gui.getBranchesView()
gui.refreshSelectedLine(&gui.State.Panels.RemoteBranches.SelectedLine, len(gui.State.RemoteBranches))
displayStrings := presentation.GetRemoteBranchListDisplayStrings(gui.State.RemoteBranches, gui.State.Diff.Ref)
gui.renderDisplayStrings(branchesView, displayStrings)
return nil
}
func (gui *Gui) handleCheckoutRemoteBranch(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCheckoutRemoteBranch(g *gocui.Gui, v *gocui.View) error {
remoteBranch := gui.getSelectedRemoteBranch() remoteBranch := gui.getSelectedRemoteBranch()
if remoteBranch == nil { if remoteBranch == nil {

View File

@@ -7,7 +7,6 @@ import (
"github.com/fatih/color" "github.com/fatih/color"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
@@ -70,17 +69,6 @@ func (gui *Gui) refreshRemotes() error {
return gui.postRefreshUpdate(gui.contextForContextKey(gui.getBranchesView().Context)) return gui.postRefreshUpdate(gui.contextForContextKey(gui.getBranchesView().Context))
} }
func (gui *Gui) renderRemotesContext() error {
branchesView := gui.getBranchesView()
gui.refreshSelectedLine(&gui.State.Panels.Remotes.SelectedLine, len(gui.State.Remotes))
displayStrings := presentation.GetRemoteListDisplayStrings(gui.State.Remotes, gui.State.Diff.Ref)
gui.renderDisplayStrings(branchesView, displayStrings)
return nil
}
func (gui *Gui) handleRemoteEnter() error { func (gui *Gui) handleRemoteEnter() error {
// naive implementation: get the branches and render them to the list, change the context // naive implementation: get the branches and render them to the list, change the context
remote := gui.getSelectedRemote() remote := gui.getSelectedRemote()

View File

@@ -3,7 +3,6 @@ package gui
import ( import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
) )
// list panel functions // list panel functions
@@ -48,18 +47,7 @@ func (gui *Gui) handleStashEntrySelect() error {
func (gui *Gui) refreshStashEntries() 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() return gui.Contexts.Stash.Context.HandleRender()
}
func (gui *Gui) renderStash() error {
gui.refreshSelectedLine(&gui.State.Panels.Stash.SelectedLine, len(gui.State.StashEntries))
stashView := gui.getStashView()
displayStrings := presentation.GetStashEntryListDisplayStrings(gui.State.StashEntries, gui.State.Diff.Ref)
gui.renderDisplayStrings(stashView, displayStrings)
return gui.resetOrigin(stashView)
} }
// specific functions // specific functions

View File

@@ -3,7 +3,6 @@ package gui
import ( import (
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
) )
// list panel functions // list panel functions
@@ -56,16 +55,6 @@ func (gui *Gui) refreshTags() error {
return gui.postRefreshUpdate(gui.Contexts.Tags.Context) return gui.postRefreshUpdate(gui.Contexts.Tags.Context)
} }
func (gui *Gui) renderTagsContext() error {
branchesView := gui.getBranchesView()
gui.refreshSelectedLine(&gui.State.Panels.Tags.SelectedLine, len(gui.State.Tags))
displayStrings := presentation.GetTagListDisplayStrings(gui.State.Tags, gui.State.Diff.Ref)
gui.renderDisplayStrings(branchesView, displayStrings)
return nil
}
func (gui *Gui) handleCheckoutTag(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCheckoutTag(g *gocui.Gui, v *gocui.View) error {
tag := gui.getSelectedTag() tag := gui.getSelectedTag()
if tag == nil { if tag == nil {
@@ -136,7 +125,10 @@ func (gui *Gui) handleCreateTag(g *gocui.Gui, v *gocui.View) error {
for i, tag := range gui.State.Tags { for i, tag := range gui.State.Tags {
if tag.Name == tagName { if tag.Name == tagName {
gui.State.Panels.Tags.SelectedLine = i gui.State.Panels.Tags.SelectedLine = i
_ = gui.renderTagsContext() if err := gui.Contexts.Tags.Context.HandleRender(); err != nil {
gui.Log.Error(err)
}
return return
} }
} }