The Great Rewrite
@@ -6,24 +6,28 @@
|
||||
|
||||
package main
|
||||
|
||||
import ui "github.com/gizak/termui"
|
||||
import (
|
||||
"log"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
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.Width = 26
|
||||
bc.Height = 10
|
||||
bc.TextColor = ui.ColorGreen
|
||||
bc.BarColor = ui.ColorRed
|
||||
bc.NumColor = ui.ColorYellow
|
||||
bc := widgets.NewBarChart()
|
||||
bc.Data = []float64{3, 2, 5, 3, 9, 3}
|
||||
bc.Labels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
||||
bc.Title = "Bar Chart"
|
||||
bc.SetRect(5, 5, 100, 25)
|
||||
bc.BarWidth = 5
|
||||
bc.BarColors = []ui.Color{ui.ColorRed, ui.ColorGreen}
|
||||
bc.LabelStyles = []ui.Style{ui.NewStyle(ui.ColorBlue)}
|
||||
bc.NumStyles = []ui.Style{ui.NewStyle(ui.ColorYellow)}
|
||||
|
||||
ui.Render(bc)
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 17 KiB |
30
_examples/canvas.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"image"
|
||||
"log"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
c := ui.NewCanvas()
|
||||
c.SetRect(0, 0, 50, 50)
|
||||
c.Line(image.Pt(0, 0), image.Pt(80, 50), ui.ColorClear)
|
||||
c.Line(image.Pt(0, 5), image.Pt(3, 10), ui.ColorClear)
|
||||
|
||||
ui.Render(c)
|
||||
|
||||
for e := range ui.PollEvents() {
|
||||
if e.Type == ui.KeyboardEvent {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 152 KiB |
@@ -1,159 +0,0 @@
|
||||
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
p := ui.NewParagraph("PRESS q TO QUIT DEMO")
|
||||
p.Height = 3
|
||||
p.Width = 50
|
||||
p.TextFgColor = ui.ColorWhite
|
||||
p.BorderLabel = "Text Box"
|
||||
p.BorderFg = ui.ColorCyan
|
||||
|
||||
updateP := func(count int) {
|
||||
if count%2 == 0 {
|
||||
p.TextFgColor = ui.ColorRed
|
||||
} else {
|
||||
p.TextFgColor = ui.ColorWhite
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
g.Width = 50
|
||||
g.Height = 3
|
||||
g.Y = 11
|
||||
g.BorderLabel = "Gauge"
|
||||
g.BarColor = ui.ColorRed
|
||||
g.BorderFg = ui.ColorWhite
|
||||
g.BorderLabelFg = ui.ColorCyan
|
||||
|
||||
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}
|
||||
|
||||
sl := ui.Sparkline{}
|
||||
sl.Height = 1
|
||||
sl.Title = "srv 0:"
|
||||
sl.Data = sparklineData
|
||||
sl.LineColor = ui.ColorCyan
|
||||
sl.TitleColor = ui.ColorWhite
|
||||
|
||||
sl2 := ui.Sparkline{}
|
||||
sl2.Height = 1
|
||||
sl2.Title = "srv 1:"
|
||||
sl2.Data = sparklineData
|
||||
sl2.TitleColor = ui.ColorWhite
|
||||
sl2.LineColor = ui.ColorRed
|
||||
|
||||
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 {
|
||||
ps[i] = 1 + math.Sin(float64(i)/5)
|
||||
}
|
||||
return ps
|
||||
})()
|
||||
|
||||
lc := ui.NewLineChart()
|
||||
lc.BorderLabel = "dot-mode Line Chart"
|
||||
lc.Data["default"] = sinData
|
||||
lc.Width = 50
|
||||
lc.Height = 11
|
||||
lc.X = 0
|
||||
lc.Y = 14
|
||||
lc.AxesColor = ui.ColorWhite
|
||||
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()
|
||||
bc.BorderLabel = "Bar Chart"
|
||||
bc.Width = 26
|
||||
bc.Height = 10
|
||||
bc.X = 51
|
||||
bc.Y = 0
|
||||
bc.DataLabels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
||||
bc.BarColor = ui.ColorGreen
|
||||
bc.NumColor = ui.ColorBlack
|
||||
|
||||
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
|
||||
|
||||
p2 := ui.NewParagraph("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(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)
|
||||
}
|
||||
|
||||
tickerCount := 1
|
||||
uiEvents := ui.PollEvents()
|
||||
ticker := time.NewTicker(time.Second).C
|
||||
for {
|
||||
select {
|
||||
case e := <-uiEvents:
|
||||
switch e.ID {
|
||||
case "q", "<C-c>":
|
||||
return
|
||||
}
|
||||
case <-ticker:
|
||||
updateP(tickerCount)
|
||||
draw(tickerCount)
|
||||
tickerCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
153
_examples/dashboard1.go
Normal file
@@ -0,0 +1,153 @@
|
||||
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
p := widgets.NewParagraph()
|
||||
p.Title = "Text Box"
|
||||
p.Text = "PRESS q TO QUIT DEMO"
|
||||
p.SetRect(0, 0, 50, 5)
|
||||
p.TextStyle.Fg = ui.ColorWhite
|
||||
p.BorderStyle.Fg = ui.ColorCyan
|
||||
|
||||
updateParagraph := func(count int) {
|
||||
if count%2 == 0 {
|
||||
p.TextStyle.Fg = ui.ColorRed
|
||||
} else {
|
||||
p.TextStyle.Fg = ui.ColorWhite
|
||||
}
|
||||
}
|
||||
|
||||
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 := widgets.NewList()
|
||||
l.Title = "List"
|
||||
l.Rows = listData
|
||||
l.SetRect(0, 5, 25, 12)
|
||||
l.TextStyle.Fg = ui.ColorYellow
|
||||
|
||||
g := widgets.NewGauge()
|
||||
g.Title = "Gauge"
|
||||
g.Percent = 50
|
||||
g.SetRect(0, 12, 50, 15)
|
||||
g.BarColor = ui.ColorRed
|
||||
g.BorderStyle.Fg = ui.ColorWhite
|
||||
g.TitleStyle.Fg = ui.ColorCyan
|
||||
|
||||
sparklineData := []float64{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}
|
||||
|
||||
sl := widgets.NewSparkline()
|
||||
sl.Title = "srv 0:"
|
||||
sl.Data = sparklineData
|
||||
sl.LineColor = ui.ColorCyan
|
||||
sl.TitleStyle.Fg = ui.ColorWhite
|
||||
|
||||
sl2 := widgets.NewSparkline()
|
||||
sl2.Title = "srv 1:"
|
||||
sl2.Data = sparklineData
|
||||
sl2.TitleStyle.Fg = ui.ColorWhite
|
||||
sl2.LineColor = ui.ColorRed
|
||||
|
||||
slg := widgets.NewSparklineGroup(sl, sl2)
|
||||
slg.Title = "Sparkline"
|
||||
slg.SetRect(25, 5, 50, 12)
|
||||
|
||||
sinData := (func() []float64 {
|
||||
n := 220
|
||||
ps := make([]float64, n)
|
||||
for i := range ps {
|
||||
ps[i] = 1 + math.Sin(float64(i)/5)
|
||||
}
|
||||
return ps
|
||||
})()
|
||||
|
||||
lc := widgets.NewLineChart()
|
||||
lc.Title = "dot-mode Line Chart"
|
||||
lc.Data = make([][]float64, 1)
|
||||
lc.Data[0] = sinData
|
||||
lc.SetRect(0, 15, 50, 25)
|
||||
lc.AxesColor = ui.ColorWhite
|
||||
lc.LineColors[0] = ui.ColorRed
|
||||
lc.LineType = widgets.DotLine
|
||||
|
||||
barchartData := []float64{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 := widgets.NewBarChart()
|
||||
bc.Title = "Bar Chart"
|
||||
bc.SetRect(50, 0, 75, 10)
|
||||
bc.Labels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
||||
bc.BarColors[0] = ui.ColorGreen
|
||||
bc.NumStyles[0] = ui.NewStyle(ui.ColorBlack)
|
||||
|
||||
lc2 := widgets.NewLineChart()
|
||||
lc2.Title = "braille-mode Line Chart"
|
||||
lc2.Data = make([][]float64, 1)
|
||||
lc2.Data[0] = sinData
|
||||
lc2.SetRect(50, 15, 75, 25)
|
||||
lc2.AxesColor = ui.ColorWhite
|
||||
lc2.LineColors[0] = ui.ColorYellow
|
||||
|
||||
p2 := widgets.NewParagraph()
|
||||
p2.Text = "Hey!\nI am a borderless block!"
|
||||
p2.Border = false
|
||||
p2.SetRect(50, 10, 75, 10)
|
||||
p2.TextStyle.Fg = ui.ColorMagenta
|
||||
|
||||
draw := func(count int) {
|
||||
g.Percent = count % 101
|
||||
l.Rows = listData[count%9:]
|
||||
slg.Sparklines[0].Data = sparklineData[:30+count%50]
|
||||
slg.Sparklines[1].Data = sparklineData[:35+count%50]
|
||||
lc.Data[0] = sinData[count/2%220:]
|
||||
lc2.Data[0] = sinData[2*count%220:]
|
||||
bc.Data = barchartData[count/2%10:]
|
||||
|
||||
ui.Render(p, l, g, slg, lc, bc, lc2, p2)
|
||||
}
|
||||
|
||||
tickerCount := 1
|
||||
draw(tickerCount)
|
||||
tickerCount++
|
||||
uiEvents := ui.PollEvents()
|
||||
ticker := time.NewTicker(time.Second).C
|
||||
for {
|
||||
select {
|
||||
case e := <-uiEvents:
|
||||
switch e.ID {
|
||||
case "q", "<C-c>":
|
||||
return
|
||||
}
|
||||
case <-ticker:
|
||||
updateParagraph(tickerCount)
|
||||
draw(tickerCount)
|
||||
tickerCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,9 @@ import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"runtime"
|
||||
@@ -20,6 +22,7 @@ import (
|
||||
"time"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
const statFilePath = "/proc/stat"
|
||||
@@ -201,27 +204,25 @@ func getMemStats() (ms MemStat, err error) {
|
||||
}
|
||||
|
||||
type CpuTabElems struct {
|
||||
GMap map[string]*ui.Gauge
|
||||
LChart *ui.LineChart
|
||||
GMap map[string]*widgets.Gauge
|
||||
LChart *widgets.LineChart
|
||||
}
|
||||
|
||||
func NewCpuTabElems(width int) *CpuTabElems {
|
||||
lc := ui.NewLineChart()
|
||||
lc.Width = width
|
||||
lc.Height = 12
|
||||
lc.X = 0
|
||||
lc.Mode = "dot"
|
||||
lc.BorderLabel = "CPU"
|
||||
return &CpuTabElems{GMap: make(map[string]*ui.Gauge),
|
||||
LChart: lc}
|
||||
lc := widgets.NewLineChart()
|
||||
lc.SetRect(0, 0, width, 12)
|
||||
lc.LineType = widgets.DotLine
|
||||
lc.Title = "CPU"
|
||||
return &CpuTabElems{
|
||||
GMap: make(map[string]*widgets.Gauge),
|
||||
LChart: lc,
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
cte.GMap[key].BorderLabel = key
|
||||
func (cte *CpuTabElems) AddGauge(key string, Y int, width int) *widgets.Gauge {
|
||||
cte.GMap[key] = widgets.NewGauge()
|
||||
cte.GMap[key].SetRect(0, Y, width, Y+3)
|
||||
cte.GMap[key].Title = key
|
||||
cte.GMap[key].Percent = 0 //int(val.user + val.nice + val.system)
|
||||
return cte.GMap[key]
|
||||
}
|
||||
@@ -231,71 +232,58 @@ func (cte *CpuTabElems) Update(cs CpusStats) {
|
||||
p := int(val.user + val.nice + val.system)
|
||||
cte.GMap[key].Percent = p
|
||||
if key == "cpu" {
|
||||
cte.LChart.Data["default"] = append(cte.LChart.Data["default"], 0)
|
||||
copy(cte.LChart.Data["default"][1:], cte.LChart.Data["default"][0:])
|
||||
cte.LChart.Data["default"][0] = float64(p)
|
||||
cte.LChart.Data = append(cte.LChart.Data, []float64{})
|
||||
cte.LChart.Data[0] = append(cte.LChart.Data[0], 0)
|
||||
copy(cte.LChart.Data[0][1:], cte.LChart.Data[0][0:])
|
||||
cte.LChart.Data[0][0] = float64(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type MemTabElems struct {
|
||||
Gauge *ui.Gauge
|
||||
SLines *ui.Sparklines
|
||||
Gauge *widgets.Gauge
|
||||
SLines *widgets.SparklineGroup
|
||||
}
|
||||
|
||||
func NewMemTabElems(width int) *MemTabElems {
|
||||
g := ui.NewGauge()
|
||||
g.Width = width
|
||||
g.Height = 3
|
||||
g.Y = 0
|
||||
g := widgets.NewGauge()
|
||||
g.SetRect(0, 5, width, 10)
|
||||
|
||||
sline := ui.NewSparkline()
|
||||
sline := widgets.NewSparkline()
|
||||
sline.Title = "MEM"
|
||||
sline.Height = 8
|
||||
|
||||
sls := ui.NewSparklines(sline)
|
||||
sls.Width = width
|
||||
sls.Height = 12
|
||||
sls.Y = 3
|
||||
sls := widgets.NewSparklineGroup(sline)
|
||||
sls.SetRect(0, 10, width, 25)
|
||||
return &MemTabElems{Gauge: g, SLines: sls}
|
||||
}
|
||||
|
||||
func (mte *MemTabElems) Update(ms MemStat) {
|
||||
used := int((ms.total - ms.free) * 100 / ms.total)
|
||||
mte.Gauge.Percent = used
|
||||
mte.SLines.Lines[0].Data = append(mte.SLines.Lines[0].Data, 0)
|
||||
copy(mte.SLines.Lines[0].Data[1:], mte.SLines.Lines[0].Data[0:])
|
||||
mte.SLines.Lines[0].Data[0] = used
|
||||
if len(mte.SLines.Lines[0].Data) > mte.SLines.Width-2 {
|
||||
mte.SLines.Lines[0].Data = mte.SLines.Lines[0].Data[0 : mte.SLines.Width-2]
|
||||
used := (ms.total - ms.free) * 100 / ms.total
|
||||
mte.Gauge.Percent = int(used)
|
||||
mte.SLines.Sparklines[0].Data = append(mte.SLines.Sparklines[0].Data, 0)
|
||||
copy(mte.SLines.Sparklines[0].Data[1:], mte.SLines.Sparklines[0].Data[0:])
|
||||
mte.SLines.Sparklines[0].Data[0] = float64(used)
|
||||
if len(mte.SLines.Sparklines[0].Data) > mte.SLines.Dx()-2 {
|
||||
mte.SLines.Sparklines[0].Data = mte.SLines.Sparklines[0].Data[0 : mte.SLines.Dx()-2]
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
if runtime.GOOS != "linux" {
|
||||
panic("Currently works only on Linux")
|
||||
log.Fatalf("Currently only works on Linux")
|
||||
}
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
termWidth := 70
|
||||
|
||||
header := ui.NewParagraph("Press q to quit, Press h or l to switch tabs")
|
||||
header.Height = 1
|
||||
header.Width = 50
|
||||
header := widgets.NewParagraph()
|
||||
header.Text = "Press q to quit, Press h or l to switch tabs"
|
||||
header.SetRect(0, 0, 50, 1)
|
||||
header.Border = false
|
||||
header.TextBgColor = ui.ColorBlue
|
||||
|
||||
tabCpu := ui.NewTab("CPU")
|
||||
tabMem := ui.NewTab("MEM")
|
||||
|
||||
tabpane := ui.NewTabPane()
|
||||
tabpane.Y = 1
|
||||
tabpane.Width = 30
|
||||
tabpane.Border = false
|
||||
header.TextStyle.Bg = ui.ColorBlue
|
||||
|
||||
cs, errcs := getCpusStatsMap()
|
||||
cpusStats := NewCpusStats(cs)
|
||||
@@ -306,19 +294,17 @@ func main() {
|
||||
|
||||
cpuTabElems := NewCpuTabElems(termWidth)
|
||||
|
||||
Y := 0
|
||||
Y := 5
|
||||
cpuKeys := make([]string, 0, len(cs))
|
||||
for key := range cs {
|
||||
cpuKeys = append(cpuKeys, key)
|
||||
}
|
||||
sort.Strings(cpuKeys)
|
||||
for _, key := range cpuKeys {
|
||||
g := cpuTabElems.AddGauge(key, Y, termWidth)
|
||||
cpuTabElems.AddGauge(key, Y, termWidth)
|
||||
Y += 3
|
||||
tabCpu.AddBlocks(g)
|
||||
}
|
||||
cpuTabElems.LChart.Y = Y
|
||||
tabCpu.AddBlocks(cpuTabElems.LChart)
|
||||
cpuTabElems.LChart.Rectangle = cpuTabElems.LChart.GetRect().Add(image.Pt(0, Y))
|
||||
|
||||
memTabElems := NewMemTabElems(termWidth)
|
||||
ms, errm := getMemStats()
|
||||
@@ -326,12 +312,24 @@ func main() {
|
||||
panic(errm)
|
||||
}
|
||||
memTabElems.Update(ms)
|
||||
tabMem.AddBlocks(memTabElems.Gauge)
|
||||
tabMem.AddBlocks(memTabElems.SLines)
|
||||
|
||||
tabpane.SetTabs(*tabCpu, *tabMem)
|
||||
tabpane := widgets.NewTabPane("CPU", "MEM")
|
||||
tabpane.SetRect(0, 1, 30, 30)
|
||||
tabpane.Border = false
|
||||
renderTab := func() {
|
||||
switch tabpane.ActiveTabIndex {
|
||||
case 0:
|
||||
ui.Render(cpuTabElems.LChart)
|
||||
for _, gauge := range cpuTabElems.GMap {
|
||||
ui.Render(gauge)
|
||||
}
|
||||
case 1:
|
||||
ui.Render(memTabElems.Gauge, memTabElems.SLines)
|
||||
}
|
||||
}
|
||||
|
||||
ui.Render(header, tabpane)
|
||||
renderTab()
|
||||
|
||||
tickerCount := 1
|
||||
uiEvents := ui.PollEvents()
|
||||
@@ -343,11 +341,13 @@ func main() {
|
||||
case "q", "<C-c>":
|
||||
return
|
||||
case "h":
|
||||
tabpane.SetActiveLeft()
|
||||
tabpane.FocusLeft()
|
||||
ui.Render(header, tabpane)
|
||||
renderTab()
|
||||
case "l":
|
||||
tabpane.SetActiveRight()
|
||||
tabpane.FocusRight()
|
||||
ui.Render(header, tabpane)
|
||||
renderTab()
|
||||
}
|
||||
case <-ticker:
|
||||
cs, errcs := getCpusStatsMap()
|
||||
@@ -363,6 +363,7 @@ func main() {
|
||||
}
|
||||
memTabElems.Update(ms)
|
||||
ui.Render(header, tabpane)
|
||||
renderTab()
|
||||
tickerCount++
|
||||
}
|
||||
}
|
||||
@@ -6,71 +6,58 @@
|
||||
|
||||
package main
|
||||
|
||||
import ui "github.com/gizak/termui"
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
g0 := ui.NewGauge()
|
||||
g0.Percent = 40
|
||||
g0.Width = 50
|
||||
g0.Height = 3
|
||||
g0.BorderLabel = "Slim Gauge"
|
||||
g0 := widgets.NewGauge()
|
||||
g0.Title = "Slim Gauge"
|
||||
g0.SetRect(20, 20, 30, 30)
|
||||
g0.Percent = 75
|
||||
g0.BarColor = ui.ColorRed
|
||||
g0.BorderFg = ui.ColorWhite
|
||||
g0.BorderLabelFg = ui.ColorCyan
|
||||
g0.BorderStyle.Fg = ui.ColorWhite
|
||||
g0.TitleStyle.Fg = ui.ColorCyan
|
||||
|
||||
gg := ui.NewBlock()
|
||||
gg.Width = 50
|
||||
gg.Height = 5
|
||||
gg.Y = 12
|
||||
gg.BorderLabel = "TEST"
|
||||
gg.Align()
|
||||
|
||||
g2 := ui.NewGauge()
|
||||
g2 := widgets.NewGauge()
|
||||
g2.Title = "Slim Gauge"
|
||||
g2.SetRect(0, 3, 50, 6)
|
||||
g2.Percent = 60
|
||||
g2.Width = 50
|
||||
g2.Height = 3
|
||||
g2.PercentColor = ui.ColorBlue
|
||||
g2.Y = 3
|
||||
g2.BorderLabel = "Slim Gauge"
|
||||
g2.BarColor = ui.ColorYellow
|
||||
g2.BorderFg = ui.ColorWhite
|
||||
g2.LabelStyle = ui.NewStyle(ui.ColorBlue)
|
||||
g2.BorderStyle.Fg = ui.ColorWhite
|
||||
|
||||
g1 := ui.NewGauge()
|
||||
g1 := widgets.NewGauge()
|
||||
g1.Title = "Big Gauge"
|
||||
g1.SetRect(0, 6, 50, 11)
|
||||
g1.Percent = 30
|
||||
g1.Width = 50
|
||||
g1.Height = 5
|
||||
g1.Y = 6
|
||||
g1.BorderLabel = "Big Gauge"
|
||||
g1.PercentColor = ui.ColorYellow
|
||||
g1.BarColor = ui.ColorGreen
|
||||
g1.BorderFg = ui.ColorWhite
|
||||
g1.BorderLabelFg = ui.ColorMagenta
|
||||
g1.LabelStyle = ui.NewStyle(ui.ColorYellow)
|
||||
g1.TitleStyle.Fg = ui.ColorMagenta
|
||||
g1.BorderStyle.Fg = ui.ColorWhite
|
||||
|
||||
g3 := ui.NewGauge()
|
||||
g3 := widgets.NewGauge()
|
||||
g3.Title = "Gauge with custom label"
|
||||
g3.SetRect(0, 11, 50, 14)
|
||||
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 = ui.AlignRight
|
||||
g3.Label = fmt.Sprintf("%v%% (100MBs free)", g3.Percent)
|
||||
|
||||
g4 := ui.NewGauge()
|
||||
g4 := widgets.NewGauge()
|
||||
g4.Title = "Gauge"
|
||||
g4.SetRect(0, 14, 50, 17)
|
||||
g4.Percent = 50
|
||||
g4.Width = 50
|
||||
g4.Height = 3
|
||||
g4.Y = 14
|
||||
g4.BorderLabel = "Gauge"
|
||||
g4.Label = "Gauge with custom highlighted label"
|
||||
g4.PercentColor = ui.ColorYellow
|
||||
g4.BarColor = ui.ColorGreen
|
||||
g4.PercentColorHighlighted = ui.ColorBlack
|
||||
g4.LabelStyle = ui.NewStyle(ui.ColorYellow)
|
||||
|
||||
ui.Render(g0, g1, g2, g3, g4)
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 782 KiB |
@@ -7,93 +7,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
sinps := (func() []float64 {
|
||||
sinFloat64 := (func() []float64 {
|
||||
n := 400
|
||||
ps := make([]float64, n)
|
||||
for i := range ps {
|
||||
ps[i] = 1 + math.Sin(float64(i)/5)
|
||||
data := make([]float64, n)
|
||||
for i := range data {
|
||||
data[i] = 1 + math.Sin(float64(i)/5)
|
||||
}
|
||||
return ps
|
||||
})()
|
||||
sinpsint := (func() []int {
|
||||
ps := make([]int, len(sinps))
|
||||
for i, v := range sinps {
|
||||
ps[i] = int(100*v + 10)
|
||||
}
|
||||
return ps
|
||||
return data
|
||||
})()
|
||||
|
||||
spark := ui.Sparkline{}
|
||||
spark.Height = 8
|
||||
spdata := sinpsint
|
||||
spark.Data = spdata[:100]
|
||||
spark.LineColor = ui.ColorCyan
|
||||
spark.TitleColor = ui.ColorWhite
|
||||
sl := widgets.NewSparkline()
|
||||
sl.Data = sinFloat64[:100]
|
||||
sl.LineColor = ui.ColorCyan
|
||||
sl.TitleStyle.Fg = ui.ColorWhite
|
||||
|
||||
sp := ui.NewSparklines(spark)
|
||||
sp.Height = 11
|
||||
sp.BorderLabel = "Sparkline"
|
||||
slg := widgets.NewSparklineGroup(sl)
|
||||
slg.Title = "Sparkline"
|
||||
|
||||
lc := ui.NewLineChart()
|
||||
lc.BorderLabel = "braille-mode Line Chart"
|
||||
lc.Data["default"] = sinps
|
||||
lc.Height = 11
|
||||
lc := widgets.NewLineChart()
|
||||
lc.Title = "braille-mode Line Chart"
|
||||
lc.Data = append(lc.Data, sinFloat64)
|
||||
lc.AxesColor = ui.ColorWhite
|
||||
lc.LineColor["default"] = ui.ColorYellow | ui.AttrBold
|
||||
lc.LineColors[0] = ui.ColorYellow
|
||||
|
||||
gs := make([]*ui.Gauge, 3)
|
||||
gs := make([]*widgets.Gauge, 3)
|
||||
for i := range gs {
|
||||
gs[i] = ui.NewGauge()
|
||||
//gs[i].LabelAlign = ui.AlignCenter
|
||||
gs[i].Height = 2
|
||||
gs[i].Border = false
|
||||
gs[i] = widgets.NewGauge()
|
||||
gs[i].Percent = i * 10
|
||||
gs[i].PaddingBottom = 1
|
||||
gs[i].BarColor = ui.ColorRed
|
||||
}
|
||||
|
||||
ls := ui.NewList()
|
||||
ls.Border = false
|
||||
ls.Items = []string{
|
||||
ls := widgets.NewList()
|
||||
ls.Rows = []string{
|
||||
"[1] Downloading File 1",
|
||||
"", // == \newline
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"[2] Downloading File 2",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"[3] Uploading File 3",
|
||||
}
|
||||
ls.Height = 5
|
||||
|
||||
p := ui.NewParagraph("<> This row has 3 columns\n<- Widgets can be stacked up like left side\n<- Stacked widgets are treated as a single widget")
|
||||
p.Height = 5
|
||||
p.BorderLabel = "Demonstration"
|
||||
p := widgets.NewParagraph()
|
||||
p.Text = "<> This row has 3 columns\n<- Widgets can be stacked up like left side\n<- Stacked widgets are treated as a single widget"
|
||||
p.Title = "Demonstration"
|
||||
|
||||
// build layout
|
||||
ui.Body.AddRows(
|
||||
ui.NewRow(
|
||||
ui.NewCol(6, 0, sp),
|
||||
ui.NewCol(6, 0, lc)),
|
||||
ui.NewRow(
|
||||
ui.NewCol(3, 0, ls),
|
||||
ui.NewCol(3, 0, gs[0], gs[1], gs[2]),
|
||||
ui.NewCol(6, 0, p)))
|
||||
grid := ui.NewGrid()
|
||||
termWidth, termHeight := ui.TerminalDimensions()
|
||||
grid.SetRect(0, 0, termWidth, termHeight)
|
||||
|
||||
// calculate layout
|
||||
ui.Body.Align()
|
||||
grid.Set(
|
||||
ui.NewRow(1.0/2,
|
||||
ui.NewCol(1.0/2, slg),
|
||||
ui.NewCol(1.0/2, lc),
|
||||
),
|
||||
ui.NewRow(1.0/2,
|
||||
ui.NewCol(1.0/4, ls),
|
||||
ui.NewCol(1.0/4,
|
||||
ui.NewRow(.9/3, gs[0]),
|
||||
ui.NewRow(.9/3, gs[1]),
|
||||
ui.NewRow(1.2/3, gs[2]),
|
||||
),
|
||||
ui.NewCol(1.0/2, p),
|
||||
),
|
||||
)
|
||||
|
||||
ui.Render(ui.Body)
|
||||
ui.Render(grid)
|
||||
|
||||
tickerCount := 1
|
||||
uiEvents := ui.PollEvents()
|
||||
@@ -106,21 +101,20 @@ func main() {
|
||||
return
|
||||
case "<Resize>":
|
||||
payload := e.Payload.(ui.Resize)
|
||||
ui.Body.Width = payload.Width
|
||||
ui.Body.Align()
|
||||
grid.SetRect(0, 0, payload.Width, payload.Height)
|
||||
ui.Clear()
|
||||
ui.Render(ui.Body)
|
||||
ui.Render(grid)
|
||||
}
|
||||
case <-ticker:
|
||||
if tickerCount > 103 {
|
||||
if tickerCount == 100 {
|
||||
return
|
||||
}
|
||||
for _, g := range gs {
|
||||
g.Percent = (g.Percent + 3) % 100
|
||||
}
|
||||
sp.Lines[0].Data = spdata[:100+tickerCount]
|
||||
lc.Data["default"] = sinps[2*tickerCount:]
|
||||
ui.Render(ui.Body)
|
||||
slg.Sparklines[0].Data = sinFloat64[tickerCount : tickerCount+100]
|
||||
lc.Data[0] = sinFloat64[2*tickerCount:]
|
||||
ui.Render(grid)
|
||||
tickerCount++
|
||||
}
|
||||
}
|
||||
|
||||
48
_examples/grid_nested.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
grid := ui.NewGrid()
|
||||
termWidth, termHeight := ui.TerminalDimensions()
|
||||
grid.SetRect(0, 0, termWidth, termHeight)
|
||||
|
||||
grid2 := ui.NewGrid()
|
||||
|
||||
grid2.Set(
|
||||
ui.NewCol(.5, ui.NewBlock()),
|
||||
ui.NewCol(.5, ui.NewRow(.5, ui.NewBlock())),
|
||||
)
|
||||
|
||||
grid.Set(
|
||||
ui.NewRow(.5, ui.NewBlock()),
|
||||
ui.NewRow(.5, grid2),
|
||||
)
|
||||
|
||||
ui.Render(grid)
|
||||
|
||||
uiEvents := ui.PollEvents()
|
||||
for {
|
||||
e := <-uiEvents
|
||||
switch e.ID {
|
||||
case "q", "<C-c>":
|
||||
return
|
||||
case "<Resize>":
|
||||
payload := e.Payload.(ui.Resize)
|
||||
grid.SetRect(0, 0, payload.Width, payload.Height)
|
||||
ui.Clear()
|
||||
ui.Render(grid)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,24 @@
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import ui "github.com/gizak/termui"
|
||||
import (
|
||||
"log"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
p := ui.NewParagraph("Hello World!")
|
||||
p.Width = 25
|
||||
p.Height = 5
|
||||
p := widgets.NewParagraph()
|
||||
p.Text = "Hello World!"
|
||||
p.SetRect(0, 0, 25, 5)
|
||||
|
||||
ui.Render(p)
|
||||
|
||||
for e := range ui.PollEvents() {
|
||||
|
||||
@@ -7,62 +7,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
sinps := (func() map[string][]float64 {
|
||||
sinData := func() [][]float64 {
|
||||
n := 220
|
||||
ps := make(map[string][]float64)
|
||||
ps["first"] = make([]float64, n)
|
||||
ps["second"] = make([]float64, n)
|
||||
data := make([][]float64, 2)
|
||||
data[0] = make([]float64, n)
|
||||
data[1] = make([]float64, n)
|
||||
for i := 0; i < n; i++ {
|
||||
ps["first"][i] = 1 + math.Sin(float64(i)/5)
|
||||
ps["second"][i] = 1 + math.Cos(float64(i)/5)
|
||||
data[0][i] = 1 + math.Sin(float64(i)/5)
|
||||
data[1][i] = 1 + math.Cos(float64(i)/5)
|
||||
}
|
||||
return ps
|
||||
})()
|
||||
return data
|
||||
}()
|
||||
|
||||
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 := widgets.NewLineChart()
|
||||
lc0.Title = "braille-mode Line Chart"
|
||||
lc0.Data = sinData
|
||||
lc0.SetRect(0, 0, 50, 15)
|
||||
lc0.AxesColor = ui.ColorWhite
|
||||
lc0.LineColor["first"] = ui.ColorGreen | ui.AttrBold
|
||||
lc0.LineColors[0] = ui.ColorGreen
|
||||
|
||||
lc1 := ui.NewLineChart()
|
||||
lc1.BorderLabel = "dot-mode Line Chart"
|
||||
lc1.Mode = "dot"
|
||||
lc1.Data = sinps
|
||||
lc1.Width = 26
|
||||
lc1.Height = 12
|
||||
lc1.X = 51
|
||||
lc1.DotStyle = '+'
|
||||
lc1 := widgets.NewLineChart()
|
||||
lc1.Title = "custom Line Chart"
|
||||
lc1.LineType = widgets.DotLine
|
||||
lc1.Data = [][]float64{[]float64{1, 2, 3, 4, 5}}
|
||||
lc1.SetRect(50, 0, 75, 10)
|
||||
lc1.DotChar = '+'
|
||||
lc1.AxesColor = ui.ColorWhite
|
||||
lc1.LineColor["first"] = ui.ColorYellow | ui.AttrBold
|
||||
lc1.LineColors[0] = ui.ColorYellow
|
||||
lc1.DrawDirection = widgets.DrawLeft
|
||||
|
||||
lc2 := ui.NewLineChart()
|
||||
lc2.BorderLabel = "dot-mode Line Chart"
|
||||
lc2.Mode = "dot"
|
||||
lc2.Data["first"] = sinps["first"][4:]
|
||||
lc2.Data["second"] = sinps["second"][4:]
|
||||
lc2.Width = 77
|
||||
lc2.Height = 16
|
||||
lc2.X = 0
|
||||
lc2.Y = 12
|
||||
lc2 := widgets.NewLineChart()
|
||||
lc2.Title = "dot-mode Line Chart"
|
||||
lc2.LineType = widgets.DotLine
|
||||
lc2.Data = make([][]float64, 2)
|
||||
lc2.Data[0] = sinData[0][4:]
|
||||
lc2.Data[1] = sinData[1][4:]
|
||||
lc2.SetRect(0, 15, 50, 30)
|
||||
lc2.AxesColor = ui.ColorWhite
|
||||
lc2.LineColor["first"] = ui.ColorCyan | ui.AttrBold
|
||||
lc2.LineColors[0] = ui.ColorCyan
|
||||
|
||||
ui.Render(lc0, lc1, lc2)
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 31 KiB |
@@ -6,34 +6,36 @@
|
||||
|
||||
package main
|
||||
|
||||
import ui "github.com/gizak/termui"
|
||||
import (
|
||||
"log"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
strs := []string{
|
||||
l := widgets.NewList()
|
||||
l.Title = "List"
|
||||
l.Rows = []string{
|
||||
"[0] github.com/gizak/termui",
|
||||
"[1] [你好,世界](fg-blue)",
|
||||
"[2] [こんにちは世界](fg-red)",
|
||||
"[3] [color output](fg-white,bg-green)",
|
||||
"[1] [你好,世界](fg:blue)",
|
||||
"[2] [こんにちは世界](fg:red)",
|
||||
"[3] c[olor outpu](fg:white,bg:green)t",
|
||||
"[4] output.go",
|
||||
"[5] random_out.go",
|
||||
"[6] dashboard.go",
|
||||
"[7] nsf/termbox-go"}
|
||||
"[7] nsf/termbox-go",
|
||||
}
|
||||
l.TextStyle = ui.NewStyle(ui.ColorYellow)
|
||||
l.Wrap = false
|
||||
l.SetRect(0, 0, 25, 50)
|
||||
|
||||
ls := ui.NewList()
|
||||
ls.Items = strs
|
||||
ls.ItemFgColor = ui.ColorYellow
|
||||
ls.BorderLabel = "List"
|
||||
ls.Height = 7
|
||||
ls.Width = 25
|
||||
ls.Y = 0
|
||||
|
||||
ui.Render(ls)
|
||||
ui.Render(l)
|
||||
|
||||
uiEvents := ui.PollEvents()
|
||||
for {
|
||||
|
||||
|
Before Width: | Height: | Size: 28 KiB |
@@ -6,41 +6,47 @@
|
||||
|
||||
package main
|
||||
|
||||
import ui "github.com/gizak/termui"
|
||||
import (
|
||||
"log"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
p0 := ui.NewParagraph("Borderless Text")
|
||||
p0.Height = 1
|
||||
p0.Width = 20
|
||||
p0.Y = 1
|
||||
p0 := widgets.NewParagraph()
|
||||
p0.Text = "Borderless Text"
|
||||
p0.SetRect(0, 0, 20, 5)
|
||||
p0.Border = false
|
||||
|
||||
p1 := ui.NewParagraph("你好,世界。")
|
||||
p1.Height = 3
|
||||
p1.Width = 17
|
||||
p1.X = 20
|
||||
p1.BorderLabel = "标签"
|
||||
p1 := widgets.NewParagraph()
|
||||
p1.Title = "标签"
|
||||
p1.Text = "你好,世界。"
|
||||
p1.SetRect(20, 0, 35, 5)
|
||||
|
||||
p2 := ui.NewParagraph("Simple colored text\nwith label. It [can be](fg-red) multilined with \\n or [break automatically](fg-red,fg-bold)")
|
||||
p2.Height = 5
|
||||
p2.Width = 37
|
||||
p2.Y = 4
|
||||
p2.BorderLabel = "Multiline"
|
||||
p2.BorderFg = ui.ColorYellow
|
||||
p2 := widgets.NewParagraph()
|
||||
p2.Title = "Multiline"
|
||||
p2.Text = "Simple colored text\nwith label. It [can be](fg:red) multilined with \\n or [break automatically](fg:red,fg:bold)"
|
||||
p2.SetRect(0, 5, 35, 10)
|
||||
p2.BorderStyle.Fg = ui.ColorYellow
|
||||
|
||||
p3 := ui.NewParagraph("Long text with label and it is auto trimmed.")
|
||||
p3.Height = 3
|
||||
p3.Width = 37
|
||||
p3.Y = 9
|
||||
p3.BorderLabel = "Auto Trim"
|
||||
p3 := widgets.NewParagraph()
|
||||
p3.Title = "Auto Trim"
|
||||
p3.Text = "Long text with label and it is auto trimmed."
|
||||
p3.SetRect(0, 10, 40, 15)
|
||||
|
||||
ui.Render(p0, p1, p2, p3)
|
||||
p4 := widgets.NewParagraph()
|
||||
p4.Title = "Text Box with Wrapping"
|
||||
p4.Text = "Press q to QUIT THE DEMO. [There](fg:blue,mod:bold) 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."
|
||||
p4.SetRect(40, 0, 70, 20)
|
||||
p4.BorderStyle.Fg = ui.ColorBlue
|
||||
|
||||
ui.Render(p0, p1, p2, p3, p4)
|
||||
|
||||
uiEvents := ui.PollEvents()
|
||||
for {
|
||||
|
||||
|
Before Width: | Height: | Size: 45 KiB |
@@ -4,17 +4,20 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
var run = true
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
@@ -28,12 +31,10 @@ func main() {
|
||||
offset = 2.0 * math.Pi * rand.Float64()
|
||||
return
|
||||
}
|
||||
run := true
|
||||
|
||||
pc := ui.NewPieChart()
|
||||
pc.BorderLabel = "Pie Chart"
|
||||
pc.Width = 70
|
||||
pc.Height = 36
|
||||
pc := widgets.NewPieChart()
|
||||
pc.Title = "Pie Chart"
|
||||
pc.SetRect(5, 5, 70, 36)
|
||||
pc.Data = []float64{.25, .25, .25, .25}
|
||||
pc.Offset = -.5 * math.Pi
|
||||
pc.Label = func(i int, v float64) string {
|
||||
@@ -43,9 +44,9 @@ func main() {
|
||||
pause := func() {
|
||||
run = !run
|
||||
if run {
|
||||
pc.BorderLabel = "Pie Chart"
|
||||
pc.Title = "Pie Chart"
|
||||
} else {
|
||||
pc.BorderLabel = "Pie Chart (Stopped)"
|
||||
pc.Title = "Pie Chart (Stopped)"
|
||||
}
|
||||
ui.Render(pc)
|
||||
}
|
||||
|
||||
67
_examples/sparkline.go
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
data := []float64{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}
|
||||
|
||||
sl0 := widgets.NewSparkline()
|
||||
sl0.Data = data[3:]
|
||||
sl0.LineColor = ui.ColorGreen
|
||||
|
||||
// single
|
||||
slg0 := widgets.NewSparklineGroup(sl0)
|
||||
slg0.Title = "Sparkline 0"
|
||||
slg0.SetRect(0, 0, 20, 10)
|
||||
|
||||
sl1 := widgets.NewSparkline()
|
||||
sl1.Title = "Sparkline 1"
|
||||
sl1.Data = data
|
||||
sl1.LineColor = ui.ColorRed
|
||||
|
||||
sl2 := widgets.NewSparkline()
|
||||
sl2.Title = "Sparkline 2"
|
||||
sl2.Data = data[5:]
|
||||
sl2.LineColor = ui.ColorMagenta
|
||||
|
||||
slg1 := widgets.NewSparklineGroup(sl0, sl1, sl2)
|
||||
slg1.Title = "Group Sparklines"
|
||||
slg1.SetRect(0, 10, 25, 25)
|
||||
|
||||
sl3 := widgets.NewSparkline()
|
||||
sl3.Title = "Enlarged Sparkline"
|
||||
sl3.Data = data
|
||||
sl3.LineColor = ui.ColorYellow
|
||||
|
||||
slg2 := widgets.NewSparklineGroup(sl3)
|
||||
slg2.Title = "Tweeked Sparkline"
|
||||
slg2.SetRect(20, 0, 50, 10)
|
||||
slg2.BorderStyle.Fg = ui.ColorCyan
|
||||
|
||||
ui.Render(slg0, slg1, slg2)
|
||||
|
||||
uiEvents := ui.PollEvents()
|
||||
for {
|
||||
e := <-uiEvents
|
||||
switch e.ID {
|
||||
case "q", "<C-c>":
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import ui "github.com/gizak/termui"
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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 := ui.NewSparkline()
|
||||
spl0.Data = data[3:]
|
||||
spl0.Title = "Sparkline 0"
|
||||
spl0.LineColor = ui.ColorGreen
|
||||
|
||||
// single
|
||||
spls0 := ui.NewSparklines(spl0)
|
||||
spls0.Height = 2
|
||||
spls0.Width = 20
|
||||
spls0.Border = false
|
||||
|
||||
spl1 := ui.NewSparkline()
|
||||
spl1.Data = data
|
||||
spl1.Title = "Sparkline 1"
|
||||
spl1.LineColor = ui.ColorRed
|
||||
|
||||
spl2 := ui.NewSparkline()
|
||||
spl2.Data = data[5:]
|
||||
spl2.Title = "Sparkline 2"
|
||||
spl2.LineColor = ui.ColorMagenta
|
||||
|
||||
// group
|
||||
spls1 := ui.NewSparklines(spl0, spl1, spl2)
|
||||
spls1.Height = 8
|
||||
spls1.Width = 20
|
||||
spls1.Y = 3
|
||||
spls1.BorderLabel = "Group Sparklines"
|
||||
|
||||
spl3 := ui.NewSparkline()
|
||||
spl3.Data = data
|
||||
spl3.Title = "Enlarged Sparkline"
|
||||
spl3.Height = 8
|
||||
spl3.LineColor = ui.ColorYellow
|
||||
|
||||
spls2 := ui.NewSparklines(spl3)
|
||||
spls2.Height = 11
|
||||
spls2.Width = 30
|
||||
spls2.BorderFg = ui.ColorCyan
|
||||
spls2.X = 21
|
||||
spls2.BorderLabel = "Tweeked Sparkline"
|
||||
|
||||
ui.Render(spls0, spls1, spls2)
|
||||
|
||||
uiEvents := ui.PollEvents()
|
||||
for {
|
||||
e := <-uiEvents
|
||||
switch e.ID {
|
||||
case "q", "<C-c>":
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 48 KiB |
44
_examples/stacked_barchart.go
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
sbc := widgets.NewStackedBarChart()
|
||||
sbc.Title = "Student's Marks: X-Axis=Name, Y-Axis=Grade% (Math, English, Science, Computer Science)"
|
||||
sbc.Labels = []string{"Ken", "Rob", "Dennis", "Linus"}
|
||||
|
||||
sbc.Data = make([][]float64, 4)
|
||||
sbc.Data[0] = []float64{90, 85, 90, 80}
|
||||
sbc.Data[1] = []float64{70, 85, 75, 60}
|
||||
sbc.Data[2] = []float64{75, 60, 80, 85}
|
||||
sbc.Data[3] = []float64{100, 100, 100, 100}
|
||||
sbc.SetRect(5, 5, 100, 30)
|
||||
sbc.BarWidth = 5
|
||||
|
||||
ui.Render(sbc)
|
||||
|
||||
uiEvents := ui.PollEvents()
|
||||
for {
|
||||
e := <-uiEvents
|
||||
switch e.ID {
|
||||
case "q", "<C-c>":
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import ui "github.com/gizak/termui"
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
sbc := ui.NewStackedBarChart()
|
||||
math := []int{90, 85, 90, 80}
|
||||
english := []int{70, 85, 75, 60}
|
||||
science := []int{75, 60, 80, 85}
|
||||
compsci := []int{100, 100, 100, 100}
|
||||
sbc.Data[0] = math
|
||||
sbc.Data[1] = english
|
||||
sbc.Data[2] = science
|
||||
sbc.Data[3] = compsci
|
||||
studentsName := []string{"Ken", "Rob", "Dennis", "Linus"}
|
||||
sbc.BorderLabel = "Student's Marks X-Axis=Name Y-Axis=Marks[Math,English,Science,ComputerScience] in %"
|
||||
sbc.Width = 100
|
||||
sbc.Height = 30
|
||||
sbc.Y = 0
|
||||
sbc.BarWidth = 10
|
||||
sbc.DataLabels = studentsName
|
||||
sbc.ShowScale = true //Show y_axis scale value (min and max)
|
||||
sbc.SetMax(400)
|
||||
|
||||
sbc.TextColor = ui.ColorGreen //this is color for label (x-axis)
|
||||
sbc.BarColor[3] = ui.ColorGreen //BarColor for computerscience
|
||||
sbc.BarColor[1] = ui.ColorYellow //Bar Color for english
|
||||
sbc.NumColor[3] = ui.ColorRed // Num color for computerscience
|
||||
sbc.NumColor[1] = ui.ColorRed // num color for english
|
||||
|
||||
//Other colors are automatically populated, btw All the students seems do well in computerscience. :p
|
||||
|
||||
ui.Render(sbc)
|
||||
|
||||
uiEvents := ui.PollEvents()
|
||||
for {
|
||||
e := <-uiEvents
|
||||
switch e.ID {
|
||||
case "q", "<C-c>":
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 71 KiB |
@@ -6,50 +6,40 @@
|
||||
|
||||
package main
|
||||
|
||||
import ui "github.com/gizak/termui"
|
||||
import (
|
||||
"log"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
rows1 := [][]string{
|
||||
table1 := widgets.NewTable()
|
||||
table1.Rows = [][]string{
|
||||
[]string{"header1", "header2", "header3"},
|
||||
[]string{"你好吗", "Go-lang is so cool", "Im working on Ruby"},
|
||||
[]string{"2016", "10", "11"},
|
||||
}
|
||||
|
||||
table1 := ui.NewTable()
|
||||
table1.Rows = rows1
|
||||
table1.FgColor = ui.ColorWhite
|
||||
table1.BgColor = ui.ColorDefault
|
||||
table1.Y = 0
|
||||
table1.X = 0
|
||||
table1.Width = 62
|
||||
table1.Height = 7
|
||||
table1.TextStyle = ui.NewStyle(ui.ColorWhite)
|
||||
table1.SetRect(0, 0, 60, 10)
|
||||
|
||||
ui.Render(table1)
|
||||
|
||||
rows2 := [][]string{
|
||||
table2 := widgets.NewTable()
|
||||
table2.Rows = [][]string{
|
||||
[]string{"header1", "header2", "header3"},
|
||||
[]string{"Foundations", "Go-lang is so cool", "Im working on Ruby"},
|
||||
[]string{"2016", "11", "11"},
|
||||
}
|
||||
|
||||
table2 := ui.NewTable()
|
||||
table2.Rows = rows2
|
||||
table2.FgColor = ui.ColorWhite
|
||||
table2.BgColor = ui.ColorDefault
|
||||
table2.TextStyle = ui.NewStyle(ui.ColorWhite)
|
||||
table2.TextAlign = ui.AlignCenter
|
||||
table2.Separator = false
|
||||
table2.Analysis()
|
||||
table2.SetSize()
|
||||
table2.BgColors[2] = ui.ColorRed
|
||||
table2.Y = 10
|
||||
table2.X = 0
|
||||
table2.Border = true
|
||||
table2.RowSeparator = false
|
||||
table2.SetRect(0, 10, 20, 20)
|
||||
|
||||
ui.Render(table2)
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 46 KiB |
@@ -7,73 +7,68 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
"github.com/gizak/termui/widgets"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err := ui.Init(); err != nil {
|
||||
log.Fatalf("failed to initialize termui: %v", err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
header := ui.NewParagraph("Press q to quit, Press h or l to switch tabs")
|
||||
header.Height = 1
|
||||
header.Width = 50
|
||||
header := widgets.NewParagraph()
|
||||
header.Text = "Press q to quit, Press h or l to switch tabs"
|
||||
header.SetRect(0, 0, 50, 1)
|
||||
header.Border = false
|
||||
header.TextBgColor = ui.ColorBlue
|
||||
header.TextStyle.Bg = ui.ColorBlue
|
||||
|
||||
tab1 := ui.NewTab("pierwszy")
|
||||
p2 := ui.NewParagraph("Press q to quit\nPress h or l to switch tabs\n")
|
||||
p2.Height = 5
|
||||
p2.Width = 37
|
||||
p2.Y = 0
|
||||
p2.BorderLabel = "Keys"
|
||||
p2.BorderFg = ui.ColorYellow
|
||||
tab1.AddBlocks(p2)
|
||||
p2 := widgets.NewParagraph()
|
||||
p2.Text = "Press q to quit\nPress h or l to switch tabs\n"
|
||||
p2.Title = "Keys"
|
||||
p2.SetRect(5, 5, 40, 15)
|
||||
p2.BorderStyle.Fg = ui.ColorYellow
|
||||
|
||||
tab2 := ui.NewTab("drugi")
|
||||
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"
|
||||
bc.Data = data
|
||||
bc.Width = 26
|
||||
bc.Height = 10
|
||||
bc.DataLabels = bclabels
|
||||
bc.TextColor = ui.ColorGreen
|
||||
bc.BarColor = ui.ColorRed
|
||||
bc.NumColor = ui.ColorYellow
|
||||
tab2.AddBlocks(bc)
|
||||
bc := widgets.NewBarChart()
|
||||
bc.Title = "Bar Chart"
|
||||
bc.Data = []float64{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.SetRect(5, 5, 35, 10)
|
||||
bc.Labels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
||||
|
||||
tab3 := ui.NewTab("trzeci")
|
||||
tab4 := ui.NewTab("żółw")
|
||||
tab5 := ui.NewTab("four")
|
||||
tab6 := ui.NewTab("five")
|
||||
|
||||
tabpane := ui.NewTabPane()
|
||||
tabpane.Y = 1
|
||||
tabpane.Width = 30
|
||||
tabpane := widgets.NewTabPane("pierwszy", "drugi", "trzeci", "żółw", "four", "five")
|
||||
tabpane.SetRect(0, 1, 50, 4)
|
||||
tabpane.Border = true
|
||||
|
||||
tabpane.SetTabs(*tab1, *tab2, *tab3, *tab4, *tab5, *tab6)
|
||||
renderTab := func() {
|
||||
switch tabpane.ActiveTabIndex {
|
||||
case 0:
|
||||
ui.Render(p2)
|
||||
case 1:
|
||||
ui.Render(bc)
|
||||
}
|
||||
}
|
||||
|
||||
ui.Render(header, tabpane)
|
||||
ui.Render(header, tabpane, p2)
|
||||
|
||||
uiEvents := ui.PollEvents()
|
||||
|
||||
for {
|
||||
e := <-uiEvents
|
||||
switch e.ID {
|
||||
case "q", "<C-c>":
|
||||
return
|
||||
case "h":
|
||||
tabpane.SetActiveLeft()
|
||||
tabpane.FocusLeft()
|
||||
ui.Clear()
|
||||
ui.Render(header, tabpane)
|
||||
renderTab()
|
||||
case "l":
|
||||
tabpane.SetActiveRight()
|
||||
tabpane.FocusRight()
|
||||
ui.Clear()
|
||||
ui.Render(header, tabpane)
|
||||
renderTab()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
// 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,
|
||||
}
|
||||
p := ui.NewParagraph(":PRESS q TO QUIT DEMO")
|
||||
p.Height = 3
|
||||
p.Width = 50
|
||||
p.BorderLabel = "Text Box"
|
||||
|
||||
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.BorderLabel = "List"
|
||||
list.Height = 7
|
||||
list.Width = 25
|
||||
list.Y = 4
|
||||
|
||||
g := ui.NewGauge()
|
||||
g.Percent = 50
|
||||
g.Width = 50
|
||||
g.Height = 3
|
||||
g.Y = 11
|
||||
g.BorderLabel = "Gauge"
|
||||
|
||||
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
|
||||
sp.BorderLabel = "Sparkline"
|
||||
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
|
||||
})()
|
||||
|
||||
lc.BorderLabel = "Line Chart"
|
||||
lc.Data["default"] = sinps
|
||||
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"}
|
||||
bc.BorderLabel = "Bar Chart"
|
||||
bc.Width = 26
|
||||
bc.Height = 10
|
||||
bc.X = 51
|
||||
bc.Y = 0
|
||||
bc.DataLabels = bclabels
|
||||
|
||||
lc1 := ui.NewLineChart()
|
||||
lc1.BorderLabel = "Line Chart"
|
||||
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
|
||||
})()
|
||||
lc1.Data["default"] = rndwalk
|
||||
lc1.Width = 26
|
||||
lc1.Height = 11
|
||||
lc1.X = 51
|
||||
lc1.Y = 14
|
||||
|
||||
p1 := ui.NewParagraph("Hey!\nI am a borderless block!")
|
||||
p1.Border = false
|
||||
p1.Width = 26
|
||||
p1.Height = 2
|
||||
p1.X = 52
|
||||
p1.Y = 11
|
||||
|
||||
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:]
|
||||
ui.Render(p, list, g, sp, lc, bc, lc1, p1)
|
||||
}
|
||||
|
||||
ui.Render(p, list, g, sp, lc, bc, lc1, p1)
|
||||
|
||||
tickerCount := 1
|
||||
uiEvents := ui.PollEvents()
|
||||
ticker := time.NewTicker(time.Second).C
|
||||
for {
|
||||
select {
|
||||
case e := <-uiEvents:
|
||||
switch e.ID {
|
||||
case "q", "<C-c>":
|
||||
return
|
||||
}
|
||||
case <-ticker:
|
||||
draw(tickerCount)
|
||||
tickerCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 88 KiB |
@@ -1,38 +0,0 @@
|
||||
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import ui "github.com/gizak/termui"
|
||||
|
||||
func main() {
|
||||
err := ui.Init()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer ui.Close()
|
||||
|
||||
p := ui.NewParagraph("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.WrapLength = 48 // this should be at least p.Width - 2
|
||||
p.Height = 20
|
||||
p.Width = 50
|
||||
p.Y = 2
|
||||
p.X = 20
|
||||
p.TextFgColor = ui.ColorWhite
|
||||
p.BorderLabel = "Text Box with Wrapping"
|
||||
p.BorderFg = ui.ColorCyan
|
||||
|
||||
ui.Render(p)
|
||||
|
||||
uiEvents := ui.PollEvents()
|
||||
for {
|
||||
e := <-uiEvents
|
||||
switch e.ID {
|
||||
case "q", "<C-c>":
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||