Minor refactor
This commit is contained in:
parent
7d98eb0bf4
commit
3629cdceea
@ -6,31 +6,27 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/gizak/termui"
|
import ui "github.com/gizak/termui"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := termui.Init(); err != nil {
|
ui.Init()
|
||||||
panic(err)
|
defer ui.Close()
|
||||||
}
|
|
||||||
defer termui.Close()
|
|
||||||
|
|
||||||
bc := termui.NewBarChart()
|
bc := ui.NewBarChart()
|
||||||
data := []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}
|
bc.Data = []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"}
|
bc.DataLabels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
||||||
bc.BorderLabel = "Bar Chart"
|
bc.BorderLabel = "Bar Chart"
|
||||||
bc.Data = data
|
|
||||||
bc.Width = 26
|
bc.Width = 26
|
||||||
bc.Height = 10
|
bc.Height = 10
|
||||||
bc.DataLabels = bclabels
|
bc.TextColor = ui.ColorGreen
|
||||||
bc.TextColor = termui.ColorGreen
|
bc.BarColor = ui.ColorRed
|
||||||
bc.BarColor = termui.ColorRed
|
bc.NumColor = ui.ColorYellow
|
||||||
bc.NumColor = termui.ColorYellow
|
|
||||||
|
|
||||||
termui.Render(bc)
|
ui.Render(bc)
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
termui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
termui.Loop()
|
|
||||||
|
|
||||||
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := ui.Init(); err != nil {
|
ui.Init()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer ui.Close()
|
defer ui.Close()
|
||||||
|
|
||||||
p := ui.NewPar(":PRESS q TO QUIT DEMO")
|
p := ui.NewPar(":PRESS q TO QUIT DEMO")
|
||||||
@ -33,14 +31,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
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"}
|
listData := []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"}
|
||||||
list := ui.NewList()
|
|
||||||
list.Items = strs
|
l := ui.NewList()
|
||||||
list.ItemFgColor = ui.ColorYellow
|
l.Items = listData
|
||||||
list.BorderLabel = "List"
|
l.ItemFgColor = ui.ColorYellow
|
||||||
list.Height = 7
|
l.BorderLabel = "List"
|
||||||
list.Width = 25
|
l.Height = 7
|
||||||
list.Y = 4
|
l.Width = 25
|
||||||
|
l.Y = 4
|
||||||
|
|
||||||
g := ui.NewGauge()
|
g := ui.NewGauge()
|
||||||
g.Percent = 50
|
g.Percent = 50
|
||||||
@ -52,29 +51,30 @@ func main() {
|
|||||||
g.BorderFg = ui.ColorWhite
|
g.BorderFg = ui.ColorWhite
|
||||||
g.BorderLabelFg = ui.ColorCyan
|
g.BorderLabelFg = ui.ColorCyan
|
||||||
|
|
||||||
spark := ui.Sparkline{}
|
sparklineData := []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.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, 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
|
|
||||||
|
|
||||||
spark1 := ui.Sparkline{}
|
sl := ui.Sparkline{}
|
||||||
spark1.Height = 1
|
sl.Height = 1
|
||||||
spark1.Title = "srv 1:"
|
sl.Title = "srv 0:"
|
||||||
spark1.Data = spdata
|
sl.Data = sparklineData
|
||||||
spark1.TitleColor = ui.ColorWhite
|
sl.LineColor = ui.ColorCyan
|
||||||
spark1.LineColor = ui.ColorRed
|
sl.TitleColor = ui.ColorWhite
|
||||||
|
|
||||||
sp := ui.NewSparklines(spark, spark1)
|
sl2 := ui.Sparkline{}
|
||||||
sp.Width = 25
|
sl2.Height = 1
|
||||||
sp.Height = 7
|
sl2.Title = "srv 1:"
|
||||||
sp.BorderLabel = "Sparkline"
|
sl2.Data = sparklineData
|
||||||
sp.Y = 4
|
sl2.TitleColor = ui.ColorWhite
|
||||||
sp.X = 25
|
sl2.LineColor = ui.ColorRed
|
||||||
|
|
||||||
sinps := (func() []float64 {
|
sls := ui.NewSparklines(sl, sl2)
|
||||||
|
sls.Width = 25
|
||||||
|
sls.Height = 7
|
||||||
|
sls.BorderLabel = "Sparkline"
|
||||||
|
sls.Y = 4
|
||||||
|
sls.X = 25
|
||||||
|
|
||||||
|
sinData := (func() []float64 {
|
||||||
n := 220
|
n := 220
|
||||||
ps := make([]float64, n)
|
ps := make([]float64, n)
|
||||||
for i := range ps {
|
for i := range ps {
|
||||||
@ -85,7 +85,7 @@ func main() {
|
|||||||
|
|
||||||
lc := ui.NewLineChart()
|
lc := ui.NewLineChart()
|
||||||
lc.BorderLabel = "dot-mode Line Chart"
|
lc.BorderLabel = "dot-mode Line Chart"
|
||||||
lc.Data["default"] = sinps
|
lc.Data["default"] = sinData
|
||||||
lc.Width = 50
|
lc.Width = 50
|
||||||
lc.Height = 11
|
lc.Height = 11
|
||||||
lc.X = 0
|
lc.X = 0
|
||||||
@ -94,52 +94,56 @@ func main() {
|
|||||||
lc.LineColor["default"] = ui.ColorRed | ui.AttrBold
|
lc.LineColor["default"] = ui.ColorRed | ui.AttrBold
|
||||||
lc.Mode = "dot"
|
lc.Mode = "dot"
|
||||||
|
|
||||||
|
barchartData := []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}
|
||||||
|
|
||||||
bc := ui.NewBarChart()
|
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"}
|
|
||||||
bc.BorderLabel = "Bar Chart"
|
bc.BorderLabel = "Bar Chart"
|
||||||
bc.Width = 26
|
bc.Width = 26
|
||||||
bc.Height = 10
|
bc.Height = 10
|
||||||
bc.X = 51
|
bc.X = 51
|
||||||
bc.Y = 0
|
bc.Y = 0
|
||||||
bc.DataLabels = bclabels
|
bc.DataLabels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
||||||
bc.BarColor = ui.ColorGreen
|
bc.BarColor = ui.ColorGreen
|
||||||
bc.NumColor = ui.ColorBlack
|
bc.NumColor = ui.ColorBlack
|
||||||
|
|
||||||
lc1 := ui.NewLineChart()
|
lc2 := ui.NewLineChart()
|
||||||
lc1.BorderLabel = "braille-mode Line Chart"
|
lc2.BorderLabel = "braille-mode Line Chart"
|
||||||
lc1.Data["default"] = sinps
|
lc2.Data["default"] = sinData
|
||||||
lc1.Width = 26
|
lc2.Width = 26
|
||||||
lc1.Height = 11
|
lc2.Height = 11
|
||||||
lc1.X = 51
|
lc2.X = 51
|
||||||
lc1.Y = 14
|
lc2.Y = 14
|
||||||
lc1.AxesColor = ui.ColorWhite
|
lc2.AxesColor = ui.ColorWhite
|
||||||
lc1.LineColor["default"] = ui.ColorYellow | ui.AttrBold
|
lc2.LineColor["default"] = ui.ColorYellow | ui.AttrBold
|
||||||
|
|
||||||
p1 := ui.NewPar("Hey!\nI am a borderless block!")
|
p2 := ui.NewPar("Hey!\nI am a borderless block!")
|
||||||
p1.Border = false
|
p2.Border = false
|
||||||
p1.Width = 26
|
p2.Width = 26
|
||||||
p1.Height = 2
|
p2.Height = 2
|
||||||
p1.TextFgColor = ui.ColorMagenta
|
p2.TextFgColor = ui.ColorMagenta
|
||||||
p1.X = 52
|
p2.X = 52
|
||||||
p1.Y = 11
|
p2.Y = 11
|
||||||
|
|
||||||
draw := func(t int) {
|
draw := func(count int) {
|
||||||
g.Percent = t % 101
|
g.Percent = count % 101
|
||||||
list.Items = strs[t%9:]
|
l.Items = listData[count%9:]
|
||||||
sp.Lines[0].Data = spdata[:30+t%50]
|
sls.Lines[0].Data = sparklineData[:30+count%50]
|
||||||
sp.Lines[1].Data = spdata[:35+t%50]
|
sls.Lines[1].Data = sparklineData[:35+count%50]
|
||||||
lc.Data["default"] = sinps[t/2%220:]
|
lc.Data["default"] = sinData[count/2%220:]
|
||||||
lc1.Data["default"] = sinps[2*t%220:]
|
lc2.Data["default"] = sinData[2*count%220:]
|
||||||
bc.Data = bcdata[t/2%10:]
|
bc.Data = barchartData[count/2%10:]
|
||||||
ui.Render(p, list, g, sp, lc, bc, lc1, p1)
|
|
||||||
|
ui.Render(p, l, g, sls, lc, bc, lc2, p2)
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
|
|
||||||
ui.Handle("/timer/1s", func(e ui.Event) {
|
ui.Handle("/timer/1s", func(e ui.Event) {
|
||||||
t := e.Data.(ui.EvtTimer)
|
t := e.Data.(ui.EvtTimer)
|
||||||
draw(int(t.Count))
|
draw(int(t.Count))
|
||||||
})
|
})
|
||||||
|
|
||||||
ui.Loop()
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
@ -6,79 +6,74 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/gizak/termui"
|
import ui "github.com/gizak/termui"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := termui.Init()
|
ui.Init()
|
||||||
if err != nil {
|
defer ui.Close()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer termui.Close()
|
|
||||||
|
|
||||||
//termui.UseTheme("helloworld")
|
g0 := ui.NewGauge()
|
||||||
|
|
||||||
g0 := termui.NewGauge()
|
|
||||||
g0.Percent = 40
|
g0.Percent = 40
|
||||||
g0.Width = 50
|
g0.Width = 50
|
||||||
g0.Height = 3
|
g0.Height = 3
|
||||||
g0.BorderLabel = "Slim Gauge"
|
g0.BorderLabel = "Slim Gauge"
|
||||||
g0.BarColor = termui.ColorRed
|
g0.BarColor = ui.ColorRed
|
||||||
g0.BorderFg = termui.ColorWhite
|
g0.BorderFg = ui.ColorWhite
|
||||||
g0.BorderLabelFg = termui.ColorCyan
|
g0.BorderLabelFg = ui.ColorCyan
|
||||||
|
|
||||||
gg := termui.NewBlock()
|
gg := ui.NewBlock()
|
||||||
gg.Width = 50
|
gg.Width = 50
|
||||||
gg.Height = 5
|
gg.Height = 5
|
||||||
gg.Y = 12
|
gg.Y = 12
|
||||||
gg.BorderLabel = "TEST"
|
gg.BorderLabel = "TEST"
|
||||||
gg.Align()
|
gg.Align()
|
||||||
|
|
||||||
g2 := termui.NewGauge()
|
g2 := ui.NewGauge()
|
||||||
g2.Percent = 60
|
g2.Percent = 60
|
||||||
g2.Width = 50
|
g2.Width = 50
|
||||||
g2.Height = 3
|
g2.Height = 3
|
||||||
g2.PercentColor = termui.ColorBlue
|
g2.PercentColor = ui.ColorBlue
|
||||||
g2.Y = 3
|
g2.Y = 3
|
||||||
g2.BorderLabel = "Slim Gauge"
|
g2.BorderLabel = "Slim Gauge"
|
||||||
g2.BarColor = termui.ColorYellow
|
g2.BarColor = ui.ColorYellow
|
||||||
g2.BorderFg = termui.ColorWhite
|
g2.BorderFg = ui.ColorWhite
|
||||||
|
|
||||||
g1 := termui.NewGauge()
|
g1 := ui.NewGauge()
|
||||||
g1.Percent = 30
|
g1.Percent = 30
|
||||||
g1.Width = 50
|
g1.Width = 50
|
||||||
g1.Height = 5
|
g1.Height = 5
|
||||||
g1.Y = 6
|
g1.Y = 6
|
||||||
g1.BorderLabel = "Big Gauge"
|
g1.BorderLabel = "Big Gauge"
|
||||||
g1.PercentColor = termui.ColorYellow
|
g1.PercentColor = ui.ColorYellow
|
||||||
g1.BarColor = termui.ColorGreen
|
g1.BarColor = ui.ColorGreen
|
||||||
g1.BorderFg = termui.ColorWhite
|
g1.BorderFg = ui.ColorWhite
|
||||||
g1.BorderLabelFg = termui.ColorMagenta
|
g1.BorderLabelFg = ui.ColorMagenta
|
||||||
|
|
||||||
g3 := termui.NewGauge()
|
g3 := ui.NewGauge()
|
||||||
g3.Percent = 50
|
g3.Percent = 50
|
||||||
g3.Width = 50
|
g3.Width = 50
|
||||||
g3.Height = 3
|
g3.Height = 3
|
||||||
g3.Y = 11
|
g3.Y = 11
|
||||||
g3.BorderLabel = "Gauge with custom label"
|
g3.BorderLabel = "Gauge with custom label"
|
||||||
g3.Label = "{{percent}}% (100MBs free)"
|
g3.Label = "{{percent}}% (100MBs free)"
|
||||||
g3.LabelAlign = termui.AlignRight
|
g3.LabelAlign = ui.AlignRight
|
||||||
|
|
||||||
g4 := termui.NewGauge()
|
g4 := ui.NewGauge()
|
||||||
g4.Percent = 50
|
g4.Percent = 50
|
||||||
g4.Width = 50
|
g4.Width = 50
|
||||||
g4.Height = 3
|
g4.Height = 3
|
||||||
g4.Y = 14
|
g4.Y = 14
|
||||||
g4.BorderLabel = "Gauge"
|
g4.BorderLabel = "Gauge"
|
||||||
g4.Label = "Gauge with custom highlighted label"
|
g4.Label = "Gauge with custom highlighted label"
|
||||||
g4.PercentColor = termui.ColorYellow
|
g4.PercentColor = ui.ColorYellow
|
||||||
g4.BarColor = termui.ColorGreen
|
g4.BarColor = ui.ColorGreen
|
||||||
g4.PercentColorHighlighted = termui.ColorBlack
|
g4.PercentColorHighlighted = ui.ColorBlack
|
||||||
|
|
||||||
termui.Render(g0, g1, g2, g3, g4)
|
ui.Render(g0, g1, g2, g3, g4)
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
termui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
|
|
||||||
termui.Loop()
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := ui.Init(); err != nil {
|
ui.Init()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer ui.Close()
|
defer ui.Close()
|
||||||
|
|
||||||
sinps := (func() []float64 {
|
sinps := (func() []float64 {
|
||||||
@ -96,6 +94,7 @@ func main() {
|
|||||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
|
|
||||||
ui.Handle("/timer/1s", func(e ui.Event) {
|
ui.Handle("/timer/1s", func(e ui.Event) {
|
||||||
t := e.Data.(ui.EvtTimer)
|
t := e.Data.(ui.EvtTimer)
|
||||||
i := t.Count
|
i := t.Count
|
||||||
|
@ -9,17 +9,12 @@ package main
|
|||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := termui.Init()
|
err := ui.Init()
|
||||||
if err != nil {
|
defer ui.Close()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer termui.Close()
|
|
||||||
|
|
||||||
//termui.UseTheme("helloworld")
|
|
||||||
|
|
||||||
sinps := (func() map[string][]float64 {
|
sinps := (func() map[string][]float64 {
|
||||||
n := 220
|
n := 220
|
||||||
@ -33,17 +28,17 @@ func main() {
|
|||||||
return ps
|
return ps
|
||||||
})()
|
})()
|
||||||
|
|
||||||
lc0 := termui.NewLineChart()
|
lc0 := ui.NewLineChart()
|
||||||
lc0.BorderLabel = "braille-mode Line Chart"
|
lc0.BorderLabel = "braille-mode Line Chart"
|
||||||
lc0.Data = sinps
|
lc0.Data = sinps
|
||||||
lc0.Width = 50
|
lc0.Width = 50
|
||||||
lc0.Height = 12
|
lc0.Height = 12
|
||||||
lc0.X = 0
|
lc0.X = 0
|
||||||
lc0.Y = 0
|
lc0.Y = 0
|
||||||
lc0.AxesColor = termui.ColorWhite
|
lc0.AxesColor = ui.ColorWhite
|
||||||
lc0.LineColor["first"] = termui.ColorGreen | termui.AttrBold
|
lc0.LineColor["first"] = ui.ColorGreen | ui.AttrBold
|
||||||
|
|
||||||
lc1 := termui.NewLineChart()
|
lc1 := ui.NewLineChart()
|
||||||
lc1.BorderLabel = "dot-mode Line Chart"
|
lc1.BorderLabel = "dot-mode Line Chart"
|
||||||
lc1.Mode = "dot"
|
lc1.Mode = "dot"
|
||||||
lc1.Data = sinps
|
lc1.Data = sinps
|
||||||
@ -51,10 +46,10 @@ func main() {
|
|||||||
lc1.Height = 12
|
lc1.Height = 12
|
||||||
lc1.X = 51
|
lc1.X = 51
|
||||||
lc1.DotStyle = '+'
|
lc1.DotStyle = '+'
|
||||||
lc1.AxesColor = termui.ColorWhite
|
lc1.AxesColor = ui.ColorWhite
|
||||||
lc1.LineColor["first"] = termui.ColorYellow | termui.AttrBold
|
lc1.LineColor["first"] = ui.ColorYellow | ui.AttrBold
|
||||||
|
|
||||||
lc2 := termui.NewLineChart()
|
lc2 := ui.NewLineChart()
|
||||||
lc2.BorderLabel = "dot-mode Line Chart"
|
lc2.BorderLabel = "dot-mode Line Chart"
|
||||||
lc2.Mode = "dot"
|
lc2.Mode = "dot"
|
||||||
lc2.Data["first"] = sinps["first"][4:]
|
lc2.Data["first"] = sinps["first"][4:]
|
||||||
@ -63,13 +58,14 @@ func main() {
|
|||||||
lc2.Height = 16
|
lc2.Height = 16
|
||||||
lc2.X = 0
|
lc2.X = 0
|
||||||
lc2.Y = 12
|
lc2.Y = 12
|
||||||
lc2.AxesColor = termui.ColorWhite
|
lc2.AxesColor = ui.ColorWhite
|
||||||
lc2.LineColor["first"] = termui.ColorCyan | termui.AttrBold
|
lc2.LineColor["first"] = ui.ColorCyan | ui.AttrBold
|
||||||
|
|
||||||
termui.Render(lc0, lc1, lc2)
|
ui.Render(lc0, lc1, lc2)
|
||||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
|
||||||
termui.StopLoop()
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
termui.Loop()
|
|
||||||
|
|
||||||
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,11 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/gizak/termui"
|
import ui "github.com/gizak/termui"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := termui.Init()
|
ui.Init()
|
||||||
if err != nil {
|
defer ui.Close()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer termui.Close()
|
|
||||||
|
|
||||||
//termui.UseTheme("helloworld")
|
|
||||||
|
|
||||||
strs := []string{
|
strs := []string{
|
||||||
"[0] github.com/gizak/termui",
|
"[0] github.com/gizak/termui",
|
||||||
@ -27,18 +22,19 @@ func main() {
|
|||||||
"[6] dashboard.go",
|
"[6] dashboard.go",
|
||||||
"[7] nsf/termbox-go"}
|
"[7] nsf/termbox-go"}
|
||||||
|
|
||||||
ls := termui.NewList()
|
ls := ui.NewList()
|
||||||
ls.Items = strs
|
ls.Items = strs
|
||||||
ls.ItemFgColor = termui.ColorYellow
|
ls.ItemFgColor = ui.ColorYellow
|
||||||
ls.BorderLabel = "List"
|
ls.BorderLabel = "List"
|
||||||
ls.Height = 7
|
ls.Height = 7
|
||||||
ls.Width = 25
|
ls.Width = 25
|
||||||
ls.Y = 0
|
ls.Y = 0
|
||||||
|
|
||||||
termui.Render(ls)
|
ui.Render(ls)
|
||||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
|
||||||
termui.StopLoop()
|
|
||||||
})
|
|
||||||
termui.Loop()
|
|
||||||
|
|
||||||
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
|
ui.StopLoop()
|
||||||
|
})
|
||||||
|
|
||||||
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,13 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/gizak/termui"
|
import ui "github.com/gizak/termui"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := termui.Init()
|
ui.Init()
|
||||||
if err != nil {
|
defer ui.Close()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer termui.Close()
|
|
||||||
|
|
||||||
//termui.UseTheme("helloworld")
|
bc := ui.NewMBarChart()
|
||||||
|
|
||||||
bc := termui.NewMBarChart()
|
|
||||||
math := []int{90, 85, 90, 80}
|
math := []int{90, 85, 90, 80}
|
||||||
english := []int{70, 85, 75, 60}
|
english := []int{70, 85, 75, 60}
|
||||||
science := []int{75, 60, 80, 85}
|
science := []int{75, 60, 80, 85}
|
||||||
@ -36,19 +31,20 @@ func main() {
|
|||||||
bc.ShowScale = true //Show y_axis scale value (min and max)
|
bc.ShowScale = true //Show y_axis scale value (min and max)
|
||||||
bc.SetMax(400)
|
bc.SetMax(400)
|
||||||
|
|
||||||
bc.TextColor = termui.ColorGreen //this is color for label (x-axis)
|
bc.TextColor = ui.ColorGreen //this is color for label (x-axis)
|
||||||
bc.BarColor[3] = termui.ColorGreen //BarColor for computerscience
|
bc.BarColor[3] = ui.ColorGreen //BarColor for computerscience
|
||||||
bc.BarColor[1] = termui.ColorYellow //Bar Color for english
|
bc.BarColor[1] = ui.ColorYellow //Bar Color for english
|
||||||
bc.NumColor[3] = termui.ColorRed // Num color for computerscience
|
bc.NumColor[3] = ui.ColorRed // Num color for computerscience
|
||||||
bc.NumColor[1] = termui.ColorRed // num color for english
|
bc.NumColor[1] = ui.ColorRed // num color for english
|
||||||
|
|
||||||
//Other colors are automatically populated, btw All the students seems do well in computerscience. :p
|
//Other colors are automatically populated, btw All the students seems do well in computerscience. :p
|
||||||
|
|
||||||
termui.Render(bc)
|
ui.Render(bc)
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
termui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
termui.Loop()
|
|
||||||
|
ui.Loop()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,47 +6,43 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/gizak/termui"
|
import ui "github.com/gizak/termui"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := termui.Init()
|
ui.Init()
|
||||||
if err != nil {
|
defer ui.Close()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer termui.Close()
|
|
||||||
|
|
||||||
//termui.UseTheme("helloworld")
|
par0 := ui.NewPar("Borderless Text")
|
||||||
|
|
||||||
par0 := termui.NewPar("Borderless Text")
|
|
||||||
par0.Height = 1
|
par0.Height = 1
|
||||||
par0.Width = 20
|
par0.Width = 20
|
||||||
par0.Y = 1
|
par0.Y = 1
|
||||||
par0.Border = false
|
par0.Border = false
|
||||||
|
|
||||||
par1 := termui.NewPar("你好,世界。")
|
par1 := ui.NewPar("你好,世界。")
|
||||||
par1.Height = 3
|
par1.Height = 3
|
||||||
par1.Width = 17
|
par1.Width = 17
|
||||||
par1.X = 20
|
par1.X = 20
|
||||||
par1.BorderLabel = "标签"
|
par1.BorderLabel = "标签"
|
||||||
|
|
||||||
par2 := termui.NewPar("Simple colored text\nwith label. It [can be](fg-red) multilined with \\n or [break automatically](fg-red,fg-bold)")
|
par2 := ui.NewPar("Simple colored text\nwith label. It [can be](fg-red) multilined with \\n or [break automatically](fg-red,fg-bold)")
|
||||||
par2.Height = 5
|
par2.Height = 5
|
||||||
par2.Width = 37
|
par2.Width = 37
|
||||||
par2.Y = 4
|
par2.Y = 4
|
||||||
par2.BorderLabel = "Multiline"
|
par2.BorderLabel = "Multiline"
|
||||||
par2.BorderFg = termui.ColorYellow
|
par2.BorderFg = ui.ColorYellow
|
||||||
|
|
||||||
par3 := termui.NewPar("Long text with label and it is auto trimmed.")
|
par3 := ui.NewPar("Long text with label and it is auto trimmed.")
|
||||||
par3.Height = 3
|
par3.Height = 3
|
||||||
par3.Width = 37
|
par3.Width = 37
|
||||||
par3.Y = 9
|
par3.Y = 9
|
||||||
par3.BorderLabel = "Auto Trim"
|
par3.BorderLabel = "Auto Trim"
|
||||||
|
|
||||||
termui.Render(par0, par1, par2, par3)
|
ui.Render(par0, par1, par2, par3)
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
termui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
termui.Loop()
|
|
||||||
|
ui.Loop()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,13 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := termui.Init(); err != nil {
|
ui.Init()
|
||||||
panic(err)
|
defer ui.Close()
|
||||||
}
|
|
||||||
defer termui.Close()
|
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
randomDataAndOffset := func() (data []float64, offset float64) {
|
randomDataAndOffset := func() (data []float64, offset float64) {
|
||||||
noSlices := 1 + rand.Intn(5)
|
noSlices := 1 + rand.Intn(5)
|
||||||
@ -28,7 +27,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
run := true
|
run := true
|
||||||
|
|
||||||
pc := termui.NewPieChart()
|
pc := ui.NewPieChart()
|
||||||
pc.BorderLabel = "Pie Chart"
|
pc.BorderLabel = "Pie Chart"
|
||||||
pc.Width = 70
|
pc.Width = 70
|
||||||
pc.Height = 36
|
pc.Height = 36
|
||||||
@ -38,26 +37,28 @@ func main() {
|
|||||||
return fmt.Sprintf("%.02f", v)
|
return fmt.Sprintf("%.02f", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
termui.Handle("/timer/1s", func(e termui.Event) {
|
ui.Handle("/timer/1s", func(e ui.Event) {
|
||||||
if run {
|
if run {
|
||||||
pc.Data, pc.Offset = randomDataAndOffset()
|
pc.Data, pc.Offset = randomDataAndOffset()
|
||||||
termui.Render(pc)
|
ui.Render(pc)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/s", func(termui.Event) {
|
ui.Handle("/sys/kbd/s", func(ui.Event) {
|
||||||
run = !run
|
run = !run
|
||||||
if run {
|
if run {
|
||||||
pc.BorderLabel = "Pie Chart"
|
pc.BorderLabel = "Pie Chart"
|
||||||
} else {
|
} else {
|
||||||
pc.BorderLabel = "Pie Chart (Stopped)"
|
pc.BorderLabel = "Pie Chart (Stopped)"
|
||||||
}
|
}
|
||||||
termui.Render(pc)
|
ui.Render(pc)
|
||||||
})
|
})
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
termui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
termui.Render(pc)
|
|
||||||
termui.Loop()
|
ui.Render(pc)
|
||||||
|
|
||||||
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
@ -6,64 +6,59 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/gizak/termui"
|
import ui "github.com/gizak/termui"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := termui.Init()
|
ui.Init()
|
||||||
if err != nil {
|
defer ui.Close()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer termui.Close()
|
|
||||||
|
|
||||||
//termui.UseTheme("helloworld")
|
|
||||||
|
|
||||||
data := []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}
|
data := []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}
|
||||||
spl0 := termui.NewSparkline()
|
spl0 := ui.NewSparkline()
|
||||||
spl0.Data = data[3:]
|
spl0.Data = data[3:]
|
||||||
spl0.Title = "Sparkline 0"
|
spl0.Title = "Sparkline 0"
|
||||||
spl0.LineColor = termui.ColorGreen
|
spl0.LineColor = ui.ColorGreen
|
||||||
|
|
||||||
// single
|
// single
|
||||||
spls0 := termui.NewSparklines(spl0)
|
spls0 := ui.NewSparklines(spl0)
|
||||||
spls0.Height = 2
|
spls0.Height = 2
|
||||||
spls0.Width = 20
|
spls0.Width = 20
|
||||||
spls0.Border = false
|
spls0.Border = false
|
||||||
|
|
||||||
spl1 := termui.NewSparkline()
|
spl1 := ui.NewSparkline()
|
||||||
spl1.Data = data
|
spl1.Data = data
|
||||||
spl1.Title = "Sparkline 1"
|
spl1.Title = "Sparkline 1"
|
||||||
spl1.LineColor = termui.ColorRed
|
spl1.LineColor = ui.ColorRed
|
||||||
|
|
||||||
spl2 := termui.NewSparkline()
|
spl2 := ui.NewSparkline()
|
||||||
spl2.Data = data[5:]
|
spl2.Data = data[5:]
|
||||||
spl2.Title = "Sparkline 2"
|
spl2.Title = "Sparkline 2"
|
||||||
spl2.LineColor = termui.ColorMagenta
|
spl2.LineColor = ui.ColorMagenta
|
||||||
|
|
||||||
// group
|
// group
|
||||||
spls1 := termui.NewSparklines(spl0, spl1, spl2)
|
spls1 := ui.NewSparklines(spl0, spl1, spl2)
|
||||||
spls1.Height = 8
|
spls1.Height = 8
|
||||||
spls1.Width = 20
|
spls1.Width = 20
|
||||||
spls1.Y = 3
|
spls1.Y = 3
|
||||||
spls1.BorderLabel = "Group Sparklines"
|
spls1.BorderLabel = "Group Sparklines"
|
||||||
|
|
||||||
spl3 := termui.NewSparkline()
|
spl3 := ui.NewSparkline()
|
||||||
spl3.Data = data
|
spl3.Data = data
|
||||||
spl3.Title = "Enlarged Sparkline"
|
spl3.Title = "Enlarged Sparkline"
|
||||||
spl3.Height = 8
|
spl3.Height = 8
|
||||||
spl3.LineColor = termui.ColorYellow
|
spl3.LineColor = ui.ColorYellow
|
||||||
|
|
||||||
spls2 := termui.NewSparklines(spl3)
|
spls2 := ui.NewSparklines(spl3)
|
||||||
spls2.Height = 11
|
spls2.Height = 11
|
||||||
spls2.Width = 30
|
spls2.Width = 30
|
||||||
spls2.BorderFg = termui.ColorCyan
|
spls2.BorderFg = ui.ColorCyan
|
||||||
spls2.X = 21
|
spls2.X = 21
|
||||||
spls2.BorderLabel = "Tweeked Sparkline"
|
spls2.BorderLabel = "Tweeked Sparkline"
|
||||||
|
|
||||||
termui.Render(spls0, spls1, spls2)
|
ui.Render(spls0, spls1, spls2)
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
termui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
termui.Loop()
|
|
||||||
|
|
||||||
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
@ -6,30 +6,28 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/gizak/termui"
|
import ui "github.com/gizak/termui"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := termui.Init()
|
ui.Init()
|
||||||
if err != nil {
|
defer ui.Close()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer termui.Close()
|
|
||||||
rows1 := [][]string{
|
rows1 := [][]string{
|
||||||
[]string{"header1", "header2", "header3"},
|
[]string{"header1", "header2", "header3"},
|
||||||
[]string{"你好吗", "Go-lang is so cool", "Im working on Ruby"},
|
[]string{"你好吗", "Go-lang is so cool", "Im working on Ruby"},
|
||||||
[]string{"2016", "10", "11"},
|
[]string{"2016", "10", "11"},
|
||||||
}
|
}
|
||||||
|
|
||||||
table1 := termui.NewTable()
|
table1 := ui.NewTable()
|
||||||
table1.Rows = rows1
|
table1.Rows = rows1
|
||||||
table1.FgColor = termui.ColorWhite
|
table1.FgColor = ui.ColorWhite
|
||||||
table1.BgColor = termui.ColorDefault
|
table1.BgColor = ui.ColorDefault
|
||||||
table1.Y = 0
|
table1.Y = 0
|
||||||
table1.X = 0
|
table1.X = 0
|
||||||
table1.Width = 62
|
table1.Width = 62
|
||||||
table1.Height = 7
|
table1.Height = 7
|
||||||
|
|
||||||
termui.Render(table1)
|
ui.Render(table1)
|
||||||
|
|
||||||
rows2 := [][]string{
|
rows2 := [][]string{
|
||||||
[]string{"header1", "header2", "header3"},
|
[]string{"header1", "header2", "header3"},
|
||||||
@ -37,22 +35,24 @@ func main() {
|
|||||||
[]string{"2016", "11", "11"},
|
[]string{"2016", "11", "11"},
|
||||||
}
|
}
|
||||||
|
|
||||||
table2 := termui.NewTable()
|
table2 := ui.NewTable()
|
||||||
table2.Rows = rows2
|
table2.Rows = rows2
|
||||||
table2.FgColor = termui.ColorWhite
|
table2.FgColor = ui.ColorWhite
|
||||||
table2.BgColor = termui.ColorDefault
|
table2.BgColor = ui.ColorDefault
|
||||||
table2.TextAlign = termui.AlignCenter
|
table2.TextAlign = ui.AlignCenter
|
||||||
table2.Separator = false
|
table2.Separator = false
|
||||||
table2.Analysis()
|
table2.Analysis()
|
||||||
table2.SetSize()
|
table2.SetSize()
|
||||||
table2.BgColors[2] = termui.ColorRed
|
table2.BgColors[2] = ui.ColorRed
|
||||||
table2.Y = 10
|
table2.Y = 10
|
||||||
table2.X = 0
|
table2.X = 0
|
||||||
table2.Border = true
|
table2.Border = true
|
||||||
|
|
||||||
termui.Render(table2)
|
ui.Render(table2)
|
||||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
|
||||||
termui.StopLoop()
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
termui.Loop()
|
|
||||||
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
@ -7,36 +7,31 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
"github.com/gizak/termui/extra"
|
"github.com/gizak/termui/extra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := termui.Init()
|
ui.Init()
|
||||||
if err != nil {
|
defer ui.Close()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer termui.Close()
|
|
||||||
|
|
||||||
//termui.UseTheme("helloworld")
|
header := ui.NewPar("Press q to quit, Press j or k to switch tabs")
|
||||||
|
|
||||||
header := termui.NewPar("Press q to quit, Press j or k to switch tabs")
|
|
||||||
header.Height = 1
|
header.Height = 1
|
||||||
header.Width = 50
|
header.Width = 50
|
||||||
header.Border = false
|
header.Border = false
|
||||||
header.TextBgColor = termui.ColorBlue
|
header.TextBgColor = ui.ColorBlue
|
||||||
|
|
||||||
tab1 := extra.NewTab("pierwszy")
|
tab1 := extra.NewTab("pierwszy")
|
||||||
par2 := termui.NewPar("Press q to quit\nPress j or k to switch tabs\n")
|
par2 := ui.NewPar("Press q to quit\nPress j or k to switch tabs\n")
|
||||||
par2.Height = 5
|
par2.Height = 5
|
||||||
par2.Width = 37
|
par2.Width = 37
|
||||||
par2.Y = 0
|
par2.Y = 0
|
||||||
par2.BorderLabel = "Keys"
|
par2.BorderLabel = "Keys"
|
||||||
par2.BorderFg = termui.ColorYellow
|
par2.BorderFg = ui.ColorYellow
|
||||||
tab1.AddBlocks(par2)
|
tab1.AddBlocks(par2)
|
||||||
|
|
||||||
tab2 := extra.NewTab("drugi")
|
tab2 := extra.NewTab("drugi")
|
||||||
bc := termui.NewBarChart()
|
bc := ui.NewBarChart()
|
||||||
data := []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}
|
data := []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"}
|
bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
||||||
bc.BorderLabel = "Bar Chart"
|
bc.BorderLabel = "Bar Chart"
|
||||||
@ -44,9 +39,9 @@ func main() {
|
|||||||
bc.Width = 26
|
bc.Width = 26
|
||||||
bc.Height = 10
|
bc.Height = 10
|
||||||
bc.DataLabels = bclabels
|
bc.DataLabels = bclabels
|
||||||
bc.TextColor = termui.ColorGreen
|
bc.TextColor = ui.ColorGreen
|
||||||
bc.BarColor = termui.ColorRed
|
bc.BarColor = ui.ColorRed
|
||||||
bc.NumColor = termui.ColorYellow
|
bc.NumColor = ui.ColorYellow
|
||||||
tab2.AddBlocks(bc)
|
tab2.AddBlocks(bc)
|
||||||
|
|
||||||
tab3 := extra.NewTab("trzeci")
|
tab3 := extra.NewTab("trzeci")
|
||||||
@ -61,23 +56,23 @@ func main() {
|
|||||||
|
|
||||||
tabpane.SetTabs(*tab1, *tab2, *tab3, *tab4, *tab5, *tab6)
|
tabpane.SetTabs(*tab1, *tab2, *tab3, *tab4, *tab5, *tab6)
|
||||||
|
|
||||||
termui.Render(header, tabpane)
|
ui.Render(header, tabpane)
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
termui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/j", func(termui.Event) {
|
ui.Handle("/sys/kbd/j", func(ui.Event) {
|
||||||
tabpane.SetActiveLeft()
|
tabpane.SetActiveLeft()
|
||||||
termui.Clear()
|
ui.Clear()
|
||||||
termui.Render(header, tabpane)
|
ui.Render(header, tabpane)
|
||||||
})
|
})
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/k", func(termui.Event) {
|
ui.Handle("/sys/kbd/k", func(ui.Event) {
|
||||||
tabpane.SetActiveRight()
|
tabpane.SetActiveRight()
|
||||||
termui.Clear()
|
ui.Clear()
|
||||||
termui.Render(header, tabpane)
|
ui.Render(header, tabpane)
|
||||||
})
|
})
|
||||||
|
|
||||||
termui.Loop()
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := ui.Init()
|
ui.Init()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer ui.Close()
|
defer ui.Close()
|
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
@ -136,12 +133,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui.Render(p, list, g, sp, lc, bc, lc1, p1)
|
ui.Render(p, list, g, sp, lc, bc, lc1, p1)
|
||||||
|
|
||||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
|
|
||||||
ui.Handle("/timer/1s", func(e ui.Event) {
|
ui.Handle("/timer/1s", func(e ui.Event) {
|
||||||
t := e.Data.(ui.EvtTimer)
|
t := e.Data.(ui.EvtTimer)
|
||||||
draw(int(t.Count))
|
draw(int(t.Count))
|
||||||
})
|
})
|
||||||
|
|
||||||
ui.Loop()
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
"github.com/gizak/termui/extra"
|
"github.com/gizak/termui/extra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -201,23 +201,23 @@ func getMemStats() (ms MemStat, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CpuTabElems struct {
|
type CpuTabElems struct {
|
||||||
GMap map[string]*termui.Gauge
|
GMap map[string]*ui.Gauge
|
||||||
LChart *termui.LineChart
|
LChart *ui.LineChart
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCpuTabElems(width int) *CpuTabElems {
|
func NewCpuTabElems(width int) *CpuTabElems {
|
||||||
lc := termui.NewLineChart()
|
lc := ui.NewLineChart()
|
||||||
lc.Width = width
|
lc.Width = width
|
||||||
lc.Height = 12
|
lc.Height = 12
|
||||||
lc.X = 0
|
lc.X = 0
|
||||||
lc.Mode = "dot"
|
lc.Mode = "dot"
|
||||||
lc.BorderLabel = "CPU"
|
lc.BorderLabel = "CPU"
|
||||||
return &CpuTabElems{GMap: make(map[string]*termui.Gauge),
|
return &CpuTabElems{GMap: make(map[string]*ui.Gauge),
|
||||||
LChart: lc}
|
LChart: lc}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cte *CpuTabElems) AddGauge(key string, Y int, width int) *termui.Gauge {
|
func (cte *CpuTabElems) AddGauge(key string, Y int, width int) *ui.Gauge {
|
||||||
cte.GMap[key] = termui.NewGauge()
|
cte.GMap[key] = ui.NewGauge()
|
||||||
cte.GMap[key].Width = width
|
cte.GMap[key].Width = width
|
||||||
cte.GMap[key].Height = 3
|
cte.GMap[key].Height = 3
|
||||||
cte.GMap[key].Y = Y
|
cte.GMap[key].Y = Y
|
||||||
@ -239,21 +239,21 @@ func (cte *CpuTabElems) Update(cs CpusStats) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MemTabElems struct {
|
type MemTabElems struct {
|
||||||
Gauge *termui.Gauge
|
Gauge *ui.Gauge
|
||||||
SLines *termui.Sparklines
|
SLines *ui.Sparklines
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMemTabElems(width int) *MemTabElems {
|
func NewMemTabElems(width int) *MemTabElems {
|
||||||
g := termui.NewGauge()
|
g := ui.NewGauge()
|
||||||
g.Width = width
|
g.Width = width
|
||||||
g.Height = 3
|
g.Height = 3
|
||||||
g.Y = 0
|
g.Y = 0
|
||||||
|
|
||||||
sline := termui.NewSparkline()
|
sline := ui.NewSparkline()
|
||||||
sline.Title = "MEM"
|
sline.Title = "MEM"
|
||||||
sline.Height = 8
|
sline.Height = 8
|
||||||
|
|
||||||
sls := termui.NewSparklines(sline)
|
sls := ui.NewSparklines(sline)
|
||||||
sls.Width = width
|
sls.Width = width
|
||||||
sls.Height = 12
|
sls.Height = 12
|
||||||
sls.Y = 3
|
sls.Y = 3
|
||||||
@ -275,21 +275,16 @@ func main() {
|
|||||||
if runtime.GOOS != "linux" {
|
if runtime.GOOS != "linux" {
|
||||||
panic("Currently works only on Linux")
|
panic("Currently works only on Linux")
|
||||||
}
|
}
|
||||||
err := termui.Init()
|
ui.Init()
|
||||||
if err != nil {
|
defer ui.Close()
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer termui.Close()
|
|
||||||
|
|
||||||
termWidth := 70
|
termWidth := 70
|
||||||
|
|
||||||
//termui.UseTheme("helloworld")
|
header := ui.NewPar("Press q to quit, Press j or k to switch tabs")
|
||||||
|
|
||||||
header := termui.NewPar("Press q to quit, Press j or k to switch tabs")
|
|
||||||
header.Height = 1
|
header.Height = 1
|
||||||
header.Width = 50
|
header.Width = 50
|
||||||
header.Border = false
|
header.Border = false
|
||||||
header.TextBgColor = termui.ColorBlue
|
header.TextBgColor = ui.ColorBlue
|
||||||
|
|
||||||
tabCpu := extra.NewTab("CPU")
|
tabCpu := extra.NewTab("CPU")
|
||||||
tabMem := extra.NewTab("MEM")
|
tabMem := extra.NewTab("MEM")
|
||||||
@ -333,23 +328,23 @@ func main() {
|
|||||||
|
|
||||||
tabpane.SetTabs(*tabCpu, *tabMem)
|
tabpane.SetTabs(*tabCpu, *tabMem)
|
||||||
|
|
||||||
termui.Render(header, tabpane)
|
ui.Render(header, tabpane)
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||||
termui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/j", func(termui.Event) {
|
ui.Handle("/sys/kbd/j", func(ui.Event) {
|
||||||
tabpane.SetActiveLeft()
|
tabpane.SetActiveLeft()
|
||||||
termui.Render(header, tabpane)
|
ui.Render(header, tabpane)
|
||||||
})
|
})
|
||||||
|
|
||||||
termui.Handle("/sys/kbd/k", func(termui.Event) {
|
ui.Handle("/sys/kbd/k", func(ui.Event) {
|
||||||
tabpane.SetActiveRight()
|
tabpane.SetActiveRight()
|
||||||
termui.Render(header, tabpane)
|
ui.Render(header, tabpane)
|
||||||
})
|
})
|
||||||
|
|
||||||
termui.Handle("/timer/1s", func(e termui.Event) {
|
ui.Handle("/timer/1s", func(e ui.Event) {
|
||||||
cs, errcs := getCpusStatsMap()
|
cs, errcs := getCpusStatsMap()
|
||||||
if errcs != nil {
|
if errcs != nil {
|
||||||
panic(errcs)
|
panic(errcs)
|
||||||
@ -362,8 +357,8 @@ func main() {
|
|||||||
panic(errm)
|
panic(errm)
|
||||||
}
|
}
|
||||||
memTabElems.Update(ms)
|
memTabElems.Update(ms)
|
||||||
termui.Render(header, tabpane)
|
ui.Render(header, tabpane)
|
||||||
})
|
})
|
||||||
|
|
||||||
termui.Loop()
|
ui.Loop()
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,7 @@ package main
|
|||||||
import ui "github.com/gizak/termui"
|
import ui "github.com/gizak/termui"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
ui.Init()
|
||||||
err := ui.Init()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer ui.Close()
|
defer ui.Close()
|
||||||
|
|
||||||
p := ui.NewPar("Press q to QUIT THE DEMO. [There](fg-blue) are other things [that](fg-red) are going to fit in here I think. What do you think? Now is the time for all good [men to](bg-blue) come to the aid of their country. [This is going to be one really really really long line](fg-green) that is going to go together and stuffs and things. Let's see how this thing renders out.\n Here is a new paragraph and stuffs and things. There should be a tab indent at the beginning of the paragraph. Let's see if that worked as well.")
|
p := ui.NewPar("Press q to QUIT THE DEMO. [There](fg-blue) are other things [that](fg-red) are going to fit in here I think. What do you think? Now is the time for all good [men to](bg-blue) come to the aid of their country. [This is going to be one really really really long line](fg-green) that is going to go together and stuffs and things. Let's see how this thing renders out.\n Here is a new paragraph and stuffs and things. There should be a tab indent at the beginning of the paragraph. Let's see if that worked as well.")
|
||||||
|
20
barchart.go
20
barchart.go
@ -40,15 +40,16 @@ type BarChart struct {
|
|||||||
|
|
||||||
// NewBarChart returns a new *BarChart with current theme.
|
// NewBarChart returns a new *BarChart with current theme.
|
||||||
func NewBarChart() *BarChart {
|
func NewBarChart() *BarChart {
|
||||||
bc := &BarChart{Block: *NewBlock()}
|
return &BarChart{
|
||||||
bc.BarColor = ThemeAttr("barchart.bar.bg")
|
Block: *NewBlock(),
|
||||||
bc.NumColor = ThemeAttr("barchart.num.fg")
|
BarColor: ThemeAttr("barchart.bar.bg"),
|
||||||
bc.TextColor = ThemeAttr("barchart.text.fg")
|
NumColor: ThemeAttr("barchart.num.fg"),
|
||||||
bc.NumFmt = func(n int) string { return fmt.Sprint(n) }
|
TextColor: ThemeAttr("barchart.text.fg"),
|
||||||
bc.BarGap = 1
|
NumFmt: func(n int) string { return fmt.Sprint(n) },
|
||||||
bc.BarWidth = 3
|
BarGap: 1,
|
||||||
bc.CellChar = ' '
|
BarWidth: 3,
|
||||||
return bc
|
CellChar: ' ',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BarChart) layout() {
|
func (bc *BarChart) layout() {
|
||||||
@ -77,7 +78,6 @@ func (bc *BarChart) layout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BarChart) SetMax(max int) {
|
func (bc *BarChart) SetMax(max int) {
|
||||||
|
|
||||||
if max > 0 {
|
if max > 0 {
|
||||||
bc.max = max
|
bc.max = max
|
||||||
}
|
}
|
||||||
|
34
block.go
34
block.go
@ -125,23 +125,23 @@ type Block struct {
|
|||||||
|
|
||||||
// NewBlock returns a *Block which inherits styles from current theme.
|
// NewBlock returns a *Block which inherits styles from current theme.
|
||||||
func NewBlock() *Block {
|
func NewBlock() *Block {
|
||||||
b := Block{}
|
return &Block{
|
||||||
b.Display = true
|
Display: true,
|
||||||
b.Border = true
|
Border: true,
|
||||||
b.BorderLeft = true
|
BorderLeft: true,
|
||||||
b.BorderRight = true
|
BorderRight: true,
|
||||||
b.BorderTop = true
|
BorderTop: true,
|
||||||
b.BorderBottom = true
|
BorderBottom: true,
|
||||||
b.BorderBg = ThemeAttr("border.bg")
|
BorderBg: ThemeAttr("border.bg"),
|
||||||
b.BorderFg = ThemeAttr("border.fg")
|
BorderFg: ThemeAttr("border.fg"),
|
||||||
b.BorderLabelBg = ThemeAttr("label.bg")
|
BorderLabelBg: ThemeAttr("label.bg"),
|
||||||
b.BorderLabelFg = ThemeAttr("label.fg")
|
BorderLabelFg: ThemeAttr("label.fg"),
|
||||||
b.Bg = ThemeAttr("block.bg")
|
Bg: ThemeAttr("block.bg"),
|
||||||
b.Width = 2
|
Width: 2,
|
||||||
b.Height = 2
|
Height: 2,
|
||||||
b.id = GenId()
|
id: GenId(),
|
||||||
b.Float = AlignNone
|
Float: AlignNone,
|
||||||
return &b
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Block) Id() string {
|
func (b Block) Id() string {
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
|
|
||||||
package termui
|
package termui
|
||||||
|
|
||||||
import (
|
import "testing"
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestBlockFloat(t *testing.T) {
|
func TestBlockFloat(t *testing.T) {
|
||||||
Init()
|
Init()
|
||||||
|
1
gauge.go
1
gauge.go
@ -43,7 +43,6 @@ func NewGauge() *Gauge {
|
|||||||
LabelAlign: AlignCenter,
|
LabelAlign: AlignCenter,
|
||||||
PercentColorHighlighted: ColorUndef,
|
PercentColorHighlighted: ColorUndef,
|
||||||
}
|
}
|
||||||
|
|
||||||
g.Width = 12
|
g.Width = 12
|
||||||
g.Height = 5
|
g.Height = 5
|
||||||
return g
|
return g
|
||||||
|
18
helper.go
18
helper.go
@ -8,9 +8,9 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
tm "github.com/nsf/termbox-go"
|
rw "github.com/mattn/go-runewidth"
|
||||||
|
tb "github.com/nsf/termbox-go"
|
||||||
)
|
)
|
||||||
import rw "github.com/mattn/go-runewidth"
|
|
||||||
|
|
||||||
/* ---------------Port from termbox-go --------------------- */
|
/* ---------------Port from termbox-go --------------------- */
|
||||||
|
|
||||||
@ -59,8 +59,8 @@ const (
|
|||||||
|
|
||||||
/* ----------------------- End ----------------------------- */
|
/* ----------------------- End ----------------------------- */
|
||||||
|
|
||||||
func toTmAttr(x Attribute) tm.Attribute {
|
func toTmAttr(x Attribute) tb.Attribute {
|
||||||
return tm.Attribute(x)
|
return tb.Attribute(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
func str2runes(s string) []rune {
|
func str2runes(s string) []rune {
|
||||||
@ -237,14 +237,14 @@ func CellsToStr(cs []Cell) string {
|
|||||||
func SetOutputMode(mode OutputMode) {
|
func SetOutputMode(mode OutputMode) {
|
||||||
switch mode {
|
switch mode {
|
||||||
case OutputCurrent:
|
case OutputCurrent:
|
||||||
tm.SetOutputMode(tm.OutputCurrent)
|
tb.SetOutputMode(tb.OutputCurrent)
|
||||||
case OutputNormal:
|
case OutputNormal:
|
||||||
tm.SetOutputMode(tm.OutputNormal)
|
tb.SetOutputMode(tb.OutputNormal)
|
||||||
case Output256:
|
case Output256:
|
||||||
tm.SetOutputMode(tm.Output256)
|
tb.SetOutputMode(tb.Output256)
|
||||||
case Output216:
|
case Output216:
|
||||||
tm.SetOutputMode(tm.Output216)
|
tb.SetOutputMode(tb.Output216)
|
||||||
case OutputGrayscale:
|
case OutputGrayscale:
|
||||||
tm.SetOutputMode(tm.OutputGrayscale)
|
tb.SetOutputMode(tb.OutputGrayscale)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
linechart.go
31
linechart.go
@ -79,21 +79,22 @@ type LineChart struct {
|
|||||||
|
|
||||||
// NewLineChart returns a new LineChart with current theme.
|
// NewLineChart returns a new LineChart with current theme.
|
||||||
func NewLineChart() *LineChart {
|
func NewLineChart() *LineChart {
|
||||||
lc := &LineChart{Block: *NewBlock()}
|
return &LineChart{
|
||||||
lc.AxesColor = ThemeAttr("linechart.axes.fg")
|
Block: *NewBlock(),
|
||||||
lc.defaultLineColor = ThemeAttr("linechart.line.fg")
|
AxesColor: ThemeAttr("linechart.axes.fg"),
|
||||||
lc.Mode = "braille"
|
defaultLineColor: ThemeAttr("linechart.line.fg"),
|
||||||
lc.DotStyle = '•'
|
Mode: "braille",
|
||||||
lc.Data = make(map[string][]float64)
|
DotStyle: '•',
|
||||||
lc.LineColor = make(map[string]Attribute)
|
Data: make(map[string][]float64),
|
||||||
lc.axisXLabelGap = 2
|
LineColor: make(map[string]Attribute),
|
||||||
lc.axisYLabelGap = 1
|
axisXLabelGap: 2,
|
||||||
lc.bottomValue = math.Inf(1)
|
axisYLabelGap: 1,
|
||||||
lc.topValue = math.Inf(-1)
|
bottomValue: math.Inf(1),
|
||||||
lc.YPadding = 0.2
|
topValue: math.Inf(-1),
|
||||||
lc.YFloor = math.Inf(-1)
|
YPadding: 0.2,
|
||||||
lc.YCeil = math.Inf(1)
|
YFloor: math.Inf(-1),
|
||||||
return lc
|
YCeil: math.Inf(1),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// one cell contains two data points, so capicity is 2x dot mode
|
// one cell contains two data points, so capicity is 2x dot mode
|
||||||
|
12
list.go
12
list.go
@ -39,11 +39,12 @@ type List struct {
|
|||||||
|
|
||||||
// NewList returns a new *List with current theme.
|
// NewList returns a new *List with current theme.
|
||||||
func NewList() *List {
|
func NewList() *List {
|
||||||
l := &List{Block: *NewBlock()}
|
return &List{
|
||||||
l.Overflow = "hidden"
|
Block: *NewBlock(),
|
||||||
l.ItemFgColor = ThemeAttr("list.item.fg")
|
Overflow: "hidden",
|
||||||
l.ItemBgColor = ThemeAttr("list.item.bg")
|
ItemFgColor: ThemeAttr("list.item.fg"),
|
||||||
return l
|
ItemBgColor: ThemeAttr("list.item.bg"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buffer implements Bufferer interface.
|
// Buffer implements Bufferer interface.
|
||||||
@ -85,5 +86,6 @@ func (l *List) Buffer() Buffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
23
mbarchart.go
23
mbarchart.go
@ -46,16 +46,18 @@ type MBarChart struct {
|
|||||||
maxScale []rune
|
maxScale []rune
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBarChart returns a new *BarChart with current theme.
|
// NewMBarChart returns a new *MBarChart with current theme.
|
||||||
func NewMBarChart() *MBarChart {
|
func NewMBarChart() *MBarChart {
|
||||||
bc := &MBarChart{Block: *NewBlock()}
|
mbc := &MBarChart{
|
||||||
bc.BarColor[0] = ThemeAttr("mbarchart.bar.bg")
|
Block: *NewBlock(),
|
||||||
bc.NumColor[0] = ThemeAttr("mbarchart.num.fg")
|
TextColor: ThemeAttr("mbarchart.text.fg"),
|
||||||
bc.TextColor = ThemeAttr("mbarchart.text.fg")
|
NumFmt: func(n int) string { return fmt.Sprint(n) },
|
||||||
bc.NumFmt = func(n int) string { return fmt.Sprint(n) }
|
BarGap: 1,
|
||||||
bc.BarGap = 1
|
BarWidth: 3,
|
||||||
bc.BarWidth = 3
|
}
|
||||||
return bc
|
mbc.BarColor[0] = ThemeAttr("mbarchart.bar.bg")
|
||||||
|
mbc.NumColor[0] = ThemeAttr("mbarchart.num.fg")
|
||||||
|
return mbc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *MBarChart) layout() {
|
func (bc *MBarChart) layout() {
|
||||||
@ -139,7 +141,6 @@ func (bc *MBarChart) layout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bc *MBarChart) SetMax(max int) {
|
func (bc *MBarChart) SetMax(max int) {
|
||||||
|
|
||||||
if max > 0 {
|
if max > 0 {
|
||||||
bc.max = max
|
bc.max = max
|
||||||
}
|
}
|
||||||
@ -148,7 +149,9 @@ func (bc *MBarChart) SetMax(max int) {
|
|||||||
// Buffer implements Bufferer interface.
|
// Buffer implements Bufferer interface.
|
||||||
func (bc *MBarChart) Buffer() Buffer {
|
func (bc *MBarChart) Buffer() Buffer {
|
||||||
buf := bc.Block.Buffer()
|
buf := bc.Block.Buffer()
|
||||||
|
|
||||||
bc.layout()
|
bc.layout()
|
||||||
|
|
||||||
var oftX int
|
var oftX int
|
||||||
|
|
||||||
for i := 0; i < bc.numBar && i < bc.minDataLen && i < len(bc.DataLabels); i++ {
|
for i := 0; i < bc.numBar && i < bc.minDataLen && i < len(bc.DataLabels); i++ {
|
||||||
|
22
render.go
22
render.go
@ -10,7 +10,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
tm "github.com/nsf/termbox-go"
|
tb "github.com/nsf/termbox-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bufferer should be implemented by all renderable components.
|
// Bufferer should be implemented by all renderable components.
|
||||||
@ -21,10 +21,10 @@ type Bufferer interface {
|
|||||||
// Init initializes termui library. This function should be called before any others.
|
// Init initializes termui library. This function should be called before any others.
|
||||||
// After initialization, the library must be finalized by 'Close' function.
|
// After initialization, the library must be finalized by 'Close' function.
|
||||||
func Init() error {
|
func Init() error {
|
||||||
if err := tm.Init(); err != nil {
|
if err := tb.Init(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tm.SetInputMode(tm.InputEsc | tm.InputMouse)
|
tb.SetInputMode(tb.InputEsc | tb.InputMouse)
|
||||||
DefaultEvtStream = NewEvtStream()
|
DefaultEvtStream = NewEvtStream()
|
||||||
|
|
||||||
sysEvtChs = make([]chan Event, 0)
|
sysEvtChs = make([]chan Event, 0)
|
||||||
@ -65,15 +65,15 @@ func Init() error {
|
|||||||
// Close finalizes termui library,
|
// Close finalizes termui library,
|
||||||
// should be called after successful initialization when termui's functionality isn't required anymore.
|
// should be called after successful initialization when termui's functionality isn't required anymore.
|
||||||
func Close() {
|
func Close() {
|
||||||
tm.Close()
|
tb.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
var renderLock sync.Mutex
|
var renderLock sync.Mutex
|
||||||
|
|
||||||
func termSync() {
|
func termSync() {
|
||||||
renderLock.Lock()
|
renderLock.Lock()
|
||||||
tm.Sync()
|
tb.Sync()
|
||||||
termWidth, termHeight = tm.Size()
|
termWidth, termHeight = tb.Size()
|
||||||
renderLock.Unlock()
|
renderLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ func render(bs ...Bufferer) {
|
|||||||
for p, c := range buf.CellMap {
|
for p, c := range buf.CellMap {
|
||||||
if p.In(buf.Area) {
|
if p.In(buf.Area) {
|
||||||
|
|
||||||
tm.SetCell(p.X, p.Y, c.Ch, toTmAttr(c.Fg), toTmAttr(c.Bg))
|
tb.SetCell(p.X, p.Y, c.Ch, toTmAttr(c.Fg), toTmAttr(c.Bg))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,25 +114,25 @@ func render(bs ...Bufferer) {
|
|||||||
|
|
||||||
renderLock.Lock()
|
renderLock.Lock()
|
||||||
// render
|
// render
|
||||||
tm.Flush()
|
tb.Flush()
|
||||||
renderLock.Unlock()
|
renderLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Clear() {
|
func Clear() {
|
||||||
tm.Clear(tm.ColorDefault, toTmAttr(ThemeAttr("bg")))
|
tb.Clear(tb.ColorDefault, toTmAttr(ThemeAttr("bg")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func clearArea(r image.Rectangle, bg Attribute) {
|
func clearArea(r image.Rectangle, bg Attribute) {
|
||||||
for i := r.Min.X; i < r.Max.X; i++ {
|
for i := r.Min.X; i < r.Max.X; i++ {
|
||||||
for j := r.Min.Y; j < r.Max.Y; j++ {
|
for j := r.Min.Y; j < r.Max.Y; j++ {
|
||||||
tm.SetCell(i, j, ' ', tm.ColorDefault, toTmAttr(bg))
|
tb.SetCell(i, j, ' ', tb.ColorDefault, toTmAttr(bg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClearArea(r image.Rectangle, bg Attribute) {
|
func ClearArea(r image.Rectangle, bg Attribute) {
|
||||||
clearArea(r, bg)
|
clearArea(r, bg)
|
||||||
tm.Flush()
|
tb.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
var renderJobs chan []Bufferer
|
var renderJobs chan []Bufferer
|
||||||
|
@ -53,8 +53,7 @@ func NewSparkline() Sparkline {
|
|||||||
|
|
||||||
// NewSparklines return a new *Sparklines with given Sparkline(s), you can always add a new Sparkline later.
|
// NewSparklines return a new *Sparklines with given Sparkline(s), you can always add a new Sparkline later.
|
||||||
func NewSparklines(ss ...Sparkline) *Sparklines {
|
func NewSparklines(ss ...Sparkline) *Sparklines {
|
||||||
s := &Sparklines{Block: *NewBlock(), Lines: ss}
|
return &Sparklines{Block: *NewBlock(), Lines: ss}
|
||||||
return s
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sl *Sparklines) update() {
|
func (sl *Sparklines) update() {
|
||||||
|
11
table.go
11
table.go
@ -51,11 +51,12 @@ type Table struct {
|
|||||||
|
|
||||||
// NewTable returns a new Table instance
|
// NewTable returns a new Table instance
|
||||||
func NewTable() *Table {
|
func NewTable() *Table {
|
||||||
table := &Table{Block: *NewBlock()}
|
return &Table{
|
||||||
table.FgColor = ColorWhite
|
Block: *NewBlock(),
|
||||||
table.BgColor = ColorDefault
|
FgColor: ColorWhite,
|
||||||
table.Separator = true
|
BgColor: ColorDefault,
|
||||||
return table
|
Separator: true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CellsWidth calculates the width of a cell array and returns an int
|
// CellsWidth calculates the width of a cell array and returns an int
|
||||||
|
1
theme.go
1
theme.go
@ -103,7 +103,6 @@ func ThemeAttr(name string) Attribute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func lookUpAttr(clrmap map[string]Attribute, name string) Attribute {
|
func lookUpAttr(clrmap map[string]Attribute, name string) Attribute {
|
||||||
|
|
||||||
a, ok := clrmap[name]
|
a, ok := clrmap[name]
|
||||||
if ok {
|
if ok {
|
||||||
return a
|
return a
|
||||||
|
@ -33,7 +33,6 @@ func NewWgtInfo(wgt Widget) WgtInfo {
|
|||||||
func NewWgtMgr() WgtMgr {
|
func NewWgtMgr() WgtMgr {
|
||||||
wm := WgtMgr(make(map[string]WgtInfo))
|
wm := WgtMgr(make(map[string]WgtInfo))
|
||||||
return wm
|
return wm
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wm WgtMgr) AddWgt(wgt Widget) {
|
func (wm WgtMgr) AddWgt(wgt Widget) {
|
||||||
|
Loading…
Reference in New Issue
Block a user