stop refreshing the screen so much

This commit is contained in:
Jesse Duffield 2022-01-15 12:04:00 +11:00
parent f5b9ad8c00
commit cdcfeb396f
20 changed files with 113 additions and 172 deletions

View file

@ -51,6 +51,8 @@ func (self *cmdObjRunner) RunWithOutput(cmdObj ICmdObj) (string, error) {
return "", err return "", err
} }
self.log.WithField("command", cmdObj.ToString()).Debug("RunCommand")
if cmdObj.ShouldLog() { if cmdObj.ShouldLog() {
self.logCmdObj(cmdObj) self.logCmdObj(cmdObj)
} }

View file

@ -4,7 +4,6 @@ import (
"sync" "sync"
"time" "time"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
@ -96,11 +95,13 @@ func (gui *Gui) renderAppStatus() {
defer ticker.Stop() defer ticker.Stop()
for range ticker.C { for range ticker.C {
appStatus := gui.statusManager.getStatusString() appStatus := gui.statusManager.getStatusString()
gui.OnUIThread(func() error {
return gui.renderString(gui.Views.AppStatus, appStatus)
})
if appStatus == "" { if appStatus == "" {
gui.renderString(gui.Views.AppStatus, "")
return return
} }
gui.renderString(gui.Views.AppStatus, appStatus)
} }
}) })
} }
@ -117,7 +118,7 @@ func (gui *Gui) WithWaitingStatus(message string, f func() error) error {
gui.renderAppStatus() gui.renderAppStatus()
if err := f(); err != nil { if err := f(); err != nil {
gui.g.Update(func(g *gocui.Gui) error { gui.OnUIThread(func() error {
return gui.surfaceError(err) return gui.surfaceError(err)
}) })
} }

View file

@ -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() { if gui.Git.Patch.PatchManager.Active() && gui.Git.Patch.PatchManager.To != gui.State.CommitFileManager.GetParent() {
return gui.ask(askOpts{ return gui.ask(askOpts{
title: gui.Tr.DiscardPatch, title: gui.Tr.DiscardPatch,
prompt: gui.Tr.DiscardPatchConfirm, prompt: gui.Tr.DiscardPatchConfirm,
handlersManageFocus: true,
handleConfirm: func() error { handleConfirm: func() error {
gui.Git.Patch.PatchManager.Reset() gui.Git.Patch.PatchManager.Reset()
return enterTheFile() return enterTheFile()
}, },
handleClose: func() error {
return gui.pushContext(gui.State.Contexts.CommitFiles)
},
}) })
} }

View file

@ -40,8 +40,7 @@ func (gui *Gui) handleCommitMessageFocused() error {
}, },
) )
gui.renderString(gui.Views.Options, message) return gui.renderString(gui.Views.Options, message)
return nil
} }
func (gui *Gui) getBufferLength(view *gocui.View) string { func (gui *Gui) getBufferLength(view *gocui.View) string {

View file

@ -54,32 +54,32 @@ func (gui *Gui) createLoaderPanel(prompt string) error {
func (gui *Gui) wrappedConfirmationFunction(handlersManageFocus bool, function func() error) func() error { func (gui *Gui) wrappedConfirmationFunction(handlersManageFocus bool, function func() error) func() error {
return func() error { return func() error {
if function != nil {
if err := function(); err != nil {
return err
}
}
if err := gui.closeConfirmationPrompt(handlersManageFocus); err != nil { if err := gui.closeConfirmationPrompt(handlersManageFocus); err != nil {
return err return err
} }
if function != nil {
if err := function(); err != nil {
return gui.surfaceError(err)
}
}
return nil return nil
} }
} }
func (gui *Gui) wrappedPromptConfirmationFunction(handlersManageFocus bool, function func(string) error, getResponse func() string) func() error { func (gui *Gui) wrappedPromptConfirmationFunction(handlersManageFocus bool, function func(string) error, getResponse func() string) func() error {
return func() error { return func() error {
if err := gui.closeConfirmationPrompt(handlersManageFocus); err != nil {
return err
}
if function != nil { if function != nil {
if err := function(getResponse()); err != nil { if err := function(getResponse()); err != nil {
return gui.surfaceError(err) return gui.surfaceError(err)
} }
} }
if err := gui.closeConfirmationPrompt(handlersManageFocus); err != nil {
return err
}
return nil return nil
} }
} }
@ -176,45 +176,43 @@ func (gui *Gui) prepareConfirmationPanel(
suggestionsView.Title = fmt.Sprintf(gui.Tr.SuggestionsTitle, gui.UserConfig.Keybinding.Universal.TogglePanel) 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 return nil
} }
func (gui *Gui) createPopupPanel(opts createPopupPanelOpts) error { func (gui *Gui) createPopupPanel(opts createPopupPanelOpts) error {
gui.g.Update(func(g *gocui.Gui) error { // remove any previous keybindings
// remove any previous keybindings gui.clearConfirmationViewKeyBindings()
gui.clearConfirmationViewKeyBindings()
err := gui.prepareConfirmationPanel( err := gui.prepareConfirmationPanel(
opts.title, opts.title,
opts.prompt, opts.prompt,
opts.hasLoader, opts.hasLoader,
opts.findSuggestionsFunc, opts.findSuggestionsFunc,
opts.editable, opts.editable,
) )
if err != nil { 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 return err
} }
confirmationView := gui.Views.Confirmation }
confirmationView.Editable = opts.editable
confirmationView.Editor = gocui.EditorFunc(gui.defaultEditor)
if opts.editable { if err := gui.setKeyBindings(opts); err != nil {
textArea := confirmationView.TextArea return err
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 gui.pushContext(gui.State.Contexts.Confirmation)
})
return nil
} }
func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error { 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 var onConfirm func() error
if opts.handleConfirmPrompt != nil { if opts.handleConfirmPrompt != nil {
onConfirm = gui.wrappedPromptConfirmationFunction(opts.handlersManageFocus, opts.handleConfirmPrompt, func() string { return gui.Views.Confirmation.TextArea.GetContent() }) onConfirm = gui.wrappedPromptConfirmationFunction(opts.handlersManageFocus, opts.handleConfirmPrompt, func() string { return gui.Views.Confirmation.TextArea.GetContent() })

View file

@ -71,21 +71,17 @@ func (gui *Gui) currentContextKeyIgnoringPopups() ContextKey {
// use replaceContext when you don't want to return to the original context upon // 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. // hitting escape: you want to go that context's parent instead.
func (gui *Gui) replaceContext(c Context) error { func (gui *Gui) replaceContext(c Context) error {
gui.g.Update(func(*gocui.Gui) error { gui.State.ContextManager.Lock()
gui.State.ContextManager.Lock() defer gui.State.ContextManager.Unlock()
defer gui.State.ContextManager.Unlock()
if len(gui.State.ContextManager.ContextStack) == 0 { if len(gui.State.ContextManager.ContextStack) == 0 {
gui.State.ContextManager.ContextStack = []Context{c} gui.State.ContextManager.ContextStack = []Context{c}
} else { } else {
// replace the last item with the given item // 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.ContextStack = append(gui.State.ContextManager.ContextStack[0:len(gui.State.ContextManager.ContextStack)-1], c)
} }
return gui.activateContext(c) return gui.activateContext(c)
})
return nil
} }
func (gui *Gui) pushContext(c Context, opts ...OnFocusOpts) error { 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") 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() gui.State.ContextManager.Lock()
// push onto stack // push onto stack
@ -139,14 +127,6 @@ func (gui *Gui) pushContextWithView(viewName string) error {
} }
func (gui *Gui) returnFromContext() 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() gui.State.ContextManager.Lock()
if len(gui.State.ContextManager.ContextStack) == 1 { if len(gui.State.ContextManager.ContextStack) == 1 {

View file

@ -3,7 +3,6 @@ package gui
import ( import (
"strings" "strings"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/utils" "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 // promptUserForCredential wait for a username, password or passphrase input from the credentials popup
func (gui *Gui) promptUserForCredential(passOrUname oscommands.CredentialType) string { func (gui *Gui) promptUserForCredential(passOrUname oscommands.CredentialType) string {
gui.credentials = make(chan string) gui.credentials = make(chan string)
gui.g.Update(func(g *gocui.Gui) error { gui.OnUIThread(func() error {
credentialsView := gui.Views.Credentials credentialsView := gui.Views.Credentials
switch passOrUname { switch passOrUname {
case oscommands.Username: case oscommands.Username:
@ -68,8 +67,7 @@ func (gui *Gui) handleCredentialsViewFocused() error {
}, },
) )
gui.renderString(gui.Views.Options, message) return gui.renderString(gui.Views.Options, message)
return nil
} }
// handleCredentialsPopup handles the views after executing a command that might ask for credentials // handleCredentialsPopup handles the views after executing a command that might ask for credentials

View file

@ -27,6 +27,7 @@ func setupGuiForTest(gui *Gui) {
gui.g = &gocui.Gui{} gui.g = &gocui.Gui{}
gui.Views.Main, _ = gui.prepareView("main") gui.Views.Main, _ = gui.prepareView("main")
gui.Views.Secondary, _ = gui.prepareView("secondary") gui.Views.Secondary, _ = gui.prepareView("secondary")
gui.Views.Options, _ = gui.prepareView("options")
gui.Git.Patch.PatchManager = &patch.PatchManager{} gui.Git.Patch.PatchManager = &patch.PatchManager{}
_, _ = gui.refreshLineByLinePanel(diffForTest, "", false, 11) _, _ = gui.refreshLineByLinePanel(diffForTest, "", false, 11)
} }
@ -47,7 +48,7 @@ func TestIncreasesContextInDiffViewByOneInContextWithDiff(t *testing.T) {
context := c(gui) context := c(gui)
setupGuiForTest(gui) setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 1 gui.UserConfig.Git.DiffContextSize = 1
_ = gui.pushContextDirect(context) _ = gui.pushContext(context)
_ = gui.IncreaseContextInDiffView() _ = gui.IncreaseContextInDiffView()
@ -73,7 +74,7 @@ func TestDoesntIncreaseContextInDiffViewInContextWithoutDiff(t *testing.T) {
context := c(gui) context := c(gui)
setupGuiForTest(gui) setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 1 gui.UserConfig.Git.DiffContextSize = 1
_ = gui.pushContextDirect(context) _ = gui.pushContext(context)
_ = gui.IncreaseContextInDiffView() _ = gui.IncreaseContextInDiffView()
@ -97,7 +98,7 @@ func TestDecreasesContextInDiffViewByOneInContextWithDiff(t *testing.T) {
context := c(gui) context := c(gui)
setupGuiForTest(gui) setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 2 gui.UserConfig.Git.DiffContextSize = 2
_ = gui.pushContextDirect(context) _ = gui.pushContext(context)
_ = gui.DecreaseContextInDiffView() _ = gui.DecreaseContextInDiffView()
@ -123,7 +124,7 @@ func TestDoesntDecreaseContextInDiffViewInContextWithoutDiff(t *testing.T) {
context := c(gui) context := c(gui)
setupGuiForTest(gui) setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 2 gui.UserConfig.Git.DiffContextSize = 2
_ = gui.pushContextDirect(context) _ = gui.pushContext(context)
_ = gui.DecreaseContextInDiffView() _ = gui.DecreaseContextInDiffView()
@ -135,7 +136,7 @@ func TestDoesntIncreaseContextInDiffViewInContextWhenInPatchBuildingMode(t *test
gui := NewDummyGui() gui := NewDummyGui()
setupGuiForTest(gui) setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 2 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) gui.Git.Patch.PatchManager.Start("from", "to", false, false)
errorCount := 0 errorCount := 0
@ -157,7 +158,7 @@ func TestDoesntDecreaseContextInDiffViewInContextWhenInPatchBuildingMode(t *test
gui := NewDummyGui() gui := NewDummyGui()
setupGuiForTest(gui) setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 2 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) gui.Git.Patch.PatchManager.Start("from", "to", false, false)
errorCount := 0 errorCount := 0

View file

@ -5,7 +5,6 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/loaders" "github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
@ -98,7 +97,7 @@ func (gui *Gui) refreshFilesAndSubmodules() error {
return err return err
} }
gui.g.Update(func(g *gocui.Gui) error { gui.OnUIThread(func() error {
if err := gui.postRefreshUpdate(gui.State.Contexts.Submodules); err != nil { if err := gui.postRefreshUpdate(gui.State.Contexts.Submodules); err != nil {
gui.Log.Error(err) 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() newSelectedPath := gui.getSelectedPath()
alreadySelected := selectedPath != "" && newSelectedPath == selectedPath alreadySelected := selectedPath != "" && newSelectedPath == selectedPath
if !alreadySelected { 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 {
if err := gui.pushContext(gui.State.Contexts.CommitMessage); err != nil { return err
return err }
}
gui.RenderCommitLength() gui.RenderCommitLength()
return nil
})
return nil return nil
} }

View file

@ -768,3 +768,9 @@ func (gui *Gui) setColorScheme() error {
return nil return nil
} }
func (gui *Gui) OnUIThread(f func() error) {
gui.g.Update(func(*gocui.Gui) error {
return f()
})
}

View file

@ -48,7 +48,7 @@ func (gui *Gui) createAllViews() error {
gui.Views.SearchPrefix.BgColor = gocui.ColorDefault gui.Views.SearchPrefix.BgColor = gocui.ColorDefault
gui.Views.SearchPrefix.FgColor = gocui.ColorGreen gui.Views.SearchPrefix.FgColor = gocui.ColorGreen
gui.Views.SearchPrefix.Frame = false 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.Title = gui.Tr.StashTitle
gui.Views.Stash.FgColor = theme.GocuiDefaultTextColor 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" gui.Views.CommitFiles.Visible = gui.getViewNameForWindow(gui.State.Contexts.CommitFiles.GetWindowName()) == "commitFiles"
if gui.State.OldInformation != informationStr { if gui.State.OldInformation != informationStr {
gui.setViewContentSync(gui.Views.Information, informationStr) gui.setViewContent(gui.Views.Information, informationStr)
gui.State.OldInformation = informationStr gui.State.OldInformation = informationStr
} }

View file

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"github.com/go-errors/errors" "github.com/go-errors/errors"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/patch" "github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/gui/lbl" "github.com/jesseduffield/lazygit/pkg/gui/lbl"
) )
@ -172,15 +171,11 @@ func (gui *Gui) focusSelection(state *LblPanelState) error {
newOrigin := state.CalculateOrigin(origin, bufferHeight) newOrigin := state.CalculateOrigin(origin, bufferHeight)
gui.g.Update(func(*gocui.Gui) error { if err := stagingView.SetOriginY(newOrigin); err != nil {
if err := stagingView.SetOriginY(newOrigin); err != nil { return err
return err }
}
return stagingView.SetCursor(0, selectedLineIdx-newOrigin) return stagingView.SetCursor(0, selectedLineIdx-newOrigin)
})
return nil
} }
func (gui *Gui) handleToggleSelectRange() error { func (gui *Gui) handleToggleSelectRange() error {

View file

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/theme" "github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
) )
@ -89,11 +88,7 @@ func (gui *Gui) createMenu(title string, items []*menuItem, createMenuOptions cr
menuView.SetContent(list) menuView.SetContent(list)
gui.State.Panels.Menu.SelectedLineIdx = 0 gui.State.Panels.Menu.SelectedLineIdx = 0
gui.g.Update(func(g *gocui.Gui) error { return gui.pushContext(gui.State.Contexts.Menu)
return gui.pushContext(gui.State.Contexts.Menu)
})
return nil
} }
func (gui *Gui) onMenuPress() error { func (gui *Gui) onMenuPress() error {

View file

@ -222,9 +222,7 @@ func (gui *Gui) centerYPos(view *gocui.View, y int) {
ox, _ := view.Origin() ox, _ := view.Origin()
_, height := view.Size() _, height := view.Size()
newOriginY := int(math.Max(0, float64(y-(height/2)))) newOriginY := int(math.Max(0, float64(y-(height/2))))
gui.g.Update(func(g *gocui.Gui) error { _ = view.SetOrigin(ox, newOriginY)
return view.SetOrigin(ox, newOriginY)
})
} }
func (gui *Gui) getMergingOptions() map[string]string { func (gui *Gui) getMergingOptions() map[string]string {

View file

@ -4,7 +4,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/commands/git_config" "github.com/jesseduffield/lazygit/pkg/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/env" "github.com/jesseduffield/lazygit/pkg/env"
@ -77,19 +76,15 @@ func (gui *Gui) dispatchSwitchToRepo(path string, reuse bool) error {
} }
gui.Git = newGitCommand 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
// 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
// switch to a repo while one of these goroutines is in the process of updating something gui.Mutexes.FetchMutex.Lock()
gui.Mutexes.FetchMutex.Lock() defer gui.Mutexes.FetchMutex.Unlock()
defer gui.Mutexes.FetchMutex.Unlock()
gui.Mutexes.RefreshingFilesMutex.Lock() gui.Mutexes.RefreshingFilesMutex.Lock()
defer gui.Mutexes.RefreshingFilesMutex.Unlock() defer gui.Mutexes.RefreshingFilesMutex.Unlock()
gui.resetState("", reuse) gui.resetState("", reuse)
return nil
})
return nil return nil
} }

View file

@ -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 { return func(y int, index int, total int) error {
if total == 0 { if total == 0 {
gui.renderString( return gui.renderString(
gui.Views.Search, gui.Views.Search,
fmt.Sprintf( fmt.Sprintf(
"no matches for '%s' %s", "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)), theme.OptionsFgColor.Sprintf("%s: exit search mode", gui.getKeyDisplay(keybindingConfig.Universal.Return)),
), ),
) )
return nil
} }
gui.renderString( _ = gui.renderString(
gui.Views.Search, gui.Views.Search,
fmt.Sprintf( fmt.Sprintf(
"matches for '%s' (%d of %d) %s", "matches for '%s' (%d of %d) %s",

View file

@ -102,21 +102,13 @@ func (gui *Gui) handleResetSelection() error {
if !gui.UserConfig.Gui.SkipUnstageLineWarning { if !gui.UserConfig.Gui.SkipUnstageLineWarning {
return gui.ask(askOpts{ return gui.ask(askOpts{
title: gui.Tr.UnstageLinesTitle, title: gui.Tr.UnstageLinesTitle,
prompt: gui.Tr.UnstageLinesPrompt, prompt: gui.Tr.UnstageLinesPrompt,
handlersManageFocus: true,
handleConfirm: func() error { handleConfirm: func() error {
return gui.withLBLActiveCheck(func(state *LblPanelState) 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) return gui.applySelection(true, state)
}) })
}, },
handleClose: func() error {
return gui.pushContext(gui.State.Contexts.Staging)
},
}) })
} else { } else {
return gui.applySelection(true, state) return gui.applySelection(true, state)

View file

@ -68,8 +68,7 @@ func (gui *Gui) newStringTaskWithKey(view *gocui.View, str string, key string) e
manager := gui.getManager(view) manager := gui.getManager(view)
f := func(stop chan struct{}) error { f := func(stop chan struct{}) error {
gui.renderString(view, str) return gui.renderString(view, str)
return nil
} }
if err := manager.NewTask(f, key); err != nil { if err := manager.NewTask(f, key); err != nil {

View file

@ -52,10 +52,14 @@ func (gui *Gui) startUpdating(newVersion string) {
func (gui *Gui) onUpdateFinish(statusId int, err error) error { func (gui *Gui) onUpdateFinish(statusId int, err error) error {
gui.State.Updating = false gui.State.Updating = false
gui.statusManager.removeStatus(statusId) gui.statusManager.removeStatus(statusId)
gui.renderString(gui.Views.AppStatus, "") gui.OnUIThread(func() error {
if err != nil { _ = gui.renderString(gui.Views.AppStatus, "")
return gui.createErrorPanel("Update failed: " + err.Error()) if err != nil {
} return gui.createErrorPanel("Update failed: " + err.Error())
}
return nil
})
return nil return nil
} }

View file

@ -180,7 +180,7 @@ func (gui *Gui) refreshSidePanels(options refreshOptions) error {
} }
if options.mode == BLOCK_UI { if options.mode == BLOCK_UI {
gui.g.Update(func(g *gocui.Gui) error { gui.OnUIThread(func() error {
f() f()
return nil return nil
}) })
@ -201,32 +201,19 @@ func (gui *Gui) cleanString(s string) string {
return utils.NormalizeLinefeeds(output) return utils.NormalizeLinefeeds(output)
} }
func (gui *Gui) setViewContentSync(v *gocui.View, s string) { func (gui *Gui) setViewContent(v *gocui.View, s string) {
v.SetContent(gui.cleanString(s)) 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
})
}
// renderString resets the origin of a view and sets its content // renderString resets the origin of a view and sets its content
func (gui *Gui) renderString(view *gocui.View, s string) { func (gui *Gui) renderString(view *gocui.View, s string) error {
gui.g.Update(func(*gocui.Gui) error {
return gui.renderStringSync(view, s)
})
}
func (gui *Gui) renderStringSync(view *gocui.View, s string) error {
if err := view.SetOrigin(0, 0); err != nil { if err := view.SetOrigin(0, 0); err != nil {
return err return err
} }
if err := view.SetCursor(0, 0); err != nil { if err := view.SetCursor(0, 0); err != nil {
return err return err
} }
gui.setViewContentSync(view, s) gui.setViewContent(view, s)
return nil return nil
} }
@ -240,7 +227,7 @@ func (gui *Gui) optionsMapToString(optionsMap map[string]string) string {
} }
func (gui *Gui) renderOptionsMap(optionsMap map[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 { func (gui *Gui) currentViewName() string {
@ -391,5 +378,5 @@ func getTabbedView(gui *Gui) *gocui.View {
} }
func (gui *Gui) render() { func (gui *Gui) render() {
gui.g.Update(func(g *gocui.Gui) error { return nil }) gui.OnUIThread(func() error { return nil })
} }