alexeyco / simpletable Goto Github PK
View Code? Open in Web Editor NEWSimple tables in terminal with Go
License: MIT License
Simple tables in terminal with Go
License: MIT License
Does this support cell coloring? foreground? background? full or partial?
hi. im wondering how to add color to your tables style
Thanks for the package!
Might be nice to strip ansi escape sequences with something like this hack, so that the cells are still calculated properly allowing colors etc.
This may already be possible and I have tried several different iterations to try and make it work but I am trying to have a header with the table name that spans the whole width and then under that the normal header with the column names.
+------------------------------------------------------------------+
| HEADER |
+---+-----------+-------------------------------+-------+----------+
| # | FIELD | FIELD | FIELD | FIELD |
+---+-----------+-------------------------------+-------+----------+
table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Span: 5, Text: "HEADER"},
{Align: simpletable.AlignCenter, Text: "#"},
{Align: simpletable.AlignCenter, Text: "FIELD"},
{Align: simpletable.AlignCenter, Text: "FIELD"},
{Align: simpletable.AlignCenter, Text: "FIELD"},
{Align: simpletable.AlignCenter, Text: "FIELD"},
},
}
Maybe something like this.
append(table.Header, Cells:[]*simpletable.Cell{
Align: simpletable.AlignCenter,
Span: 5,
Text: "HEADER"
})
This code is obviously not going to work but I have been unable to figure out a way to do this. Is this possible? Or do you have any suggestions and finally I am sorry to bother you with this your time is greatly appreciated I hate submitting issues for things like this but I have been unable to locate any information on forums about this.
Thank you,
Jason C.
Hello, I found this a very useful tool, but can you support Chinese, because if the table content is Chinese and the table cannot be aligned, I try to modify the realLength function in content.go and change utf8.RuneCountInString to len, but it no effect
Hey Alex,
Thanks for this great library.
I am having an issue adding Span to the header. Any idea what I am doing wrong? I posted the error and code below.
Regards,
Maruf
Error:
/usr/local/Cellar/go/1.15.5/libexec/bin/go build -o /private/var/folders/wh/fnt_yh0n5mxfmttpjts9l9jc0000gp/T/___go_build_main_go__2_ /Users/m0a00v4/go/src/github.com/simpletable/_example/05-colorize/main.go #gosetup
/private/var/folders/wh/fnt_yh0n5mxfmttpjts9l9jc0000gp/T/___go_build_main_go__2_
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x10d2ca9]
goroutine 1 [running]:
github.com/alexeyco/simpletable.(*Table).prepareColumns(0xc0000de000)
/Users/m0a00v4/go/src/github.com/alexeyco/simpletable/table.go:257 +0xb69
github.com/alexeyco/simpletable.(*Table).String(0xc0000de000, 0xc000092b60, 0xc0000ac040)
/Users/m0a00v4/go/src/github.com/alexeyco/simpletable/table.go:34 +0xdc
github.com/alexeyco/simpletable.(*Table).Println(0xc0000de000)
/Users/m0a00v4/go/src/github.com/alexeyco/simpletable/table.go:65 +0x2f
main.main()
/Users/m0a00v4/go/src/github.com/simpletable/_example/05-colorize/main.go:47 +0x97f
Process finished with exit code 2
Code:
func main() {
table := simpletable.New()
table.Header = &simpletable.Header{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Text: "FOO"},
{Align: simpletable.AlignCenter, Text: "BAZ"},
{Align: simpletable.AlignRight, Span: 2, Text: "BAR"},
},
}
table.Body = &simpletable.Body{
Cells: [][]*simpletable.Cell{
{
&simpletable.Cell{Text: red("I am red")},
&simpletable.Cell{Text: green("I am green")},
&simpletable.Cell{Text: blue("I am blue")},
&simpletable.Cell{Text: blue("I am blue 2")},
},
},
}
table.Footer = &simpletable.Footer{
Cells: []*simpletable.Cell{
{Align: simpletable.AlignCenter, Span: 4, Text: gray("And all columns is well sized")},
},
}
table.Println()
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.