Return channel from run method

This commit is contained in:
Sasha Koshka 2022-11-09 01:18:56 -05:00
parent 11bdae78a0
commit e7b5136ea6
4 changed files with 9 additions and 9 deletions

View File

@ -18,13 +18,13 @@ func (application *Application) SetTitle (title string) {
application.backend.SetTitle(title)
}
// Run initializes the application, and then calls callback. Operations inside
// of callback are allowed to interact with the application. Depending on the
// backend used, this function may bind to the main thread.
// Run initializes the application, starts it, and then returns a channel that
// broadcasts events. If no suitable backend can be found, an error is returned.
func (application *Application) Run (
callback func (application *Application),
) (
err error,
channel chan(Event),
err error,
) {
// default values for certain parameters
width, height := application.Size()
@ -44,7 +44,7 @@ func (application *Application) Run (
application.backend, err = instantiateBackend(application)
if err != nil { return }
application.backend.Run(callback)
channel = application.backend.Run()
return
}

View File

@ -1,11 +1,10 @@
package stone
import "time"
import "image"
import "errors"
type Backend interface {
Run () (chan(Event))
Run () (channel chan(Event))
SetTitle (title string)
SetIcon (icons []image.Image)
}

View File

@ -1,7 +1,8 @@
package application
package stone
type Event interface { }
type EventQuit struct { }
type EventPress Button
type EventRelease Button
type EventResize struct { }

View File

@ -3,7 +3,7 @@ package main
import "fmt"
import "time"
import "git.tebibyte.media/sashakoshka/stone"
import _ "git.tebibyte.media/sashakoshka/stone/backends/pixel"
// import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
func main () {
application := stone.Application { }