From 5aa48ab0f3d7eb54be7e8a3e41469f56824451ef Mon Sep 17 00:00:00 2001 From: NHOrus Date: Mon, 20 Apr 2015 10:41:55 +0300 Subject: [PATCH] Decoupled interface drawing from value updating for more fluidity on resize. goes into gizak/termui#32 , but does not fix the bug, just prettifies visuals of demo --- example/grid.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/example/grid.go b/example/grid.go index c010b4b..9dbbc11 100644 --- a/example/grid.go +++ b/example/grid.go @@ -92,34 +92,39 @@ func main() { // calculate layout ui.Body.Align() - draw := func(t int) { - sp.Lines[0].Data = spdata[t:] - lc.Data = sinps[2*t:] - ui.Render(ui.Body) + done := make(chan bool) + + draw := func() { + for i := 0; i < 103; i++ { + for _, g := range gs { + g.Percent = (g.Percent + 3) % 100 + } + + sp.Lines[0].Data = spdata[i:] + lc.Data = sinps[2*i:] + + time.Sleep(time.Second / 2) + } + done <- true } evt := ui.EventCh() - i := 0 + go draw() for { select { case e := <-evt: if e.Type == ui.EventKey && e.Ch == 'q' { return } + if e.Type == ui.EventResize { + ui.Body.Width = ui.TermWidth() + ui.Body.Align() + } + case <-done: + return default: - for _, g := range gs { - g.Percent = (g.Percent + 3) % 100 - } - ui.Body.Width = ui.TermWidth() - ui.Body.Align() - - draw(i) - i++ - if i == 102 { - return - } - time.Sleep(time.Second / 2) + ui.Render(ui.Body) } } }