cleo icon indicating copy to clipboard operation
cleo copied to clipboard

Table rendering throws ValueError (invalid width) for tables wider than screen

Open vduseev opened this issue 5 years ago • 0 comments

Summary

When we try to render a table that does not fit into a screen width (terminal width) a ValueError is thrown.

What happens

In the example below I have a table with 42 columns which is approximately 4x times wider than terminal's screen allows.

self.render_table(headers, rows)

ValueError

  invalid width -9 (must be > 0)

  at /usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/textwrap.py:248 in _wrap_chunks
      244│         lines, but apart from that whitespace is preserved.
      245│         """
      246│         lines = []
      247│         if self.width <= 0:
    → 248│             raise ValueError("invalid width %r (must be > 0)" % self.width)
      249│         if self.max_lines is not None:
      250│             if self.max_lines > 1:
      251│                 indent = self.subsequent_indent
      252│             else:

What's expected

Either table is shrinked into given width or is rendered despite not fitting into the screen. Both options look ugly as hell though. More options are below

Fix suggestions

A. Fit table into terminal despite ugly outcome B. Draw table wider than terminal despite ugly outcome C. Somehow smartly draw the table in such a way that too long content becomes multi-line (already implemented somewhat). Also issue #47 talks about that option. D. Add option to transpose table when redered (like \x flag does in PostgreSQL's psql command line tool) E. Add option to break table into multiple pages where each page fits into screen

vduseev avatar Sep 25 '20 10:09 vduseev