Skip to content

Commit

Permalink
fixup! Add WithWaitingStatusSync
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaller committed Sep 1, 2023
1 parent e17213d commit ab35e77
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pkg/gui/controllers/helpers/app_status_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ func (self *AppStatusHelper) renderAppStatus() {
func (self *AppStatusHelper) renderAppStatusSync(stop chan struct{}) {
ticker := time.NewTicker(time.Millisecond * 50)
go func() {
self.c.SetFreezeInformationView(true)
defer func() { self.c.SetFreezeInformationView(false) }()

outer:
for {
select {
case <-ticker.C:
appStatus := self.statusMgr().GetStatusString()
self.c.SetViewContent(self.c.Views().AppStatus, " "+appStatus)
_ = self.c.GocuiGui().ForceRedrawView(self.c.Views().AppStatus)
_ = self.c.GocuiGui().ForceRedrawViews(self.c.Views().AppStatus, self.c.Views().Options)
case <-stop:
break outer
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ type Gui struct {
c *helpers.HelperCommon
helpers *helpers.Helpers

// freeze what's displayed in the Information view to this string. Empty
// when not frozen
frozenInformationStr string

integrationTest integrationTypes.IntegrationTest

afterLayoutFuncs chan func() error
Expand Down
8 changes: 8 additions & 0 deletions pkg/gui/gui_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ func (self *guiCommon) MainViewPairs() types.MainViewPairs {
}
}

func (self *guiCommon) SetFreezeInformationView(freeze bool) {
if freeze {
self.gui.frozenInformationStr = self.gui.informationStr()
} else {
self.gui.frozenInformationStr = ""
}
}

func (self *guiCommon) State() types.IStateAccessor {
return self.gui.stateAccessor
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/gui/information_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
)

func (gui *Gui) informationStr() string {
if gui.frozenInformationStr != "" {
return gui.frozenInformationStr
}

if activeMode, ok := gui.helpers.Mode.GetActiveMode(); ok {
return activeMode.Description()
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/gui/types/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ type IGuiCommon interface {
// used purely for the sake of RenderToMainViews to provide the pair of main views we want to render to
MainViewPairs() MainViewPairs

// set the information view (right side of the status bar) to frozen so that
// it doesn't change when modes change. Useful during blocking operations
// that want to redraw the status view (WithWaitingStatusSync) to avoid flicker.
SetFreezeInformationView(freeze bool)

// returns true if command completed successfully
RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error)
RunSubprocessAndRefresh(oscommands.ICmdObj) error
Expand Down
10 changes: 6 additions & 4 deletions vendor/github.com/jesseduffield/gocui/gui.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ab35e77

Please sign in to comment.