2014-07-06 20:42:11 -05:00
|
|
|
// 6 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
2014-07-07 20:04:44 -05:00
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Go initializes package ui.
|
|
|
|
// TODO write this bit
|
|
|
|
func Go() error {
|
|
|
|
runtime.LockOSThread()
|
|
|
|
if err := uiinit(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
go uitask()
|
|
|
|
uimsgloop()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Stop
|
2014-07-06 20:42:11 -05:00
|
|
|
|
|
|
|
// This is the ui main loop.
|
|
|
|
// It is spawned by Go as a goroutine.
|
|
|
|
func uitask() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case req := <-Do:
|
|
|
|
// TODO foreign event
|
|
|
|
issue(req)
|
|
|
|
case <-stall: // wait for event to finish
|
|
|
|
<-stall // see below for information
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// At each event, this is pulsed twice: once when the event begins, and once when the event ends.
|
|
|
|
// Do is not processed in between.
|
|
|
|
var stall = make(chan struct{})
|
|
|
|
|
|
|
|
// This is the common code for running an event.
|
|
|
|
// TODO
|
|
|
|
// - define event
|
|
|
|
// - figure out how to return values from event handlers
|
|
|
|
func doevent(e event) {
|
|
|
|
stall <- struct{}{} // enter event handler
|
|
|
|
c := make(Doer)
|
|
|
|
go func() {
|
|
|
|
e.do(c)
|
|
|
|
close(c)
|
|
|
|
}()
|
|
|
|
for req := range c {
|
|
|
|
issue(req)
|
|
|
|
}
|
|
|
|
stall <- struct{}{} // leave event handler
|
|
|
|
}
|