File renaming

This commit is contained in:
Caleb Bassi
2018-09-06 14:15:57 -07:00
parent 07edbb9c11
commit 7d98eb0bf4
29 changed files with 1 additions and 1 deletions

View File

@@ -1,36 +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 "github.com/gizak/termui"
func main() {
if err := termui.Init(); err != nil {
panic(err)
}
defer termui.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.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
termui.Render(bc)
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 152 KiB

View File

@@ -1,145 +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"
ui "github.com/gizak/termui"
)
func main() {
if err := ui.Init(); err != nil {
panic(err)
}
defer ui.Close()
p := ui.NewPar(":PRESS q TO QUIT DEMO")
p.Height = 3
p.Width = 50
p.TextFgColor = ui.ColorWhite
p.BorderLabel = "Text Box"
p.BorderFg = ui.ColorCyan
p.Handle("/timer/1s", func(e ui.Event) {
cnt := e.Data.(ui.EvtTimer)
if cnt.Count%2 == 0 {
p.TextFgColor = ui.ColorRed
} else {
p.TextFgColor = ui.ColorWhite
}
})
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
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
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
spark1 := ui.Sparkline{}
spark1.Height = 1
spark1.Title = "srv 1:"
spark1.Data = spdata
spark1.TitleColor = ui.ColorWhite
spark1.LineColor = ui.ColorRed
sp := ui.NewSparklines(spark, spark1)
sp.Width = 25
sp.Height = 7
sp.BorderLabel = "Sparkline"
sp.Y = 4
sp.X = 25
sinps := (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"] = sinps
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"
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.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
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
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)
}
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()
}

View File

@@ -1,84 +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 "github.com/gizak/termui"
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
//termui.UseTheme("helloworld")
g0 := termui.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
gg := termui.NewBlock()
gg.Width = 50
gg.Height = 5
gg.Y = 12
gg.BorderLabel = "TEST"
gg.Align()
g2 := termui.NewGauge()
g2.Percent = 60
g2.Width = 50
g2.Height = 3
g2.PercentColor = termui.ColorBlue
g2.Y = 3
g2.BorderLabel = "Slim Gauge"
g2.BarColor = termui.ColorYellow
g2.BorderFg = termui.ColorWhite
g1 := termui.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
g3 := termui.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
g4 := termui.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
termui.Render(g0, g1, g2, g3, g4)
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 782 KiB

View File

@@ -1,124 +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"
ui "github.com/gizak/termui"
)
func main() {
if err := ui.Init(); err != nil {
panic(err)
}
defer ui.Close()
sinps := (func() []float64 {
n := 400
ps := make([]float64, n)
for i := range ps {
ps[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
})()
spark := ui.Sparkline{}
spark.Height = 8
spdata := sinpsint
spark.Data = spdata[:100]
spark.LineColor = ui.ColorCyan
spark.TitleColor = ui.ColorWhite
sp := ui.NewSparklines(spark)
sp.Height = 11
sp.BorderLabel = "Sparkline"
lc := ui.NewLineChart()
lc.BorderLabel = "braille-mode Line Chart"
lc.Data["default"] = sinps
lc.Height = 11
lc.AxesColor = ui.ColorWhite
lc.LineColor["default"] = ui.ColorYellow | ui.AttrBold
gs := make([]*ui.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].Percent = i * 10
gs[i].PaddingBottom = 1
gs[i].BarColor = ui.ColorRed
}
ls := ui.NewList()
ls.Border = false
ls.Items = []string{
"[1] Downloading File 1",
"", // == \newline
"[2] Downloading File 2",
"",
"[3] Uploading File 3",
}
ls.Height = 5
par := ui.NewPar("<> This row has 3 columns\n<- Widgets can be stacked up like left side\n<- Stacked widgets are treated as a single widget")
par.Height = 5
par.BorderLabel = "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, par)))
// calculate layout
ui.Body.Align()
ui.Render(ui.Body)
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
if i > 103 {
ui.StopLoop()
return
}
for _, g := range gs {
g.Percent = (g.Percent + 3) % 100
}
sp.Lines[0].Data = spdata[:100+i]
lc.Data["default"] = sinps[2*i:]
ui.Render(ui.Body)
})
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
ui.Body.Width = ui.TermWidth()
ui.Body.Align()
ui.Clear()
ui.Render(ui.Body)
})
ui.Loop()
}

View File

@@ -1,75 +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"
"github.com/gizak/termui"
)
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
//termui.UseTheme("helloworld")
sinps := (func() map[string][]float64 {
n := 220
ps := make(map[string][]float64)
ps["first"] = make([]float64, n)
ps["second"] = 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)
}
return ps
})()
lc0 := termui.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
lc1 := termui.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.AxesColor = termui.ColorWhite
lc1.LineColor["first"] = termui.ColorYellow | termui.AttrBold
lc2 := termui.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.AxesColor = termui.ColorWhite
lc2.LineColor["first"] = termui.ColorCyan | termui.AttrBold
termui.Render(lc0, lc1, lc2)
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

View File

@@ -1,44 +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 "github.com/gizak/termui"
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
//termui.UseTheme("helloworld")
strs := []string{
"[0] github.com/gizak/termui",
"[1] [你好,世界](fg-blue)",
"[2] [こんにちは世界](fg-red)",
"[3] [color output](fg-white,bg-green)",
"[4] output.go",
"[5] random_out.go",
"[6] dashboard.go",
"[7] nsf/termbox-go"}
ls := termui.NewList()
ls.Items = strs
ls.ItemFgColor = termui.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()
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -1,54 +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 "github.com/gizak/termui"
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
//termui.UseTheme("helloworld")
bc := termui.NewMBarChart()
math := []int{90, 85, 90, 80}
english := []int{70, 85, 75, 60}
science := []int{75, 60, 80, 85}
compsci := []int{100, 100, 100, 100}
bc.Data[0] = math
bc.Data[1] = english
bc.Data[2] = science
bc.Data[3] = compsci
studentsName := []string{"Ken", "Rob", "Dennis", "Linus"}
bc.BorderLabel = "Student's Marks X-Axis=Name Y-Axis=Marks[Math,English,Science,ComputerScience] in %"
bc.Width = 100
bc.Height = 30
bc.Y = 0
bc.BarWidth = 10
bc.DataLabels = studentsName
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
//Other colors are automatically populated, btw All the students seems do well in computerscience. :p
termui.Render(bc)
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

View File

@@ -1,52 +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 "github.com/gizak/termui"
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
//termui.UseTheme("helloworld")
par0 := termui.NewPar("Borderless Text")
par0.Height = 1
par0.Width = 20
par0.Y = 1
par0.Border = false
par1 := termui.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.Height = 5
par2.Width = 37
par2.Y = 4
par2.BorderLabel = "Multiline"
par2.BorderFg = termui.ColorYellow
par3 := termui.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)
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

View File

@@ -1,63 +0,0 @@
// +build ignore
package main
import (
"fmt"
"math"
"math/rand"
"time"
"github.com/gizak/termui"
)
func main() {
if err := termui.Init(); err != nil {
panic(err)
}
defer termui.Close()
rand.Seed(time.Now().UTC().UnixNano())
randomDataAndOffset := func() (data []float64, offset float64) {
noSlices := 1 + rand.Intn(5)
data = make([]float64, noSlices)
for i := range data {
data[i] = rand.Float64()
}
offset = 2.0 * math.Pi * rand.Float64()
return
}
run := true
pc := termui.NewPieChart()
pc.BorderLabel = "Pie Chart"
pc.Width = 70
pc.Height = 36
pc.Data = []float64{.25, .25, .25, .25}
pc.Offset = -.5 * math.Pi
pc.Label = func(i int, v float64) string {
return fmt.Sprintf("%.02f", v)
}
termui.Handle("/timer/1s", func(e termui.Event) {
if run {
pc.Data, pc.Offset = randomDataAndOffset()
termui.Render(pc)
}
})
termui.Handle("/sys/kbd/s", func(termui.Event) {
run = !run
if run {
pc.BorderLabel = "Pie Chart"
} else {
pc.BorderLabel = "Pie Chart (Stopped)"
}
termui.Render(pc)
})
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Render(pc)
termui.Loop()
}

View File

@@ -1,69 +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 "github.com/gizak/termui"
func main() {
err := termui.Init()
if err != nil {
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}
spl0 := termui.NewSparkline()
spl0.Data = data[3:]
spl0.Title = "Sparkline 0"
spl0.LineColor = termui.ColorGreen
// single
spls0 := termui.NewSparklines(spl0)
spls0.Height = 2
spls0.Width = 20
spls0.Border = false
spl1 := termui.NewSparkline()
spl1.Data = data
spl1.Title = "Sparkline 1"
spl1.LineColor = termui.ColorRed
spl2 := termui.NewSparkline()
spl2.Data = data[5:]
spl2.Title = "Sparkline 2"
spl2.LineColor = termui.ColorMagenta
// group
spls1 := termui.NewSparklines(spl0, spl1, spl2)
spls1.Height = 8
spls1.Width = 20
spls1.Y = 3
spls1.BorderLabel = "Group Sparklines"
spl3 := termui.NewSparkline()
spl3.Data = data
spl3.Title = "Enlarged Sparkline"
spl3.Height = 8
spl3.LineColor = termui.ColorYellow
spls2 := termui.NewSparklines(spl3)
spls2.Height = 11
spls2.Width = 30
spls2.BorderFg = termui.ColorCyan
spls2.X = 21
spls2.BorderLabel = "Tweeked Sparkline"
termui.Render(spls0, spls1, spls2)
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

View File

@@ -1,58 +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 "github.com/gizak/termui"
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.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.Rows = rows1
table1.FgColor = termui.ColorWhite
table1.BgColor = termui.ColorDefault
table1.Y = 0
table1.X = 0
table1.Width = 62
table1.Height = 7
termui.Render(table1)
rows2 := [][]string{
[]string{"header1", "header2", "header3"},
[]string{"Foundations", "Go-lang is so cool", "Im working on Ruby"},
[]string{"2016", "11", "11"},
}
table2 := termui.NewTable()
table2.Rows = rows2
table2.FgColor = termui.ColorWhite
table2.BgColor = termui.ColorDefault
table2.TextAlign = termui.AlignCenter
table2.Separator = false
table2.Analysis()
table2.SetSize()
table2.BgColors[2] = termui.ColorRed
table2.Y = 10
table2.X = 0
table2.Border = true
termui.Render(table2)
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -1,83 +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 (
"github.com/gizak/termui"
"github.com/gizak/termui/extra"
)
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
//termui.UseTheme("helloworld")
header := termui.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
tab1 := extra.NewTab("pierwszy")
par2 := termui.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
tab1.AddBlocks(par2)
tab2 := extra.NewTab("drugi")
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.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
tab2.AddBlocks(bc)
tab3 := extra.NewTab("trzeci")
tab4 := extra.NewTab("żółw")
tab5 := extra.NewTab("four")
tab6 := extra.NewTab("five")
tabpane := extra.NewTabpane()
tabpane.Y = 1
tabpane.Width = 30
tabpane.Border = true
tabpane.SetTabs(*tab1, *tab2, *tab3, *tab4, *tab5, *tab6)
termui.Render(header, tabpane)
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Handle("/sys/kbd/j", func(termui.Event) {
tabpane.SetActiveLeft()
termui.Clear()
termui.Render(header, tabpane)
})
termui.Handle("/sys/kbd/k", func(termui.Event) {
tabpane.SetActiveRight()
termui.Clear()
termui.Render(header, tabpane)
})
termui.Loop()
}

View File

@@ -1,147 +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"
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.NewPar(":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.NewPar("Hey!\nI am a borderless block!")
p1.Border = false
p1.Width = 26
p1.Height = 2
p1.X = 52
p1.Y = 11
draw := func(t int) {
g.Percent = t % 101
list.Items = strs[t%9:]
sp.Lines[0].Data = spdata[t%10:]
sp.Lines[1].Data = spdata[t/2%10:]
lc.Data["default"] = sinps[t/2:]
lc1.Data["default"] = rndwalk[t:]
bc.Data = bcdata[t/2%10:]
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.StopLoop()
})
ui.Handle("/timer/1s", func(e ui.Event) {
t := e.Data.(ui.EvtTimer)
draw(int(t.Count))
})
ui.Loop()
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

View File

@@ -1,369 +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 (
"bufio"
"errors"
"fmt"
"io"
"os"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
"github.com/gizak/termui"
"github.com/gizak/termui/extra"
)
const statFilePath = "/proc/stat"
const meminfoFilePath = "/proc/meminfo"
type CpuStat struct {
user float32
nice float32
system float32
idle float32
}
type CpusStats struct {
stat map[string]CpuStat
proc map[string]CpuStat
}
func NewCpusStats(s map[string]CpuStat) *CpusStats {
return &CpusStats{stat: s, proc: make(map[string]CpuStat)}
}
func (cs *CpusStats) String() (ret string) {
for key, _ := range cs.proc {
ret += fmt.Sprintf("%s: %.2f %.2f %.2f %.2f\n", key, cs.proc[key].user, cs.proc[key].nice, cs.proc[key].system, cs.proc[key].idle)
}
return
}
func subCpuStat(m CpuStat, s CpuStat) CpuStat {
return CpuStat{user: m.user - s.user,
nice: m.nice - s.nice,
system: m.system - s.system,
idle: m.idle - s.idle}
}
func procCpuStat(c CpuStat) CpuStat {
sum := c.user + c.nice + c.system + c.idle
return CpuStat{user: c.user / sum * 100,
nice: c.nice / sum * 100,
system: c.system / sum * 100,
idle: c.idle / sum * 100}
}
func (cs *CpusStats) tick(ns map[string]CpuStat) {
for key, _ := range cs.stat {
proc := subCpuStat(ns[key], cs.stat[key])
cs.proc[key] = procCpuStat(proc)
cs.stat[key] = ns[key]
}
}
type errIntParser struct {
err error
}
func (eip *errIntParser) parse(s string) (ret int64) {
if eip.err != nil {
return 0
}
ret, eip.err = strconv.ParseInt(s, 10, 0)
return
}
type LineProcessor interface {
process(string) error
finalize() interface{}
}
type CpuLineProcessor struct {
m map[string]CpuStat
}
func (clp *CpuLineProcessor) process(line string) (err error) {
r := regexp.MustCompile("^cpu([0-9]*)")
if r.MatchString(line) {
tab := strings.Fields(line)
if len(tab) < 5 {
err = errors.New("cpu info line has not enough fields")
return
}
parser := errIntParser{}
cs := CpuStat{user: float32(parser.parse(tab[1])),
nice: float32(parser.parse(tab[2])),
system: float32(parser.parse(tab[3])),
idle: float32(parser.parse(tab[4]))}
clp.m[tab[0]] = cs
err = parser.err
if err != nil {
return
}
}
return
}
func (clp *CpuLineProcessor) finalize() interface{} {
return clp.m
}
type MemStat struct {
total int64
free int64
}
func (ms MemStat) String() (ret string) {
ret = fmt.Sprintf("TotalMem: %d, FreeMem: %d\n", ms.total, ms.free)
return
}
func (ms *MemStat) process(line string) (err error) {
rtotal := regexp.MustCompile("^MemTotal:")
rfree := regexp.MustCompile("^MemFree:")
var aux int64
if rtotal.MatchString(line) || rfree.MatchString(line) {
tab := strings.Fields(line)
if len(tab) < 3 {
err = errors.New("mem info line has not enough fields")
return
}
aux, err = strconv.ParseInt(tab[1], 10, 0)
}
if err != nil {
return
}
if rtotal.MatchString(line) {
ms.total = aux
}
if rfree.MatchString(line) {
ms.free = aux
}
return
}
func (ms *MemStat) finalize() interface{} {
return *ms
}
func processFileLines(filePath string, lp LineProcessor) (ret interface{}, err error) {
var statFile *os.File
statFile, err = os.Open(filePath)
if err != nil {
fmt.Printf("open: %v\n", err)
}
defer statFile.Close()
statFileReader := bufio.NewReader(statFile)
for {
var line string
line, err = statFileReader.ReadString('\n')
if err == io.EOF {
err = nil
break
}
if err != nil {
fmt.Printf("open: %v\n", err)
break
}
line = strings.TrimSpace(line)
err = lp.process(line)
}
ret = lp.finalize()
return
}
func getCpusStatsMap() (m map[string]CpuStat, err error) {
var aux interface{}
aux, err = processFileLines(statFilePath, &CpuLineProcessor{m: make(map[string]CpuStat)})
return aux.(map[string]CpuStat), err
}
func getMemStats() (ms MemStat, err error) {
var aux interface{}
aux, err = processFileLines(meminfoFilePath, &MemStat{})
return aux.(MemStat), err
}
type CpuTabElems struct {
GMap map[string]*termui.Gauge
LChart *termui.LineChart
}
func NewCpuTabElems(width int) *CpuTabElems {
lc := termui.NewLineChart()
lc.Width = width
lc.Height = 12
lc.X = 0
lc.Mode = "dot"
lc.BorderLabel = "CPU"
return &CpuTabElems{GMap: make(map[string]*termui.Gauge),
LChart: lc}
}
func (cte *CpuTabElems) AddGauge(key string, Y int, width int) *termui.Gauge {
cte.GMap[key] = termui.NewGauge()
cte.GMap[key].Width = width
cte.GMap[key].Height = 3
cte.GMap[key].Y = Y
cte.GMap[key].BorderLabel = key
cte.GMap[key].Percent = 0 //int(val.user + val.nice + val.system)
return cte.GMap[key]
}
func (cte *CpuTabElems) Update(cs CpusStats) {
for key, val := range cs.proc {
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)
}
}
}
type MemTabElems struct {
Gauge *termui.Gauge
SLines *termui.Sparklines
}
func NewMemTabElems(width int) *MemTabElems {
g := termui.NewGauge()
g.Width = width
g.Height = 3
g.Y = 0
sline := termui.NewSparkline()
sline.Title = "MEM"
sline.Height = 8
sls := termui.NewSparklines(sline)
sls.Width = width
sls.Height = 12
sls.Y = 3
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]
}
}
func main() {
if runtime.GOOS != "linux" {
panic("Currently works only on Linux")
}
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
termWidth := 70
//termui.UseTheme("helloworld")
header := termui.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
tabCpu := extra.NewTab("CPU")
tabMem := extra.NewTab("MEM")
tabpane := extra.NewTabpane()
tabpane.Y = 1
tabpane.Width = 30
tabpane.Border = false
cs, errcs := getCpusStatsMap()
cpusStats := NewCpusStats(cs)
if errcs != nil {
panic("error")
}
cpuTabElems := NewCpuTabElems(termWidth)
Y := 0
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)
Y += 3
tabCpu.AddBlocks(g)
}
cpuTabElems.LChart.Y = Y
tabCpu.AddBlocks(cpuTabElems.LChart)
memTabElems := NewMemTabElems(termWidth)
ms, errm := getMemStats()
if errm != nil {
panic(errm)
}
memTabElems.Update(ms)
tabMem.AddBlocks(memTabElems.Gauge)
tabMem.AddBlocks(memTabElems.SLines)
tabpane.SetTabs(*tabCpu, *tabMem)
termui.Render(header, tabpane)
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Handle("/sys/kbd/j", func(termui.Event) {
tabpane.SetActiveLeft()
termui.Render(header, tabpane)
})
termui.Handle("/sys/kbd/k", func(termui.Event) {
tabpane.SetActiveRight()
termui.Render(header, tabpane)
})
termui.Handle("/timer/1s", func(e termui.Event) {
cs, errcs := getCpusStatsMap()
if errcs != nil {
panic(errcs)
}
cpusStats.tick(cs)
cpuTabElems.Update(*cpusStats)
ms, errm := getMemStats()
if errm != nil {
panic(errm)
}
memTabElems.Update(ms)
termui.Render(header, tabpane)
})
termui.Loop()
}

View File

@@ -1,37 +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.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.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
//p.Border = false
ui.Render(p)
ui.Handle("/sys/kbd/q", func(ui.Event) {
ui.StopLoop()
})
ui.Loop()
}