diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-09 11:34:10 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-09 12:23:13 +1100 |
commit | e47ad846c4b6100aaff7013a3516d329bde19194 (patch) | |
tree | ead7f3f0a911d7ee4f4f46640c2bf449a74e8e05 /pkg/gui | |
parent | 8f68ac21293f1a0476802974817d9f87875f8743 (diff) |
big golangci-lint cleanup
Diffstat (limited to 'pkg/gui')
28 files changed, 134 insertions, 224 deletions
diff --git a/pkg/gui/app_status_manager.go b/pkg/gui/app_status_manager.go index 431486ee9..ed8f0c935 100644 --- a/pkg/gui/app_status_manager.go +++ b/pkg/gui/app_status_manager.go @@ -66,9 +66,7 @@ func (gui *Gui) WithWaitingStatus(name string, f func() error) error { if appStatus == "" { return } - if err := gui.renderString(gui.g, "appStatus", appStatus); err != nil { - gui.Log.Warn(err) - } + gui.renderString(gui.g, "appStatus", appStatus) } }() diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 44cd9415b..caac8e218 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -40,9 +40,7 @@ func (gui *Gui) handleBranchSelect(g *gocui.Gui, v *gocui.View) error { return gui.newStringTask("main", gui.Tr.SLocalize("NoBranchesThisRepo")) } branch := gui.getSelectedBranch() - if err := gui.focusPoint(0, gui.State.Panels.Branches.SelectedLine, len(gui.State.Branches), v); err != nil { - return err - } + v.FocusPoint(0, gui.State.Panels.Branches.SelectedLine) if err := gui.RenderSelectedBranchUpstreamDifferences(); err != nil { return err } @@ -161,7 +159,7 @@ func (gui *Gui) handleForceCheckout(g *gocui.Gui, v *gocui.View) error { title := gui.Tr.SLocalize("ForceCheckoutBranch") return gui.createConfirmationPanel(g, v, true, title, message, func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.Checkout(branch.Name, true); err != nil { - gui.createErrorPanel(g, err.Error()) + _ = gui.createErrorPanel(g, err.Error()) } return gui.refreshSidePanels(g) }, nil) @@ -205,10 +203,9 @@ func (gui *Gui) handleCheckoutRef(ref string) error { } func (gui *Gui) handleCheckoutByName(g *gocui.Gui, v *gocui.View) error { - gui.createPromptPanel(g, v, gui.Tr.SLocalize("BranchName")+":", "", func(g *gocui.Gui, v *gocui.View) error { + return gui.createPromptPanel(g, v, gui.Tr.SLocalize("BranchName")+":", "", func(g *gocui.Gui, v *gocui.View) error { return gui.handleCheckoutRef(gui.trimmedContent(v)) }) - return nil } func (gui *Gui) getCheckedOutBranch() *commands.Branch { @@ -230,24 +227,21 @@ func (gui *Gui) handleNewBranch(g *gocui.Gui, v *gocui.View) error { "branchName": branch.Name, }, ) - gui.createPromptPanel(g, v, message, "", func(g *gocui.Gui, v *gocui.View) error { + return gui.createPromptPanel(g, v, message, "", func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.NewBranch(gui.trimmedContent(v), branch.Name); err != nil { return gui.createErrorPanel(g, err.Error()) } - gui.refreshSidePanels(g) + if err := gui.refreshSidePanels(g); err != nil { + return gui.createErrorPanel(g, err.Error()) + } return gui.handleBranchSelect(g, v) }) - return nil } func (gui *Gui) handleDeleteBranch(g *gocui.Gui, v *gocui.View) error { return gui.deleteBranch(g, v, false) } -func (gui *Gui) handleForceDeleteBranch(g *gocui.Gui, v *gocui.View) error { - return gui.deleteBranch(g, v, true) -} - func (gui *Gui) deleteBranch(g *gocui.Gui, v *gocui.View, force bool) error { selectedBranch := gui.getSelectedBranch() if selectedBranch == nil { @@ -400,7 +394,9 @@ func (gui *Gui) onBranchesTabClick(tabIndex int) error { func (gui *Gui) switchBranchesPanelContext(context string) error { branchesView := gui.getBranchesView() branchesView.Context = context - gui.onSearchEscape() + if err := gui.onSearchEscape(); err != nil { + return err + } contextTabIndexMap := map[string]int{ "local-branches": 0, diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 5fa7a4683..cafc4f95b 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -36,16 +36,15 @@ func (gui *Gui) handleCommitFileSelect(g *gocui.Gui, v *gocui.View) error { commitFile := gui.getSelectedCommitFile(g) if commitFile == nil { - return gui.renderString(g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) + gui.renderString(g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) + return nil } if err := gui.refreshSecondaryPatchPanel(); err != nil { return err } - if err := gui.focusPoint(0, gui.State.Panels.CommitFiles.SelectedLine, len(gui.State.CommitFiles), v); err != nil { - return err - } + v.FocusPoint(0, gui.State.Panels.CommitFiles.SelectedLine) cmd := gui.OSCommand.ExecutableFromString( gui.GitCommand.ShowCommitFileCmdStr(commitFile.Sha, commitFile.Name, false), @@ -132,7 +131,8 @@ func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error { commitFile := gui.getSelectedCommitFile(g) if commitFile == nil { - return gui.renderString(g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) + gui.renderString(g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) + return nil } toggleTheFile := func() error { @@ -187,7 +187,8 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error { commitFile := gui.getSelectedCommitFile(gui.g) if commitFile == nil { - return gui.renderString(gui.g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) + gui.renderString(gui.g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) + return nil } enterTheFile := func(selectedLineIdx int) error { diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index 8d2d02524..ea65dc9cf 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -52,7 +52,7 @@ func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleCommitClose(g *gocui.Gui, v *gocui.View) error { - g.SetViewOnBottom("commitMessage") + _, _ = g.SetViewOnBottom("commitMessage") return gui.switchFocus(g, v, gui.getFilesView()) } @@ -68,7 +68,8 @@ func (gui *Gui) handleCommitFocused(g *gocui.Gui, v *gocui.View) error { "keyBindConfirm": "enter", }, ) - return gui.renderString(g, "options", message) + gui.renderString(g, "options", message) + return nil } func (gui *Gui) getBufferLength(view *gocui.View) string { diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 0c901d085..8baa5c9e5 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -3,8 +3,6 @@ package gui import ( "strconv" - "github.com/go-errors/errors" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/gui/presentation" @@ -55,9 +53,7 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { return gui.newStringTask("main", gui.Tr.SLocalize("NoCommitsThisBranch")) } - if err := gui.focusPoint(0, gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits), v); err != nil { - return err - } + v.FocusPoint(0, gui.State.Panels.Commits.SelectedLine) // if specific diff mode is on, don't show diff if gui.State.Panels.Commits.SpecificDiffMode { @@ -77,7 +73,7 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) refreshCommits(g *gocui.Gui) error { g.Update(func(*gocui.Gui) error { // I think this is here for the sake of some kind of rebasing thing - gui.refreshStatus(g) + _ = gui.refreshStatus(g) if err := gui.refreshCommitsWithLimit(); err != nil { return err @@ -121,28 +117,6 @@ func (gui *Gui) refreshCommitsWithLimit() error { // specific functions -func (gui *Gui) handleResetToCommit(g *gocui.Gui, commitView *gocui.View) error { - return gui.createConfirmationPanel(g, commitView, true, gui.Tr.SLocalize("ResetToCommit"), gui.Tr.SLocalize("SureResetThisCommit"), func(g *gocui.Gui, v *gocui.View) error { - commit := gui.getSelectedCommit(g) - if commit == nil { - panic(errors.New(gui.Tr.SLocalize("NoCommitsThisBranch"))) - } - - if err := gui.GitCommand.ResetToCommit(commit.Sha, "mixed"); err != nil { - return gui.createErrorPanel(g, err.Error()) - } - if err := gui.refreshCommits(g); err != nil { - panic(err) - } - if err := gui.refreshFiles(); err != nil { - panic(err) - } - gui.resetOrigin(commitView) - gui.State.Panels.Commits.SelectedLine = 0 - return gui.handleCommitSelect(g, commitView) - }, nil) -} - func (gui *Gui) handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error { if len(gui.State.Commits) <= 1 { return gui.createErrorPanel(g, gui.Tr.SLocalize("YouNoCommitsToSquash")) @@ -156,23 +130,12 @@ func (gui *Gui) handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error { return nil } - gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("Squash"), gui.Tr.SLocalize("SureSquashThisCommit"), func(g *gocui.Gui, v *gocui.View) error { + return gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("Squash"), gui.Tr.SLocalize("SureSquashThisCommit"), func(g *gocui.Gui, v *gocui.View) error { return gui.WithWaitingStatus(gui.Tr.SLocalize("SquashingStatus"), func() error { err := gui.GitCommand.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLine, "squash") return gui.handleGenericMergeCommandResult(err) }) }, nil) - return nil -} - -// TODO: move to files panel -func (gui *Gui) anyUnStagedChanges(files []*commands.File) bool { - for _, file := range files { - if file.Tracked && file.HasUnstagedChanges { - return true - } - } - return false } func (gui *Gui) handleCommitFixup(g *gocui.Gui, v *gocui.View) error { @@ -188,13 +151,12 @@ func (gui *Gui) handleCommitFixup(g *gocui.Gui, v *gocui.View) error { return nil } - gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("Fixup"), gui.Tr.SLocalize("SureFixupThisCommit"), func(g *gocui.Gui, v *gocui.View) error { + return gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("Fixup"), gui.Tr.SLocalize("SureFixupThisCommit"), func(g *gocui.Gui, v *gocui.View) error { return gui.WithWaitingStatus(gui.Tr.SLocalize("FixingStatus"), func() error { err := gui.GitCommand.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLine, "fixup") return gui.handleGenericMergeCommandResult(err) }) }, nil) - return nil } func (gui *Gui) handleRenameCommit(g *gocui.Gui, v *gocui.View) error { @@ -264,21 +226,6 @@ func (gui *Gui) handleMidRebaseCommand(action string) (bool, error) { return true, gui.refreshCommits(gui.g) } -// handleMoveTodoDown like handleMidRebaseCommand but for moving an item up in the todo list -func (gui *Gui) handleMoveTodoDown(index int) (bool, error) { - selectedCommit := gui.State.Commits[index] - if selectedCommit.Status != "rebasing" { - return false, nil - } - if gui.State.Commits[index+1].Status != "rebasing" { - return true, nil - } - if err := gui.GitCommand.MoveTodoDown(index); err != nil { - return true, gui.createErrorPanel(gui.g, err.Error()) - } - return true, gui.refreshCommits(gui.g) -} - func (gui *Gui) handleCommitDelete(g *gocui.Gui, v *gocui.View) error { applied, err := gui.handleMidRebaseCommand("drop") if err != nil { @@ -504,7 +451,7 @@ func (gui *Gui) setDiffMode() { v.Title = gui.Tr.SLocalize("CommitsTitle") } - gui.refreshCommits(gui.g) + _ = gui.refreshCommits(gui.g) } func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) { @@ -623,7 +570,9 @@ func (gui *Gui) onCommitsTabClick(tabIndex int) error { func (gui *Gui) switchCommitsPanelContext(context string) error { commitsView := gui.getCommitsView() commitsView.Context = context - gui.onSearchEscape() + if err := gui.onSearchEscape(); err != nil { + return err + } contextTabIndexMap := map[string]int{ "branch-commits": 0, diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index efb5a34d8..755d13f96 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -122,9 +122,7 @@ func (gui *Gui) createPopupPanel(g *gocui.Gui, currentView *gocui.View, title, p }() } - if err := gui.renderString(g, "confirmation", prompt); err != nil { - return err - } + gui.renderString(g, "confirmation", prompt) return gui.setKeyBindings(g, handleConfirm, handleClose, returnFocusOnClose) }) return nil @@ -151,19 +149,13 @@ func (gui *Gui) setKeyBindings(g *gocui.Gui, handleConfirm, handleClose func(*go "keyBindConfirm": "enter", }, ) - if err := gui.renderString(g, "options", actions); err != nil { - return err - } + gui.renderString(g, "options", actions) if err := g.SetKeybinding("confirmation", nil, gocui.KeyEnter, gocui.ModNone, gui.wrappedConfirmationFunction(handleConfirm, returnFocusOnClose)); err != nil { return err } return g.SetKeybinding("confirmation", nil, gocui.KeyEsc, gocui.ModNone, gui.wrappedConfirmationFunction(handleClose, returnFocusOnClose)) } -func (gui *Gui) createMessagePanel(g *gocui.Gui, currentView *gocui.View, title, prompt string) error { - return gui.createPopupPanel(g, currentView, title, prompt, false, true, false, nil, nil) -} - // createSpecificErrorPanel allows you to create an error popup, specifying the // view to be focused when the user closes the popup, and a boolean specifying // whether we will log the error. If the message may include a user password, diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 53b884cc7..bf3ec2778 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -16,5 +16,4 @@ func (gui *Gui) changeMainViewsContext(context string) { } gui.State.MainContext = context - return } diff --git a/pkg/gui/credentials_panel.go b/pkg/gui/credentials_panel.go index ff35ce57c..aa2caecfa 100644 --- a/pkg/gui/credentials_panel.go +++ b/pkg/gui/credentials_panel.go @@ -82,7 +82,8 @@ func (gui *Gui) handleCredentialsViewFocused(g *gocui.Gui, v *gocui.View) error "keyBindConfirm": "enter", }, ) - return gui.renderString(g, "options", message) + gui.renderString(g, "options", message) + return nil } // HandleCredentialsPopup handles the views after executing a command that might ask for credentials diff --git a/pkg/gui/file_watching.go b/pkg/gui/file_watching.go index 3a9532116..47d426c87 100644 --- a/pkg/gui/file_watching.go +++ b/pkg/gui/file_watching.go @@ -23,11 +23,13 @@ type fileWatcher struct { } func NewFileWatcher(log *logrus.Entry) *fileWatcher { - watcher, err := fsnotify.NewWatcher() - log.Error(err) + // TODO: get this going again, and ensure we don't see any crashes from it return &fileWatcher{ Disabled: true, } + + watcher, err := fsnotify.NewWatcher() + if err != nil { log.Error(err) return &fileWatcher{ diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 6bd2c7076..0b761bff7 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -37,9 +37,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error { return gui.newStringTask("main", gui.Tr.SLocalize("NoChangedFiles")) } - if err := gui.focusPoint(0, gui.State.Panels.Files.SelectedLine, len(gui.State.Files), gui.getFilesView()); err != nil { - return err - } + gui.getFilesView().FocusPoint(0, gui.State.Panels.Files.SelectedLine) if file.HasInlineMergeConflicts { gui.getMainView().Title = gui.Tr.SLocalize("MergeConflictsTitle") @@ -188,9 +186,12 @@ func (gui *Gui) handleFilePress(g *gocui.Gui, v *gocui.View) error { } if file.HasUnstagedChanges { - gui.GitCommand.StageFile(file.Name) + err = gui.GitCommand.StageFile(file.Name) } else { - gui.GitCommand.UnStageFile(file.Name, file.Tracked) + err = gui.GitCommand.UnStageFile(file.Name, file.Tracked) + } + if err != nil { + return gui.createErrorPanel(gui.g, err.Error()) } if err := gui.refreshFiles(); err != nil { @@ -268,9 +269,7 @@ func (gui *Gui) handleWIPCommitPress(g *gocui.Gui, filesView *gocui.View) error return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("SkipHookPrefixNotConfigured")) } - if err := gui.renderString(g, "commitMessage", skipHookPreifx); err != nil { - return err - } + gui.renderString(g, "commitMessage", skipHookPreifx) if err := gui.getCommitMessageView().SetCursor(len(skipHookPreifx), 0); err != nil { return err } @@ -284,8 +283,14 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error { } commitMessageView := gui.getCommitMessageView() g.Update(func(g *gocui.Gui) error { - g.SetViewOnTop("commitMessage") - gui.switchFocus(g, filesView, commitMessageView) + if _, err := g.SetViewOnTop("commitMessage"); err != nil { + return err + } + + if err := gui.switchFocus(g, filesView, commitMessageView); err != nil { + return err + } + gui.RenderCommitLength() return nil }) @@ -509,15 +514,6 @@ func (gui *Gui) handleSwitchToMerge(g *gocui.Gui, v *gocui.View) error { return gui.refreshMergePanel() } -func (gui *Gui) handleAbortMerge(g *gocui.Gui, v *gocui.View) error { - if err := gui.GitCommand.AbortMerge(); err != nil { - return gui.createErrorPanel(g, err.Error()) - } - gui.createMessagePanel(g, v, "", gui.Tr.SLocalize("MergeAborted")) - gui.refreshStatus(g) - return gui.refreshFiles() -} - func (gui *Gui) openFile(filename string) error { if err := gui.OSCommand.OpenFile(filename); err != nil { return gui.createErrorPanel(gui.g, err.Error()) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index db3787f7c..4321cc11b 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -81,7 +81,7 @@ type Gui struct { GitCommand *commands.GitCommand OSCommand *commands.OSCommand SubProcess *exec.Cmd - State guiState + State *guiState Config config.AppConfigurer Tr *i18n.Localizer Errors SentinelErrors @@ -221,7 +221,7 @@ type guiState struct { // NewGui builds a new gui handler func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *commands.OSCommand, tr *i18n.Localizer, config config.AppConfigurer, updater *updates.Updater) (*Gui, error) { - initialState := guiState{ + initialState := &guiState{ Files: make([]*commands.File, 0), PreviousView: "files", Commits: make([]*commands.Commit, 0), @@ -381,7 +381,9 @@ func (gui *Gui) onFocusLost(v *gocui.View, newView *gocui.View) error { return nil } if v.IsSearching() && newView.Name() != "search" { - gui.onSearchEscape() + if err := gui.onSearchEscape(); err != nil { + return err + } } switch v.Name() { case "branches": @@ -518,7 +520,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { } _, _ = g.SetViewOnBottom("limit") - g.DeleteView("limit") + _ = g.DeleteView("limit") sidePanelWidthRatio := gui.Config.GetUserConfig().GetFloat64("gui.sidePanelWidth") @@ -538,7 +540,6 @@ func (gui *Gui) layout(g *gocui.Gui) error { } } - panelSplitX := width - 1 mainPanelLeft := leftSideWidth + 1 mainPanelRight := width - 1 secondaryPanelLeft := width - 1 @@ -547,7 +548,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { if gui.State.SplitMainPanel { if gui.State.ScreenMode == SCREEN_FULL { mainPanelLeft = 0 - panelSplitX = width/2 - 4 + panelSplitX := width/2 - 4 mainPanelRight = panelSplitX secondaryPanelLeft = panelSplitX + 1 } else if width < 220 { @@ -558,7 +559,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { units := 5 leftSideWidth = width / units mainPanelLeft = leftSideWidth + 1 - panelSplitX = (1 + ((units - 1) / 2)) * width / units + panelSplitX := (1 + ((units - 1) / 2)) * width / units mainPanelRight = panelSplitX secondaryPanelLeft = panelSplitX + 1 } @@ -693,7 +694,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { if err.Error() != "unknown view" { return err } - g.SetViewOnBottom("commitMessage") + _, _ = g.SetViewOnBottom("commitMessage") commitMessageView.Title = gui.Tr.SLocalize("CommitMessage") commitMessageView.FgColor = textColor commitMessageView.Editable = true @@ -765,9 +766,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { v.BgColor = gocui.ColorDefault v.FgColor = gocui.ColorGreen v.Frame = false - if err := gui.renderString(g, "information", information); err != nil { - return err - } + gui.renderString(g, "information", information) // doing this here because it'll only happen once if err := gui.onInitialViewsCreation(); err != nil { @@ -812,9 +811,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { continue } // check if the selected line is now out of view and if so refocus it - if err := gui.focusPoint(0, listView.selectedLine, listView.lineCount, listView.view); err != nil { - return err - } + listView.view.FocusPoint(0, listView.selectedLine) } mainViewWidth, mainViewHeight := gui.getMainView().Size() @@ -909,7 +906,10 @@ func (gui *Gui) fetch(g *gocui.Gui, v *gocui.View, canAskForCredentials bool) (u _ = gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("Error"), coloredMessage, close, close) } - gui.refreshStatus(g) + if err := gui.refreshStatus(g); err != nil { + return unamePassOpend, err + } + return unamePassOpend, err } @@ -918,7 +918,7 @@ func (gui *Gui) renderGlobalOptions() error { fmt.Sprintf("%s/%s", gui.getKeyDisplay("universal.scrollUpMain"), gui.getKeyDisplay("universal.scrollDownMain")): gui.Tr.SLocalize("scroll"), fmt.Sprintf("%s %s %s %s", gui.getKeyDisplay("universal.prevBlock"), gui.getKeyDisplay("universal.nextBlock"), gui.getKeyDisplay("universal.prevItem"), gui.getKeyDisplay("universal.nextItem")): gui.Tr.SLocalize("navigate"), fmt.Sprintf("%s/%s", gui.getKeyDisplay("universal.return"), gui.getKeyDisplay("universal.quit")): gui.Tr.SLocalize("close"), - fmt.Sprintf("%s", gui.getKeyDisplay("universal.optionMenu")): gui.Tr.SLocalize("menu"), + gui.getKeyDisplay("universal.optionMenu"): gui.Tr.SLocalize("menu"), "1-5": gui.Tr.SLocalize("jump"), }) } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index ee673839c..dfc2513fa 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -162,15 +162,15 @@ func (gui *Gui) getKeyDisplay(name string) string { func GetKeyDisplay(key interface{}) string { keyInt := 0 - switch key.(type) { + switch key := key.(type) { case rune: - keyInt = int(key.(rune)) + keyInt = int(key) case gocui.Key: - value, ok := keyMapReversed[key.(gocui.Key)] + value, ok := keyMapReversed[key] if ok { return value } - keyInt = int(key.(gocui.Key)) + keyInt = int(key) } return string(keyInt) diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go index 4a0f1258d..0b5171cb1 100644 --- a/pkg/gui/line_by_line_panel.go +++ b/pkg/gui/line_by_line_panel.go @@ -88,7 +88,8 @@ func (gui *Gui) refreshLineByLinePanel(diff string, secondaryDiff string, second } gui.g.Update(func(*gocui.Gui) error { - return gui.setViewContent(gui.g, gui.getSecondaryView(), secondaryPatchParser.Render(-1, -1, nil)) + gui.setViewContent(gui.g, gui.getSecondaryView(), secondaryPatchParser.Render(-1, -1, nil)) + return nil }) return false, nil @@ -241,7 +242,8 @@ func (gui *Gui) refreshMainView() error { mainView.Wrap = false gui.g.Update(func(*gocui.Gui) error { - return gui.setViewContent(gui.g, gui.getMainView(), colorDiff) + gui.setViewContent(gui.g, gui.getMainView(), colorDiff) + return nil }) return nil diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index da511f6b2..8f7734c25 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -17,7 +17,8 @@ type menuItem struct { // list panel functions func (gui *Gui) handleMenuSelect(g *gocui.Gui, v *gocui.View) error { - return gui.focusPoint(0, gui.State.Panels.Menu.SelectedLine, gui.State.MenuItemCount, v) + v.FocusPoint(0, gui.State.Panels.Menu.SelectedLine) + return nil } // specific functions diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go index 5e6272f38..89e83b2d9 100644 --- a/pkg/gui/merge_panel.go +++ b/pkg/gui/merge_panel.go @@ -151,13 +151,19 @@ func (gui *Gui) handlePopFileSnapshot(g *gocui.Gui, v *gocui.View) error { if err != nil { return err } - ioutil.WriteFile(gitFile.Name, []byte(prevContent), 0644) + if err := ioutil.WriteFile(gitFile.Name, []byte(prevContent), 0644); err != nil { + return err + } + return gui.refreshMergePanel() } func (gui *Gui) handlePickHunk(g *gocui.Gui, v *gocui.View) error { conflict := gui.State.Panels.Merging.Conflicts[gui.State.Panels.Merging.ConflictIndex] - gui.pushFileSnapshot(g) |