From ed219e8c05e8a81754558fc8fa1576363018eb2b Mon Sep 17 00:00:00 2001 From: Caleb Bassi Date: Thu, 29 Nov 2018 15:32:42 -0800 Subject: [PATCH] Update readme and examples Moved the PollEvents call outside of the for loop --- README.md | 3 ++- _examples/barchart.go | 3 ++- _examples/dashboard.go | 6 ++++-- _examples/gauge.go | 3 ++- _examples/grid.go | 6 ++++-- _examples/linechart.go | 3 ++- _examples/list.go | 3 ++- _examples/paragraph.go | 3 ++- _examples/piechart.go | 6 ++++-- _examples/sparklines.go | 3 ++- _examples/stackedbarchart.go | 3 ++- _examples/table.go | 3 ++- _examples/tabs.go | 3 ++- _examples/theme.go | 6 ++++-- _examples/ttop.go | 13 +++++++------ _examples/wrapper.go | 3 ++- 16 files changed, 45 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 0af3c62..d9f7007 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,9 @@ func main() { p.Height = 5 ui.Render(p) + uiEvents := ui.PollEvents() for { - e := <-ui.PollEvent() + e := <-uiEvents if e.Type == ui.KeyboardEvent { return } diff --git a/_examples/barchart.go b/_examples/barchart.go index 7d8f8e3..8934860 100644 --- a/_examples/barchart.go +++ b/_examples/barchart.go @@ -27,8 +27,9 @@ func main() { ui.Render(bc) + uiEvents := ui.PollEvents() for { - e := <-ui.PollEvent() + e := <-uiEvents switch e.ID { case "q", "": return diff --git a/_examples/dashboard.go b/_examples/dashboard.go index 7be1324..473a6ec 100644 --- a/_examples/dashboard.go +++ b/_examples/dashboard.go @@ -141,14 +141,16 @@ func main() { } tickerCount := 1 + uiEvents := ui.PollEvents() + ticker := time.NewTicker(time.Second).C for { select { - case e := <-ui.PollEvent(): + case e := <-uiEvents: switch e.ID { case "q", "": return } - case <-time.NewTicker(time.Second).C: + case <-ticker: updateP(tickerCount) draw(tickerCount) tickerCount++ diff --git a/_examples/gauge.go b/_examples/gauge.go index 6983ffe..6bffffc 100644 --- a/_examples/gauge.go +++ b/_examples/gauge.go @@ -74,8 +74,9 @@ func main() { ui.Render(g0, g1, g2, g3, g4) + uiEvents := ui.PollEvents() for { - e := <-ui.PollEvent() + e := <-uiEvents switch e.ID { case "q", "": return diff --git a/_examples/grid.go b/_examples/grid.go index a2c2997..f2d5931 100644 --- a/_examples/grid.go +++ b/_examples/grid.go @@ -96,9 +96,11 @@ func main() { ui.Render(ui.Body) tickerCount := 1 + uiEvents := ui.PollEvents() + ticker := time.NewTicker(time.Second).C for { select { - case e := <-ui.PollEvent(): + case e := <-uiEvents: switch e.ID { case "q", "": return @@ -109,7 +111,7 @@ func main() { ui.Clear() ui.Render(ui.Body) } - case <-time.NewTicker(time.Second).C: + case <-ticker: if tickerCount > 103 { return } diff --git a/_examples/linechart.go b/_examples/linechart.go index ead1800..837aebc 100644 --- a/_examples/linechart.go +++ b/_examples/linechart.go @@ -66,8 +66,9 @@ func main() { ui.Render(lc0, lc1, lc2) + uiEvents := ui.PollEvents() for { - e := <-ui.PollEvent() + e := <-uiEvents switch e.ID { case "q", "": return diff --git a/_examples/list.go b/_examples/list.go index 544ec9e..cd10c32 100644 --- a/_examples/list.go +++ b/_examples/list.go @@ -35,8 +35,9 @@ func main() { ui.Render(ls) + uiEvents := ui.PollEvents() for { - e := <-ui.PollEvent() + e := <-uiEvents switch e.ID { case "q", "": return diff --git a/_examples/paragraph.go b/_examples/paragraph.go index f370ff4..6e37782 100644 --- a/_examples/paragraph.go +++ b/_examples/paragraph.go @@ -42,8 +42,9 @@ func main() { ui.Render(p0, p1, p2, p3) + uiEvents := ui.PollEvents() for { - e := <-ui.PollEvent() + e := <-uiEvents switch e.ID { case "q", "": return diff --git a/_examples/piechart.go b/_examples/piechart.go index fa18af2..42db648 100644 --- a/_examples/piechart.go +++ b/_examples/piechart.go @@ -52,16 +52,18 @@ func main() { ui.Render(pc) + uiEvents := ui.PollEvents() + ticker := time.NewTicker(time.Second).C for { select { - case e := <-ui.PollEvent(): + case e := <-uiEvents: switch e.ID { case "q", "": return case "s": pause() } - case <-time.NewTicker(time.Second).C: + case <-ticker: if run { pc.Data, pc.Offset = randomDataAndOffset() ui.Render(pc) diff --git a/_examples/sparklines.go b/_examples/sparklines.go index b806085..d861fee 100644 --- a/_examples/sparklines.go +++ b/_examples/sparklines.go @@ -59,8 +59,9 @@ func main() { ui.Render(spls0, spls1, spls2) + uiEvents := ui.PollEvents() for { - e := <-ui.PollEvent() + e := <-uiEvents switch e.ID { case "q", "": return diff --git a/_examples/stackedbarchart.go b/_examples/stackedbarchart.go index 92ab439..f1de132 100644 --- a/_examples/stackedbarchart.go +++ b/_examples/stackedbarchart.go @@ -44,8 +44,9 @@ func main() { ui.Render(sbc) + uiEvents := ui.PollEvents() for { - e := <-ui.PollEvent() + e := <-uiEvents switch e.ID { case "q", "": return diff --git a/_examples/table.go b/_examples/table.go index bdef09a..5a4f462 100644 --- a/_examples/table.go +++ b/_examples/table.go @@ -53,8 +53,9 @@ func main() { ui.Render(table2) + uiEvents := ui.PollEvents() for { - e := <-ui.PollEvent() + e := <-uiEvents switch e.ID { case "q", "": return diff --git a/_examples/tabs.go b/_examples/tabs.go index 4e08f82..8434bd0 100644 --- a/_examples/tabs.go +++ b/_examples/tabs.go @@ -60,8 +60,9 @@ func main() { ui.Render(header, tabpane) + uiEvents := ui.PollEvents() for { - e := <-ui.PollEvent() + e := <-uiEvents switch e.ID { case "q", "": return diff --git a/_examples/theme.go b/_examples/theme.go index 8a9bb79..4788af4 100644 --- a/_examples/theme.go +++ b/_examples/theme.go @@ -139,14 +139,16 @@ func main() { ui.Render(p, list, g, sp, lc, bc, lc1, p1) tickerCount := 1 + uiEvents := ui.PollEvents() + ticker := time.NewTicker(time.Second).C for { select { - case e := <-ui.PollEvent(): + case e := <-uiEvents: switch e.ID { case "q", "": return } - case <-time.NewTicker(time.Second).C: + case <-ticker: draw(tickerCount) tickerCount++ } diff --git a/_examples/ttop.go b/_examples/ttop.go index 1d03eb2..b4a5a27 100644 --- a/_examples/ttop.go +++ b/_examples/ttop.go @@ -20,7 +20,6 @@ import ( "time" ui "github.com/gizak/termui" - "github.com/gizak/termui/extra" ) const statFilePath = "/proc/stat" @@ -290,10 +289,10 @@ func main() { header.Border = false header.TextBgColor = ui.ColorBlue - tabCpu := extra.NewTab("CPU") - tabMem := extra.NewTab("MEM") + tabCpu := ui.NewTab("CPU") + tabMem := ui.NewTab("MEM") - tabpane := extra.NewTabpane() + tabpane := ui.NewTabPane() tabpane.Y = 1 tabpane.Width = 30 tabpane.Border = false @@ -335,9 +334,11 @@ func main() { ui.Render(header, tabpane) tickerCount := 1 + uiEvents := ui.PollEvents() + ticker := time.NewTicker(time.Second).C for { select { - case e := <-ui.PollEvent(): + case e := <-uiEvents: switch e.ID { case "q", "": return @@ -348,7 +349,7 @@ func main() { tabpane.SetActiveRight() ui.Render(header, tabpane) } - case <-time.NewTicker(time.Second).C: + case <-ticker: cs, errcs := getCpusStatsMap() if errcs != nil { panic(errcs) diff --git a/_examples/wrapper.go b/_examples/wrapper.go index 23be0a5..2d390c2 100644 --- a/_examples/wrapper.go +++ b/_examples/wrapper.go @@ -27,8 +27,9 @@ func main() { ui.Render(p) + uiEvents := ui.PollEvents() for { - e := <-ui.PollEvent() + e := <-uiEvents switch e.ID { case "q", "": return