- Notifications
You must be signed in to change notification settings - Fork26
Produces a string that represents slice data in a text table, inspired by gajus/table.
License
modood/table
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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)
$ go get github.com/modood/table
package mainimport ("github.com/modood/table")typeHousestruct {Namestring`table:"Name"`SigilstringMottostring}funcmain() {hs:= []House{{"Stark","direwolf","Winter is coming"},{"Targaryen","dragon","Fire and Blood"},{"Lannister","lion","Hear Me Roar"},}// Output to stdouttable.Output(hs)// Or just return table string and then do somethings:=table.Table(hs)_=s}
output:
┌───────────┬──────────┬──────────────────┐│ Name │ Sigil │ Motto │├───────────┼──────────┼──────────────────┤│ Stark │ direwolf │ Winter is coming ││ Targaryen │ dragon │ Fire and Blood ││ Lannister │ lion │ Hear Me Roar │└───────────┴──────────┴──────────────────┘
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)
comparebox drawing characters withstandard 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 |+-----------+----------+------------------+
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
this repo is released under theMIT License.
About
Produces a string that represents slice data in a text table, inspired by gajus/table.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.