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

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

Comments

Projects
None yet
6 participants

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

Contributor

rrrene commented Oct 17, 2011

This has been partially fixed here: visionmedia#11

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.

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 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 reply@reply.github.com
To: Alex Fortuna alex.r@askit.org
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:
visionmedia#1 (comment)

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 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 changed the title from Feature: set column max width to Feature: set column max width (or automatically truncate input) Apr 13, 2015

lacostej referenced this issue in fastlane-old/fastlane_core Oct 30, 2015

Closed

PrintTable: recurse over hashes #38

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