From: Simon J Mudd Date: Tue, 24 Feb 2015 08:29:26 +0000 (+0100) Subject: move termbox.Events generator into screen X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=eb20c891f4e19c96d700989aa7c5006ba3e3b310;hp=28f3ee44f6591ee899de237d7de027ae664d3eea;p=pstop.git move termbox.Events generator into screen --- diff --git a/app/app.go b/app/app.go index c6c43bf..3588133 100644 --- a/app/app.go +++ b/app/app.go @@ -496,18 +496,6 @@ func (app *App) Cleanup() { } } -// make chan for termbox events and run a poller to send events to the channel -// - return the channel -func new_tb_chan() chan termbox.Event { - termboxChan := make(chan termbox.Event) - go func() { - for { - termboxChan <- termbox.PollEvent() - } - }() - return termboxChan -} - // get into a run loop func (app *App) Run() { app.done = make(chan struct{}) @@ -518,7 +506,7 @@ func (app *App) Run() { app.wi.SetWaitInterval(time.Second) - termboxChan := new_tb_chan() + termboxChan := app.screen.TermBoxChan() for !app.Finished() { select { diff --git a/screen/screen.go b/screen/screen.go index c29c6ba..0478b46 100644 --- a/screen/screen.go +++ b/screen/screen.go @@ -114,3 +114,15 @@ func (s *TermboxScreen) SetSize(width, height int) { func (s *TermboxScreen) Size() (int, int) { return s.width, s.height } + +// create a channel for termbox.Events and run a poller to send +// these events to the channel. Return the channel. +func (s TermboxScreen) TermBoxChan() chan termbox.Event { + termboxChan := make(chan termbox.Event) + go func() { + for { + termboxChan <- termbox.PollEvent() + } + }() + return termboxChan +}