• Stars
    star
    138
  • Rank 263,543 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Produces a string that represents slice data in a text table, inspired by gajus/table.

table

Build Status Coverage Status GoDoc

Produces a string that represents slice of structs data in a text table, inspired by gajus/table.

Features:

  • No dependency.
  • Cell content aligned.
  • Column width self-adaptation
  • Support type of struct field: int, float, string, bool, slice, struct, map, time.Time and everything.
  • Support custom table header by declaring optional tag: table.(Thanks @skyfireitdiy)

Installation

$ go get github.com/modood/table

Quick start

package main

import (
	"github.com/modood/table"
)

type House struct {
	Name  string `table:"Name"`
	Sigil string
	Motto string
}

func main() {
	hs := []House{
		{"Stark", "direwolf", "Winter is coming"},
		{"Targaryen", "dragon", "Fire and Blood"},
		{"Lannister", "lion", "Hear Me Roar"},
	}

	// Output to stdout
	table.Output(hs)

	// Or just return table string and then do something
	s := table.Table(hs)
	_ = s
}

output:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Name      โ”‚ Sigil    โ”‚ Motto            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Stark     โ”‚ direwolf โ”‚ Winter is coming โ”‚
โ”‚ Targaryen โ”‚ dragon   โ”‚ Fire and Blood   โ”‚
โ”‚ Lannister โ”‚ lion     โ”‚ Hear Me Roar     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Document

  • func Output(slice interface{})

    formats slice of structs data and writes to standard output.(Using box drawing characters)

  • func OutputA(slice interface{})

    formats slice of structs data and writes to standard output.(Using standard ascii characters)

  • func Table(slice interface{}) string

    formats slice of structs data and returns the resulting string.(Using box drawing characters)

  • func AsciiTable(slice interface{}) string

    formats slice of structs data and returns the resulting string.(Using standard ascii characters)

  • compare box drawing characters with standard ascii characters

    box drawing:

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ Name      โ”‚ Sigil    โ”‚ Motto            โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚ Stark     โ”‚ direwolf โ”‚ Winter is coming โ”‚
    โ”‚ Targaryen โ”‚ dragon   โ”‚ Fire and Blood   โ”‚
    โ”‚ Lannister โ”‚ lion     โ”‚ Hear Me Roar     โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    

    standard ascii:

    +-----------+----------+------------------+
    | Name      | Sigil    | Motto            |
    +-----------+----------+------------------+
    | Stark     | direwolf | Winter is coming |
    | Targaryen | dragon   | Fire and Blood   |
    | Lannister | lion     | Hear Me Roar     |
    +-----------+----------+------------------+
    

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

this repo is released under the MIT License.

More Repositories

1

Administrative-divisions-of-China

ไธญๅŽไบบๆฐ‘ๅ…ฑๅ’Œๅ›ฝ่กŒๆ”ฟๅŒบๅˆ’๏ผš็œ็บง๏ผˆ็œไปฝ๏ผ‰ใ€ ๅœฐ็บง๏ผˆๅŸŽๅธ‚๏ผ‰ใ€ ๅŽฟ็บง๏ผˆๅŒบๅŽฟ๏ผ‰ใ€ ไนก็บง๏ผˆไนก้•‡่ก—้“๏ผ‰ใ€ ๆ‘็บง๏ผˆๆ‘ๅง”ไผšๅฑ…ๅง”ไผš๏ผ‰ ๏ผŒไธญๅ›ฝ็œๅธ‚ๅŒบ้•‡ๆ‘ไบŒ็บงไธ‰็บงๅ››็บงไบ”็บง่”ๅŠจๅœฐๅ€ๆ•ฐๆฎใ€‚
JavaScript
15,566
star
2

btckeygen

A very simple and easy to use bitcoin(btc) key/wallet generator. A Golang implementation of the BIP32/BIP39/BIP43/BIP44/SLIP44/BIP49/BIP84/BIP173 for creating keys, mnemonic seeds and Hierarchical Deterministic (HD) addresses.
Go
94
star
3

vimrc

A shell script to deploy my vim configuration
Vim Script
19
star
4

xmrkeygen

A very simple and easy to use monero(xmr) key/wallet generator.
Go
17
star
5

pushapi

ๅฎ‰ๅ“ๆ‰‹ๆœบๆŽจ้€ api ๆŽฅๅ…ฅ๏ผˆvivo oppo ๅฐ็ฑณ ๅŽไธบ๏ผ‰
Go
10
star
6

gulp-markdown-github-style

Markdown to HTML with github style, inspired by gulp-markdown.
HTML
10
star
7

modood.github.io

Blogs are here to stay.
HTML
10
star
8

genesis

shell scripts to setup my ubuntu development environment
Shell
1
star
9

tmux-gateio-ticker

Display prices of coins from gate.io in tmux status bar
Shell
1
star