sampler-fork/event/handler.go

41 lines
752 B
Go
Raw Normal View History

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"
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:
return
2019-02-11 02:51:55 +00:00
case console.KeyPause:
pause = !pause
case console.SignalResize:
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)
}
}
}
}