2019-02-02 04:39:34 +00:00
|
|
|
package event
|
|
|
|
|
|
|
|
import (
|
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 {
|
|
|
|
case EventQuit, EventExit:
|
|
|
|
return
|
|
|
|
case EventPause:
|
|
|
|
pause = !pause
|
|
|
|
case EventResize:
|
|
|
|
payload := e.Payload.(ui.Resize)
|
|
|
|
self.Layout.ChangeDimensions(payload.Width, payload.Height)
|
|
|
|
case EventMouseClick:
|
2019-02-05 03:28:17 +00:00
|
|
|
//payload := e.Payload.(ui.Mouse)
|
2019-02-02 04:39:34 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|