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:
parent
ce9bf21e3a
commit
f23ed68e30
@ -47,7 +47,7 @@ func main() {
|
|||||||
spark := ui.Sparkline{}
|
spark := ui.Sparkline{}
|
||||||
spark.Height = 1
|
spark.Height = 1
|
||||||
spark.Title = "srv 0:"
|
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.Data = spdata
|
||||||
spark.LineColor = ui.ColorCyan
|
spark.LineColor = ui.ColorCyan
|
||||||
spark.TitleColor = ui.ColorWhite
|
spark.TitleColor = ui.ColorWhite
|
||||||
@ -119,8 +119,8 @@ func main() {
|
|||||||
draw := func(t int) {
|
draw := func(t int) {
|
||||||
g.Percent = t % 101
|
g.Percent = t % 101
|
||||||
list.Items = strs[t%9:]
|
list.Items = strs[t%9:]
|
||||||
sp.Lines[0].Data = spdata[t%10:]
|
sp.Lines[0].Data = spdata[:30+t%50]
|
||||||
sp.Lines[1].Data = spdata[t/2%10:]
|
sp.Lines[1].Data = spdata[:35+t%50]
|
||||||
lc.Data = sinps[t/2:]
|
lc.Data = sinps[t/2:]
|
||||||
lc1.Data = sinps[2*t:]
|
lc1.Data = sinps[2*t:]
|
||||||
bc.Data = bcdata[t/2%10:]
|
bc.Data = bcdata[t/2%10:]
|
||||||
|
@ -8,7 +8,6 @@ package main
|
|||||||
|
|
||||||
import ui "github.com/gizak/termui"
|
import ui "github.com/gizak/termui"
|
||||||
import "math"
|
import "math"
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -39,7 +38,7 @@ func main() {
|
|||||||
spark := ui.Sparkline{}
|
spark := ui.Sparkline{}
|
||||||
spark.Height = 8
|
spark.Height = 8
|
||||||
spdata := sinpsint
|
spdata := sinpsint
|
||||||
spark.Data = spdata
|
spark.Data = spdata[:100]
|
||||||
spark.LineColor = ui.ColorCyan
|
spark.LineColor = ui.ColorCyan
|
||||||
spark.TitleColor = ui.ColorWhite
|
spark.TitleColor = ui.ColorWhite
|
||||||
|
|
||||||
@ -93,24 +92,28 @@ func main() {
|
|||||||
ui.Body.Align()
|
ui.Body.Align()
|
||||||
|
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
|
redraw := make(chan bool)
|
||||||
|
|
||||||
draw := func() {
|
update := func() {
|
||||||
for i := 0; i < 103; i++ {
|
for i := 0; i < 103; i++ {
|
||||||
for _, g := range gs {
|
for _, g := range gs {
|
||||||
g.Percent = (g.Percent + 3) % 100
|
g.Percent = (g.Percent + 3) % 100
|
||||||
}
|
}
|
||||||
|
|
||||||
sp.Lines[0].Data = spdata[i:]
|
sp.Lines[0].Data = spdata[:100+i]
|
||||||
lc.Data = sinps[2*i:]
|
lc.Data = sinps[2*i:]
|
||||||
|
|
||||||
time.Sleep(time.Second / 2)
|
time.Sleep(time.Second / 2)
|
||||||
|
redraw <- true
|
||||||
}
|
}
|
||||||
done <- true
|
done <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
evt := ui.EventCh()
|
evt := ui.EventCh()
|
||||||
|
|
||||||
go draw()
|
ui.Render(ui.Body)
|
||||||
|
go update()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case e := <-evt:
|
case e := <-evt:
|
||||||
@ -120,10 +123,11 @@ func main() {
|
|||||||
if e.Type == ui.EventResize {
|
if e.Type == ui.EventResize {
|
||||||
ui.Body.Width = ui.TermWidth()
|
ui.Body.Width = ui.TermWidth()
|
||||||
ui.Body.Align()
|
ui.Body.Align()
|
||||||
|
go func() { redraw <- true }()
|
||||||
}
|
}
|
||||||
case <-done:
|
case <-done:
|
||||||
return
|
return
|
||||||
default:
|
case <-redraw:
|
||||||
ui.Render(ui.Body)
|
ui.Render(ui.Body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,12 +34,14 @@ func Close() {
|
|||||||
|
|
||||||
// TermWidth returns the current terminal's width.
|
// TermWidth returns the current terminal's width.
|
||||||
func TermWidth() int {
|
func TermWidth() int {
|
||||||
|
tm.Sync()
|
||||||
w, _ := tm.Size()
|
w, _ := tm.Size()
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
// TermHeight returns the current terminal's height.
|
// TermHeight returns the current terminal's height.
|
||||||
func TermHeight() int {
|
func TermHeight() int {
|
||||||
|
tm.Sync()
|
||||||
_, h := tm.Size()
|
_, h := tm.Size()
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user