2017-01-14 06:07:43 +00:00
|
|
|
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
2016-01-27 01:45:18 +00:00
|
|
|
// Use of this source code is governed by a MIT license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
2015-06-16 21:16:37 +00:00
|
|
|
// +build ignore
|
|
|
|
|
2015-05-25 18:55:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-01-24 04:12:10 +00:00
|
|
|
"log"
|
|
|
|
|
2019-03-07 10:50:20 +00:00
|
|
|
ui "github.com/gizak/termui/v3"
|
|
|
|
"github.com/gizak/termui/v3/widgets"
|
2015-05-25 18:55:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2019-01-24 04:12:10 +00:00
|
|
|
if err := ui.Init(); err != nil {
|
|
|
|
log.Fatalf("failed to initialize termui: %v", err)
|
2018-09-07 01:22:04 +00:00
|
|
|
}
|
2018-09-06 21:48:09 +00:00
|
|
|
defer ui.Close()
|
2015-05-25 18:55:34 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
header := widgets.NewParagraph()
|
|
|
|
header.Text = "Press q to quit, Press h or l to switch tabs"
|
|
|
|
header.SetRect(0, 0, 50, 1)
|
2016-11-03 05:41:47 +00:00
|
|
|
header.Border = false
|
2019-01-24 04:12:10 +00:00
|
|
|
header.TextStyle.Bg = ui.ColorBlue
|
2015-05-25 18:55:34 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
p2 := widgets.NewParagraph()
|
|
|
|
p2.Text = "Press q to quit\nPress h or l to switch tabs\n"
|
|
|
|
p2.Title = "Keys"
|
|
|
|
p2.SetRect(5, 5, 40, 15)
|
|
|
|
p2.BorderStyle.Fg = ui.ColorYellow
|
2015-05-25 18:55:34 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
bc := widgets.NewBarChart()
|
|
|
|
bc.Title = "Bar Chart"
|
|
|
|
bc.Data = []float64{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}
|
|
|
|
bc.SetRect(5, 5, 35, 10)
|
|
|
|
bc.Labels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
|
2015-05-25 18:55:34 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
tabpane := widgets.NewTabPane("pierwszy", "drugi", "trzeci", "żółw", "four", "five")
|
|
|
|
tabpane.SetRect(0, 1, 50, 4)
|
2016-11-03 05:41:47 +00:00
|
|
|
tabpane.Border = true
|
2015-05-25 18:55:34 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
renderTab := func() {
|
|
|
|
switch tabpane.ActiveTabIndex {
|
|
|
|
case 0:
|
|
|
|
ui.Render(p2)
|
|
|
|
case 1:
|
|
|
|
ui.Render(bc)
|
|
|
|
}
|
|
|
|
}
|
2015-05-25 18:55:34 +00:00
|
|
|
|
2019-01-24 04:12:10 +00:00
|
|
|
ui.Render(header, tabpane, p2)
|
2015-10-21 01:45:28 +00:00
|
|
|
|
2018-11-29 23:32:42 +00:00
|
|
|
uiEvents := ui.PollEvents()
|
2019-01-24 04:12:10 +00:00
|
|
|
|
2018-11-29 02:19:34 +00:00
|
|
|
for {
|
2018-11-29 23:32:42 +00:00
|
|
|
e := <-uiEvents
|
2018-11-29 02:19:34 +00:00
|
|
|
switch e.ID {
|
|
|
|
case "q", "<C-c>":
|
|
|
|
return
|
|
|
|
case "h":
|
2019-01-24 04:12:10 +00:00
|
|
|
tabpane.FocusLeft()
|
2018-11-29 02:19:34 +00:00
|
|
|
ui.Clear()
|
|
|
|
ui.Render(header, tabpane)
|
2019-01-24 04:12:10 +00:00
|
|
|
renderTab()
|
2018-11-29 02:19:34 +00:00
|
|
|
case "l":
|
2019-01-24 04:12:10 +00:00
|
|
|
tabpane.FocusRight()
|
2018-11-29 02:19:34 +00:00
|
|
|
ui.Clear()
|
|
|
|
ui.Render(header, tabpane)
|
2019-01-24 04:12:10 +00:00
|
|
|
renderTab()
|
2018-11-29 02:19:34 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-25 18:55:34 +00:00
|
|
|
}
|