termui/_examples/tabs.go

79 lines
1.7 KiB
Go
Raw Normal View History

2017-01-13 23:07:43 -07:00
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2016-01-26 18:45:18 -07:00
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
2015-06-16 15:16:37 -06:00
// +build ignore
2015-05-25 12:55:34 -06:00
package main
import (
2018-09-06 15:48:09 -06:00
ui "github.com/gizak/termui"
2015-05-25 12:55:34 -06:00
)
func main() {
err := ui.Init()
if err != nil {
panic(err)
}
2018-09-06 15:48:09 -06:00
defer ui.Close()
2015-05-25 12:55:34 -06:00
2018-11-28 19:24:38 -07:00
header := ui.NewParagraph("Press q to quit, Press h or l to switch tabs")
2015-05-25 12:55:34 -06:00
header.Height = 1
header.Width = 50
2016-11-02 23:41:47 -06:00
header.Border = false
2018-09-06 15:48:09 -06:00
header.TextBgColor = ui.ColorBlue
2015-05-25 12:55:34 -06:00
tab1 := ui.NewTab("pierwszy")
2018-11-28 19:24:38 -07:00
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)
2015-05-25 12:55:34 -06:00
tab2 := ui.NewTab("drugi")
2018-09-06 15:48:09 -06:00
bc := ui.NewBarChart()
2015-05-25 12:55:34 -06:00
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"}
2016-10-14 05:48:50 -06:00
bc.BorderLabel = "Bar Chart"
2015-05-25 12:55:34 -06:00
bc.Data = data
bc.Width = 26
bc.Height = 10
bc.DataLabels = bclabels
2018-09-06 15:48:09 -06:00
bc.TextColor = ui.ColorGreen
bc.BarColor = ui.ColorRed
bc.NumColor = ui.ColorYellow
2015-05-25 12:55:34 -06:00
tab2.AddBlocks(bc)
tab3 := ui.NewTab("trzeci")
tab4 := ui.NewTab("żółw")
tab5 := ui.NewTab("four")
tab6 := ui.NewTab("five")
2015-05-25 12:55:34 -06:00
tabpane := ui.NewTabPane()
2015-05-25 12:55:34 -06:00
tabpane.Y = 1
2015-10-20 19:45:28 -06:00
tabpane.Width = 30
2016-11-02 23:41:47 -06:00
tabpane.Border = 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
2018-09-06 15:48:09 -06:00
ui.Render(header, tabpane)
2015-10-20 19:45:28 -06:00
2018-11-28 19:19:34 -07:00
for {
e := <-ui.PollEvent()
switch e.ID {
case "q", "<C-c>":
return
case "h":
tabpane.SetActiveLeft()
ui.Clear()
ui.Render(header, tabpane)
case "l":
tabpane.SetActiveRight()
ui.Clear()
ui.Render(header, tabpane)
}
}
2015-05-25 12:55:34 -06:00
}