eldargab / easy-table

Nice text table for Node.js
314 stars 31 forks source link

Support colorizing? #8

Closed kenperkins closed 9 years ago

kenperkins commented 9 years ago

Have you considered any approaches to allow color for the table? either the column headers, footers, or cell values?

I tried a limited test, and it seemed to impact the row length using the colors packges for field values, so I figured I'd ask before doing any more research.

eldargab commented 9 years ago

Right now the only reasonable way to do this is something like

// Coloring too big numbers in red
function markTooBigs (val, width) {
    if (width == null) return Table.string(val)
    return val > 100
        ? '\033[31m' + String(val) + '\033[39m'
        : Table.string(val)
}
...
t.cell('foo', 300, markTooBigs)

Probably I'll rewrite this some day...

cheahkhing commented 9 years ago

+1 on this. maybe we could utilize colors / chalk to colors the headers, it would be nice to do that. thanks.

eldargab commented 9 years ago

As of 1.0 colors are supported

WasabiFan commented 9 years ago

Is there a way to intercept the drawing for a whole row so that I can colorize the background? If I pass colorized strings into the cell call, it only colorizes the text, and not the empty space for the whole row.

Past that, is there a way to add sub-headings for sections of the table?

eldargab commented 9 years ago

No, there is no such options