sampler-fork/event/handler.go

57 lines
1.2 KiB
Go
Raw Normal View History

package event
import (
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 {
case EventQuit, EventExit:
return
case EventPause:
pause = !pause
case EventResize:
payload := e.Payload.(ui.Resize)
self.Layout.ChangeDimensions(payload.Width, payload.Height)
case EventMouseClick:
payload := e.Payload.(ui.Mouse)
self.handleMouseClick(payload.X, payload.Y)
case EventKeyboardLeft:
// here we are going to move selection (special type of layout item)
//layout.GetItem("").Move(-1, 0)
case EventKeyboardRight:
//layout.GetItem(0).Move(1, 0)
case EventKeyboardDown:
//layout.GetItem(0).Move(0, 1)
case EventKeyboardUp:
//layout.GetItem(0).Move(0, -1)
}
}
}
}
func (self *Handler) handleMouseClick(x, y int) {
for _, chart := range self.Layout.GetComponents(widgets.TypeRunChart) {
runChart := chart.(*widgets.RunChart)
2019-02-03 03:30:45 +00:00
runChart.SelectPoint(x, y)
}
}