Skip to content

Commit

Permalink
Widgets API adaption
Browse files Browse the repository at this point in the history
  • Loading branch information
gizak committed Oct 9, 2015
1 parent e0dec9d commit ca69e25
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 268 deletions.
10 changes: 7 additions & 3 deletions _example/barchart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,5 +31,9 @@ func main() {

termui.Render(bc)

<-termui.EventCh()
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()

}
90 changes: 0 additions & 90 deletions _example/coloredList.go

This file was deleted.

13 changes: 8 additions & 5 deletions _example/linechart.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
}
defer termui.Close()

termui.UseTheme("helloworld")
//termui.UseTheme("helloworld")

sinps := (func() []float64 {
n := 220
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
}
15 changes: 9 additions & 6 deletions _example/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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()
}
14 changes: 9 additions & 5 deletions _example/mbarchart.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
}
defer termui.Close()

termui.UseTheme("helloworld")
//termui.UseTheme("helloworld")

bc := termui.NewMBarChart()
math := []int{90, 85, 90, 80}
Expand All @@ -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)
Expand All @@ -46,5 +46,9 @@ func main() {

termui.Render(bc)

<-termui.EventCh()
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()

}
21 changes: 12 additions & 9 deletions _example/par.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

}
16 changes: 10 additions & 6 deletions _example/sparklines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()

}
19 changes: 9 additions & 10 deletions barchart.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build ignore

// Copyright 2015 Zack Guo <gizak@icloud.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
Expand Down Expand Up @@ -107,13 +105,14 @@ func (bc *BarChart) Buffer() Buffer {
// plot text
for j, k := 0, 0; j < len(bc.labels[i]); j++ {
w := charWidth(bc.labels[i][j])
c := Cell{}
p.Ch = bc.labels[i][j]
p.Bg = bc.BgColor
p.Fg = bc.TextColor
p.Y = bc.innerArea.Min.Y + bc.innerArea.Dy() - 1
p.X = bc.innerArea.Min.X + oftX + k
ps = append(ps, p)
c := Cell{
Ch: bc.labels[i][j],
Bg: bc.Bg,
Fg: bc.TextColor,
}
y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 1
x := bc.innerArea.Min.X + oftX + k
buf.Set(x, y, c)
k += w
}
// plot num
Expand All @@ -127,7 +126,7 @@ func (bc *BarChart) Buffer() Buffer {
c.Bg |= AttrReverse
}
if h == 0 {
c.Bg = bc.BgColor
c.Bg = bc.Bg
}
x := bc.innerArea.Min.X + oftX + (bc.BarWidth-len(bc.dataNum[i]))/2 + j
y := bc.innerArea.Min.Y + bc.innerArea.Dy() - 2
Expand Down
12 changes: 4 additions & 8 deletions canvas.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build ignore

// Copyright 2015 Zack Guo <gizak@icloud.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
Expand Down Expand Up @@ -65,12 +63,10 @@ func (c Canvas) Unset(x, y int) {
}

// Buffer returns un-styled points
func (c Canvas) Buffer() []Point {
ps := make([]Point, len(c))
i := 0
func (c Canvas) Buffer() Buffer {
buf := NewBuffer()
for k, v := range c {
ps[i] = newPoint(v+brailleBase, k[0], k[1])
i++
buf.Set(k[0], k[1], Cell{Ch: v + brailleBase})
}
return ps
return buf
}
Loading

0 comments on commit ca69e25

Please sign in to comment.