text-table icon indicating copy to clipboard operation
text-table copied to clipboard

support for ansi escapes in text

Open mikecarlton-illumio opened this issue 10 years ago • 2 comments

This PR adds support for ansi escapes, allowing you to have colorized text in tables.

mikecarlton-illumio avatar Oct 22 '15 20:10 mikecarlton-illumio

Thanks for the PR @mikecarlton-illumio. The request to be able to colorize the cell contents has come up before. I've been wanting to add this feature and I've been thinking of doing so through a formatter block. Something like:

table.formatter = ->(cell) {
  colorize(cell.value)
}

This way, width computation is done before formatting (colorizing) the cell value.

aptinio avatar Nov 02 '15 01:11 aptinio

That's interesting, but if I understand your comment correctly, I would define a function to apply color to a cell as a whole?

I think our use case is slightly different -- I'm including status info by coloring the text (green or red). Thus the color isn't a function of the cell or of the value itself, but is only known when the text is added to the cell. Here's a sample: image

mikecarlton-illumio avatar Nov 04 '15 17:11 mikecarlton-illumio