1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-09 13:47:11 +02:00

more removing of g

This commit is contained in:
Jesse Duffield 2020-08-15 17:23:16 +10:00
parent 15229bbdab
commit 9b7a6934b3
21 changed files with 114 additions and 117 deletions

View File

@ -277,10 +277,10 @@ func (gui *Gui) createNewBranchWithName(newBranchName string) error {
} }
func (gui *Gui) handleDeleteBranch(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleDeleteBranch(g *gocui.Gui, v *gocui.View) error {
return gui.deleteBranch(g, v, false) return gui.deleteBranch(false)
} }
func (gui *Gui) deleteBranch(g *gocui.Gui, v *gocui.View, force bool) error { func (gui *Gui) deleteBranch(force bool) error {
selectedBranch := gui.getSelectedBranch() selectedBranch := gui.getSelectedBranch()
if selectedBranch == nil { if selectedBranch == nil {
return nil return nil
@ -289,10 +289,10 @@ func (gui *Gui) deleteBranch(g *gocui.Gui, v *gocui.View, force bool) error {
if checkedOutBranch.Name == selectedBranch.Name { if checkedOutBranch.Name == selectedBranch.Name {
return gui.createErrorPanel(gui.Tr.SLocalize("CantDeleteCheckOutBranch")) return gui.createErrorPanel(gui.Tr.SLocalize("CantDeleteCheckOutBranch"))
} }
return gui.deleteNamedBranch(g, v, selectedBranch, force) return gui.deleteNamedBranch(selectedBranch, force)
} }
func (gui *Gui) deleteNamedBranch(g *gocui.Gui, v *gocui.View, selectedBranch *commands.Branch, force bool) error { func (gui *Gui) deleteNamedBranch(selectedBranch *commands.Branch, force bool) error {
title := gui.Tr.SLocalize("DeleteBranch") title := gui.Tr.SLocalize("DeleteBranch")
var messageID string var messageID string
if force { if force {
@ -308,7 +308,7 @@ func (gui *Gui) deleteNamedBranch(g *gocui.Gui, v *gocui.View, selectedBranch *c
) )
return gui.ask(askOpts{ return gui.ask(askOpts{
returnToView: v, returnToView: gui.getBranchesView(),
returnFocusOnClose: true, returnFocusOnClose: true,
title: title, title: title,
prompt: message, prompt: message,
@ -316,7 +316,7 @@ func (gui *Gui) deleteNamedBranch(g *gocui.Gui, v *gocui.View, selectedBranch *c
if err := gui.GitCommand.DeleteBranch(selectedBranch.Name, force); err != nil { if err := gui.GitCommand.DeleteBranch(selectedBranch.Name, force); err != nil {
errMessage := err.Error() errMessage := err.Error()
if !force && strings.Contains(errMessage, "is not fully merged") { if !force && strings.Contains(errMessage, "is not fully merged") {
return gui.deleteNamedBranch(g, v, selectedBranch, true) return gui.deleteNamedBranch(selectedBranch, true)
} }
return gui.createErrorPanel(errMessage) return gui.createErrorPanel(errMessage)
} }

View File

@ -512,7 +512,7 @@ func (gui *Gui) HandlePasteCommits(g *gocui.Gui, v *gocui.View) error {
}) })
} }
func (gui *Gui) handleSwitchToCommitFilesPanel(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleSwitchToCommitFilesPanel() error {
if err := gui.refreshCommitFilesView(); err != nil { if err := gui.refreshCommitFilesView(); err != nil {
return err return err
} }

View File

@ -76,7 +76,7 @@ func (gui *Gui) wrappedConfirmationFunction(function func() error, returnFocusOn
} }
} }
return gui.closeConfirmationPrompt(g, returnFocusOnClose) return gui.closeConfirmationPrompt(returnFocusOnClose)
} }
} }
@ -89,24 +89,24 @@ func (gui *Gui) wrappedPromptConfirmationFunction(function func(string) error, r
} }
} }
return gui.closeConfirmationPrompt(g, returnFocusOnClose) return gui.closeConfirmationPrompt(returnFocusOnClose)
} }
} }
func (gui *Gui) closeConfirmationPrompt(g *gocui.Gui, returnFocusOnClose bool) error { func (gui *Gui) closeConfirmationPrompt(returnFocusOnClose bool) error {
view, err := g.View("confirmation") view, err := gui.g.View("confirmation")
if err != nil { if err != nil {
return nil // if it's already been closed we can just return return nil // if it's already been closed we can just return
} }
view.Editable = false view.Editable = false
if returnFocusOnClose { if returnFocusOnClose {
if err := gui.returnFocus(g, view); err != nil { if err := gui.returnFocus(view); err != nil {
panic(err) panic(err)
} }
} }
g.DeleteKeybinding("confirmation", gocui.KeyEnter, gocui.ModNone) gui.g.DeleteKeybinding("confirmation", gocui.KeyEnter, gocui.ModNone)
g.DeleteKeybinding("confirmation", gocui.KeyEsc, gocui.ModNone) gui.g.DeleteKeybinding("confirmation", gocui.KeyEsc, gocui.ModNone)
return g.DeleteView("confirmation") return gui.g.DeleteView("confirmation")
} }
func (gui *Gui) getMessageHeight(wrap bool, message string, width int) int { func (gui *Gui) getMessageHeight(wrap bool, message string, width int) int {
@ -123,8 +123,8 @@ func (gui *Gui) getMessageHeight(wrap bool, message string, width int) int {
return lineCount return lineCount
} }
func (gui *Gui) getConfirmationPanelDimensions(g *gocui.Gui, wrap bool, prompt string) (int, int, int, int) { func (gui *Gui) getConfirmationPanelDimensions(wrap bool, prompt string) (int, int, int, int) {
width, height := g.Size() width, height := gui.g.Size()
// we want a minimum width up to a point, then we do it based on ratio. // we want a minimum width up to a point, then we do it based on ratio.
panelWidth := 4 * width / 7 panelWidth := 4 * width / 7
minWidth := 80 minWidth := 80
@ -146,7 +146,7 @@ func (gui *Gui) getConfirmationPanelDimensions(g *gocui.Gui, wrap bool, prompt s
} }
func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt string, hasLoader bool) (*gocui.View, error) { func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt string, hasLoader bool) (*gocui.View, error) {
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, true, prompt) x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(true, prompt)
confirmationView, err := gui.g.SetView("confirmation", x0, y0, x1, y1, 0) confirmationView, err := gui.g.SetView("confirmation", x0, y0, x1, y1, 0)
if err != nil { if err != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
@ -180,7 +180,7 @@ func (gui *Gui) createPopupPanel(opts createPopupPanelOpts) error {
gui.g.Update(func(g *gocui.Gui) error { gui.g.Update(func(g *gocui.Gui) error {
// delete the existing confirmation panel if it exists // delete the existing confirmation panel if it exists
if view, _ := g.View("confirmation"); view != nil { if view, _ := g.View("confirmation"); view != nil {
if err := gui.closeConfirmationPrompt(g, true); err != nil { if err := gui.closeConfirmationPrompt(true); err != nil {
gui.Log.Error(err) gui.Log.Error(err)
} }
} }

View File

@ -87,6 +87,6 @@ func (gui *Gui) handleCredentialsPopup(cmdErr error) {
// we are not logging this error because it may contain a password // we are not logging this error because it may contain a password
gui.createErrorPanel(errMessage) gui.createErrorPanel(errMessage)
} else { } else {
_ = gui.closeConfirmationPrompt(gui.g, true) _ = gui.closeConfirmationPrompt(true)
} }
} }

View File

@ -166,7 +166,7 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error
return nil return nil
} }
if file.HasInlineMergeConflicts { if file.HasInlineMergeConflicts {
return gui.handleSwitchToMerge(gui.g, gui.getFilesView()) return gui.handleSwitchToMerge()
} }
if file.HasMergeConflicts { if file.HasMergeConflicts {
return gui.createErrorPanel(gui.Tr.SLocalize("FileStagingRequirements")) return gui.createErrorPanel(gui.Tr.SLocalize("FileStagingRequirements"))
@ -178,7 +178,7 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error
return gui.refreshStagingPanel(forceSecondaryFocused, selectedLineIdx) return gui.refreshStagingPanel(forceSecondaryFocused, selectedLineIdx)
} }
func (gui *Gui) handleFilePress(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleFilePress() error {
file, err := gui.getSelectedFile() file, err := gui.getSelectedFile()
if err != nil { if err != nil {
if err == gui.Errors.ErrNoFiles { if err == gui.Errors.ErrNoFiles {
@ -188,7 +188,7 @@ func (gui *Gui) handleFilePress(g *gocui.Gui, v *gocui.View) error {
} }
if file.HasInlineMergeConflicts { if file.HasInlineMergeConflicts {
return gui.handleSwitchToMerge(g, v) return gui.handleSwitchToMerge()
} }
if file.HasUnstagedChanges { if file.HasUnstagedChanges {
@ -284,13 +284,13 @@ func (gui *Gui) handleWIPCommitPress(g *gocui.Gui, filesView *gocui.View) error
return err return err
} }
return gui.handleCommitPress(g, filesView) return gui.handleCommitPress()
} }
func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error { func (gui *Gui) handleCommitPress() error {
if len(gui.stagedFiles()) == 0 { if len(gui.stagedFiles()) == 0 {
return gui.promptToStageAllAndRetry(func() error { return gui.promptToStageAllAndRetry(func() error {
return gui.handleCommitPress(gui.g, filesView) return gui.handleCommitPress()
}) })
} }
@ -309,12 +309,12 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
} }
} }
g.Update(func(g *gocui.Gui) error { gui.g.Update(func(g *gocui.Gui) error {
if _, err := g.SetViewOnTop("commitMessage"); err != nil { if _, err := g.SetViewOnTop("commitMessage"); err != nil {
return err return err
} }
if err := gui.switchFocus(filesView, commitMessageView); err != nil { if err := gui.switchFocus(gui.getFilesView(), commitMessageView); err != nil {
return err return err
} }
@ -343,10 +343,10 @@ func (gui *Gui) promptToStageAllAndRetry(retry func() error) error {
}) })
} }
func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) error { func (gui *Gui) handleAmendCommitPress() error {
if len(gui.stagedFiles()) == 0 { if len(gui.stagedFiles()) == 0 {
return gui.promptToStageAllAndRetry(func() error { return gui.promptToStageAllAndRetry(func() error {
return gui.handleAmendCommitPress(gui.g, filesView) return gui.handleAmendCommitPress()
}) })
} }
@ -355,7 +355,7 @@ func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) erro
} }
return gui.ask(askOpts{ return gui.ask(askOpts{
returnToView: filesView, returnToView: gui.getFilesView(),
returnFocusOnClose: true, returnFocusOnClose: true,
title: strings.Title(gui.Tr.SLocalize("AmendLastCommit")), title: strings.Title(gui.Tr.SLocalize("AmendLastCommit")),
prompt: gui.Tr.SLocalize("SureToAmend"), prompt: gui.Tr.SLocalize("SureToAmend"),
@ -375,21 +375,21 @@ func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) erro
// handleCommitEditorPress - handle when the user wants to commit changes via // handleCommitEditorPress - handle when the user wants to commit changes via
// their editor rather than via the popup panel // their editor rather than via the popup panel
func (gui *Gui) handleCommitEditorPress(g *gocui.Gui, filesView *gocui.View) error { func (gui *Gui) handleCommitEditorPress() error {
if len(gui.stagedFiles()) == 0 { if len(gui.stagedFiles()) == 0 {
return gui.promptToStageAllAndRetry(func() error { return gui.promptToStageAllAndRetry(func() error {
return gui.handleCommitEditorPress(gui.g, filesView) return gui.handleCommitEditorPress()
}) })
} }
gui.PrepareSubProcess(g, "git", "commit") gui.PrepareSubProcess("git", "commit")
return nil return nil
} }
// PrepareSubProcess - prepare a subprocess for execution and tell the gui to switch to it // PrepareSubProcess - prepare a subprocess for execution and tell the gui to switch to it
func (gui *Gui) PrepareSubProcess(g *gocui.Gui, commands ...string) { func (gui *Gui) PrepareSubProcess(commands ...string) {
gui.SubProcess = gui.GitCommand.PrepareCommitSubProcess() gui.SubProcess = gui.GitCommand.PrepareCommitSubProcess()
g.Update(func(g *gocui.Gui) error { gui.g.Update(func(g *gocui.Gui) error {
return gui.Errors.ErrSubProcess return gui.Errors.ErrSubProcess
}) })
} }
@ -521,7 +521,7 @@ func (gui *Gui) pullWithMode(mode string, opts PullFilesOptions) error {
} }
} }
func (gui *Gui) pushWithForceFlag(g *gocui.Gui, v *gocui.View, force bool, upstream string, args string) error { func (gui *Gui) pushWithForceFlag(v *gocui.View, force bool, upstream string, args string) error {
if err := gui.createLoaderPanel(v, gui.Tr.SLocalize("PushWait")); err != nil { if err := gui.createLoaderPanel(v, gui.Tr.SLocalize("PushWait")); err != nil {
return err return err
} }
@ -535,7 +535,7 @@ func (gui *Gui) pushWithForceFlag(g *gocui.Gui, v *gocui.View, force bool, upstr
title: gui.Tr.SLocalize("ForcePush"), title: gui.Tr.SLocalize("ForcePush"),
prompt: gui.Tr.SLocalize("ForcePushPrompt"), prompt: gui.Tr.SLocalize("ForcePushPrompt"),
handleConfirm: func() error { handleConfirm: func() error {
return gui.pushWithForceFlag(gui.g, v, true, upstream, args) return gui.pushWithForceFlag(v, true, upstream, args)
}, },
}) })
@ -559,19 +559,19 @@ func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error {
} }
for branchName, branch := range conf.Branches { for branchName, branch := range conf.Branches {
if branchName == currentBranch.Name { if branchName == currentBranch.Name {
return gui.pushWithForceFlag(g, v, false, "", fmt.Sprintf("%s %s", branch.Remote, branchName)) return gui.pushWithForceFlag(v, false, "", fmt.Sprintf("%s %s", branch.Remote, branchName))
} }
} }
if gui.GitCommand.PushToCurrent { if gui.GitCommand.PushToCurrent {
return gui.pushWithForceFlag(g, v, false, "", "--set-upstream") return gui.pushWithForceFlag(v, false, "", "--set-upstream")
} else { } else {
return gui.prompt(v, gui.Tr.SLocalize("EnterUpstream"), "origin "+currentBranch.Name, func(response string) error { return gui.prompt(v, gui.Tr.SLocalize("EnterUpstream"), "origin "+currentBranch.Name, func(response string) error {
return gui.pushWithForceFlag(g, v, false, response, "") return gui.pushWithForceFlag(v, false, response, "")
}) })
} }
} else if currentBranch.Pullables == "0" { } else if currentBranch.Pullables == "0" {
return gui.pushWithForceFlag(g, v, false, "", "") return gui.pushWithForceFlag(v, false, "", "")
} }
return gui.ask(askOpts{ return gui.ask(askOpts{
@ -580,12 +580,12 @@ func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error {
title: gui.Tr.SLocalize("ForcePush"), title: gui.Tr.SLocalize("ForcePush"),
prompt: gui.Tr.SLocalize("ForcePushPrompt"), prompt: gui.Tr.SLocalize("ForcePushPrompt"),
handleConfirm: func() error { handleConfirm: func() error {
return gui.pushWithForceFlag(g, v, true, "", "") return gui.pushWithForceFlag(v, true, "", "")
}, },
}) })
} }
func (gui *Gui) handleSwitchToMerge(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleSwitchToMerge() error {
file, err := gui.getSelectedFile() file, err := gui.getSelectedFile()
if err != nil { if err != nil {
if err != gui.Errors.ErrNoFiles { if err != gui.Errors.ErrNoFiles {
@ -597,7 +597,7 @@ func (gui *Gui) handleSwitchToMerge(g *gocui.Gui, v *gocui.View) error {
return gui.createErrorPanel(gui.Tr.SLocalize("FileNoMergeCons")) return gui.createErrorPanel(gui.Tr.SLocalize("FileNoMergeCons"))
} }
gui.changeMainViewsContext("merging") gui.changeMainViewsContext("merging")
if err := gui.switchFocus(v, gui.getMainView()); err != nil { if err := gui.switchFocus(gui.g.CurrentView(), gui.getMainView()); err != nil {
return err return err
} }
return gui.refreshMergePanel() return gui.refreshMergePanel()

View File

@ -202,7 +202,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "", ViewName: "",
Key: gui.getKey("universal.quit"), Key: gui.getKey("universal.quit"),
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleQuit, Handler: gui.wrappedHandler(gui.handleQuit),
}, },
{ {
ViewName: "", ViewName: "",
@ -214,7 +214,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "", ViewName: "",
Key: gui.getKey("universal.quit-alt1"), Key: gui.getKey("universal.quit-alt1"),
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleQuit, Handler: gui.wrappedHandler(gui.handleQuit),
}, },
{ {
ViewName: "", ViewName: "",
@ -263,7 +263,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
{ {
ViewName: "", ViewName: "",
Key: gui.getKey("universal.createRebaseOptionsMenu"), Key: gui.getKey("universal.createRebaseOptionsMenu"),
Handler: gui.handleCreateRebaseOptionsMenu, Handler: gui.wrappedHandler(gui.handleCreateRebaseOptionsMenu),
Description: gui.Tr.SLocalize("ViewMergeRebaseOptions"), Description: gui.Tr.SLocalize("ViewMergeRebaseOptions"),
}, },
{ {
@ -353,13 +353,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
{ {
ViewName: "status", ViewName: "status",
Key: gui.getKey("status.recentRepos"), Key: gui.getKey("status.recentRepos"),
Handler: gui.handleCreateRecentReposMenu, Handler: gui.wrappedHandler(gui.handleCreateRecentReposMenu),
Description: gui.Tr.SLocalize("SwitchRepo"), Description: gui.Tr.SLocalize("SwitchRepo"),
}, },
{ {
ViewName: "files", ViewName: "files",
Key: gui.getKey("files.commitChanges"), Key: gui.getKey("files.commitChanges"),
Handler: gui.handleCommitPress, Handler: gui.wrappedHandler(gui.handleCommitPress),
Description: gui.Tr.SLocalize("CommitChanges"), Description: gui.Tr.SLocalize("CommitChanges"),
}, },
{ {
@ -371,19 +371,19 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
{ {
ViewName: "files", ViewName: "files",
Key: gui.getKey("files.amendLastCommit"), Key: gui.getKey("files.amendLastCommit"),
Handler: gui.handleAmendCommitPress, Handler: gui.wrappedHandler(gui.handleAmendCommitPress),
Description: gui.Tr.SLocalize("AmendLastCommit"), Description: gui.Tr.SLocalize("AmendLastCommit"),
}, },
{ {
ViewName: "files", ViewName: "files",
Key: gui.getKey("files.commitChangesWithEditor"), Key: gui.getKey("files.commitChangesWithEditor"),
Handler: gui.handleCommitEditorPress, Handler: gui.wrappedHandler(gui.handleCommitEditorPress),
Description: gui.Tr.SLocalize("CommitChangesWithEditor"), Description: gui.Tr.SLocalize("CommitChangesWithEditor"),
}, },
{ {
ViewName: "files", ViewName: "files",
Key: gui.getKey("universal.select"), Key: gui.getKey("universal.select"),
Handler: gui.handleFilePress, Handler: gui.wrappedHandler(gui.handleFilePress),
Description: gui.Tr.SLocalize("toggleStaged"), Description: gui.Tr.SLocalize("toggleStaged"),
}, },
{ {
@ -765,7 +765,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "commits", ViewName: "commits",
Contexts: []string{"branch-commits"}, Contexts: []string{"branch-commits"},
Key: gui.getKey("universal.goInto"), Key: gui.getKey("universal.goInto"),
Handler: gui.handleSwitchToCommitFilesPanel, Handler: gui.wrappedHandler(gui.handleSwitchToCommitFilesPanel),
Description: gui.Tr.SLocalize("viewCommitFiles"), Description: gui.Tr.SLocalize("viewCommitFiles"),
}, },
{ {
@ -964,7 +964,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "main", ViewName: "main",
Contexts: []string{"staging"}, Contexts: []string{"staging"},
Key: gui.getKey("universal.return"), Key: gui.getKey("universal.return"),
Handler: gui.handleStagingEscape, Handler: gui.wrappedHandler(gui.handleStagingEscape),
Description: gui.Tr.SLocalize("ReturnToFilesPanel"), Description: gui.Tr.SLocalize("ReturnToFilesPanel"),
}, },
{ {
@ -992,7 +992,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "main", ViewName: "main",
Contexts: []string{"patch-building"}, Contexts: []string{"patch-building"},
Key: gui.getKey("universal.return"), Key: gui.getKey("universal.return"),
Handler: gui.handleEscapePatchBuildingPanel, Handler: gui.wrappedHandler(gui.handleEscapePatchBuildingPanel),
Description: gui.Tr.SLocalize("ExitLineByLineMode"), Description: gui.Tr.SLocalize("ExitLineByLineMode"),
}, },
{ {
@ -1147,7 +1147,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "main", ViewName: "main",
Contexts: []string{"staging"}, Contexts: []string{"staging"},
Key: gui.getKey("files.commitChanges"), Key: gui.getKey("files.commitChanges"),
Handler: gui.handleCommitPress, Handler: gui.wrappedHandler(gui.handleCommitPress),
Description: gui.Tr.SLocalize("CommitChanges"), Description: gui.Tr.SLocalize("CommitChanges"),
}, },
{ {
@ -1161,14 +1161,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
ViewName: "main", ViewName: "main",
Contexts: []string{"staging"}, Contexts: []string{"staging"},
Key: gui.getKey("files.commitChangesWithEditor"), Key: gui.getKey("files.commitChangesWithEditor"),
Handler: gui.handleCommitEditorPress, Handler: gui.wrappedHandler(gui.handleCommitEditorPress),
Description: gui.Tr.SLocalize("CommitChangesWithEditor"), Description: gui.Tr.SLocalize("CommitChangesWithEditor"),
}, },
{ {
ViewName: "main", ViewName: "main",
Contexts: []string{"merging"}, Contexts: []string{"merging"},
Key: gui.getKey("universal.return"), Key: gui.getKey("universal.return"),
Handler: gui.handleEscapeMerge, Handler: gui.wrappedHandler(gui.handleEscapeMerge),
Description: gui.Tr.SLocalize("ReturnToFilesPanel"), Description: gui.Tr.SLocalize("ReturnToFilesPanel"),
}, },
{ {
@ -1267,7 +1267,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Contexts: []string{"remotes"}, Contexts: []string{"remotes"},
Key: gui.getKey("universal.goInto"), Key: gui.getKey("universal.goInto"),
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleRemoteEnter, Handler: gui.wrappedHandler(gui.handleRemoteEnter),
}, },
{ {
ViewName: "branches", ViewName: "branches",

View File

@ -393,7 +393,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
// if you download humanlog and do tail -f development.log | humanlog // if you download humanlog and do tail -f development.log | humanlog
// this will let you see these branches as prettified json // this will let you see these branches as prettified json
// gui.Log.Info(utils.AsJson(gui.State.Branches[0:4])) // gui.Log.Info(utils.AsJson(gui.State.Branches[0:4]))
return gui.resizeCurrentPopupPanel(g) return gui.resizeCurrentPopupPanel()
} }
func (gui *Gui) onInitialViewsCreation() error { func (gui *Gui) onInitialViewsCreation() error {

View File

@ -123,7 +123,7 @@ func (gui *Gui) getListViews() []*listView {
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Files.SelectedLine }, getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Files.SelectedLine },
handleFocus: gui.wrappedHandler(gui.focusAndSelectFile), handleFocus: gui.wrappedHandler(gui.focusAndSelectFile),
handleItemSelect: gui.wrappedHandler(gui.focusAndSelectFile), handleItemSelect: gui.wrappedHandler(gui.focusAndSelectFile),
handleClickSelectedItem: gui.handleFilePress, handleClickSelectedItem: gui.wrappedHandler(gui.handleFilePress),
gui: gui, gui: gui,
rendersToMainView: true, rendersToMainView: true,
}, },
@ -144,7 +144,7 @@ func (gui *Gui) getListViews() []*listView {
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Remotes.SelectedLine }, getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Remotes.SelectedLine },
handleFocus: gui.wrappedHandler(gui.renderRemotesWithSelection), handleFocus: gui.wrappedHandler(gui.renderRemotesWithSelection),
handleItemSelect: gui.wrappedHandler(gui.handleRemoteSelect), handleItemSelect: gui.wrappedHandler(gui.handleRemoteSelect),
handleClickSelectedItem: gui.handleRemoteEnter, handleClickSelectedItem: gui.wrappedHandler(gui.handleRemoteEnter),
gui: gui, gui: gui,
rendersToMainView: true, rendersToMainView: true,
}, },
@ -176,7 +176,7 @@ func (gui *Gui) getListViews() []*listView {
getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Commits.SelectedLine }, getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Commits.SelectedLine },
handleFocus: gui.wrappedHandler(gui.handleCommitSelect), handleFocus: gui.wrappedHandler(gui.handleCommitSelect),
handleItemSelect: gui.wrappedHandler(gui.handleCommitSelect), handleItemSelect: gui.wrappedHandler(gui.handleCommitSelect),
handleClickSelectedItem: gui.handleSwitchToCommitFilesPanel, handleClickSelectedItem: gui.wrappedHandler(gui.handleSwitchToCommitFilesPanel),
gui: gui, gui: gui,
rendersToMainView: true, rendersToMainView: true,
}, },

View File

@ -42,7 +42,7 @@ func (gui *Gui) handleMenuClose(g *gocui.Gui, v *gocui.View) error {
if err != nil { if err != nil {
return err return err
} }
return gui.returnFocus(g, v) return gui.returnFocus(v)
} }
type createMenuOptions struct { type createMenuOptions struct {
@ -73,7 +73,7 @@ func (gui *Gui) createMenu(title string, items []*menuItem, createMenuOptions cr
list := utils.RenderDisplayStrings(stringArrays) list := utils.RenderDisplayStrings(stringArrays)
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, false, list) x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(false, list)
menuView, _ := gui.g.SetView("menu", x0, y0, x1, y1, 0) menuView, _ := gui.g.SetView("menu", x0, y0, x1, y1, 0)
menuView.Title = title menuView.Title = title
menuView.FgColor = theme.GocuiDefaultTextColor menuView.FgColor = theme.GocuiDefaultTextColor
@ -99,7 +99,7 @@ func (gui *Gui) createMenu(title string, items []*menuItem, createMenuOptions cr
} }
} }
return gui.returnFocus(gui.g, menuView) return gui.returnFocus(menuView)
} }
gui.State.Panels.Menu.OnPress = wrappedHandlePress gui.State.Panels.Menu.OnPress = wrappedHandlePress

View File

@ -112,7 +112,7 @@ func (gui *Gui) isIndexToDelete(i int, conflict commands.Conflict, pick string)
(pick == "top" && i > conflict.Middle && i < conflict.End) (pick == "top" && i > conflict.Middle && i < conflict.End)
} }
func (gui *Gui) resolveConflict(g *gocui.Gui, conflict commands.Conflict, pick string) error { func (gui *Gui) resolveConflict(conflict commands.Conflict, pick string) error {
gitFile, err := gui.getSelectedFile() gitFile, err := gui.getSelectedFile()
if err != nil { if err != nil {
return err return err
@ -179,7 +179,7 @@ func (gui *Gui) handlePickHunk(g *gocui.Gui, v *gocui.View) error {
if gui.State.Panels.Merging.ConflictTop { if gui.State.Panels.Merging.ConflictTop {
pick = "top" pick = "top"
} }
err := gui.resolveConflict(g, conflict, pick) err := gui.resolveConflict(conflict, pick)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -200,7 +200,7 @@ func (gui *Gui) handlePickBothHunks(g *gocui.Gui, v *gocui.View) error {
if err := gui.pushFileSnapshot(g); err != nil { if err := gui.pushFileSnapshot(g); err != nil {
return err return err
} }
err := gui.resolveConflict(g, conflict, "both") err := gui.resolveConflict(conflict, "both")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -298,7 +298,7 @@ func (gui *Gui) renderMergeOptions() error {
}) })
} }
func (gui *Gui) handleEscapeMerge(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleEscapeMerge() error {
gui.takeOverScrolling() gui.takeOverScrolling()
gui.State.Panels.Merging.EditHistory = stack.New() gui.State.Panels.Merging.EditHistory = stack.New()
@ -308,7 +308,7 @@ func (gui *Gui) handleEscapeMerge(g *gocui.Gui, v *gocui.View) error {
// it's possible this method won't be called from the merging view so we need to // it's possible this method won't be called from the merging view so we need to
// ensure we only 'return' focus if we already have it // ensure we only 'return' focus if we already have it
if gui.g.CurrentView() == gui.getMainView() { if gui.g.CurrentView() == gui.getMainView() {
return gui.switchFocus(v, gui.getFilesView()) return gui.switchFocus(gui.getMainView(), gui.getFilesView())
} }
return nil return nil
} }
@ -323,13 +323,13 @@ func (gui *Gui) handleCompleteMerge() error {
// if we got conflicts after unstashing, we don't want to call any git // if we got conflicts after unstashing, we don't want to call any git
// commands to continue rebasing/merging here // commands to continue rebasing/merging here
if gui.GitCommand.WorkingTreeState() == "normal" { if gui.GitCommand.WorkingTreeState() == "normal" {
return gui.handleEscapeMerge(gui.g, gui.getMainView()) return gui.handleEscapeMerge()
} }
// if there are no more files with merge conflicts, we should ask whether the user wants to continue // if there are no more files with merge conflicts, we should ask whether the user wants to continue
if !gui.anyFilesWithMergeConflicts() { if !gui.anyFilesWithMergeConflicts() {
return gui.promptToContinue() return gui.promptToContinue()
} }
return gui.handleEscapeMerge(gui.g, gui.getMainView()) return gui.handleEscapeMerge()
} }
// promptToContinue asks the user if they want to continue the rebase/merge that's in progress // promptToContinue asks the user if they want to continue the rebase/merge that's in progress

View File

@ -7,7 +7,7 @@ import (
func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error { func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error {
if !gui.GitCommand.PatchManager.CommitSelected() { if !gui.GitCommand.PatchManager.CommitSelected() {
return gui.handleEscapePatchBuildingPanel(gui.g, nil) return gui.handleEscapePatchBuildingPanel()
} }
gui.State.SplitMainPanel = true gui.State.SplitMainPanel = true
@ -38,7 +38,7 @@ func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error {
} }
if empty { if empty {
return gui.handleEscapePatchBuildingPanel(gui.g, nil) return gui.handleEscapePatchBuildingPanel()
} }
return nil return nil
@ -75,7 +75,7 @@ func (gui *Gui) handleToggleSelectionForPatch(g *gocui.Gui, v *gocui.View) error
return nil return nil
} }
func (gui *Gui) handleEscapePatchBuildingPanel(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleEscapePatchBuildingPanel() error {
gui.handleEscapeLineByLinePanel() gui.handleEscapeLineByLinePanel()
if gui.GitCommand.PatchManager.IsEmpty() { if gui.GitCommand.PatchManager.IsEmpty() {

View File

@ -78,7 +78,7 @@ func (gui *Gui) validateNormalWorkingTreeState() (bool, error) {
func (gui *Gui) returnFocusFromLineByLinePanelIfNecessary() error { func (gui *Gui) returnFocusFromLineByLinePanelIfNecessary() error {
if gui.State.MainContext == "patch-building" { if gui.State.MainContext == "patch-building" {
return gui.handleEscapePatchBuildingPanel(gui.g, nil) return gui.handleEscapePatchBuildingPanel()
} }
return nil return nil
} }

View File

@ -26,12 +26,12 @@ func (gui *Gui) recordCurrentDirectory() error {
func (gui *Gui) handleQuitWithoutChangingDirectory(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleQuitWithoutChangingDirectory(g *gocui.Gui, v *gocui.View) error {
gui.State.RetainOriginalDir = true gui.State.RetainOriginalDir = true
return gui.quit(v) return gui.quit()
} }
func (gui *Gui) handleQuit(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleQuit() error {
gui.State.RetainOriginalDir = false gui.State.RetainOriginalDir = false
return gui.quit(v) return gui.quit()
} }
func (gui *Gui) handleTopLevelReturn(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleTopLevelReturn(g *gocui.Gui, v *gocui.View) error {
@ -43,20 +43,20 @@ func (gui *Gui) handleTopLevelReturn(g *gocui.Gui, v *gocui.View) error {
} }
if gui.Config.GetUserConfig().GetBool("quitOnTopLevelReturn") { if gui.Config.GetUserConfig().GetBool("quitOnTopLevelReturn") {
return gui.handleQuit(g, v) return gui.handleQuit()
} }
return nil return nil
} }
func (gui *Gui) quit(v *gocui.View) error { func (gui *Gui) quit() error {
if gui.State.Updating { if gui.State.Updating {
return gui.createUpdateQuitConfirmation(gui.g, v) return gui.createUpdateQuitConfirmation()
} }
if gui.Config.GetUserConfig().GetBool("confirmOnQuit") { if gui.Config.GetUserConfig().GetBool("confirmOnQuit") {
return gui.ask(askOpts{ return gui.ask(askOpts{
returnToView: v, returnToView: gui.g.CurrentView(),
returnFocusOnClose: true, returnFocusOnClose: true,
title: "", title: "",
prompt: gui.Tr.SLocalize("ConfirmQuit"), prompt: gui.Tr.SLocalize("ConfirmQuit"),

View File

@ -3,11 +3,9 @@ package gui
import ( import (
"fmt" "fmt"
"strings" "strings"
"github.com/jesseduffield/gocui"
) )
func (gui *Gui) handleCreateRebaseOptionsMenu(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCreateRebaseOptionsMenu() error {
options := []string{"continue", "abort"} options := []string{"continue", "abort"}
if gui.GitCommand.WorkingTreeState() == "rebasing" { if gui.GitCommand.WorkingTreeState() == "rebasing" {

View File

@ -5,12 +5,11 @@ import (
"path/filepath" "path/filepath"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
func (gui *Gui) handleCreateRecentReposMenu(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCreateRecentReposMenu() error {
recentRepoPaths := gui.Config.GetAppState().RecentRepos recentRepoPaths := gui.Config.GetAppState().RecentRepos
reposCount := utils.Min(len(recentRepoPaths), 20) reposCount := utils.Min(len(recentRepoPaths), 20)
yellow := color.New(color.FgMagenta) yellow := color.New(color.FgMagenta)

View File

@ -96,7 +96,7 @@ func (gui *Gui) renderRemotesWithSelection() error {
return nil return nil
} }
func (gui *Gui) handleRemoteEnter(g *gocui.Gui, v *gocui.View) 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()
if remote == nil { if remote == nil {

View File

@ -24,11 +24,11 @@ func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx
if err != gui.Errors.ErrNoFiles { if err != gui.Errors.ErrNoFiles {
return err return err
} }
return gui.handleStagingEscape(gui.g, nil) return gui.handleStagingEscape()
} }
if !file.HasUnstagedChanges && !file.HasStagedChanges { if !file.HasUnstagedChanges && !file.HasStagedChanges {
return gui.handleStagingEscape(gui.g, nil) return gui.handleStagingEscape()
} }
secondaryFocused := false secondaryFocused := false
@ -60,7 +60,7 @@ func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx
// 4-5 lines in which case we'll swap panels // 4-5 lines in which case we'll swap panels
if len(strings.Split(diff, "\n")) < 5 { if len(strings.Split(diff, "\n")) < 5 {
if len(strings.Split(secondaryDiff, "\n")) < 5 { if len(strings.Split(secondaryDiff, "\n")) < 5 {
return gui.handleStagingEscape(gui.g, nil) return gui.handleStagingEscape()
} }
secondaryFocused = !secondaryFocused secondaryFocused = !secondaryFocused
diff, secondaryDiff = secondaryDiff, diff diff, secondaryDiff = secondaryDiff, diff
@ -72,7 +72,7 @@ func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx
} }
if empty { if empty {
return gui.handleStagingEscape(gui.g, nil) return gui.handleStagingEscape()
} }
return nil return nil
@ -93,7 +93,7 @@ func (gui *Gui) handleTogglePanel(g *gocui.Gui, v *gocui.View) error {
return gui.refreshStagingPanel(false, -1) return gui.refreshStagingPanel(false, -1)
} }
func (gui *Gui) handleStagingEscape(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleStagingEscape() error {
gui.handleEscapeLineByLinePanel() gui.handleEscapeLineByLinePanel()
return gui.switchFocus(nil, gui.getFilesView()) return gui.switchFocus(nil, gui.getFilesView())

View File

@ -69,7 +69,7 @@ func (gui *Gui) handleStashApply(g *gocui.Gui, v *gocui.View) error {
skipStashWarning := gui.Config.GetUserConfig().GetBool("gui.skipStashWarning") skipStashWarning := gui.Config.GetUserConfig().GetBool("gui.skipStashWarning")
apply := func() error { apply := func() error {
return gui.stashDo(g, v, "apply") return gui.stashDo("apply")
} }
if skipStashWarning { if skipStashWarning {
@ -91,7 +91,7 @@ func (gui *Gui) handleStashPop(g *gocui.Gui, v *gocui.View) error {
skipStashWarning := gui.Config.GetUserConfig().GetBool("gui.skipStashWarning") skipStashWarning := gui.Config.GetUserConfig().GetBool("gui.skipStashWarning")
pop := func() error { pop := func() error {
return gui.stashDo(g, v, "pop") return gui.stashDo("pop")
} }
if skipStashWarning { if skipStashWarning {
@ -116,12 +116,12 @@ func (gui *Gui) handleStashDrop(g *gocui.Gui, v *gocui.View) error {
title: gui.Tr.SLocalize("StashDrop"), title: gui.Tr.SLocalize("StashDrop"),
prompt: gui.Tr.SLocalize("SureDropStashEntry"), prompt: gui.Tr.SLocalize("SureDropStashEntry"),
handleConfirm: func() error { handleConfirm: func() error {
return gui.stashDo(g, v, "drop") return gui.stashDo("drop")
}, },
}) })
} }
func (gui *Gui) stashDo(g *gocui.Gui, v *gocui.View, method string) error { func (gui *Gui) stashDo(method string) error {
stashEntry := gui.getSelectedStashEntry() stashEntry := gui.getSelectedStashEntry()
if stashEntry == nil { if stashEntry == nil {
errorMessage := gui.Tr.TemplateLocalize( errorMessage := gui.Tr.TemplateLocalize(

View File

@ -70,14 +70,14 @@ func (gui *Gui) handleStatusClick(g *gocui.Gui, v *gocui.View) error {
case "rebasing", "merging": case "rebasing", "merging":
workingTreeStatus := fmt.Sprintf("(%s)", gui.GitCommand.WorkingTreeState()) workingTreeStatus := fmt.Sprintf("(%s)", gui.GitCommand.WorkingTreeState())
if cursorInSubstring(cx, upstreamStatus+" ", workingTreeStatus) { if cursorInSubstring(cx, upstreamStatus+" ", workingTreeStatus) {
return gui.handleCreateRebaseOptionsMenu(gui.g, v) return gui.handleCreateRebaseOptionsMenu()
} }
if cursorInSubstring(cx, upstreamStatus+" "+workingTreeStatus+" ", repoName) { if cursorInSubstring(cx, upstreamStatus+" "+workingTreeStatus+" ", repoName) {
return gui.handleCreateRecentReposMenu(gui.g, v) return gui.handleCreateRecentReposMenu()
} }
default: default:
if cursorInSubstring(cx, upstreamStatus+" ", repoName) { if cursorInSubstring(cx, upstreamStatus+" ", repoName) {
return gui.handleCreateRecentReposMenu(gui.g, v) return gui.handleCreateRecentReposMenu()
} }
} }

View File

@ -59,9 +59,9 @@ func (gui *Gui) onUpdateFinish(err error) error {
return nil return nil
} }
func (gui *Gui) createUpdateQuitConfirmation(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) createUpdateQuitConfirmation() error {
return gui.ask(askOpts{ return gui.ask(askOpts{
returnToView: v, returnToView: gui.g.CurrentView(),
returnFocusOnClose: true, returnFocusOnClose: true,
title: "Currently Updating", title: "Currently Updating",
prompt: "An update is in progress. Are you sure you want to quit?", prompt: "An update is in progress. Are you sure you want to quit?",

View File

@ -216,7 +216,7 @@ func (gui *Gui) previousView(g *gocui.Gui, v *gocui.View) error {
return gui.switchFocus(v, focusedView) return gui.switchFocus(v, focusedView)
} }
func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) newLineFocused(v *gocui.View) error {
switch v.Name() { switch v.Name() {
case "menu": case "menu":
return gui.handleMenuSelect() return gui.handleMenuSelect()
@ -263,11 +263,11 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error {
} }
} }
func (gui *Gui) returnFocus(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) returnFocus(v *gocui.View) error {
previousView, err := g.View(gui.State.PreviousView) previousView, err := gui.g.View(gui.State.PreviousView)
if err != nil { if err != nil {
// always fall back to files view if there's no 'previous' view stored // always fall back to files view if there's no 'previous' view stored
previousView, err = g.View("files") previousView, err = gui.g.View("files")
if err != nil { if err != nil {
gui.Log.Error(err) gui.Log.Error(err)
} }
@ -293,7 +293,7 @@ func (gui *Gui) goToSideView(sideViewName string) func(g *gocui.Gui, v *gocui.Vi
func (gui *Gui) closePopupPanels() error { func (gui *Gui) closePopupPanels() error {
gui.onNewPopupPanel() gui.onNewPopupPanel()
err := gui.closeConfirmationPrompt(gui.g, true) err := gui.closeConfirmationPrompt(true)
if err != nil { if err != nil {
gui.Log.Error(err) gui.Log.Error(err)
return err return err
@ -331,7 +331,7 @@ func (gui *Gui) switchFocus(oldView, newView *gocui.View) error {
return err return err
} }
return gui.newLineFocused(gui.g, newView) return gui.newLineFocused(newView)
} }
func (gui *Gui) resetOrigin(v *gocui.View) error { func (gui *Gui) resetOrigin(v *gocui.View) error {
@ -450,25 +450,25 @@ func (gui *Gui) currentViewName() string {
return currentView.Name() return currentView.Name()
} }
func (gui *Gui) resizeCurrentPopupPanel(g *gocui.Gui) error { func (gui *Gui) resizeCurrentPopupPanel() error {
v := g.CurrentView() v := gui.g.CurrentView()
if gui.isPopupPanel(v.Name()) { if gui.isPopupPanel(v.Name()) {
return gui.resizePopupPanel(g, v) return gui.resizePopupPanel(v)
} }
return nil return nil
} }
func (gui *Gui) resizePopupPanel(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) resizePopupPanel(v *gocui.View) error {
// If the confirmation panel is already displayed, just resize the width, // If the confirmation panel is already displayed, just resize the width,
// otherwise continue // otherwise continue
content := v.Buffer() content := v.Buffer()
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(g, v.Wrap, content) x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(v.Wrap, content)
vx0, vy0, vx1, vy1 := v.Dimensions() vx0, vy0, vx1, vy1 := v.Dimensions()
if vx0 == x0 && vy0 == y0 && vx1 == x1 && vy1 == y1 { if vx0 == x0 && vy0 == y0 && vx1 == x1 && vy1 == y1 {
return nil return nil
} }
gui.Log.Info(gui.Tr.SLocalize("resizingPopupPanel")) gui.Log.Info(gui.Tr.SLocalize("resizingPopupPanel"))
_, err := g.SetView(v.Name(), x0, y0, x1, y1, 0) _, err := gui.g.SetView(v.Name(), x0, y0, x1, y1, 0)
return err return err
} }