table.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. package main
  5. import "notabug.org/themusicgod1/termui"
  6. func main() {
  7. err := termui.Init()
  8. if err != nil {
  9. panic(err)
  10. }
  11. defer termui.Close()
  12. rows1 := [][]string{
  13. []string{"header1", "header2", "header3"},
  14. []string{"你好吗", "Go-lang is so cool", "Im working on Ruby"},
  15. []string{"2016", "10", "11"},
  16. }
  17. table1 := termui.NewTable()
  18. table1.Rows = rows1
  19. table1.FgColor = termui.ColorWhite
  20. table1.BgColor = termui.ColorDefault
  21. table1.Y = 0
  22. table1.X = 0
  23. table1.Width = 62
  24. table1.Height = 7
  25. termui.Render(table1)
  26. rows2 := [][]string{
  27. []string{"header1", "header2", "header3"},
  28. []string{"Foundations", "Go-lang is so cool", "Im working on Ruby"},
  29. []string{"2016", "11", "11"},
  30. }
  31. table2 := termui.NewTable()
  32. table2.Rows = rows2
  33. table2.FgColor = termui.ColorWhite
  34. table2.BgColor = termui.ColorDefault
  35. table2.TextAlign = termui.AlignCenter
  36. table2.Separator = false
  37. table2.Analysis()
  38. table2.SetSize()
  39. table2.BgColors[2] = termui.ColorRed
  40. table2.Y = 10
  41. table2.X = 0
  42. table2.Border = true
  43. termui.Render(table2)
  44. termui.Handle("/sys/kbd/q", func(termui.Event) {
  45. termui.StopLoop()
  46. })
  47. termui.Loop()
  48. }