/
statusline.go
62 lines (49 loc) · 1.17 KB
/
statusline.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package view
import (
"time"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
type StatuslineView struct {
*tview.Flex
container *tview.Application
hint *tview.TextView
}
func NewStatuslineView(app *tview.Application) *StatuslineView {
view := &StatuslineView{
Flex: tview.NewFlex(),
container: app,
hint: tview.NewTextView().SetDynamicColors(true),
}
view.setDefaultHint()
view.AddItem(view.hint, 0, 1, false)
return view
}
func (s *StatuslineView) setDefaultHint() {
s.hint.SetTextColor(tcell.ColorBlue).
SetTextAlign(tview.AlignLeft).
SetText("q: quit, x: menu, ↑/k ↓/j: navigate")
}
func (s *StatuslineView) restore() {
s.container.QueueUpdateDraw(func() {
s.setDefaultHint()
})
}
// Used to skip queued restore of Status panel
// in case of new showForSeconds within waiting period
var restorInQ = 0
func (s *StatuslineView) showForSeconds(message string, duration int) {
if s.container == nil {
return
}
s.hint.SetText(message)
restorInQ++
go func() {
time.Sleep(time.Second * time.Duration(duration))
// Apply restore only if this is the last pending restore
if restorInQ == 1 {
s.restore()
}
restorInQ--
}()
}