Skip to content

Commit

Permalink
Fall back to WithWaitingStatus if view showing the item is not visible
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaller committed Dec 10, 2023
1 parent 240948b commit 0fd4983
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/gui/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (gui *Gui) resetHelpersAndControllers() {
Confirmation: helpers.NewConfirmationHelper(helperCommon),
Mode: modeHelper,
AppStatus: appStatusHelper,
InlineStatus: helpers.NewInlineStatusHelper(helperCommon),
InlineStatus: helpers.NewInlineStatusHelper(helperCommon, windowHelper),
WindowArrangement: helpers.NewWindowArrangementHelper(
gui.c,
windowHelper,
Expand Down
42 changes: 30 additions & 12 deletions pkg/gui/controllers/helpers/inline_status_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/sasha-s/go-deadlock"
Expand All @@ -12,13 +13,15 @@ import (
type InlineStatusHelper struct {
c *HelperCommon

windowHelper *WindowHelper
contextsWithInlineStatus map[types.ContextKey]*inlineStatusInfo
mutex *deadlock.Mutex
}

func NewInlineStatusHelper(c *HelperCommon) *InlineStatusHelper {
func NewInlineStatusHelper(c *HelperCommon, windowHelper *WindowHelper) *InlineStatusHelper {
return &InlineStatusHelper{
c: c,
windowHelper: windowHelper,
contextsWithInlineStatus: make(map[types.ContextKey]*inlineStatusInfo),
mutex: &deadlock.Mutex{},
}
Expand Down Expand Up @@ -61,18 +64,33 @@ func (self inlineStatusHelperTask) Continue() {
}

func (self *InlineStatusHelper) WithInlineStatus(opts InlineStatusOpts, f func(gocui.Task) error) {
self.c.OnWorker(func(task gocui.Task) {
self.start(opts)

err := f(inlineStatusHelperTask{task, self, opts})
if err != nil {
self.c.OnUIThread(func() error {
return self.c.Error(err)
})
}
context := self.c.ContextForKey(opts.ContextKey)
view := context.GetView()
visible := view.Visible && self.windowHelper.TopViewInWindow(context.GetWindowName()) == view
if visible {
self.c.OnWorker(func(task gocui.Task) {
self.start(opts)

err := f(inlineStatusHelperTask{task, self, opts})
if err != nil {
self.c.OnUIThread(func() error {
return self.c.Error(err)
})
}

self.stop(opts)
})
self.stop(opts)
})
} else {
message := presentation.ItemOperationToString(opts.Operation, self.c.Tr)
_ = self.c.WithWaitingStatus(message, func(t gocui.Task) error {
// We still need to set the item operation, because it might be used
// for other (non-presentation) purposes
self.c.State().SetItemOperation(opts.Item, opts.Operation)
defer self.c.State().ClearItemOperation(opts.Item)

return f(t)
})
}
}

func (self *InlineStatusHelper) start(opts InlineStatusOpts) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/presentation/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func ColoredBranchStatus(branch *models.Branch, itemOperation types.ItemOperatio
}

func BranchStatus(branch *models.Branch, itemOperation types.ItemOperation, tr *i18n.TranslationSet, now time.Time) string {
itemOperationStr := itemOperationToString(itemOperation, tr)
itemOperationStr := ItemOperationToString(itemOperation, tr)
if itemOperationStr != "" {
return itemOperationStr + " " + utils.Loader(now)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/presentation/item_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/i18n"
)

func itemOperationToString(itemOperation types.ItemOperation, tr *i18n.TranslationSet) string {
func ItemOperationToString(itemOperation types.ItemOperation, tr *i18n.TranslationSet) string {
switch itemOperation {
case types.ItemOperationNone:
return ""
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/presentation/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func getTagDisplayStrings(t *models.Tag, itemOperation types.ItemOperation, diff
}
descriptionColor := style.FgYellow
descriptionStr := descriptionColor.Sprint(t.Description())
itemOperationStr := itemOperationToString(itemOperation, tr)
itemOperationStr := ItemOperationToString(itemOperation, tr)
if itemOperationStr != "" {
descriptionStr = style.FgCyan.Sprint(itemOperationStr+" "+utils.Loader(time.Now())) + " " + descriptionStr
}
Expand Down

0 comments on commit 0fd4983

Please sign in to comment.