Update readme and examples

Moved the PollEvents call outside of the for loop
This commit is contained in:
Caleb Bassi 2018-11-29 15:32:42 -08:00
parent 27bbe8c0de
commit ed219e8c05
16 changed files with 45 additions and 25 deletions

View File

@ -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
}

View File

@ -27,8 +27,9 @@ func main() {
ui.Render(bc)
uiEvents := ui.PollEvents()
for {
e := <-ui.PollEvent()
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return

View File

@ -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", "<C-c>":
return
}
case <-time.NewTicker(time.Second).C:
case <-ticker:
updateP(tickerCount)
draw(tickerCount)
tickerCount++

View File

@ -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", "<C-c>":
return

View File

@ -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", "<C-c>":
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
}

View File

@ -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", "<C-c>":
return

View File

@ -35,8 +35,9 @@ func main() {
ui.Render(ls)
uiEvents := ui.PollEvents()
for {
e := <-ui.PollEvent()
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return

View File

@ -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", "<C-c>":
return

View File

@ -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", "<C-c>":
return
case "s":
pause()
}
case <-time.NewTicker(time.Second).C:
case <-ticker:
if run {
pc.Data, pc.Offset = randomDataAndOffset()
ui.Render(pc)

View File

@ -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", "<C-c>":
return

View File

@ -44,8 +44,9 @@ func main() {
ui.Render(sbc)
uiEvents := ui.PollEvents()
for {
e := <-ui.PollEvent()
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return

View File

@ -53,8 +53,9 @@ func main() {
ui.Render(table2)
uiEvents := ui.PollEvents()
for {
e := <-ui.PollEvent()
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return

View File

@ -60,8 +60,9 @@ func main() {
ui.Render(header, tabpane)
uiEvents := ui.PollEvents()
for {
e := <-ui.PollEvent()
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return

View File

@ -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", "<C-c>":
return
}
case <-time.NewTicker(time.Second).C:
case <-ticker:
draw(tickerCount)
tickerCount++
}

View File

@ -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", "<C-c>":
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)

View File

@ -27,8 +27,9 @@ func main() {
ui.Render(p)
uiEvents := ui.PollEvents()
for {
e := <-ui.PollEvent()
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return