diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-15 12:04:00 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-15 14:15:41 +1100 |
commit | cdcfeb396fda1e61dee9b6d88ab4659152a10948 (patch) | |
tree | 6b796b8ffc9e30c08e5249e936feacca76f8d8ba /pkg | |
parent | f5b9ad8c002eb359959d41f4cd494007ca3e9bf3 (diff) |
stop refreshing the screen so much
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/oscommands/cmd_obj_runner.go | 2 | ||||
-rw-r--r-- | pkg/gui/app_status_manager.go | 9 | ||||
-rw-r--r-- | pkg/gui/commit_files_panel.go | 8 | ||||
-rw-r--r-- | pkg/gui/commit_message_panel.go | 3 | ||||
-rw-r--r-- | pkg/gui/confirmation_panel.go | 82 | ||||
-rw-r--r-- | pkg/gui/context.go | 38 | ||||
-rw-r--r-- | pkg/gui/credentials_panel.go | 6 | ||||
-rw-r--r-- | pkg/gui/diff_context_size_test.go | 13 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 16 | ||||
-rw-r--r-- | pkg/gui/gui.go | 6 | ||||
-rw-r--r-- | pkg/gui/layout.go | 4 | ||||
-rw-r--r-- | pkg/gui/line_by_line_panel.go | 13 | ||||
-rw-r--r-- | pkg/gui/menu_panel.go | 7 | ||||
-rw-r--r-- | pkg/gui/merge_panel.go | 4 | ||||
-rw-r--r-- | pkg/gui/recent_repos_panel.go | 19 | ||||
-rw-r--r-- | pkg/gui/searching.go | 5 | ||||
-rw-r--r-- | pkg/gui/staging_panel.go | 12 | ||||
-rw-r--r-- | pkg/gui/tasks_adapter.go | 3 | ||||
-rw-r--r-- | pkg/gui/updates.go | 12 | ||||
-rw-r--r-- | pkg/gui/view_helpers.go | 25 |
20 files changed, 114 insertions, 173 deletions
diff --git a/pkg/commands/oscommands/cmd_obj_runner.go b/pkg/commands/oscommands/cmd_obj_runner.go index 24ce5a73b..37f46e76d 100644 --- a/pkg/commands/oscommands/cmd_obj_runner.go +++ b/pkg/commands/oscommands/cmd_obj_runner.go @@ -51,6 +51,8 @@ func (self *cmdObjRunner) RunWithOutput(cmdObj ICmdObj) (string, error) { return "", err } + self.log.WithField("command", cmdObj.ToString()).Debug("RunCommand") + if cmdObj.ShouldLog() { self.logCmdObj(cmdObj) } diff --git a/pkg/gui/app_status_manager.go b/pkg/gui/app_status_manager.go index 1fcad4f30..e625fcad2 100644 --- a/pkg/gui/app_status_manager.go +++ b/pkg/gui/app_status_manager.go @@ -4,7 +4,6 @@ import ( "sync" "time" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -96,11 +95,13 @@ func (gui *Gui) renderAppStatus() { defer ticker.Stop() for range ticker.C { appStatus := gui.statusManager.getStatusString() + gui.OnUIThread(func() error { + return gui.renderString(gui.Views.AppStatus, appStatus) + }) + if appStatus == "" { - gui.renderString(gui.Views.AppStatus, "") return } - gui.renderString(gui.Views.AppStatus, appStatus) } }) } @@ -117,7 +118,7 @@ func (gui *Gui) WithWaitingStatus(message string, f func() error) error { gui.renderAppStatus() if err := f(); err != nil { - gui.g.Update(func(g *gocui.Gui) error { + gui.OnUIThread(func() error { return gui.surfaceError(err) }) } diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index e28c5bd7b..7e1ecd130 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -226,16 +226,12 @@ func (gui *Gui) enterCommitFile(opts OnFocusOpts) error { if gui.Git.Patch.PatchManager.Active() && gui.Git.Patch.PatchManager.To != gui.State.CommitFileManager.GetParent() { return gui.ask(askOpts{ - title: gui.Tr.DiscardPatch, - prompt: gui.Tr.DiscardPatchConfirm, - handlersManageFocus: true, + title: gui.Tr.DiscardPatch, + prompt: gui.Tr.DiscardPatchConfirm, handleConfirm: func() error { gui.Git.Patch.PatchManager.Reset() return enterTheFile() }, - handleClose: func() error { - return gui.pushContext(gui.State.Contexts.CommitFiles) - }, }) } diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index 292e37a68..5f5a8741f 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -40,8 +40,7 @@ func (gui *Gui) handleCommitMessageFocused() error { }, ) - gui.renderString(gui.Views.Options, message) - return nil + return gui.renderString(gui.Views.Options, message) } func (gui *Gui) getBufferLength(view *gocui.View) string { diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index bf17bcc52..ecb7d26ac 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -54,32 +54,32 @@ func (gui *Gui) createLoaderPanel(prompt string) error { func (gui *Gui) wrappedConfirmationFunction(handlersManageFocus bool, function func() error) func() error { return func() error { + if err := gui.closeConfirmationPrompt(handlersManageFocus); err != nil { + return err + } + if function != nil { if err := function(); err != nil { - return err + return gui.surfaceError(err) } } - if err := gui.closeConfirmationPrompt(handlersManageFocus); err != nil { - return err - } - return nil } } func (gui *Gui) wrappedPromptConfirmationFunction(handlersManageFocus bool, function func(string) error, getResponse func() string) func() error { return func() error { + if err := gui.closeConfirmationPrompt(handlersManageFocus); err != nil { + return err + } + if function != nil { if err := function(getResponse()); err != nil { return gui.surfaceError(err) } } - if err := gui.closeConfirmationPrompt(handlersManageFocus); err != nil { - return err - } - return nil } } @@ -176,45 +176,43 @@ func (gui *Gui) prepareConfirmationPanel( suggestionsView.Title = fmt.Sprintf(gui.Tr.SuggestionsTitle, gui.UserConfig.Keybinding.Universal.TogglePanel) } - gui.g.Update(func(g *gocui.Gui) error { - return gui.pushContext(gui.State.Contexts.Confirmation) - }) return nil } func (gui *Gui) createPopupPanel(opts createPopupPanelOpts) error { - gui.g.Update(func(g *gocui.Gui) error { - // remove any previous keybindings - gui.clearConfirmationViewKeyBindings() - - err := gui.prepareConfirmationPanel( - opts.title, - opts.prompt, - opts.hasLoader, - opts.findSuggestionsFunc, - opts.editable, - ) - if err != nil { + // remove any previous keybindings + gui.clearConfirmationViewKeyBindings() + + err := gui.prepareConfirmationPanel( + opts.title, + opts.prompt, + opts.hasLoader, + opts.findSuggestionsFunc, + opts.editable, + ) + if err != nil { + return err + } + confirmationView := gui.Views.Confirmation + confirmationView.Editable = opts.editable + confirmationView.Editor = gocui.EditorFunc(gui.defaultEditor) + + if opts.editable { + textArea := confirmationView.TextArea + textArea.Clear() + textArea.TypeString(opts.prompt) + confirmationView.RenderTextArea() + } else { + if err := gui.renderString(confirmationView, opts.prompt); err != nil { return err } - confirmationView := gui.Views.Confirmation - confirmationView.Editable = opts.editable - confirmationView.Editor = gocui.EditorFunc(gui.defaultEditor) - - if opts.editable { - textArea := confirmationView.TextArea - textArea.Clear() - textArea.TypeString(opts.prompt) - confirmationView.RenderTextArea() - } else { - if err := gui.renderStringSync(confirmationView, opts.prompt); err != nil { - return err - } - } + } - return gui.setKeyBindings(opts) - }) - return nil + if err := gui.setKeyBindings(opts); err != nil { + return err + } + + return gui.pushContext(gui.State.Contexts.Confirmation) } func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error { @@ -226,7 +224,7 @@ func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error { }, ) - gui.renderString(gui.Views.Options, actions) + _ = gui.renderString(gui.Views.Options, actions) var onConfirm func() error if opts.handleConfirmPrompt != nil { onConfirm = gui.wrappedPromptConfirmationFunction(opts.handlersManageFocus, opts.handleConfirmPrompt, func() string { return gui.Views.Confirmation.TextArea.GetContent() }) diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 2c9d20f7e..7aa9a1046 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -71,21 +71,17 @@ func (gui *Gui) currentContextKeyIgnoringPopups() ContextKey { // use replaceContext when you don't want to return to the original context upon // hitting escape: you want to go that context's parent instead. func (gui *Gui) replaceContext(c Context) error { - gui.g.Update(func(*gocui.Gui) error { - gui.State.ContextManager.Lock() - defer gui.State.ContextManager.Unlock() - - if len(gui.State.ContextManager.ContextStack) == 0 { - gui.State.ContextManager.ContextStack = []Context{c} - } else { - // replace the last item with the given item - gui.State.ContextManager.ContextStack = append(gui.State.ContextManager.ContextStack[0:len(gui.State.ContextManager.ContextStack)-1], c) - } + gui.State.ContextManager.Lock() + defer gui.State.ContextManager.Unlock() - return gui.activateContext(c) - }) + if len(gui.State.ContextManager.ContextStack) == 0 { + gui.State.ContextManager.ContextStack = []Context{c} + } else { + // replace the last item with the given item + gui.State.ContextManager.ContextStack = append(gui.State.ContextManager.ContextStack[0:len(gui.State.ContextManager.ContextStack)-1], c) + } - return nil + return gui.activateContext(c) } func (gui *Gui) pushContext(c Context, opts ...OnFocusOpts) error { @@ -94,14 +90,6 @@ func (gui *Gui) pushContext(c Context, opts ...OnFocusOpts) error { return errors.New("cannot pass multiple opts to pushContext") } - gui.g.Update(func(*gocui.Gui) error { - return gui.pushContextDirect(c, opts...) - }) - - return nil -} - -func (gui *Gui) pushContextDirect(c Context, opts ...OnFocusOpts) error { gui.State.ContextManager.Lock() // push onto stack @@ -139,14 +127,6 @@ func (gui *Gui) pushContextWithView(viewName string) error { } func (gui *Gui) returnFromContext() error { - gui.g.Update(func(*gocui.Gui) error { - return gui.returnFromContextSync() - }) - - return nil -} - -func (gui *Gui) returnFromContextSync() error { gui.State.ContextManager.Lock() if len(gui.State.ContextManager.ContextStack) == 1 { diff --git a/pkg/gui/credentials_panel.go b/pkg/gui/credentials_panel.go index b4c313e07..984591a62 100644 --- a/pkg/gui/credentials_panel.go +++ b/pkg/gui/credentials_panel.go @@ -3,7 +3,6 @@ package gui import ( "strings" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -13,7 +12,7 @@ type credentials chan string // promptUserForCredential wait for a username, password or passphrase input from the credentials popup func (gui *Gui) promptUserForCredential(passOrUname oscommands.CredentialType) string { gui.credentials = make(chan string) - gui.g.Update(func(g *gocui.Gui) error { + gui.OnUIThread(func() error { credentialsView := gui.Views.Credentials switch passOrUname { case oscommands.Username: @@ -68,8 +67,7 @@ func (gui *Gui) handleCredentialsViewFocused() error { }, ) - gui.renderString(gui.Views.Options, message) - return nil + return gui.renderString(gui.Views.Options, message) } // handleCredentialsPopup handles the views after executing a command that might ask for credentials diff --git a/pkg/gui/diff_context_size_test.go b/pkg/gui/diff_context_size_test.go index 4fd923bc2..11bd0712b 100644 --- a/pkg/gui/diff_context_size_test.go +++ b/pkg/gui/diff_context_size_test.go @@ -27,6 +27,7 @@ func setupGuiForTest(gui *Gui) { gui.g = &gocui.Gui{} gui.Views.Main, _ = gui.prepareView("main") gui.Views.Secondary, _ = gui.prepareView("secondary") + gui.Views.Options, _ = gui.prepareView("options") gui.Git.Patch.PatchManager = &patch.PatchManager{} _, _ = gui.refreshLineByLinePanel(diffForTest, "", false, 11) } @@ -47,7 +48,7 @@ func TestIncreasesContextInDiffViewByOneInContextWithDiff(t *testing.T) { context := c(gui) setupGuiForTest(gui) gui.UserConfig.Git.DiffContextSize = 1 - _ = gui.pushContextDirect(context) + _ = gui.pushContext(context) _ = gui.IncreaseContextInDiffView() @@ -73,7 +74,7 @@ func TestDoesntIncreaseContextInDiffViewInContextWithoutDiff(t *testing.T) { context := c(gui) setupGuiForTest(gui) gui.UserConfig.Git.DiffContextSize = 1 - _ = gui.pushContextDirect(context) + _ = gui.pushContext(context) _ = gui.IncreaseContextInDiffView() @@ -97,7 +98,7 @@ func TestDecreasesContextInDiffViewByOneInContextWithDiff(t *testing.T) { context := c(gui) setupGuiForTest(gui) gui.UserConfig.Git.DiffContextSize = 2 - _ = gui.pushContextDirect(context) + _ = gui.pushContext(context) _ = gui.DecreaseContextInDiffView() @@ -123,7 +124,7 @@ func TestDoesntDecreaseContextInDiffViewInContextWithoutDiff(t *testing.T) { context := c(gui) setupGuiForTest(gui) gui.UserConfig.Git.DiffContextSize = 2 - _ = gui.pushContextDirect(context) + _ = gui.pushContext(context) _ = gui.DecreaseContextInDiffView() @@ -135,7 +136,7 @@ func TestDoesntIncreaseContextInDiffViewInContextWhenInPatchBuildingMode(t *test gui := NewDummyGui() setupGuiForTest(gui) gui.UserConfig.Git.DiffContextSize = 2 - _ = gui.pushContextDirect(gui.State.Contexts.CommitFiles) + _ = gui.pushContext(gui.State.Contexts.CommitFiles) gui.Git.Patch.PatchManager.Start("from", "to", false, false) errorCount := 0 @@ -157,7 +158,7 @@ func TestDoesntDecreaseContextInDiffViewInContextWhenInPatchBuildingMode(t *test gui := NewDummyGui() setupGuiForTest(gui) gui.UserConfig.Git.DiffContextSize = 2 - _ = gui.pushContextDirect(gui.State.Contexts.CommitFiles) + _ = gui.pushContext(gui.State.Contexts.CommitFiles) gui.Git.Patch.PatchManager.Start("from", "to", false, false) errorCount := 0 diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 1dd0f2d2c..05bf8d4ed 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -5,7 +5,6 @@ import ( "regexp" "strings" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/loaders" "github.com/jesseduffield/lazygit/pkg/commands/models" @@ -98,7 +97,7 @@ func (gui *Gui) refreshFilesAndSubmodules() error { return err } - gui.g.Update(func(g *gocui.Gui) error { + gui.OnUIThread(func() error { if err := gui.postRefreshUpdate(gui.State.Contexts.Submodules); err != nil { gui.Log.Error(err) } @@ -110,7 +109,7 @@ func (gui *Gui) refreshFilesAndSubmodules() error { } } - if gui.currentContext().GetKey() == FILES_CONTEXT_KEY || (g.CurrentView() == gui.Views.Main && ContextKey(g.CurrentView().Context) == MAIN_MERGING_CONTEXT_KEY) { + if gui.currentContext().GetKey() == FILES_CONTEXT_KEY || (gui.g.CurrentView() == gui.Views.Main && ContextKey(gui.g.CurrentView().Context) == MAIN_MERGING_CONTEXT_KEY) { newSelectedPath := gui.getSelectedPath() alreadySelected := selectedPath != "" && newSelectedPath == selectedPath if !alreadySelected { @@ -407,14 +406,11 @@ func (gui *Gui) handleCommitPress() error { } } - gui.g.Update(func(g *gocui.Gui) error { - if err := gui.pushContext(gui.State.Contexts.CommitMessage); err != nil { - return err - } + if err := gui.pushContext(gui.State.Contexts.CommitMessage); err != nil { + return err + } - gui.RenderCommitLength() - return nil - }) + gui.RenderCommitLength() return nil } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 2017a236e..328d76ef8 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -768,3 +768,9 @@ func (gui *Gui) setColorScheme() error { return nil } + +func (gui *Gui) OnUIThread(f func() error) { + gui.g.Update(func(*gocui.Gui) error { + return f() + }) +} diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index 106c8f2a0..c5872654a 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -48,7 +48,7 @@ func (gui *Gui) createAllViews() error { gui.Views.SearchPrefix.BgColor = gocui.ColorDefault gui.Views.SearchPrefix.FgColor = gocui.ColorGreen gui.Views.SearchPrefix.Frame = false - gui.setViewContentSync(gui.Views.SearchPrefix, SEARCH_PREFIX) + gui.setViewContent(gui.Views.SearchPrefix, SEARCH_PREFIX) gui.Views.Stash.Title = gui.Tr.StashTitle gui.Views.Stash.FgColor = theme.GocuiDefaultTextColor @@ -235,7 +235,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { gui.Views.CommitFiles.Visible = gui.getViewNameForWindow(gui.State.Contexts.CommitFiles.GetWindowName()) == "commitFiles" if gui.State.OldInformation != informationStr { - gui.setViewContentSync(gui.Views.Information, informationStr) + gui.setViewContent(gui.Views.Information, informationStr) gui.State.OldInformation = informationStr } diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go index 101224d70..3c1668b76 100644 --- a/pkg/gui/line_by_line_panel.go +++ b/pkg/gui/line_by_line_panel.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/go-errors/errors" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/patch" "github.com/jesseduffield/lazygit/pkg/gui/lbl" ) @@ -172,15 +171,11 @@ func (gui *Gui) focusSelection(state *LblPanelState) error { newOrigin := state.CalculateOrigin(origin, bufferHeight) - gui.g.Update(func(*gocui.Gui) error { - if err := stagingView.SetOriginY(newOrigin); err != nil { - return err - } - - return stagingView.SetCursor(0, selectedLineIdx-newOrigin) - }) + if err := stagingView.SetOriginY(newOrigin); err != nil { + return err + } - return nil + return stagingView.SetCursor(0, selectedLineIdx-newOrigin) } func (gui *Gui) handleToggleSelectRange() error { diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index 32ed2a7ea..be17d352d 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -5,7 +5,6 @@ import ( "fmt" "strings" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/theme" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -89,11 +88,7 @@ func (gui *Gui) createMenu(title string, items []*menuItem, createMenuOptions cr menuView.SetContent(list) gui.State.Panels.Menu.SelectedLineIdx = 0 - gui.g.Update(func(g *gocui.Gui) error { - return gui.pushContext(gui.State.Contexts.Menu) - }) - - return nil + return gui.pushContext(gui.State.Contexts.Menu) } func (gui *Gui) onMenuPress() error { diff --git a/pkg/gui/merge_panel.go b/pkg/gui/merge_panel.go index dafd03b24..5b7502f64 100644 --- a/pkg/gui/merge_panel.go +++ b/pkg/gui/merge_panel.go @@ -222,9 +222,7 @@ func (gui *Gui) centerYPos(view *gocui.View, y int) { ox, _ := view.Origin() _, height := view.Size() newOriginY := int(math.Max(0, float64(y-(height/2)))) - gui.g.Update(func(g *gocui.Gui) error { - return view.SetOrigin(ox, newOriginY) - }) + _ = view.SetOrigin(ox, newOriginY) } func (gui *Gui) getMergingOptions() map[string]string { diff --git a/pkg/gui/recent_repos_panel.go b/pkg/gui/recent_repos_panel.go index c2f389a78..7bf6b068c 100644 --- a/pkg/gui/recent_repos_panel.go +++ b/pkg/gui/recent_repos_panel.go @@ -4,7 +4,6 @@ import ( "os" "path/filepath" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/git_config" "github.com/jesseduffield/lazygit/pkg/env" @@ -77,19 +76,15 @@ func (gui *Gui) dispatchSwitchToRepo(path string, reuse bool) error { } gui.Git = newGitCommand - gui.g.Update(func(*gocui.Gui) error { - // these two mutexes are used by our background goroutines (triggered via `gui.goEvery`. We don't want to - // switch to a repo while one of these goroutines is in the process of updating something - gui.Mutexes.FetchMutex.Lock() - defer gui.Mutexes.FetchMutex.Unlock() + // these two mutexes are used by our background goroutines (triggered via `gui.goEvery`. We don't want to + // switch to a repo while one of these goroutines is in the process of updating something + gui.Mutexes.FetchMutex.Lock() + defer gui.Mutexes.FetchMutex.Unlock() - gui.Mutexes.RefreshingFilesMutex.Lock() - defer gui.Mutexes.RefreshingFilesMutex.Unlock() + gui.Mutexes.RefreshingFilesMutex.Lock() + defer gui.Mutexes.RefreshingFilesMutex.Unlock() - gui.resetState("", reuse) - - return nil - }) + gui.resetState("", reuse) return nil } diff --git a/pkg/gui/searching.go b/pkg/gui/searching.go index 64929afd2..dd7697363 100644 --- a/pkg/gui/searching.go +++ b/pkg/gui/searching.go @@ -47,7 +47,7 @@ func (gui *Gui) onSelectItemWrapper(innerFunc func(int) error) func(int, int, in return func(y int, index int, total int) error { if total == 0 { - gui.renderString( + return gui.renderString( gui.Views.Search, fmt.Sprintf( "no matches for '%s' %s", @@ -55,9 +55,8 @@ func (gui *Gui) onSelectItemWrapper(innerFunc func(int) error) func(int, int, in theme.OptionsFgColor.Sprintf("%s: exit search mode", gui.getKeyDisplay(keybindingConfig.Universal.Return)), ), ) - return nil } - gui.renderString( + _ = gui.renderString( gui.Views.Search, fmt.Sprintf( "matches for '%s' (%d of %d) %s", diff --git a/pkg/gui/staging_panel.go b/pkg/gui/staging_panel.go index 2afbf07cd..f4409d76c 100644 --- a/pkg/gui/staging_panel.go +++ b/pkg/gui/staging_panel.go @@ -102,21 +102,13 @@ func (gui *Gui) handleResetSelection() error { if !gui.UserConfig.Gui.SkipUnstageLineWarning { return gui.ask(askOpts{ - title: gui.Tr.UnstageLinesTitle, - prompt: gui.Tr.UnstageLinesPrompt, - handlersManageFocus: true, + title: gui.Tr.UnstageLinesTitle, + prompt: gui.Tr.UnstageLinesPrompt, handleConfirm: func() error { return gui.withLBLActiveCheck(func(state *LblPanelState) error { - if err := gui.pushContext(gui.State.Contexts.Staging); err != nil { - return err - } - return gui.applySelection(true, state) }) }, - handleClose: func() error { - return gui.pushContext(gui.State.Contexts.Staging) - }, }) } else { return gui.applySelection(true, state) diff --git a/pkg/gui/tasks_adapter.go b/pkg/gui/tasks_adapter.go index fad3e6284..4c268c14d 100644 --- a/pkg/gui/tasks_adapter.go +++ b/pkg/gui/tasks_adapter.go @@ -68,8 +68,7 @@ func (gui *Gui) newStringTaskWithKey(view *gocui.View, str string, key string) e manager := gui.getManager(view) f := func(stop chan struct{}) error { - gui.renderString(view, str) - return nil + return gui.renderString(view, str) } if err := manager.NewTask(f, key); err != nil { diff --git a/pkg/gui/updates.go b/pkg/gui/updates.go index 9b3b6771c..cce723c4f 100644 --- a/pkg/gui/updates.go +++ b/pkg/gui/updates.go @@ -52,10 +52,14 @@ func (gui *Gui) startUpdating(newVersion string) { func (gui *Gui) onUpdateFinish(statusId int, err error) error { gui.State.Updating = false gui.statusManager.removeStatus(statusId) - gui.renderString(gui.Views.AppStatus, "") - if err != nil { - return gui.createErrorPanel("Update failed: " + err.Error()) - } + gui.OnUIThread(func() error { + _ = gui.renderString(gui.Views.AppStatus, "") + if err != nil { + return gui.createErrorPanel("Update failed: " + err.Error()) + } + return nil + }) + return nil } diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 00b28b45c..3f559b400 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -180,7 +180,7 @@ func (gui *Gui) refreshSidePanels(options refreshOptions) error { } if options.mode == BLOCK_UI { - gui.g.Update(func(g *gocui.Gui) error { + gui.OnUIThread(func() error { f() return nil }) @@ -201,32 +201,19 @@ func (gui *Gui) cleanString(s string) string { return utils.NormalizeLinefeeds(output) } -func (gui *Gui) setViewContentSync(v *gocui.View, s string) { - v.SetContent(gui.cleanString(s)) -} - func (gui *Gui) setViewContent(v *gocui.View, s string) { - gui.g.Update(func(*gocui.Gui) error { - gui.setViewContentSync(v, s) - return nil - }) + v.SetContent(gui.cleanString(s)) } // renderString resets the origin of a view and sets its content -func (gui *Gui) renderString(view *gocui.View, s string) { - gui.g.Update(func(*gocui.Gui) error { - return gui.renderStringSync(view, s) - }) -} - -func (gui *Gui) renderStringSync(view *gocui.View, s string) error { +func (gui *Gui) renderString(view *gocui.View, s string) error { if err := view.SetOrigin(0, 0); err != nil { return err } if err := view.SetCursor(0, 0); err != nil { return err } - gui.setViewContentSync(view, s) + gui.setViewContent(view, s) return nil } @@ -240,7 +227,7 @@ func (gui *Gui) optionsMapToString(optionsMap map[string]string) string { } func (gui *Gui) renderOptionsMap(optionsMap map[string]string) { - gui.renderString(gui.Views.Options, gui.optionsMapToString(optionsMap)) + _ = gui.renderString(gui.Views.Options, gui.optionsMapToString(optionsMap)) } func (gui *Gui) currentViewName() string { @@ -391,5 +378,5 @@ func getTabbedView(gui *Gui) *gocui.View { } func (gui *Gui) render() { - gui.g.Update(func(g *gocui.Gui) error { return nil }) + gui.OnUIThread(func() error { return nil }) } |