mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-31 22:22:14 +02:00
Add WithWaitingStatusSync
This commit is contained in:
parent
a46f26e148
commit
79fe885dcd
pkg/gui
@ -77,6 +77,7 @@ func (gui *Gui) resetHelpersAndControllers() {
|
|||||||
appStatusHelper := helpers.NewAppStatusHelper(
|
appStatusHelper := helpers.NewAppStatusHelper(
|
||||||
helperCommon,
|
helperCommon,
|
||||||
func() *status.StatusManager { return gui.statusManager },
|
func() *status.StatusManager { return gui.statusManager },
|
||||||
|
modeHelper,
|
||||||
)
|
)
|
||||||
|
|
||||||
setSubCommits := func(commits []*models.Commit) {
|
setSubCommits := func(commits []*models.Commit) {
|
||||||
|
@ -11,13 +11,15 @@ import (
|
|||||||
type AppStatusHelper struct {
|
type AppStatusHelper struct {
|
||||||
c *HelperCommon
|
c *HelperCommon
|
||||||
|
|
||||||
statusMgr func() *status.StatusManager
|
statusMgr func() *status.StatusManager
|
||||||
|
modeHelper *ModeHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAppStatusHelper(c *HelperCommon, statusMgr func() *status.StatusManager) *AppStatusHelper {
|
func NewAppStatusHelper(c *HelperCommon, statusMgr func() *status.StatusManager, modeHelper *ModeHelper) *AppStatusHelper {
|
||||||
return &AppStatusHelper{
|
return &AppStatusHelper{
|
||||||
c: c,
|
c: c,
|
||||||
statusMgr: statusMgr,
|
statusMgr: statusMgr,
|
||||||
|
modeHelper: modeHelper,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +70,18 @@ func (self *AppStatusHelper) WithWaitingStatus(message string, f func(gocui.Task
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *AppStatusHelper) WithWaitingStatusSync(message string, f func() error) {
|
||||||
|
self.statusMgr().WithWaitingStatus(message, func() {}, func(*status.WaitingStatusHandle) {
|
||||||
|
stop := make(chan struct{})
|
||||||
|
defer func() { close(stop) }()
|
||||||
|
self.renderAppStatusSync(stop)
|
||||||
|
|
||||||
|
if err := f(); err != nil {
|
||||||
|
_ = self.c.Error(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (self *AppStatusHelper) HasStatus() bool {
|
func (self *AppStatusHelper) HasStatus() bool {
|
||||||
return self.statusMgr().HasStatus()
|
return self.statusMgr().HasStatus()
|
||||||
}
|
}
|
||||||
@ -93,3 +107,37 @@ func (self *AppStatusHelper) renderAppStatus() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *AppStatusHelper) renderAppStatusSync(stop chan struct{}) {
|
||||||
|
go func() {
|
||||||
|
ticker := time.NewTicker(time.Millisecond * 50)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
// Forcing a re-layout and redraw after we added the waiting status;
|
||||||
|
// this is needed in case the gui.showBottomLine config is set to false,
|
||||||
|
// to make sure the bottom line appears. It's also useful for redrawing
|
||||||
|
// once after each of several consecutive keypresses, e.g. pressing
|
||||||
|
// ctrl-j to move a commit down several steps.
|
||||||
|
_ = self.c.GocuiGui().ForceLayoutAndRedraw()
|
||||||
|
|
||||||
|
self.modeHelper.SetSuppressRebasingMode(true)
|
||||||
|
defer func() { self.modeHelper.SetSuppressRebasingMode(false) }()
|
||||||
|
|
||||||
|
outer:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
appStatus := self.statusMgr().GetStatusString()
|
||||||
|
self.c.SetViewContent(self.c.Views().AppStatus, appStatus)
|
||||||
|
// Redraw all views of the bottom line:
|
||||||
|
bottomLineViews := []*gocui.View{
|
||||||
|
self.c.Views().AppStatus, self.c.Views().Options, self.c.Views().Information,
|
||||||
|
self.c.Views().StatusSpacer1, self.c.Views().StatusSpacer2,
|
||||||
|
}
|
||||||
|
_ = self.c.GocuiGui().ForceRedrawViews(bottomLineViews...)
|
||||||
|
case <-stop:
|
||||||
|
break outer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@ type ModeHelper struct {
|
|||||||
cherryPickHelper *CherryPickHelper
|
cherryPickHelper *CherryPickHelper
|
||||||
mergeAndRebaseHelper *MergeAndRebaseHelper
|
mergeAndRebaseHelper *MergeAndRebaseHelper
|
||||||
bisectHelper *BisectHelper
|
bisectHelper *BisectHelper
|
||||||
|
suppressRebasingMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewModeHelper(
|
func NewModeHelper(
|
||||||
@ -114,7 +115,7 @@ func (self *ModeHelper) Statuses() []ModeStatus {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
IsActive: func() bool {
|
IsActive: func() bool {
|
||||||
return self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE
|
return !self.suppressRebasingMode && self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE
|
||||||
},
|
},
|
||||||
Description: func() string {
|
Description: func() string {
|
||||||
workingTreeState := self.c.Git().Status.WorkingTreeState()
|
workingTreeState := self.c.Git().Status.WorkingTreeState()
|
||||||
@ -168,3 +169,7 @@ func (self *ModeHelper) ClearFiltering() error {
|
|||||||
|
|
||||||
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}})
|
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *ModeHelper) SetSuppressRebasingMode(value bool) {
|
||||||
|
self.suppressRebasingMode = value
|
||||||
|
}
|
||||||
|
@ -513,6 +513,9 @@ func NewGui(
|
|||||||
func() types.Context { return gui.State.ContextMgr.Current() },
|
func() types.Context { return gui.State.ContextMgr.Current() },
|
||||||
gui.createMenu,
|
gui.createMenu,
|
||||||
func(message string, f func(gocui.Task) error) { gui.helpers.AppStatus.WithWaitingStatus(message, f) },
|
func(message string, f func(gocui.Task) error) { gui.helpers.AppStatus.WithWaitingStatus(message, f) },
|
||||||
|
func(message string, f func() error) {
|
||||||
|
gui.helpers.AppStatus.WithWaitingStatusSync(message, f)
|
||||||
|
},
|
||||||
func(message string) { gui.helpers.AppStatus.Toast(message) },
|
func(message string) { gui.helpers.AppStatus.Toast(message) },
|
||||||
func() string { return gui.Views.Confirmation.TextArea.GetContent() },
|
func() string { return gui.Views.Confirmation.TextArea.GetContent() },
|
||||||
func() bool { return gui.c.InDemo() },
|
func() bool { return gui.c.InDemo() },
|
||||||
|
@ -15,15 +15,16 @@ type PopupHandler struct {
|
|||||||
*common.Common
|
*common.Common
|
||||||
index int
|
index int
|
||||||
deadlock.Mutex
|
deadlock.Mutex
|
||||||
createPopupPanelFn func(context.Context, types.CreatePopupPanelOpts) error
|
createPopupPanelFn func(context.Context, types.CreatePopupPanelOpts) error
|
||||||
onErrorFn func() error
|
onErrorFn func() error
|
||||||
popContextFn func() error
|
popContextFn func() error
|
||||||
currentContextFn func() types.Context
|
currentContextFn func() types.Context
|
||||||
createMenuFn func(types.CreateMenuOptions) error
|
createMenuFn func(types.CreateMenuOptions) error
|
||||||
withWaitingStatusFn func(message string, f func(gocui.Task) error)
|
withWaitingStatusFn func(message string, f func(gocui.Task) error)
|
||||||
toastFn func(message string)
|
withWaitingStatusSyncFn func(message string, f func() error)
|
||||||
getPromptInputFn func() string
|
toastFn func(message string)
|
||||||
inDemo func() bool
|
getPromptInputFn func() string
|
||||||
|
inDemo func() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ types.IPopupHandler = &PopupHandler{}
|
var _ types.IPopupHandler = &PopupHandler{}
|
||||||
@ -36,22 +37,24 @@ func NewPopupHandler(
|
|||||||
currentContextFn func() types.Context,
|
currentContextFn func() types.Context,
|
||||||
createMenuFn func(types.CreateMenuOptions) error,
|
createMenuFn func(types.CreateMenuOptions) error,
|
||||||
withWaitingStatusFn func(message string, f func(gocui.Task) error),
|
withWaitingStatusFn func(message string, f func(gocui.Task) error),
|
||||||
|
withWaitingStatusSyncFn func(message string, f func() error),
|
||||||
toastFn func(message string),
|
toastFn func(message string),
|
||||||
getPromptInputFn func() string,
|
getPromptInputFn func() string,
|
||||||
inDemo func() bool,
|
inDemo func() bool,
|
||||||
) *PopupHandler {
|
) *PopupHandler {
|
||||||
return &PopupHandler{
|
return &PopupHandler{
|
||||||
Common: common,
|
Common: common,
|
||||||
index: 0,
|
index: 0,
|
||||||
createPopupPanelFn: createPopupPanelFn,
|
createPopupPanelFn: createPopupPanelFn,
|
||||||
onErrorFn: onErrorFn,
|
onErrorFn: onErrorFn,
|
||||||
popContextFn: popContextFn,
|
popContextFn: popContextFn,
|
||||||
currentContextFn: currentContextFn,
|
currentContextFn: currentContextFn,
|
||||||
createMenuFn: createMenuFn,
|
createMenuFn: createMenuFn,
|
||||||
withWaitingStatusFn: withWaitingStatusFn,
|
withWaitingStatusFn: withWaitingStatusFn,
|
||||||
toastFn: toastFn,
|
withWaitingStatusSyncFn: withWaitingStatusSyncFn,
|
||||||
getPromptInputFn: getPromptInputFn,
|
toastFn: toastFn,
|
||||||
inDemo: inDemo,
|
getPromptInputFn: getPromptInputFn,
|
||||||
|
inDemo: inDemo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +71,11 @@ func (self *PopupHandler) WithWaitingStatus(message string, f func(gocui.Task) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *PopupHandler) WithWaitingStatusSync(message string, f func() error) error {
|
||||||
|
self.withWaitingStatusSyncFn(message, f)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (self *PopupHandler) Error(err error) error {
|
func (self *PopupHandler) Error(err error) error {
|
||||||
if err == gocui.ErrQuit {
|
if err == gocui.ErrQuit {
|
||||||
return err
|
return err
|
||||||
|
@ -141,6 +141,7 @@ type IPopupHandler interface {
|
|||||||
// Shows a popup prompting the user for input.
|
// Shows a popup prompting the user for input.
|
||||||
Prompt(opts PromptOpts) error
|
Prompt(opts PromptOpts) error
|
||||||
WithWaitingStatus(message string, f func(gocui.Task) error) error
|
WithWaitingStatus(message string, f func(gocui.Task) error) error
|
||||||
|
WithWaitingStatusSync(message string, f func() error) error
|
||||||
Menu(opts CreateMenuOptions) error
|
Menu(opts CreateMenuOptions) error
|
||||||
Toast(message string)
|
Toast(message string)
|
||||||
GetPromptInput() string
|
GetPromptInput() string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user