parent
4f02cf47c7
commit
4f5b4e6dbf
37
ui.go
37
ui.go
@ -453,52 +453,19 @@ func newUI(screen tcell.Screen) *ui {
|
|||||||
msgWin: newWin(wtot, 1, 0, htot-1),
|
msgWin: newWin(wtot, 1, 0, htot-1),
|
||||||
menuWin: newWin(wtot, 1, 0, htot-2),
|
menuWin: newWin(wtot, 1, 0, htot-2),
|
||||||
keyChan: make(chan string, 1000),
|
keyChan: make(chan string, 1000),
|
||||||
|
evChan: make(chan tcell.Event),
|
||||||
styles: parseStyles(),
|
styles: parseStyles(),
|
||||||
icons: parseIcons(),
|
icons: parseIcons(),
|
||||||
}
|
}
|
||||||
|
|
||||||
evQueue := make(chan tcell.Event)
|
|
||||||
go func() {
|
go func() {
|
||||||
var ev tcell.Event
|
var ev tcell.Event
|
||||||
for {
|
for {
|
||||||
ev = ui.screen.PollEvent()
|
ev = ui.screen.PollEvent()
|
||||||
evQueue <- ev
|
ui.evChan <- ev
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
evChan := make(chan tcell.Event)
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
ev := <-evQueue
|
|
||||||
// .(type) can't be used outside a switch
|
|
||||||
switch tev := ev.(type) {
|
|
||||||
case *tcell.EventKey:
|
|
||||||
// tcell.KeyESC is one of the few cases we don't need Rune() for
|
|
||||||
if tev.Key() == tcell.KeyESC {
|
|
||||||
select {
|
|
||||||
case ev2 := <-evQueue:
|
|
||||||
switch tev2 := ev2.(type) {
|
|
||||||
case *tcell.EventKey:
|
|
||||||
evChan <- tcell.NewEventKey(tev2.Key(), tev2.Rune(), tcell.ModAlt)
|
|
||||||
default:
|
|
||||||
evChan <- ev2
|
|
||||||
}
|
|
||||||
|
|
||||||
if ev2 == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
continue
|
|
||||||
case <-time.After(100 * time.Millisecond):
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
evChan <- ev
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
ui.evChan = evChan
|
|
||||||
|
|
||||||
return ui
|
return ui
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user