@@ -57,13 +57,13 @@ type UIState struct {
5757 textWindow * tview.TextView
5858 treeView * tview.TreeView
5959
60+ LiveNode * tview.TreeNode
61+
6062 logger util.Logger
6163
6264 // TODO: replace activeTheme
6365 // theme config.Theme
6466
65- changes chan * tview.TreeNode
66-
6767 v2 * f1tv.F1TV
6868
6969 cmd * cmd.Store
@@ -73,7 +73,6 @@ func NewUI(cfg config.Config, version string) *UIState {
7373 ui := UIState {
7474 version : version ,
7575 cfg : cfg ,
76- changes : make (chan * tview.TreeNode ),
7776 v2 : f1tv .NewF1TV (version ),
7877 }
7978 ui .applyTheme (cfg .Theme )
@@ -158,7 +157,6 @@ func (ui *UIState) Run() error {
158157 done <- ui .app .Run ()
159158 }()
160159
161- go ui .handleEvents ()
162160 go ui .checkLive ()
163161 go ui .loadUpdate ()
164162
@@ -307,11 +305,17 @@ func (s *UIState) blinkNode(node *tview.TreeNode, done chan struct{}) {
307305 }
308306}
309307
310- func (ui * UIState ) handleEvents () {
311- for node := range ui .changes {
312- insertNodeAtTop (ui .treeView .GetRoot (), node )
313- ui .app .Draw ()
308+ func (ui * UIState ) addLiveNode (newNode * tview.TreeNode ) {
309+ if ui .LiveNode != nil {
310+ ui .treeView .GetRoot ().RemoveChild (ui .LiveNode )
311+ }
312+
313+ // newNode if nil if the previous session is no longer live and there is no new live session
314+ if newNode != nil {
315+ ui .LiveNode = newNode
316+ insertNodeAtTop (ui .treeView .GetRoot (), newNode )
314317 }
318+ ui .app .Draw ()
315319}
316320
317321func (ui * UIState ) loadUpdate () {
@@ -341,5 +345,5 @@ func (ui *UIState) loadUpdate() {
341345 })
342346
343347 appendNodes (updateNode , getUpdateNode )
344- ui .changes <- updateNode
348+ insertNodeAtTop ( ui .treeView . GetRoot (), updateNode )
345349}
0 commit comments