Skip to content

chulinx/gottable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gottable

Golang Terminal Table

Easy terminal table for golang

How to use

package main

import (
	"github.com/chulinx/gottable"
	"github.com/gookit/color"
)

var (
	data = [][]string{
	{"name","source","sex","age"},
	{"Meter","80","man",""},
	{"Peter","92","man","21"},
	{"xiMing","86","woman","18"},
   }
	
)

func main(){
    tableParams := gottable.TableParams{Position: gottable.PositionLeft}
    table := gottable.New(data,tableParams)
    table.Render()
// out
/* 
go run main.go
+---------+---------+--------+------+
|name     |source   |sex     |age   |
+---------+---------+--------+------+
|Meter    |80       |man     |      |
+---------+---------+--------+------+
|Peter    |92       |man     |21    |
+---------+---------+--------+------+
|xiMing   |86       |woman   |18    |
+---------+---------+--------+------+
*/
    tableParams = gottable.TableParams{Position: gottable.PositionRight}
    table = gottable.New(data,tableParams)
    table.Render()
// out 
/*
+---------+---------+--------+------+
|     name|   source|     sex|   age|
+---------+---------+--------+------+
|    Meter|       80|     man|      |
+---------+---------+--------+------+
|    Peter|       92|     man|    21|
+---------+---------+--------+------+
|   xiMing|       86|   woman|    18|
+---------+---------+--------+------+
*/
    tableParams = gottable.TableParams{Position: gottable.PositionCenter}
    table = gottable.New(data,tableParams)
    table.Render()
// out
/*
+----------+----------+--------+------+
|   name   |  source  |  sex   | age  |
+----------+----------+--------+------+
|  Meter   |    80    |  man   |      |
+----------+----------+--------+------+
|  Peter   |    92    |  man   |  21  |
+----------+----------+--------+------+
|  xiMing  |    86    | woman  |  18  |
+----------+----------+--------+------+
*/  
    tableParams = gottable.TableParams{Position: gottable.PositionCenter,Style: gottable.StyleSimple}
    table = gottable.New(data,tableParams)
    table.Render()
// out
/*
+----------+----------+--------+------+
|   name   |  source  |  sex   | age  |
+----------+----------+--------+------+
|  Meter   |    80    |  man   |      |
|  Peter   |    92    |  man   |  21  |
|  xiMing  |    86    | woman  |  18  |
+----------+----------+--------+------+
*/

    tableParams = gottable.TableParams{HeadStyle:gottable.HeadStyle{IsBorder: true,TextColor:color.Red }}
    table = gottable.New(data,tableParams)
    table.Print()
}

About

Golang Terminal Table

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages