2017-01-13 23:07:43 -07:00
|
|
|
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
2015-03-20 14:21:50 -06:00
|
|
|
// Use of this source code is governed by a MIT license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build ignore
|
|
|
|
|
2015-03-11 14:15:59 -06:00
|
|
|
package main
|
|
|
|
|
2018-08-17 00:18:16 -06:00
|
|
|
import (
|
|
|
|
"math"
|
2018-09-06 17:36:14 -06:00
|
|
|
"time"
|
2018-08-17 00:18:16 -06:00
|
|
|
|
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
2015-03-11 14:15:59 -06:00
|
|
|
|
|
|
|
func main() {
|
2018-09-06 15:48:09 -06:00
|
|
|
ui.Init()
|
2015-03-11 14:15:59 -06:00
|
|
|
defer ui.Close()
|
|
|
|
|
2017-05-02 08:11:46 -06:00
|
|
|
// Deprecated
|
|
|
|
//ui.UseTheme("helloworld")
|
|
|
|
ui.ColorMap = map[string]ui.Attribute{
|
|
|
|
"fg": ui.ColorWhite,
|
|
|
|
"bg": ui.ColorDefault,
|
|
|
|
"border.fg": ui.ColorYellow,
|
|
|
|
"label.fg": ui.ColorGreen,
|
|
|
|
"par.fg": ui.ColorYellow,
|
|
|
|
"par.label.bg": ui.ColorWhite,
|
|
|
|
"gauge.bar.bg": ui.ColorCyan,
|
|
|
|
"gauge.percent.fg": ui.ColorBlue,
|
|
|
|
"barchart.bar.bg": ui.ColorRed,
|
|
|
|
}
|
2015-03-11 14:15:59 -06:00
|
|
|
p := ui.NewPar(":PRESS q TO QUIT DEMO")
|
|
|
|
p.Height = 3
|
|
|
|
p.Width = 50
|
2016-10-14 05:48:50 -06:00
|
|
|
p.BorderLabel = "Text Box"
|
2015-03-11 14:15:59 -06:00
|
|
|
|
2016-03-13 23:47:50 -06:00
|
|
|
strs := []string{"[0] gizak/termui", "[1] editbox.go", "[2] interrupt.go", "[3] keyboard.go", "[4] output.go", "[5] random_out.go", "[6] dashboard.go", "[7] nsf/termbox-go"}
|
2015-03-11 14:15:59 -06:00
|
|
|
list := ui.NewList()
|
|
|
|
list.Items = strs
|
2016-10-14 05:48:50 -06:00
|
|
|
list.BorderLabel = "List"
|
2015-03-11 14:15:59 -06:00
|
|
|
list.Height = 7
|
|
|
|
list.Width = 25
|
|
|
|
list.Y = 4
|
|
|
|
|
|
|
|
g := ui.NewGauge()
|
|
|
|
g.Percent = 50
|
|
|
|
g.Width = 50
|
|
|
|
g.Height = 3
|
|
|
|
g.Y = 11
|
2016-10-14 05:48:50 -06:00
|
|
|
g.BorderLabel = "Gauge"
|
2015-03-11 14:15:59 -06:00
|
|
|
|
|
|
|
spark := ui.NewSparkline()
|
|
|
|
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}
|
|
|
|
spark.Data = spdata
|
|
|
|
|
|
|
|
spark1 := ui.NewSparkline()
|
|
|
|
spark1.Title = "srv 1:"
|
|
|
|
spark1.Data = spdata
|
|
|
|
|
|
|
|
sp := ui.NewSparklines(spark, spark1)
|
|
|
|
sp.Width = 25
|
|
|
|
sp.Height = 7
|
2016-10-14 05:48:50 -06:00
|
|
|
sp.BorderLabel = "Sparkline"
|
2015-03-11 14:15:59 -06:00
|
|
|
sp.Y = 4
|
|
|
|
sp.X = 25
|
|
|
|
|
|
|
|
lc := ui.NewLineChart()
|
|
|
|
sinps := (func() []float64 {
|
|
|
|
n := 100
|
|
|
|
ps := make([]float64, n)
|
|
|
|
for i := range ps {
|
|
|
|
ps[i] = 1 + math.Sin(float64(i)/4)
|
|
|
|
}
|
|
|
|
return ps
|
|
|
|
})()
|
|
|
|
|
2016-10-14 05:48:50 -06:00
|
|
|
lc.BorderLabel = "Line Chart"
|
2018-08-17 00:18:16 -06:00
|
|
|
lc.Data["default"] = sinps
|
2015-03-11 14:15:59 -06:00
|
|
|
lc.Width = 50
|
|
|
|
lc.Height = 11
|
|
|
|
lc.X = 0
|
|
|
|
lc.Y = 14
|
|
|
|
lc.Mode = "dot"
|
|
|
|
|
|
|
|
bc := ui.NewBarChart()
|
|
|
|
bcdata := []int{3, 2, 5, 3, 9, 5, 3, 2, 5, 8, 3, 2, 4, 5, 3, 2, 5, 7, 5, 3, 2, 6, 7, 4, 6, 3, 6, 7, 8, 3, 6, 4, 5, 3, 2, 4, 6, 4, 8, 5, 9, 4, 3, 6, 5, 3, 6}
|
|
|
|
bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
2016-10-14 05:48:50 -06:00
|
|
|
bc.BorderLabel = "Bar Chart"
|
2015-03-11 14:15:59 -06:00
|
|
|
bc.Width = 26
|
|
|
|
bc.Height = 10
|
|
|
|
bc.X = 51
|
|
|
|
bc.Y = 0
|
|
|
|
bc.DataLabels = bclabels
|
|
|
|
|
|
|
|
lc1 := ui.NewLineChart()
|
2016-10-14 05:48:50 -06:00
|
|
|
lc1.BorderLabel = "Line Chart"
|
2015-03-11 14:15:59 -06:00
|
|
|
rndwalk := (func() []float64 {
|
|
|
|
n := 150
|
|
|
|
d := make([]float64, n)
|
|
|
|
for i := 1; i < n; i++ {
|
|
|
|
if i < 20 {
|
|
|
|
d[i] = d[i-1] + 0.01
|
|
|
|
}
|
|
|
|
if i > 20 {
|
|
|
|
d[i] = d[i-1] - 0.05
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return d
|
|
|
|
})()
|
2018-08-17 00:18:16 -06:00
|
|
|
lc1.Data["default"] = rndwalk
|
2015-03-11 14:15:59 -06:00
|
|
|
lc1.Width = 26
|
|
|
|
lc1.Height = 11
|
|
|
|
lc1.X = 51
|
|
|
|
lc1.Y = 14
|
|
|
|
|
|
|
|
p1 := ui.NewPar("Hey!\nI am a borderless block!")
|
2017-05-02 08:11:46 -06:00
|
|
|
p1.Border = false
|
2015-03-11 14:15:59 -06:00
|
|
|
p1.Width = 26
|
|
|
|
p1.Height = 2
|
|
|
|
p1.X = 52
|
|
|
|
p1.Y = 11
|
|
|
|
|
2018-09-06 17:55:27 -06:00
|
|
|
draw := func(count int) {
|
|
|
|
g.Percent = count % 101
|
|
|
|
list.Items = strs[count%9:]
|
|
|
|
sp.Lines[0].Data = spdata[count%10:]
|
|
|
|
sp.Lines[1].Data = spdata[count/2%10:]
|
|
|
|
lc.Data["default"] = sinps[count/2:]
|
|
|
|
lc1.Data["default"] = rndwalk[count:]
|
|
|
|
bc.Data = bcdata[count/2%10:]
|
2015-03-11 14:15:59 -06:00
|
|
|
ui.Render(p, list, g, sp, lc, bc, lc1, p1)
|
|
|
|
}
|
|
|
|
|
2017-05-02 08:11:46 -06:00
|
|
|
ui.Render(p, list, g, sp, lc, bc, lc1, p1)
|
2018-09-06 15:48:09 -06:00
|
|
|
|
2018-09-06 17:36:14 -06:00
|
|
|
ui.Handle("q", func(ui.Event) {
|
2017-05-02 08:11:46 -06:00
|
|
|
ui.StopLoop()
|
|
|
|
})
|
2018-09-06 15:48:09 -06:00
|
|
|
|
2018-09-06 17:36:14 -06:00
|
|
|
drawTicker := time.NewTicker(time.Second)
|
|
|
|
drawTickerCount := 1
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
draw(drawTickerCount)
|
|
|
|
|
|
|
|
drawTickerCount++
|
|
|
|
<-drawTicker.C
|
|
|
|
}
|
|
|
|
}()
|
2018-09-06 15:48:09 -06:00
|
|
|
|
2017-05-02 08:11:46 -06:00
|
|
|
ui.Loop()
|
2015-03-11 14:15:59 -06:00
|
|
|
}
|