Skip to content

Commit 33de0c3

Browse files
fmuellnerprarit
authored andcommitted
ci_view: Fix screen freeze
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.
1 parent f50f4fc commit 33de0c3

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

cmd/ci_view.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Feedback Encouraged!: https://github.com/zaquestion/lab/issues`,
7272

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

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

100100
func inputCapture(a *tview.Application, root *tview.Pages, navi navigator, inputCh chan struct{}) func(event *tcell.EventKey) *tcell.EventKey {
101+
queueInputUpdate := func() {
102+
if len(inputCh) == 0 {
103+
inputCh <- struct{}{}
104+
}
105+
}
101106
return func(event *tcell.EventKey) *tcell.EventKey {
102107
if event.Rune() == 'q' || event.Key() == tcell.KeyEscape {
103108
switch {
104109
case modalVisible:
105110
modalVisible = !modalVisible
106111
root.HidePage("yesno")
107-
inputCh <- struct{}{}
112+
queueInputUpdate()
108113
case logsVisible:
109114
logsVisible = !logsVisible
110115
root.HidePage("logs-" + curJob.Name)
111-
inputCh <- struct{}{}
116+
queueInputUpdate()
112117
a.ForceDraw()
113118
default:
114119
a.Stop()
@@ -119,7 +124,7 @@ func inputCapture(a *tview.Application, root *tview.Pages, navi navigator, input
119124
curJob = navi.Navigate(jobs, event)
120125
root.SendToFront("jobs-" + curJob.Name)
121126
// update jobs view on input changes
122-
inputCh <- struct{}{}
127+
queueInputUpdate()
123128
}
124129
switch event.Rune() {
125130
case 'c':
@@ -130,7 +135,7 @@ func inputCapture(a *tview.Application, root *tview.Pages, navi navigator, input
130135
}
131136
curJob = job
132137
root.RemovePage("logs-" + curJob.Name)
133-
inputCh <- struct{}{}
138+
queueInputUpdate()
134139
a.ForceDraw()
135140
case 'p', 'r':
136141
if modalVisible {
@@ -161,15 +166,15 @@ func inputCapture(a *tview.Application, root *tview.Pages, navi navigator, input
161166
}
162167
})
163168
root.AddAndSwitchToPage("yesno", modal, false)
164-
inputCh <- struct{}{}
169+
queueInputUpdate()
165170
a.ForceDraw()
166171
return nil
167172
case 't':
168173
logsVisible = !logsVisible
169174
if !logsVisible {
170175
root.HidePage("logs-" + curJob.Name)
171176
}
172-
inputCh <- struct{}{}
177+
queueInputUpdate()
173178
a.ForceDraw()
174179
return nil
175180
case 'T':
@@ -198,10 +203,10 @@ func inputCapture(a *tview.Application, root *tview.Pages, navi navigator, input
198203
}
199204
}
200205
})
201-
inputCh <- struct{}{}
206+
queueInputUpdate()
202207
return nil
203208
}
204-
inputCh <- struct{}{}
209+
queueInputUpdate()
205210
return event
206211
}
207212
}

0 commit comments

Comments
 (0)