Skip to content

Commit

Permalink
ci_view: Fix screen freeze
Browse files Browse the repository at this point in the history
After the tcell/v2 update, any key press during `lab ci view` results
in a lock up. It is unclear whether the changes in input handling on
the tcell side are intentional, but we can address the issue by making
the channel that notifies about input events asynchronous and ensure
that we don't overrun its queue.
  • Loading branch information
fmuellner authored and prarit committed Dec 23, 2020
1 parent f50f4fc commit 33de0c3
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions cmd/ci_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Feedback Encouraged!: https://github.com/zaquestion/lab/issues`,

boxes = make(map[string]*tview.TextView)
jobsCh := make(chan []*gitlab.Job)
inputCh := make(chan struct{})
inputCh := make(chan struct{}, 1)

screen, err := tcell.NewScreen()
if err != nil {
Expand All @@ -98,17 +98,22 @@ Feedback Encouraged!: https://github.com/zaquestion/lab/issues`,
}

func inputCapture(a *tview.Application, root *tview.Pages, navi navigator, inputCh chan struct{}) func(event *tcell.EventKey) *tcell.EventKey {
queueInputUpdate := func() {
if len(inputCh) == 0 {
inputCh <- struct{}{}
}
}
return func(event *tcell.EventKey) *tcell.EventKey {
if event.Rune() == 'q' || event.Key() == tcell.KeyEscape {
switch {
case modalVisible:
modalVisible = !modalVisible
root.HidePage("yesno")
inputCh <- struct{}{}
queueInputUpdate()
case logsVisible:
logsVisible = !logsVisible
root.HidePage("logs-" + curJob.Name)
inputCh <- struct{}{}
queueInputUpdate()
a.ForceDraw()
default:
a.Stop()
Expand All @@ -119,7 +124,7 @@ func inputCapture(a *tview.Application, root *tview.Pages, navi navigator, input
curJob = navi.Navigate(jobs, event)
root.SendToFront("jobs-" + curJob.Name)
// update jobs view on input changes
inputCh <- struct{}{}
queueInputUpdate()
}
switch event.Rune() {
case 'c':
Expand All @@ -130,7 +135,7 @@ func inputCapture(a *tview.Application, root *tview.Pages, navi navigator, input
}
curJob = job
root.RemovePage("logs-" + curJob.Name)
inputCh <- struct{}{}
queueInputUpdate()
a.ForceDraw()
case 'p', 'r':
if modalVisible {
Expand Down Expand Up @@ -161,15 +166,15 @@ func inputCapture(a *tview.Application, root *tview.Pages, navi navigator, input
}
})
root.AddAndSwitchToPage("yesno", modal, false)
inputCh <- struct{}{}
queueInputUpdate()
a.ForceDraw()
return nil
case 't':
logsVisible = !logsVisible
if !logsVisible {
root.HidePage("logs-" + curJob.Name)
}
inputCh <- struct{}{}
queueInputUpdate()
a.ForceDraw()
return nil
case 'T':
Expand Down Expand Up @@ -198,10 +203,10 @@ func inputCapture(a *tview.Application, root *tview.Pages, navi navigator, input
}
}
})
inputCh <- struct{}{}
queueInputUpdate()
return nil
}
inputCh <- struct{}{}
queueInputUpdate()
return event
}
}
Expand Down

0 comments on commit 33de0c3

Please sign in to comment.