Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: set column max width (or automatically truncate input) #1

Open
ckoehler opened this issue Jun 3, 2010 · 7 comments
Open

Comments

@ckoehler
Copy link

ckoehler commented Jun 3, 2010

Hello,

I really appreciate what you did here! I was wondering if/when you are planning to add an optional max width for a column, with some kind of word wrap, or even just respecting newlines in a string and looking at the longest line only.

Thanks!

Christoph

@rrrene
Copy link
Contributor

rrrene commented Oct 17, 2011

This has been partially fixed here: #11

@dadooda
Copy link

dadooda commented Feb 21, 2012

@rrrene

Any plans/progress implementing the max column width, too?

Word wrapping might take substantial effort to implement, but there are applications which would accept broken layout for values which are too long, like this:

+-------+-----------------+
| Price | Name            |
+-------+-----------------+
|  5.95 | Green mug       |
|  9.95 | Red kettle      |
| 49.99 | Long long long long long long name which is actually invalid data |
+-------+-----------------+

It's "garbage in, garbage out", fair principle.

@rrrene
Copy link
Contributor

rrrene commented Feb 22, 2012

I thought about max_width, and unfortunately it seems like an overly complicated thing to do for little reward (imho).

One problem that sprung to mind was having multiple cells with colspans and one of the columns has a max_width...

So - no plans, sorry.

If you have values that should have a max_width just truncate or word-wrap the values in advance (that's one reason I implemented multi-line columns in the first place).

@dadooda
Copy link

dadooda commented Feb 22, 2012

One problem that sprung to mind was having multiple cells with
colspans and one of the columns has a max_width...
So - no plans, sorry.

No problem, just wanted to confirm.

Looks like using text tables for development reports (my case) and
drawing text tables in general differ more than it seems at first
glance.

E.g. I'm okay with no fancy decorative features like colspans and
styles, but the ability to limit the width is critical.

----- Original Message -----
From: René Föhring [email protected]
To: Alex Fortuna [email protected]
CC:
Time: Wed, 22 Feb 2012 01:37:04 -0800
Subject: [terminal-table] Feature: set column max width (#1)
Attachments:

I thought about max_width, and unfortunately it seems like an overly complicated thing to do for little reward (imho).

One problem that sprung to mind was having multiple cells with colspans and one of the columns has a max_width...

So - no plans, sorry.

If you have values that should have a max_width just truncate or word-wrap the values in advance (that's one reason I implemented multi-line columns in the first place).


Reply to this email directly or view it on GitHub:
#1 (comment)

@rrrene
Copy link
Contributor

rrrene commented Feb 22, 2012

You can (indirectly) set the max-width by controlling the input data. That is not as sweet as setting :max-width => 80 but you have other advantages like being transparent and in total control of the outputted data.

@glebm
Copy link

glebm commented Jul 14, 2014

I wrote the following code to wrap (break-word) a string in i18n-tasks:

def wrap_string(s, max)
  chars = []
  dist = 0
  s.chars.each do |c|
    chars << c
    dist += 1
    if c == "\n"
      dist = 0
    elsif dist == max
      dist = 0
      chars << "\n"
    end
  end
  chars = chars[0..-2] if chars.last == "\n"
  chars.join
end

@nateberkopec nateberkopec changed the title Feature: set column max width Feature: set column max width (or automatically truncate input) Apr 13, 2015
@fwolfst
Copy link

fwolfst commented Jan 28, 2016

In a similar vain, I would find it great if Terminal-Table had a :wrap option (maybe true|truncate|false) to break long rows into two rows. Too busy right now to implement or write a spec. Should I open another issue for that? Thanks.

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

No branches or pull requests

6 participants