termui/_examples/table.go

55 lines
1.2 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.
2018-08-16 21:05:56 -06:00
// +build ignore
2016-11-10 03:46:23 -07:00
package main
2019-01-23 21:12:10 -07:00
import (
"log"
ui "github.com/gizak/termui"
"github.com/gizak/termui/widgets"
)
2016-11-10 03:46:23 -07:00
func main() {
2019-01-23 21:12:10 -07:00
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
2018-09-06 15:48:09 -06:00
defer ui.Close()
2019-01-23 21:12:10 -07:00
table1 := widgets.NewTable()
table1.Rows = [][]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"},
}
2019-01-23 21:12:10 -07:00
table1.TextStyle = ui.NewStyle(ui.ColorWhite)
table1.SetRect(0, 0, 60, 10)
2018-09-06 15:48:09 -06:00
ui.Render(table1)
2016-11-10 03:46:23 -07:00
2019-01-23 21:12:10 -07:00
table2 := widgets.NewTable()
table2.Rows = [][]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"},
}
2019-01-23 21:12:10 -07:00
table2.TextStyle = ui.NewStyle(ui.ColorWhite)
2018-09-06 15:48:09 -06:00
table2.TextAlign = ui.AlignCenter
2019-01-23 21:12:10 -07:00
table2.RowSeparator = false
table2.SetRect(0, 10, 20, 20)
2017-01-15 21:17:50 -07:00
2018-09-06 15:48:09 -06:00
ui.Render(table2)
uiEvents := ui.PollEvents()
2018-11-28 19:19:34 -07:00
for {
e := <-uiEvents
2018-11-28 19:19:34 -07:00
switch e.ID {
case "q", "<C-c>":
return
}
}
2016-11-10 03:46:23 -07:00
}