tabs.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
  2. // Use of this source code is governed by a MIT license that can
  3. // be found in the LICENSE file.
  4. // +build ignore
  5. package main
  6. import (
  7. "notabug.org/themusicgod1/termui"
  8. "notabug.org/themusicgod1/termui/extra"
  9. )
  10. func main() {
  11. err := termui.Init()
  12. if err != nil {
  13. panic(err)
  14. }
  15. defer termui.Close()
  16. //termui.UseTheme("helloworld")
  17. header := termui.NewPar("Press q to quit, Press j or k to switch tabs")
  18. header.Height = 1
  19. header.Width = 50
  20. header.Border = false
  21. header.TextBgColor = termui.ColorBlue
  22. tab1 := extra.NewTab("pierwszy")
  23. par2 := termui.NewPar("Press q to quit\nPress j or k to switch tabs\n")
  24. par2.Height = 5
  25. par2.Width = 37
  26. par2.Y = 0
  27. par2.BorderLabel = "Keys"
  28. par2.BorderFg = termui.ColorYellow
  29. tab1.AddBlocks(par2)
  30. tab2 := extra.NewTab("drugi")
  31. bc := termui.NewBarChart()
  32. 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}
  33. bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
  34. bc.BorderLabel = "Bar Chart"
  35. bc.Data = data
  36. bc.Width = 26
  37. bc.Height = 10
  38. bc.DataLabels = bclabels
  39. bc.TextColor = termui.ColorGreen
  40. bc.BarColor = termui.ColorRed
  41. bc.NumColor = termui.ColorYellow
  42. tab2.AddBlocks(bc)
  43. tab3 := extra.NewTab("trzeci")
  44. tab4 := extra.NewTab("żółw")
  45. tab5 := extra.NewTab("four")
  46. tab6 := extra.NewTab("five")
  47. tabpane := extra.NewTabpane()
  48. tabpane.Y = 1
  49. tabpane.Width = 30
  50. tabpane.Border = true
  51. tabpane.SetTabs(*tab1, *tab2, *tab3, *tab4, *tab5, *tab6)
  52. termui.Render(header, tabpane)
  53. termui.Handle("/sys/kbd/q", func(termui.Event) {
  54. termui.StopLoop()
  55. })
  56. termui.Handle("/sys/kbd/j", func(termui.Event) {
  57. tabpane.SetActiveLeft()
  58. termui.Clear()
  59. termui.Render(header, tabpane)
  60. })
  61. termui.Handle("/sys/kbd/k", func(termui.Event) {
  62. tabpane.SetActiveRight()
  63. termui.Clear()
  64. termui.Render(header, tabpane)
  65. })
  66. termui.Loop()
  67. }