mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	stop refreshing the screen so much
This commit is contained in:
		| @@ -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) | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -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) | ||||||
| 			}) | 			}) | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -228,14 +228,10 @@ func (gui *Gui) enterCommitFile(opts OnFocusOpts) error { | |||||||
| 		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) |  | ||||||
| 			}, |  | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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 { | ||||||
|   | |||||||
| @@ -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,14 +176,10 @@ 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() | ||||||
|  |  | ||||||
| @@ -207,14 +203,16 @@ func (gui *Gui) createPopupPanel(opts createPopupPanelOpts) error { | |||||||
| 		textArea.TypeString(opts.prompt) | 		textArea.TypeString(opts.prompt) | ||||||
| 		confirmationView.RenderTextArea() | 		confirmationView.RenderTextArea() | ||||||
| 	} else { | 	} else { | ||||||
| 			if err := gui.renderStringSync(confirmationView, opts.prompt); err != nil { | 		if err := gui.renderString(confirmationView, opts.prompt); err != nil { | ||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 		return gui.setKeyBindings(opts) | 	if err := gui.setKeyBindings(opts); err != nil { | ||||||
| 	}) | 		return err | ||||||
| 	return nil | 	} | ||||||
|  |  | ||||||
|  | 	return gui.pushContext(gui.State.Contexts.Confirmation) | ||||||
| } | } | ||||||
|  |  | ||||||
| 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() }) | ||||||
|   | |||||||
| @@ -71,7 +71,6 @@ 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() | ||||||
|  |  | ||||||
| @@ -83,9 +82,6 @@ func (gui *Gui) replaceContext(c Context) error { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	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 { | ||||||
|   | |||||||
| @@ -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 | ||||||
|   | |||||||
| @@ -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 | ||||||
|   | |||||||
| @@ -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,15 +406,12 @@ 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 |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func (gui *Gui) promptToStageAllAndRetry(retry func() error) error { | func (gui *Gui) promptToStageAllAndRetry(retry func() error) error { | ||||||
|   | |||||||
| @@ -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() | ||||||
|  | 	}) | ||||||
|  | } | ||||||
|   | |||||||
| @@ -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 | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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 { | ||||||
|   | |||||||
| @@ -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 { | ||||||
|   | |||||||
| @@ -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 { | ||||||
|   | |||||||
| @@ -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,7 +76,6 @@ 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() | ||||||
| @@ -88,9 +86,6 @@ func (gui *Gui) dispatchSwitchToRepo(path string, reuse bool) error { | |||||||
|  |  | ||||||
| 	gui.resetState("", reuse) | 	gui.resetState("", reuse) | ||||||
|  |  | ||||||
| 		return nil |  | ||||||
| 	}) |  | ||||||
|  |  | ||||||
| 	return nil | 	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 { | 	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", | ||||||
|   | |||||||
| @@ -104,19 +104,11 @@ func (gui *Gui) handleResetSelection() error { | |||||||
| 			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) | ||||||
|   | |||||||
| @@ -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 { | ||||||
|   | |||||||
| @@ -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 { | ||||||
|  | 		_ = gui.renderString(gui.Views.AppStatus, "") | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return gui.createErrorPanel("Update failed: " + err.Error()) | 			return gui.createErrorPanel("Update failed: " + err.Error()) | ||||||
| 		} | 		} | ||||||
|  | 		return nil | ||||||
|  | 	}) | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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 }) | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user