Fixed issue with sudden restore of status bar message
It was hapening in case of new message display (statusBar.showForSeconds) within delay period.
This commit is contained in:
@@ -19,6 +19,10 @@ const (
|
|||||||
messagePage = "message"
|
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 {
|
func prepareStatusBar(app *tview.Application) *StatusBar {
|
||||||
statusBar = &StatusBar{
|
statusBar = &StatusBar{
|
||||||
Pages: tview.NewPages(),
|
Pages: tview.NewPages(),
|
||||||
@@ -42,6 +46,12 @@ func prepareStatusBar(app *tview.Application) *StatusBar {
|
|||||||
return statusBar
|
return statusBar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bar *StatusBar) restore() {
|
||||||
|
bar.container.QueueUpdateDraw(func() {
|
||||||
|
bar.SwitchToPage(defaultPage)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (bar *StatusBar) showForSeconds(message string, timeout int) {
|
func (bar *StatusBar) showForSeconds(message string, timeout int) {
|
||||||
if bar.container == nil {
|
if bar.container == nil {
|
||||||
return
|
return
|
||||||
@@ -49,11 +59,15 @@ func (bar *StatusBar) showForSeconds(message string, timeout int) {
|
|||||||
|
|
||||||
bar.message.SetText(message)
|
bar.message.SetText(message)
|
||||||
bar.SwitchToPage(messagePage)
|
bar.SwitchToPage(messagePage)
|
||||||
|
restorInQ++
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Second * time.Duration(timeout))
|
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--
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user