2019-02-02 04:39:34 +00:00
|
|
|
package event
|
|
|
|
|
|
|
|
import (
|
2019-02-11 02:51:55 +00:00
|
|
|
"github.com/sqshq/sampler/console"
|
2019-02-02 14:45:53 +00:00
|
|
|
"github.com/sqshq/sampler/widgets"
|
2019-02-02 04:39:34 +00:00
|
|
|
ui "github.com/sqshq/termui"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Handler struct {
|
|
|
|
Layout *widgets.Layout
|
|
|
|
RenderEvents <-chan time.Time
|
|
|
|
ConsoleEvents <-chan ui.Event
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *Handler) HandleEvents() {
|
|
|
|
|
|
|
|
pause := false
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-self.RenderEvents:
|
|
|
|
if !pause {
|
|
|
|
ui.Render(self.Layout)
|
|
|
|
}
|
|
|
|
case e := <-self.ConsoleEvents:
|
|
|
|
switch e.ID {
|
2019-02-11 02:51:55 +00:00
|
|
|
case console.KeyQuit, console.KeyExit:
|
2019-02-02 04:39:34 +00:00
|
|
|
return
|
2019-02-11 02:51:55 +00:00
|
|
|
case console.KeyPause:
|
2019-02-02 04:39:34 +00:00
|
|
|
pause = !pause
|
2019-02-11 03:26:51 +00:00
|
|
|
case console.SignalResize:
|
2019-02-02 04:39:34 +00:00
|
|
|
payload := e.Payload.(ui.Resize)
|
|
|
|
self.Layout.ChangeDimensions(payload.Width, payload.Height)
|
2019-02-11 02:51:55 +00:00
|
|
|
default:
|
|
|
|
self.Layout.HandleConsoleEvent(e.ID)
|
2019-02-02 04:39:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|