Add termbox.Sync() call before getting terminal's width/height
Adjust examples see https://github.com/gizak/termui/pull/39
This commit is contained in:
gizak 2015-05-05 10:55:35 -04:00
parent ce9bf21e3a
commit f23ed68e30
3 changed files with 15 additions and 9 deletions

View File

@ -47,7 +47,7 @@ func main() {
spark := ui.Sparkline{}
spark.Height = 1
spark.Title = "srv 0:"
spdata := []int{4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6}
spdata := []int{4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6, 4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6, 4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6, 4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1, 7, 10, 10, 14, 13, 6}
spark.Data = spdata
spark.LineColor = ui.ColorCyan
spark.TitleColor = ui.ColorWhite
@ -119,8 +119,8 @@ func main() {
draw := func(t int) {
g.Percent = t % 101
list.Items = strs[t%9:]
sp.Lines[0].Data = spdata[t%10:]
sp.Lines[1].Data = spdata[t/2%10:]
sp.Lines[0].Data = spdata[:30+t%50]
sp.Lines[1].Data = spdata[:35+t%50]
lc.Data = sinps[t/2:]
lc1.Data = sinps[2*t:]
bc.Data = bcdata[t/2%10:]

View File

@ -8,7 +8,6 @@ package main
import ui "github.com/gizak/termui"
import "math"
import "time"
func main() {
@ -39,7 +38,7 @@ func main() {
spark := ui.Sparkline{}
spark.Height = 8
spdata := sinpsint
spark.Data = spdata
spark.Data = spdata[:100]
spark.LineColor = ui.ColorCyan
spark.TitleColor = ui.ColorWhite
@ -93,24 +92,28 @@ func main() {
ui.Body.Align()
done := make(chan bool)
redraw := make(chan bool)
draw := func() {
update := func() {
for i := 0; i < 103; i++ {
for _, g := range gs {
g.Percent = (g.Percent + 3) % 100
}
sp.Lines[0].Data = spdata[i:]
sp.Lines[0].Data = spdata[:100+i]
lc.Data = sinps[2*i:]
time.Sleep(time.Second / 2)
redraw <- true
}
done <- true
}
evt := ui.EventCh()
go draw()
ui.Render(ui.Body)
go update()
for {
select {
case e := <-evt:
@ -120,10 +123,11 @@ func main() {
if e.Type == ui.EventResize {
ui.Body.Width = ui.TermWidth()
ui.Body.Align()
go func() { redraw <- true }()
}
case <-done:
return
default:
case <-redraw:
ui.Render(ui.Body)
}
}

View File

@ -34,12 +34,14 @@ func Close() {
// TermWidth returns the current terminal's width.
func TermWidth() int {
tm.Sync()
w, _ := tm.Size()
return w
}
// TermHeight returns the current terminal's height.
func TermHeight() int {
tm.Sync()
_, h := tm.Size()
return h
}