From eb20c891f4e19c96d700989aa7c5006ba3e3b310 Mon Sep 17 00:00:00 2001 From: Simon J Mudd Date: Tue, 24 Feb 2015 09:29:26 +0100 Subject: [PATCH] move termbox.Events generator into screen --- app/app.go | 14 +------------- screen/screen.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) 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 +} -- 2.7.4