termui/_example/tabs.go

82 lines
1.7 KiB
Go
Raw Normal View History

2015-06-16 15:16:37 -06:00
// +build ignore
2015-05-25 12:55:34 -06:00
package main
import (
2015-10-20 19:45:28 -06:00
"github.com/gizak/termui"
"github.com/gizak/termui/extra"
2015-05-25 12:55:34 -06:00
)
func main() {
2015-10-20 19:45:28 -06:00
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
2015-05-25 12:55:34 -06:00
termui.UseTheme("helloworld")
header := termui.NewPar("Press q to quit, Press j or k to switch tabs")
header.Height = 1
header.Width = 50
header.HasBorder = false
header.TextBgColor = termui.ColorBlue
2015-10-20 19:45:28 -06:00
tab1 := extra.NewTab("pierwszy")
2015-05-25 12:55:34 -06:00
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.Border.Label = "Keys"
par2.Border.FgColor = termui.ColorYellow
tab1.AddBlocks(par2)
2015-10-20 19:45:28 -06:00
tab2 := extra.NewTab("drugi")
2015-05-25 12:55:34 -06:00
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.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)
2015-10-20 19:45:28 -06:00
tab3 := extra.NewTab("trzeci")
tab4 := extra.NewTab("żółw")
tab5 := extra.NewTab("four")
tab6 := extra.NewTab("five")
2015-05-25 12:55:34 -06:00
2015-10-20 19:45:28 -06:00
tabpane := extra.NewTabpane()
2015-05-25 12:55:34 -06:00
tabpane.Y = 1
2015-10-20 19:45:28 -06:00
tabpane.Width = 30
tabpane.HasBorder = true
2015-05-25 12:55:34 -06:00
2015-10-20 19:45:28 -06:00
tabpane.SetTabs(*tab1, *tab2, *tab3, *tab4, *tab5, *tab6)
2015-05-25 12:55:34 -06:00
evt := termui.EventCh()
2015-10-20 19:45:28 -06:00
termui.Render(header, tabpane)
2015-05-25 12:55:34 -06:00
for {
select {
2015-10-20 19:45:28 -06:00
case e := <-evt:
2015-05-25 12:55:34 -06:00
if e.Type == termui.EventKey {
switch e.Ch {
case 'q':
return
case 'j':
tabpane.SetActiveLeft()
termui.Render(header, tabpane)
case 'k':
tabpane.SetActiveRight()
termui.Render(header, tabpane)
}
}
}
}
}