termui/_example/table.go

57 lines
1.3 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.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
2016-11-10 03:46:23 -07:00
package main
import "github.com/gizak/termui"
2016-11-10 03:46:23 -07:00
func main() {
err := termui.Init()
if err != nil {
panic(err)
}
defer termui.Close()
2017-01-15 21:17:50 -07:00
rows1 := [][]string{
[]string{"header1", "header2", "header3"},
2017-01-15 21:17:50 -07:00
[]string{"你好吗", "Go-lang is so cool", "Im working on Ruby"},
2016-11-25 01:35:00 -07:00
[]string{"2016", "10", "11"},
}
2017-01-15 21:17:50 -07:00
table1 := termui.NewTable()
table1.Rows = rows1
table1.FgColor = termui.ColorWhite
table1.BgColor = termui.ColorDefault
table1.Y = 0
table1.X = 0
table1.Width = 62
table1.Height = 7
2017-01-15 21:17:50 -07:00
termui.Render(table1)
2016-11-10 03:46:23 -07:00
2017-01-15 21:17:50 -07:00
rows2 := [][]string{
2016-11-10 03:46:23 -07:00
[]string{"header1", "header2", "header3"},
2016-11-25 01:35:00 -07:00
[]string{"Foundations", "Go-lang is so cool", "Im working on Ruby"},
2016-11-10 03:46:23 -07:00
[]string{"2016", "11", "11"},
}
2017-01-15 21:17:50 -07:00
table2 := termui.NewTable()
table2.Rows = rows2
table2.FgColor = termui.ColorWhite
table2.BgColor = termui.ColorDefault
table2.TextAlign = termui.AlignCenter
table2.Separator = false
table2.Analysis()
table2.SetSize()
table2.BgColors[2] = termui.ColorRed
table2.Y = 10
table2.X = 0
table2.Border = true
termui.Render(table2)
2016-11-10 03:46:23 -07:00
termui.Handle("/sys/kbd/q", func(termui.Event) {
termui.StopLoop()
})
termui.Loop()
}