Widgets API adaption

This commit is contained in:
gizak
2015-10-08 22:11:26 -04:00
parent e0dec9dbb9
commit ca69e25d1b
19 changed files with 173 additions and 270 deletions

View File

@@ -15,12 +15,12 @@ func main() {
}
defer termui.Close()
termui.UseTheme("helloworld")
//termui.UseTheme("helloworld")
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.Border.Label = "Bar Chart"
bc.BorderLabel = "Bar Chart"
bc.Data = data
bc.Width = 26
bc.Height = 10
@@ -31,5 +31,9 @@ func main() {
termui.Render(bc)
<-termui.EventCh()
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}

View File

@@ -1,90 +0,0 @@
// +build ignore
package main
import "github.com/gizak/termui"
import "github.com/nsf/termbox-go"
func markdownList() *termui.List {
strs := []string{
"[0] github.com/gizak/termui",
"[1] 笀耔 [澉 灊灅甗](RED) 郔镺 笀耔 澉 [灊灅甗](yellow) 郔镺",
"[2] こんにちは世界",
"[3] keyboard.go",
"[4] [output](RED).go",
"[5] random_out.go",
"[6] [dashboard](BOLD).go",
"[7] nsf/termbox-go",
"[8] OVERFLOW!!!!!!![!!!!!!!!!!!!](red,bold)!!!"}
list := termui.NewList()
list.Items = strs
list.Height = 15
list.Width = 26
list.RendererFactory = termui.MarkdownTextRendererFactory{}
return list
}
func hideList(list *termui.List) *termui.List {
list.Border.Label = "List - Hidden"
list.Overflow = "hidden"
return list
}
func wrapList(list *termui.List) *termui.List {
list.Border.Label = "List - Wrapped"
list.Overflow = "wrap"
list.X = 30
return list
}
func escapeList() *termui.List {
strs := []string{
"[0] github.com/gizak/termui",
"[1] 笀耔 \033[31m澉 灊灅甗 \033[0m郔镺 笀耔 澉 \033[33m灊灅甗 郔镺",
"[2] こんにちは世界",
"[3] keyboard.go",
"[4] \033[31moutput\033[0m.go",
"[5] random_out.go",
"[6] \033[1mdashboard\033[0m.go",
"[7] nsf/termbox-go",
"[8] OVERFLOW!!!!!!!\033[31;1m!!!!!!!!!!!!\033[0m!!!",
}
list := termui.NewList()
list.RendererFactory = termui.EscapeCodeRendererFactory{}
list.Items = strs
list.Height = 15
list.Width = 26
list.Y = 15
return list
}
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
hiddenMarkdownList := hideList(markdownList())
wrappedMarkdownList := wrapList(markdownList())
hiddenEscapeList := hideList(escapeList())
wrappedEscapeList := wrapList(escapeList())
lists := []termui.Bufferer{
hiddenEscapeList,
hiddenMarkdownList,
wrappedMarkdownList,
wrappedEscapeList,
}
termui.UseTheme("helloworld")
termui.Render(lists...)
termbox.PollEvent()
}

View File

@@ -19,7 +19,7 @@ func main() {
}
defer termui.Close()
termui.UseTheme("helloworld")
//termui.UseTheme("helloworld")
sinps := (func() []float64 {
n := 220
@@ -31,7 +31,7 @@ func main() {
})()
lc0 := termui.NewLineChart()
lc0.Border.Label = "braille-mode Line Chart"
lc0.BorderLabel = "braille-mode Line Chart"
lc0.Data = sinps
lc0.Width = 50
lc0.Height = 12
@@ -41,7 +41,7 @@ func main() {
lc0.LineColor = termui.ColorGreen | termui.AttrBold
lc1 := termui.NewLineChart()
lc1.Border.Label = "dot-mode Line Chart"
lc1.BorderLabel = "dot-mode Line Chart"
lc1.Mode = "dot"
lc1.Data = sinps
lc1.Width = 26
@@ -52,7 +52,7 @@ func main() {
lc1.LineColor = termui.ColorYellow | termui.AttrBold
lc2 := termui.NewLineChart()
lc2.Border.Label = "dot-mode Line Chart"
lc2.BorderLabel = "dot-mode Line Chart"
lc2.Mode = "dot"
lc2.Data = sinps[4:]
lc2.Width = 77
@@ -63,6 +63,9 @@ func main() {
lc2.LineColor = termui.ColorCyan | termui.AttrBold
termui.Render(lc0, lc1, lc2)
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
<-termui.EventCh()
}

View File

@@ -15,13 +15,13 @@ func main() {
}
defer termui.Close()
termui.UseTheme("helloworld")
//termui.UseTheme("helloworld")
strs := []string{
"[0] github.com/gizak/termui",
"[1] 你好,世界",
"[2] こんにちは世界",
"[3] keyboard.go",
"[1] [你好,世界](fg-blue)",
"[2] [こんにちは世界](fg-red)",
"[3] [color output](fg-white,bg-green)",
"[4] output.go",
"[5] random_out.go",
"[6] dashboard.go",
@@ -30,12 +30,15 @@ func main() {
ls := termui.NewList()
ls.Items = strs
ls.ItemFgColor = termui.ColorYellow
ls.Border.Label = "List"
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()
<-termui.EventCh()
}

View File

@@ -15,7 +15,7 @@ func main() {
}
defer termui.Close()
termui.UseTheme("helloworld")
//termui.UseTheme("helloworld")
bc := termui.NewMBarChart()
math := []int{90, 85, 90, 80}
@@ -27,10 +27,10 @@ func main() {
bc.Data[2] = science
bc.Data[3] = compsci
studentsName := []string{"Ken", "Rob", "Dennis", "Linus"}
bc.Border.Label = "Student's Marks X-Axis=Name Y-Axis=Marks[Math,English,Science,ComputerScience] in %"
bc.BorderLabel = "Student's Marks X-Axis=Name Y-Axis=Marks[Math,English,Science,ComputerScience] in %"
bc.Width = 100
bc.Height = 50
bc.Y = 10
bc.Height = 30
bc.Y = 0
bc.BarWidth = 10
bc.DataLabels = studentsName
bc.ShowScale = true //Show y_axis scale value (min and max)
@@ -46,5 +46,9 @@ func main() {
termui.Render(bc)
<-termui.EventCh()
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}

View File

@@ -15,35 +15,38 @@ func main() {
}
defer termui.Close()
termui.UseTheme("helloworld")
//termui.UseTheme("helloworld")
par0 := termui.NewPar("Borderless Text")
par0.Height = 1
par0.Width = 20
par0.Y = 1
par0.HasBorder = false
par0.Border = false
par1 := termui.NewPar("你好,世界。")
par1.Height = 3
par1.Width = 17
par1.X = 20
par1.Border.Label = "标签"
par1.BorderLabel = "标签"
par2 := termui.NewPar("Simple colored text\nwith label. It [can be](RED) multilined with \\n or [break automatically](GREEN, BOLD)")
par2.RendererFactory = termui.MarkdownTextRendererFactory{}
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.Border.Label = "Multiline"
par2.Border.FgColor = termui.ColorYellow
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.Border.Label = "Auto Trim"
par3.BorderLabel = "Auto Trim"
termui.Render(par0, par1, par2, par3)
<-termui.EventCh()
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}

View File

@@ -15,7 +15,7 @@ func main() {
}
defer termui.Close()
termui.UseTheme("helloworld")
//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()
@@ -27,7 +27,7 @@ func main() {
spls0 := termui.NewSparklines(spl0)
spls0.Height = 2
spls0.Width = 20
spls0.HasBorder = false
spls0.Border = false
spl1 := termui.NewSparkline()
spl1.Data = data
@@ -44,7 +44,7 @@ func main() {
spls1.Height = 8
spls1.Width = 20
spls1.Y = 3
spls1.Border.Label = "Group Sparklines"
spls1.BorderLabel = "Group Sparklines"
spl3 := termui.NewSparkline()
spl3.Data = data
@@ -55,11 +55,15 @@ func main() {
spls2 := termui.NewSparklines(spl3)
spls2.Height = 11
spls2.Width = 30
spls2.Border.FgColor = termui.ColorCyan
spls2.BorderFg = termui.ColorCyan
spls2.X = 21
spls2.Border.Label = "Tweeked Sparkline"
spls2.BorderLabel = "Tweeked Sparkline"
termui.Render(spls0, spls1, spls2)
<-termui.EventCh()
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}