mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-04 03:48:07 +02:00
stop refreshing the screen so much
This commit is contained in:
parent
f5b9ad8c00
commit
cdcfeb396f
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
@ -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)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 function != nil {
|
||||
if err := function(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := gui.closeConfirmationPrompt(handlersManageFocus); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if function != nil {
|
||||
if err := function(); err != nil {
|
||||
return gui.surfaceError(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()
|
||||
// remove any previous keybindings
|
||||
gui.clearConfirmationViewKeyBindings()
|
||||
|
||||
err := gui.prepareConfirmationPanel(
|
||||
opts.title,
|
||||
opts.prompt,
|
||||
opts.hasLoader,
|
||||
opts.findSuggestionsFunc,
|
||||
opts.editable,
|
||||
)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
}
|
||||
if err := gui.setKeyBindings(opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return gui.setKeyBindings(opts)
|
||||
})
|
||||
return nil
|
||||
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() })
|
||||
|
@ -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()
|
||||
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)
|
||||
}
|
||||
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 gui.activateContext(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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
if err := stagingView.SetOriginY(newOrigin); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return stagingView.SetCursor(0, selectedLineIdx-newOrigin)
|
||||
})
|
||||
|
||||
return nil
|
||||
return stagingView.SetCursor(0, selectedLineIdx-newOrigin)
|
||||
}
|
||||
|
||||
func (gui *Gui) handleToggleSelectRange() error {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
func (gui *Gui) setViewContent(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
|
||||
})
|
||||
}
|
||||
|
||||
// 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 })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user