arches / table_print

The best data slicer! Watch a 3 minute screencast at http://tableprintgem.com
MIT License
903 stars 43 forks source link

Colors truncate column width #69

Open mikkergimenez opened 9 years ago

mikkergimenez commented 9 years ago

It seems whenever I use colors, it truncates the column width and causes weird readability issues:

For the following example I used: https://github.com/janlelis/paint

Example:

AAAAAAA                     | BBBBBBBBBBBB          | CCCCCC                 | DDDDDD                         | EEEEEEE        | FFFFFFFF
----------------------------|-----------------------|-----------------------|--------------------------------|----------------|---------------
aaaaaaaa_aaaaaaa_aaaaaaaaaa | b/b                   | c/c                   | d/d                            | eeee  | ffff
aaaaa_aaaaaaa-aaaaaaaaaa-aa | b                     | c                     | ddd                            | eeee | ffff

As you (might) be able to see, column e and f resized to four characters, they were the ones that I colorized.

When I try to colorize C and D, it gets even weirder, removing some columns and inserting special characters.

I assume it has something to do with the way table_print encodes the special table characters, but not sure.

arches commented 9 years ago

colors are tricky =\ The problem is, we need to do two things: count the string length, and truncate long strings. The string length calculator is naively counting nonprinting characters, and the truncation naively cuts off any nonprinting characters after the truncation point.

Honestly it's going to be a while before I would get to this, but if you want to poke around here's where to start:

truncation - https://github.com/arches/table_print/blob/master/lib/table_print/formatter.rb#L33-L40 width detection - https://github.com/arches/table_print/blob/master/lib/table_print/column.rb#L36-L48

You'll note in the width detection there's a multibyte approach and a naive approach - multibyte counting is much slower so it's off by default.

pablofullana commented 7 years ago

👍

k-ta-yamada commented 6 years ago

👍 #70