use the same input goroutine when ui is resumed

Related #459
This commit is contained in:
Gokcehan 2020-09-04 18:07:50 +03:00
parent eab7b61846
commit 4f02cf47c7

52
ui.go
View File

@ -443,17 +443,26 @@ func getWins(screen tcell.Screen) []*win {
return wins return wins
} }
func startEventListening(screen tcell.Screen) chan tcell.Event { func newUI(screen tcell.Screen) *ui {
wtot, htot := screen.Size()
ui := &ui{
screen: screen,
wins: getWins(screen),
promptWin: newWin(wtot, 1, 0, 0),
msgWin: newWin(wtot, 1, 0, htot-1),
menuWin: newWin(wtot, 1, 0, htot-2),
keyChan: make(chan string, 1000),
styles: parseStyles(),
icons: parseIcons(),
}
evQueue := make(chan tcell.Event) evQueue := make(chan tcell.Event)
go func() { go func() {
var ev tcell.Event var ev tcell.Event
for { for {
ev = screen.PollEvent() ev = ui.screen.PollEvent()
evQueue <- ev evQueue <- ev
if ev == nil {
return
}
} }
}() }()
@ -485,30 +494,12 @@ func startEventListening(screen tcell.Screen) chan tcell.Event {
} }
} }
evChan <- ev evChan <- ev
if ev == nil {
return
}
} }
}() }()
return evChan ui.evChan = evChan
}
func newUI(screen tcell.Screen) *ui { return ui
wtot, htot := screen.Size()
return &ui{
screen: screen,
wins: getWins(screen),
promptWin: newWin(wtot, 1, 0, 0),
msgWin: newWin(wtot, 1, 0, htot-1),
menuWin: newWin(wtot, 1, 0, htot-2),
keyChan: make(chan string, 1000),
evChan: startEventListening(screen),
styles: parseStyles(),
icons: parseIcons(),
}
} }
func (ui *ui) renew() { func (ui *ui) renew() {
@ -1025,16 +1016,15 @@ func (ui *ui) pause() {
} }
func (ui *ui) resume() { func (ui *ui) resume() {
var screen tcell.Screen
var err error var err error
if screen, err = tcell.NewScreen(); err != nil {
if ui.screen, err = tcell.NewScreen(); err != nil {
log.Fatalf("creating screen: %s", err) log.Fatalf("creating screen: %s", err)
} else if err = ui.screen.Init(); err != nil { } else if err = screen.Init(); err != nil {
log.Fatalf("initializing screen: %s", err) log.Fatalf("initializing screen: %s", err)
} }
close(ui.evChan) ui.screen = screen
ui.evChan = startEventListening(ui.screen)
ui.renew() ui.renew()
} }