djm / table_rex

An Elixir app which generates text-based tables for display

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ANSI colors in the data

apognu opened this issue · comments

Hi,

I generate tables with colors already included in the strings that form the rows. I do this because some of my column have a "state" meaning, and some cells will be red and other green. Here's what my rows could look like:

rows = [
  [ "First", IO.ANSI.format([:red, "Hello"]), "Last" ],
  ...
]

When I render the table, the spacings are all mangled, as if the length could not be computed properly. The columns containing colored cells are wider than they should be.

Am I missing something or is colored text in cells not supported yet?

Hi @apognu.

TableRex does support color, but not if you add it yourself first as the ANSI formatting will mess with the string length calculations.

For a full guide see the README. In particular the "Set color for the column, header, and cell" section.

I saw this after I submitted PR #26. @apognu was hoping to do exactly what I was. Hopefully we can get this into master.