Fixed the behaviour of Table when the specified width exceeds column width #30

Merged
merged 1 commit into from Apr 13, 2015

7 participants

@bcandrea

This should fix issues/23.

@terabyte

I ran into this bug too. I'm going to open up a separate issue though because a much bigger problem is how you figure out how to wrap a column without knowing its length, there isn't really a way for the user to find out the evetual length to wrap things properly...

@bcandrea

If you don't care about the overall table width, having fields with unknown length should be already handled by the default behaviour of the Table object. On the other hand, if you still want the table to have a fixed width, I guess the only option is to either throw an Error or add a style modifier to truncate the contents artificially:

rows << ['Four', 'A' * 120]
table = Terminal::Table.new
table.headings = ['Word', 'Number']
table.rows = rows
table.style = {:width => 80, :truncate => true}

# > puts table
#
# +--------------------------------------+---------------------------------------+
# | Word                                 | Number                                |
# +--------------------------------------+---------------------------------------+
# | One                                  | 1                                     |
# | Two                                  | 2                                     |
# | Three                                | 3                                     |
# | Four                                 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
# +--------------------------------------+---------------------------------------+
@jonathanchrisp

Hey all, is this likely to be fixed soon?

@achanda

Can I help in merging this? We have a number of bugs depending on this.

@darrencauthon

I came across this same issue, started to write a PR but found this. Is this to be merged?

@hakunin

...year and a half later. whats the status on this?

@nateberkopec
Collaborator

Thanks!

@nateberkopec nateberkopec merged commit eb34698 into tj:master Apr 13, 2015
@darrencauthon

Thank you @nateberkopec ! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment