-
Notifications
You must be signed in to change notification settings - Fork 2
Description
The documentation
formatter: a Proc to format the cells, while conserving the inferred alignment from the body contents. Default to "->(n : CellType) { n.to_s }"
suggests that the value from the fomatter does not influence the calculation / alignment of the cell.
When using a formatter to output the value with a color (using Crystal's Colorize) the cell width is not calculated based on the data value, but based on the value provided by the formatter.
Tablo::Table.new(table_data, connectors: Tablo::CONNECTORS_SINGLE_ROUNDED) do |t|
t.add_column("Diff", width: COLUMN_WIDTH, formatter: ->(n : Tablo::CellType) { n.colorize(:red).to_s }) { |n| n[1] }
endTabulo also mentions this:
In most terminals, if you want to print text that is coloured, or has certain other styles such as underlining, you need to use ANSI escape sequences, either directly, or by means of a library such as Rainbow that uses them internally. Tabulo needs to properly account for escape sequences when performing the width calculations required to render tables. The styler option on the add_column method is intended to facilitate this.
Is this the intended behaviour for tablo as well? If so the width calculation should be based on the data value instead of the formatted value.