Minor refactor
This commit is contained in:
@@ -6,31 +6,27 @@
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/gizak/termui"
|
||||
import ui "github.com/gizak/termui"
|
||||
|
||||
func main() {
|
||||
if err := termui.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termui.Close()
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
bc := termui.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}
|
||||
bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
||||
bc := ui.NewBarChart()
|
||||
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}
|
||||
bc.DataLabels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
||||
bc.BorderLabel = "Bar Chart"
|
||||
bc.Data = data
|
||||
bc.Width = 26
|
||||
bc.Height = 10
|
||||
bc.DataLabels = bclabels
|
||||
bc.TextColor = termui.ColorGreen
|
||||
bc.BarColor = termui.ColorRed
|
||||
bc.NumColor = termui.ColorYellow
|
||||
bc.TextColor = ui.ColorGreen
|
||||
bc.BarColor = ui.ColorRed
|
||||
bc.NumColor = ui.ColorYellow
|
||||
|
||||
termui.Render(bc)
|
||||
ui.Render(bc)
|
||||
|
||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
||||
termui.StopLoop()
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
termui.Loop()
|
||||
|
||||
ui.Loop()
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := ui.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
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"}
|
||||
list := ui.NewList()
|
||||
list.Items = strs
|
||||
list.ItemFgColor = ui.ColorYellow
|
||||
list.BorderLabel = "List"
|
||||
list.Height = 7
|
||||
list.Width = 25
|
||||
list.Y = 4
|
||||
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"}
|
||||
|
||||
l := ui.NewList()
|
||||
l.Items = listData
|
||||
l.ItemFgColor = ui.ColorYellow
|
||||
l.BorderLabel = "List"
|
||||
l.Height = 7
|
||||
l.Width = 25
|
||||
l.Y = 4
|
||||
|
||||
g := ui.NewGauge()
|
||||
g.Percent = 50
|
||||
@@ -52,29 +51,30 @@ func main() {
|
||||
g.BorderFg = ui.ColorWhite
|
||||
g.BorderLabelFg = ui.ColorCyan
|
||||
|
||||
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, 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
|
||||
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}
|
||||
|
||||
spark1 := ui.Sparkline{}
|
||||
spark1.Height = 1
|
||||
spark1.Title = "srv 1:"
|
||||
spark1.Data = spdata
|
||||
spark1.TitleColor = ui.ColorWhite
|
||||
spark1.LineColor = ui.ColorRed
|
||||
sl := ui.Sparkline{}
|
||||
sl.Height = 1
|
||||
sl.Title = "srv 0:"
|
||||
sl.Data = sparklineData
|
||||
sl.LineColor = ui.ColorCyan
|
||||
sl.TitleColor = ui.ColorWhite
|
||||
|
||||
sp := ui.NewSparklines(spark, spark1)
|
||||
sp.Width = 25
|
||||
sp.Height = 7
|
||||
sp.BorderLabel = "Sparkline"
|
||||
sp.Y = 4
|
||||
sp.X = 25
|
||||
sl2 := ui.Sparkline{}
|
||||
sl2.Height = 1
|
||||
sl2.Title = "srv 1:"
|
||||
sl2.Data = sparklineData
|
||||
sl2.TitleColor = ui.ColorWhite
|
||||
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
|
||||
ps := make([]float64, n)
|
||||
for i := range ps {
|
||||
@@ -85,7 +85,7 @@ func main() {
|
||||
|
||||
lc := ui.NewLineChart()
|
||||
lc.BorderLabel = "dot-mode Line Chart"
|
||||
lc.Data["default"] = sinps
|
||||
lc.Data["default"] = sinData
|
||||
lc.Width = 50
|
||||
lc.Height = 11
|
||||
lc.X = 0
|
||||
@@ -94,52 +94,56 @@ func main() {
|
||||
lc.LineColor["default"] = ui.ColorRed | ui.AttrBold
|
||||
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()
|
||||
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.Width = 26
|
||||
bc.Height = 10
|
||||
bc.X = 51
|
||||
bc.Y = 0
|
||||
bc.DataLabels = bclabels
|
||||
bc.DataLabels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
||||
bc.BarColor = ui.ColorGreen
|
||||
bc.NumColor = ui.ColorBlack
|
||||
|
||||
lc1 := ui.NewLineChart()
|
||||
lc1.BorderLabel = "braille-mode Line Chart"
|
||||
lc1.Data["default"] = sinps
|
||||
lc1.Width = 26
|
||||
lc1.Height = 11
|
||||
lc1.X = 51
|
||||
lc1.Y = 14
|
||||
lc1.AxesColor = ui.ColorWhite
|
||||
lc1.LineColor["default"] = ui.ColorYellow | ui.AttrBold
|
||||
lc2 := ui.NewLineChart()
|
||||
lc2.BorderLabel = "braille-mode Line Chart"
|
||||
lc2.Data["default"] = sinData
|
||||
lc2.Width = 26
|
||||
lc2.Height = 11
|
||||
lc2.X = 51
|
||||
lc2.Y = 14
|
||||
lc2.AxesColor = ui.ColorWhite
|
||||
lc2.LineColor["default"] = ui.ColorYellow | ui.AttrBold
|
||||
|
||||
p1 := ui.NewPar("Hey!\nI am a borderless block!")
|
||||
p1.Border = false
|
||||
p1.Width = 26
|
||||
p1.Height = 2
|
||||
p1.TextFgColor = ui.ColorMagenta
|
||||
p1.X = 52
|
||||
p1.Y = 11
|
||||
p2 := ui.NewPar("Hey!\nI am a borderless block!")
|
||||
p2.Border = false
|
||||
p2.Width = 26
|
||||
p2.Height = 2
|
||||
p2.TextFgColor = ui.ColorMagenta
|
||||
p2.X = 52
|
||||
p2.Y = 11
|
||||
|
||||
draw := func(t int) {
|
||||
g.Percent = t % 101
|
||||
list.Items = strs[t%9:]
|
||||
sp.Lines[0].Data = spdata[:30+t%50]
|
||||
sp.Lines[1].Data = spdata[:35+t%50]
|
||||
lc.Data["default"] = sinps[t/2%220:]
|
||||
lc1.Data["default"] = sinps[2*t%220:]
|
||||
bc.Data = bcdata[t/2%10:]
|
||||
ui.Render(p, list, g, sp, lc, bc, lc1, p1)
|
||||
draw := func(count int) {
|
||||
g.Percent = count % 101
|
||||
l.Items = listData[count%9:]
|
||||
sls.Lines[0].Data = sparklineData[:30+count%50]
|
||||
sls.Lines[1].Data = sparklineData[:35+count%50]
|
||||
lc.Data["default"] = sinData[count/2%220:]
|
||||
lc2.Data["default"] = sinData[2*count%220:]
|
||||
bc.Data = barchartData[count/2%10:]
|
||||
|
||||
ui.Render(p, l, g, sls, lc, bc, lc2, p2)
|
||||
}
|
||||
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
|
||||
ui.Handle("/timer/1s", func(e ui.Event) {
|
||||
t := e.Data.(ui.EvtTimer)
|
||||
draw(int(t.Count))
|
||||
})
|
||||
|
||||
ui.Loop()
|
||||
}
|
||||
|
||||
@@ -6,79 +6,74 @@
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/gizak/termui"
|
||||
import ui "github.com/gizak/termui"
|
||||
|
||||
func main() {
|
||||
err := termui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termui.Close()
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
//termui.UseTheme("helloworld")
|
||||
|
||||
g0 := termui.NewGauge()
|
||||
g0 := ui.NewGauge()
|
||||
g0.Percent = 40
|
||||
g0.Width = 50
|
||||
g0.Height = 3
|
||||
g0.BorderLabel = "Slim Gauge"
|
||||
g0.BarColor = termui.ColorRed
|
||||
g0.BorderFg = termui.ColorWhite
|
||||
g0.BorderLabelFg = termui.ColorCyan
|
||||
g0.BarColor = ui.ColorRed
|
||||
g0.BorderFg = ui.ColorWhite
|
||||
g0.BorderLabelFg = ui.ColorCyan
|
||||
|
||||
gg := termui.NewBlock()
|
||||
gg := ui.NewBlock()
|
||||
gg.Width = 50
|
||||
gg.Height = 5
|
||||
gg.Y = 12
|
||||
gg.BorderLabel = "TEST"
|
||||
gg.Align()
|
||||
|
||||
g2 := termui.NewGauge()
|
||||
g2 := ui.NewGauge()
|
||||
g2.Percent = 60
|
||||
g2.Width = 50
|
||||
g2.Height = 3
|
||||
g2.PercentColor = termui.ColorBlue
|
||||
g2.PercentColor = ui.ColorBlue
|
||||
g2.Y = 3
|
||||
g2.BorderLabel = "Slim Gauge"
|
||||
g2.BarColor = termui.ColorYellow
|
||||
g2.BorderFg = termui.ColorWhite
|
||||
g2.BarColor = ui.ColorYellow
|
||||
g2.BorderFg = ui.ColorWhite
|
||||
|
||||
g1 := termui.NewGauge()
|
||||
g1 := ui.NewGauge()
|
||||
g1.Percent = 30
|
||||
g1.Width = 50
|
||||
g1.Height = 5
|
||||
g1.Y = 6
|
||||
g1.BorderLabel = "Big Gauge"
|
||||
g1.PercentColor = termui.ColorYellow
|
||||
g1.BarColor = termui.ColorGreen
|
||||
g1.BorderFg = termui.ColorWhite
|
||||
g1.BorderLabelFg = termui.ColorMagenta
|
||||
g1.PercentColor = ui.ColorYellow
|
||||
g1.BarColor = ui.ColorGreen
|
||||
g1.BorderFg = ui.ColorWhite
|
||||
g1.BorderLabelFg = ui.ColorMagenta
|
||||
|
||||
g3 := termui.NewGauge()
|
||||
g3 := ui.NewGauge()
|
||||
g3.Percent = 50
|
||||
g3.Width = 50
|
||||
g3.Height = 3
|
||||
g3.Y = 11
|
||||
g3.BorderLabel = "Gauge with custom label"
|
||||
g3.Label = "{{percent}}% (100MBs free)"
|
||||
g3.LabelAlign = termui.AlignRight
|
||||
g3.LabelAlign = ui.AlignRight
|
||||
|
||||
g4 := termui.NewGauge()
|
||||
g4 := ui.NewGauge()
|
||||
g4.Percent = 50
|
||||
g4.Width = 50
|
||||
g4.Height = 3
|
||||
g4.Y = 14
|
||||
g4.BorderLabel = "Gauge"
|
||||
g4.Label = "Gauge with custom highlighted label"
|
||||
g4.PercentColor = termui.ColorYellow
|
||||
g4.BarColor = termui.ColorGreen
|
||||
g4.PercentColorHighlighted = termui.ColorBlack
|
||||
g4.PercentColor = ui.ColorYellow
|
||||
g4.BarColor = ui.ColorGreen
|
||||
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) {
|
||||
termui.StopLoop()
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
|
||||
termui.Loop()
|
||||
ui.Loop()
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := ui.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
sinps := (func() []float64 {
|
||||
@@ -96,6 +94,7 @@ func main() {
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
|
||||
ui.Handle("/timer/1s", func(e ui.Event) {
|
||||
t := e.Data.(ui.EvtTimer)
|
||||
i := t.Count
|
||||
|
||||
@@ -9,17 +9,12 @@ package main
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/gizak/termui"
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := termui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termui.Close()
|
||||
|
||||
//termui.UseTheme("helloworld")
|
||||
err := ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
sinps := (func() map[string][]float64 {
|
||||
n := 220
|
||||
@@ -33,17 +28,17 @@ func main() {
|
||||
return ps
|
||||
})()
|
||||
|
||||
lc0 := termui.NewLineChart()
|
||||
lc0 := ui.NewLineChart()
|
||||
lc0.BorderLabel = "braille-mode Line Chart"
|
||||
lc0.Data = sinps
|
||||
lc0.Width = 50
|
||||
lc0.Height = 12
|
||||
lc0.X = 0
|
||||
lc0.Y = 0
|
||||
lc0.AxesColor = termui.ColorWhite
|
||||
lc0.LineColor["first"] = termui.ColorGreen | termui.AttrBold
|
||||
lc0.AxesColor = ui.ColorWhite
|
||||
lc0.LineColor["first"] = ui.ColorGreen | ui.AttrBold
|
||||
|
||||
lc1 := termui.NewLineChart()
|
||||
lc1 := ui.NewLineChart()
|
||||
lc1.BorderLabel = "dot-mode Line Chart"
|
||||
lc1.Mode = "dot"
|
||||
lc1.Data = sinps
|
||||
@@ -51,10 +46,10 @@ func main() {
|
||||
lc1.Height = 12
|
||||
lc1.X = 51
|
||||
lc1.DotStyle = '+'
|
||||
lc1.AxesColor = termui.ColorWhite
|
||||
lc1.LineColor["first"] = termui.ColorYellow | termui.AttrBold
|
||||
lc1.AxesColor = ui.ColorWhite
|
||||
lc1.LineColor["first"] = ui.ColorYellow | ui.AttrBold
|
||||
|
||||
lc2 := termui.NewLineChart()
|
||||
lc2 := ui.NewLineChart()
|
||||
lc2.BorderLabel = "dot-mode Line Chart"
|
||||
lc2.Mode = "dot"
|
||||
lc2.Data["first"] = sinps["first"][4:]
|
||||
@@ -63,13 +58,14 @@ func main() {
|
||||
lc2.Height = 16
|
||||
lc2.X = 0
|
||||
lc2.Y = 12
|
||||
lc2.AxesColor = termui.ColorWhite
|
||||
lc2.LineColor["first"] = termui.ColorCyan | termui.AttrBold
|
||||
lc2.AxesColor = ui.ColorWhite
|
||||
lc2.LineColor["first"] = ui.ColorCyan | ui.AttrBold
|
||||
|
||||
termui.Render(lc0, lc1, lc2)
|
||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
||||
termui.StopLoop()
|
||||
ui.Render(lc0, lc1, lc2)
|
||||
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
termui.Loop()
|
||||
|
||||
ui.Loop()
|
||||
}
|
||||
|
||||
@@ -6,16 +6,11 @@
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/gizak/termui"
|
||||
import ui "github.com/gizak/termui"
|
||||
|
||||
func main() {
|
||||
err := termui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termui.Close()
|
||||
|
||||
//termui.UseTheme("helloworld")
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
strs := []string{
|
||||
"[0] github.com/gizak/termui",
|
||||
@@ -27,18 +22,19 @@ func main() {
|
||||
"[6] dashboard.go",
|
||||
"[7] nsf/termbox-go"}
|
||||
|
||||
ls := termui.NewList()
|
||||
ls := ui.NewList()
|
||||
ls.Items = strs
|
||||
ls.ItemFgColor = termui.ColorYellow
|
||||
ls.ItemFgColor = ui.ColorYellow
|
||||
ls.BorderLabel = "List"
|
||||
ls.Height = 7
|
||||
ls.Width = 25
|
||||
ls.Y = 0
|
||||
|
||||
termui.Render(ls)
|
||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
||||
termui.StopLoop()
|
||||
})
|
||||
termui.Loop()
|
||||
ui.Render(ls)
|
||||
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
|
||||
ui.Loop()
|
||||
}
|
||||
|
||||
@@ -6,18 +6,13 @@
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/gizak/termui"
|
||||
import ui "github.com/gizak/termui"
|
||||
|
||||
func main() {
|
||||
err := termui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termui.Close()
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
//termui.UseTheme("helloworld")
|
||||
|
||||
bc := termui.NewMBarChart()
|
||||
bc := ui.NewMBarChart()
|
||||
math := []int{90, 85, 90, 80}
|
||||
english := []int{70, 85, 75, 60}
|
||||
science := []int{75, 60, 80, 85}
|
||||
@@ -36,19 +31,20 @@ func main() {
|
||||
bc.ShowScale = true //Show y_axis scale value (min and max)
|
||||
bc.SetMax(400)
|
||||
|
||||
bc.TextColor = termui.ColorGreen //this is color for label (x-axis)
|
||||
bc.BarColor[3] = termui.ColorGreen //BarColor for computerscience
|
||||
bc.BarColor[1] = termui.ColorYellow //Bar Color for english
|
||||
bc.NumColor[3] = termui.ColorRed // Num color for computerscience
|
||||
bc.NumColor[1] = termui.ColorRed // num color for english
|
||||
bc.TextColor = ui.ColorGreen //this is color for label (x-axis)
|
||||
bc.BarColor[3] = ui.ColorGreen //BarColor for computerscience
|
||||
bc.BarColor[1] = ui.ColorYellow //Bar Color for english
|
||||
bc.NumColor[3] = ui.ColorRed // Num color for computerscience
|
||||
bc.NumColor[1] = ui.ColorRed // num color for english
|
||||
|
||||
//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) {
|
||||
termui.StopLoop()
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
termui.Loop()
|
||||
|
||||
ui.Loop()
|
||||
|
||||
}
|
||||
|
||||
@@ -6,47 +6,43 @@
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/gizak/termui"
|
||||
import ui "github.com/gizak/termui"
|
||||
|
||||
func main() {
|
||||
err := termui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termui.Close()
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
//termui.UseTheme("helloworld")
|
||||
|
||||
par0 := termui.NewPar("Borderless Text")
|
||||
par0 := ui.NewPar("Borderless Text")
|
||||
par0.Height = 1
|
||||
par0.Width = 20
|
||||
par0.Y = 1
|
||||
par0.Border = false
|
||||
|
||||
par1 := termui.NewPar("你好,世界。")
|
||||
par1 := ui.NewPar("你好,世界。")
|
||||
par1.Height = 3
|
||||
par1.Width = 17
|
||||
par1.X = 20
|
||||
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.Width = 37
|
||||
par2.Y = 4
|
||||
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.Width = 37
|
||||
par3.Y = 9
|
||||
par3.BorderLabel = "Auto Trim"
|
||||
|
||||
termui.Render(par0, par1, par2, par3)
|
||||
ui.Render(par0, par1, par2, par3)
|
||||
|
||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
||||
termui.StopLoop()
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
termui.Loop()
|
||||
|
||||
ui.Loop()
|
||||
|
||||
}
|
||||
|
||||
@@ -8,14 +8,13 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/gizak/termui"
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := termui.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termui.Close()
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
randomDataAndOffset := func() (data []float64, offset float64) {
|
||||
noSlices := 1 + rand.Intn(5)
|
||||
@@ -28,7 +27,7 @@ func main() {
|
||||
}
|
||||
run := true
|
||||
|
||||
pc := termui.NewPieChart()
|
||||
pc := ui.NewPieChart()
|
||||
pc.BorderLabel = "Pie Chart"
|
||||
pc.Width = 70
|
||||
pc.Height = 36
|
||||
@@ -38,26 +37,28 @@ func main() {
|
||||
return fmt.Sprintf("%.02f", v)
|
||||
}
|
||||
|
||||
termui.Handle("/timer/1s", func(e termui.Event) {
|
||||
ui.Handle("/timer/1s", func(e ui.Event) {
|
||||
if run {
|
||||
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
|
||||
if run {
|
||||
pc.BorderLabel = "Pie Chart"
|
||||
} else {
|
||||
pc.BorderLabel = "Pie Chart (Stopped)"
|
||||
}
|
||||
termui.Render(pc)
|
||||
ui.Render(pc)
|
||||
})
|
||||
|
||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
||||
termui.StopLoop()
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
termui.Render(pc)
|
||||
termui.Loop()
|
||||
|
||||
ui.Render(pc)
|
||||
|
||||
ui.Loop()
|
||||
}
|
||||
|
||||
@@ -6,64 +6,59 @@
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/gizak/termui"
|
||||
import ui "github.com/gizak/termui"
|
||||
|
||||
func main() {
|
||||
err := termui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termui.Close()
|
||||
|
||||
//termui.UseTheme("helloworld")
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
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.Title = "Sparkline 0"
|
||||
spl0.LineColor = termui.ColorGreen
|
||||
spl0.LineColor = ui.ColorGreen
|
||||
|
||||
// single
|
||||
spls0 := termui.NewSparklines(spl0)
|
||||
spls0 := ui.NewSparklines(spl0)
|
||||
spls0.Height = 2
|
||||
spls0.Width = 20
|
||||
spls0.Border = false
|
||||
|
||||
spl1 := termui.NewSparkline()
|
||||
spl1 := ui.NewSparkline()
|
||||
spl1.Data = data
|
||||
spl1.Title = "Sparkline 1"
|
||||
spl1.LineColor = termui.ColorRed
|
||||
spl1.LineColor = ui.ColorRed
|
||||
|
||||
spl2 := termui.NewSparkline()
|
||||
spl2 := ui.NewSparkline()
|
||||
spl2.Data = data[5:]
|
||||
spl2.Title = "Sparkline 2"
|
||||
spl2.LineColor = termui.ColorMagenta
|
||||
spl2.LineColor = ui.ColorMagenta
|
||||
|
||||
// group
|
||||
spls1 := termui.NewSparklines(spl0, spl1, spl2)
|
||||
spls1 := ui.NewSparklines(spl0, spl1, spl2)
|
||||
spls1.Height = 8
|
||||
spls1.Width = 20
|
||||
spls1.Y = 3
|
||||
spls1.BorderLabel = "Group Sparklines"
|
||||
|
||||
spl3 := termui.NewSparkline()
|
||||
spl3 := ui.NewSparkline()
|
||||
spl3.Data = data
|
||||
spl3.Title = "Enlarged Sparkline"
|
||||
spl3.Height = 8
|
||||
spl3.LineColor = termui.ColorYellow
|
||||
spl3.LineColor = ui.ColorYellow
|
||||
|
||||
spls2 := termui.NewSparklines(spl3)
|
||||
spls2 := ui.NewSparklines(spl3)
|
||||
spls2.Height = 11
|
||||
spls2.Width = 30
|
||||
spls2.BorderFg = termui.ColorCyan
|
||||
spls2.BorderFg = ui.ColorCyan
|
||||
spls2.X = 21
|
||||
spls2.BorderLabel = "Tweeked Sparkline"
|
||||
|
||||
termui.Render(spls0, spls1, spls2)
|
||||
ui.Render(spls0, spls1, spls2)
|
||||
|
||||
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,30 +6,28 @@
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/gizak/termui"
|
||||
import ui "github.com/gizak/termui"
|
||||
|
||||
func main() {
|
||||
err := termui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termui.Close()
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
rows1 := [][]string{
|
||||
[]string{"header1", "header2", "header3"},
|
||||
[]string{"你好吗", "Go-lang is so cool", "Im working on Ruby"},
|
||||
[]string{"2016", "10", "11"},
|
||||
}
|
||||
|
||||
table1 := termui.NewTable()
|
||||
table1 := ui.NewTable()
|
||||
table1.Rows = rows1
|
||||
table1.FgColor = termui.ColorWhite
|
||||
table1.BgColor = termui.ColorDefault
|
||||
table1.FgColor = ui.ColorWhite
|
||||
table1.BgColor = ui.ColorDefault
|
||||
table1.Y = 0
|
||||
table1.X = 0
|
||||
table1.Width = 62
|
||||
table1.Height = 7
|
||||
|
||||
termui.Render(table1)
|
||||
ui.Render(table1)
|
||||
|
||||
rows2 := [][]string{
|
||||
[]string{"header1", "header2", "header3"},
|
||||
@@ -37,22 +35,24 @@ func main() {
|
||||
[]string{"2016", "11", "11"},
|
||||
}
|
||||
|
||||
table2 := termui.NewTable()
|
||||
table2 := ui.NewTable()
|
||||
table2.Rows = rows2
|
||||
table2.FgColor = termui.ColorWhite
|
||||
table2.BgColor = termui.ColorDefault
|
||||
table2.TextAlign = termui.AlignCenter
|
||||
table2.FgColor = ui.ColorWhite
|
||||
table2.BgColor = ui.ColorDefault
|
||||
table2.TextAlign = ui.AlignCenter
|
||||
table2.Separator = false
|
||||
table2.Analysis()
|
||||
table2.SetSize()
|
||||
table2.BgColors[2] = termui.ColorRed
|
||||
table2.BgColors[2] = ui.ColorRed
|
||||
table2.Y = 10
|
||||
table2.X = 0
|
||||
table2.Border = true
|
||||
|
||||
termui.Render(table2)
|
||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
||||
termui.StopLoop()
|
||||
ui.Render(table2)
|
||||
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
termui.Loop()
|
||||
|
||||
ui.Loop()
|
||||
}
|
||||
|
||||
@@ -7,36 +7,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gizak/termui"
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/extra"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := termui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termui.Close()
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
//termui.UseTheme("helloworld")
|
||||
|
||||
header := termui.NewPar("Press q to quit, Press j or k to switch tabs")
|
||||
header := ui.NewPar("Press q to quit, Press j or k to switch tabs")
|
||||
header.Height = 1
|
||||
header.Width = 50
|
||||
header.Border = false
|
||||
header.TextBgColor = termui.ColorBlue
|
||||
header.TextBgColor = ui.ColorBlue
|
||||
|
||||
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.Width = 37
|
||||
par2.Y = 0
|
||||
par2.BorderLabel = "Keys"
|
||||
par2.BorderFg = termui.ColorYellow
|
||||
par2.BorderFg = ui.ColorYellow
|
||||
tab1.AddBlocks(par2)
|
||||
|
||||
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}
|
||||
bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
||||
bc.BorderLabel = "Bar Chart"
|
||||
@@ -44,9 +39,9 @@ func main() {
|
||||
bc.Width = 26
|
||||
bc.Height = 10
|
||||
bc.DataLabels = bclabels
|
||||
bc.TextColor = termui.ColorGreen
|
||||
bc.BarColor = termui.ColorRed
|
||||
bc.NumColor = termui.ColorYellow
|
||||
bc.TextColor = ui.ColorGreen
|
||||
bc.BarColor = ui.ColorRed
|
||||
bc.NumColor = ui.ColorYellow
|
||||
tab2.AddBlocks(bc)
|
||||
|
||||
tab3 := extra.NewTab("trzeci")
|
||||
@@ -61,23 +56,23 @@ func main() {
|
||||
|
||||
tabpane.SetTabs(*tab1, *tab2, *tab3, *tab4, *tab5, *tab6)
|
||||
|
||||
termui.Render(header, tabpane)
|
||||
ui.Render(header, tabpane)
|
||||
|
||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
||||
termui.StopLoop()
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
|
||||
termui.Handle("/sys/kbd/j", func(termui.Event) {
|
||||
ui.Handle("/sys/kbd/j", func(ui.Event) {
|
||||
tabpane.SetActiveLeft()
|
||||
termui.Clear()
|
||||
termui.Render(header, tabpane)
|
||||
ui.Clear()
|
||||
ui.Render(header, tabpane)
|
||||
})
|
||||
|
||||
termui.Handle("/sys/kbd/k", func(termui.Event) {
|
||||
ui.Handle("/sys/kbd/k", func(ui.Event) {
|
||||
tabpane.SetActiveRight()
|
||||
termui.Clear()
|
||||
termui.Render(header, tabpane)
|
||||
ui.Clear()
|
||||
ui.Render(header, tabpane)
|
||||
})
|
||||
|
||||
termui.Loop()
|
||||
ui.Loop()
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
// Deprecated
|
||||
@@ -136,12 +133,15 @@ func main() {
|
||||
}
|
||||
|
||||
ui.Render(p, list, g, sp, lc, bc, lc1, p1)
|
||||
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
|
||||
ui.Handle("/timer/1s", func(e ui.Event) {
|
||||
t := e.Data.(ui.EvtTimer)
|
||||
draw(int(t.Count))
|
||||
})
|
||||
|
||||
ui.Loop()
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gizak/termui"
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/extra"
|
||||
)
|
||||
|
||||
@@ -201,23 +201,23 @@ func getMemStats() (ms MemStat, err error) {
|
||||
}
|
||||
|
||||
type CpuTabElems struct {
|
||||
GMap map[string]*termui.Gauge
|
||||
LChart *termui.LineChart
|
||||
GMap map[string]*ui.Gauge
|
||||
LChart *ui.LineChart
|
||||
}
|
||||
|
||||
func NewCpuTabElems(width int) *CpuTabElems {
|
||||
lc := termui.NewLineChart()
|
||||
lc := ui.NewLineChart()
|
||||
lc.Width = width
|
||||
lc.Height = 12
|
||||
lc.X = 0
|
||||
lc.Mode = "dot"
|
||||
lc.BorderLabel = "CPU"
|
||||
return &CpuTabElems{GMap: make(map[string]*termui.Gauge),
|
||||
return &CpuTabElems{GMap: make(map[string]*ui.Gauge),
|
||||
LChart: lc}
|
||||
}
|
||||
|
||||
func (cte *CpuTabElems) AddGauge(key string, Y int, width int) *termui.Gauge {
|
||||
cte.GMap[key] = termui.NewGauge()
|
||||
func (cte *CpuTabElems) AddGauge(key string, Y int, width int) *ui.Gauge {
|
||||
cte.GMap[key] = ui.NewGauge()
|
||||
cte.GMap[key].Width = width
|
||||
cte.GMap[key].Height = 3
|
||||
cte.GMap[key].Y = Y
|
||||
@@ -239,21 +239,21 @@ func (cte *CpuTabElems) Update(cs CpusStats) {
|
||||
}
|
||||
|
||||
type MemTabElems struct {
|
||||
Gauge *termui.Gauge
|
||||
SLines *termui.Sparklines
|
||||
Gauge *ui.Gauge
|
||||
SLines *ui.Sparklines
|
||||
}
|
||||
|
||||
func NewMemTabElems(width int) *MemTabElems {
|
||||
g := termui.NewGauge()
|
||||
g := ui.NewGauge()
|
||||
g.Width = width
|
||||
g.Height = 3
|
||||
g.Y = 0
|
||||
|
||||
sline := termui.NewSparkline()
|
||||
sline := ui.NewSparkline()
|
||||
sline.Title = "MEM"
|
||||
sline.Height = 8
|
||||
|
||||
sls := termui.NewSparklines(sline)
|
||||
sls := ui.NewSparklines(sline)
|
||||
sls.Width = width
|
||||
sls.Height = 12
|
||||
sls.Y = 3
|
||||
@@ -275,21 +275,16 @@ func main() {
|
||||
if runtime.GOOS != "linux" {
|
||||
panic("Currently works only on Linux")
|
||||
}
|
||||
err := termui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer termui.Close()
|
||||
ui.Init()
|
||||
defer ui.Close()
|
||||
|
||||
termWidth := 70
|
||||
|
||||
//termui.UseTheme("helloworld")
|
||||
|
||||
header := termui.NewPar("Press q to quit, Press j or k to switch tabs")
|
||||
header := ui.NewPar("Press q to quit, Press j or k to switch tabs")
|
||||
header.Height = 1
|
||||
header.Width = 50
|
||||
header.Border = false
|
||||
header.TextBgColor = termui.ColorBlue
|
||||
header.TextBgColor = ui.ColorBlue
|
||||
|
||||
tabCpu := extra.NewTab("CPU")
|
||||
tabMem := extra.NewTab("MEM")
|
||||
@@ -333,23 +328,23 @@ func main() {
|
||||
|
||||
tabpane.SetTabs(*tabCpu, *tabMem)
|
||||
|
||||
termui.Render(header, tabpane)
|
||||
ui.Render(header, tabpane)
|
||||
|
||||
termui.Handle("/sys/kbd/q", func(termui.Event) {
|
||||
termui.StopLoop()
|
||||
ui.Handle("/sys/kbd/q", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
|
||||
termui.Handle("/sys/kbd/j", func(termui.Event) {
|
||||
ui.Handle("/sys/kbd/j", func(ui.Event) {
|
||||
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()
|
||||
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()
|
||||
if errcs != nil {
|
||||
panic(errcs)
|
||||
@@ -362,8 +357,8 @@ func main() {
|
||||
panic(errm)
|
||||
}
|
||||
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"
|
||||
|
||||
func main() {
|
||||
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ui.Init()
|
||||
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.")
|
||||
|
||||
Reference in New Issue
Block a user