From 283c3a36f2a4addfc52c50e94002fddbf45dabf1 Mon Sep 17 00:00:00 2001 From: Zack Guo Date: Sat, 8 Aug 2015 19:07:32 -0400 Subject: [PATCH] WIP Wrap up Event --- events.go | 83 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/events.go b/events.go index 23a189b..6bdc028 100644 --- a/events.go +++ b/events.go @@ -8,10 +8,10 @@ package termui -import "github.com/nsf/termbox-go" +//import "github.com/nsf/termbox-go" /***********************************termbox-go**************************************/ - +/* type ( EventType uint8 Modifier uint8 @@ -127,9 +127,9 @@ const ( EventRaw EventNone ) - +*/ /**************************************end**************************************/ - +/* // convert termbox.Event to termui.Event func uiEvt(e termbox.Event) Event { event := Event{} @@ -171,49 +171,52 @@ func evtListen() { } }() } - -/* -// EventHandlers is a handler sequence -var EventHandlers []func(Event) - -var signalQuit = make(chan bool) - -// Quit sends quit signal to terminate termui -func Quit() { - signalQuit <- true +*/ +type Event struct { + Type string + Uri string + Data interface{} + Time int + Refer string } -// Wait listening to signalQuit, block operation. -func Wait() { - <-signalQuit +type evtCtl struct { + in chan Event + out chan Event + suspend chan int + recover chan int + close chan int } -// RegEvtHandler register function into TSEventHandler sequence. -func RegEvtHandler(fn func(Event)) { - EventHandlers = append(EventHandlers, fn) +// +type EvtStream struct { + srcMap map[string]evtCtl + stream chan Event } -// EventLoop handles all events and -// redirects every event to callbacks in EventHandlers -func EventLoop() { - evt := make(chan termbox.Event) +func newEvtCtl() evtCtl { + ec := evtCtl{} + ec.in = make(chan Event) + ec.suspend = make(chan int) + ec.recover = make(chan int) + ec.close = make(chan int) + ec.out = make(chan Event) + return ec +} - go func() { - for { - evt <- termbox.PollEvent() - } - }() - - for { - select { - case c := <-signalQuit: - defer func() { signalQuit <- c }() - return - case e := <-evt: - for _, fn := range EventHandlers { - fn(uiEvt(e)) - } - } +func NewEvtStream() EvtStream { + return EvtStream{ + srcMap: make(map[string]evtCtl), + stream: make(chan Event), } } + +/* +func (es *EvtStream) hookup() { + +} + +func (es EvtStream) Subscribe(uri string) chan Event { + +} */