From c3f18968ee79a6cdd2504398a90acf16ea3fda70 Mon Sep 17 00:00:00 2001 From: Anis Ahmad Date: Mon, 15 Mar 2021 09:32:11 +0600 Subject: [PATCH] Fixed issue with sudden restore of status bar message It was hapening in case of new message display (statusBar.showForSeconds) within delay period. --- app/status_bar.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/status_bar.go b/app/status_bar.go index 1ee874b..c48edae 100644 --- a/app/status_bar.go +++ b/app/status_bar.go @@ -19,6 +19,10 @@ const ( messagePage = "message" ) +// Used to skip queued restore of statusBar +// in case of new showForSeconds within waiting period +var restorInQ = 0 + func prepareStatusBar(app *tview.Application) *StatusBar { statusBar = &StatusBar{ Pages: tview.NewPages(), @@ -42,6 +46,12 @@ func prepareStatusBar(app *tview.Application) *StatusBar { return statusBar } +func (bar *StatusBar) restore() { + bar.container.QueueUpdateDraw(func() { + bar.SwitchToPage(defaultPage) + }) +} + func (bar *StatusBar) showForSeconds(message string, timeout int) { if bar.container == nil { return @@ -49,11 +59,15 @@ func (bar *StatusBar) showForSeconds(message string, timeout int) { bar.message.SetText(message) bar.SwitchToPage(messagePage) + restorInQ++ go func() { time.Sleep(time.Second * time.Duration(timeout)) - bar.container.QueueUpdateDraw(func() { - bar.SwitchToPage(defaultPage) - }) + + // Apply restore only if this is the last pending restore + if restorInQ == 1 { + bar.restore() + } + restorInQ-- }() }