cl-ansi-term icon indicating copy to clipboard operation
cl-ansi-term copied to clipboard

Table function should calculate width for every column before outputting it to the screen [DONE]

Open svetlyak40wt opened this issue 5 years ago • 5 comments

Here is example where table is broken:

POFTHEDAY> (term:table '(("name" "age" "email")
                         ("me" 7 "some@blah")
                         ("me" 7 "[email protected]")))
+---------+---------+---------+
|name     |age      |email    |
+---------+---------+---------+
|me       |7        |some@blah|
+---------+---------+---------+
|me       |7        |[email protected]|
+---------+---------+---------+

svetlyak40wt avatar Jun 01 '20 09:06 svetlyak40wt

thanks for the tests and reports. To make it fit now we have to expand all columns width:

(term:table '(("name" "age" "email")
                         ("me" 7 "some@blah")
                         ("me" 7 "[email protected]"))
                         :column-width 30)

+-----------------------------+-----------------------------+-----------------------------+
|name                         |age                          |email                        |
+-----------------------------+-----------------------------+-----------------------------+
|me                           |7                            |some@blah                    |
+-----------------------------+-----------------------------+-----------------------------+
|me                           |7                            |[email protected]  |
+-----------------------------+-----------------------------+-----------------------------+

I'll want to evaluate if https://github.com/telephil/cl-ascii-table/ is overall better at printing tables…

vindarel avatar Jun 01 '20 10:06 vindarel

I got this fixed:

;; A long cell is truncated to :column-width, 10 by default.

(term:table '(("name" "age" "email")
              ("me" 7 "some@blah")
              ("me" 7 "[email protected]")))
+---------+---------+---------+
|name     |age      |email    |
+---------+---------+---------+
|me       |7        |some@blah|
+---------+---------+---------+
|me       |7        |some@w(…)|
+---------+---------+---------+

;; Each column can have a different length.

(term:table '(("name" "age" "email")
              ("me" 7 "some@blah")
              ("me" 7 "[email protected]"))
             :column-width '(10 4 20))
+---------+---+-------------------+
|name     |age|email              |
+---------+---+-------------------+
|me       |7  |some@blah          |
+---------+---+-------------------+
|me       |7  |some@with-some-l(…)|
+---------+---+-------------------+

vindarel avatar Jun 01 '20 11:06 vindarel

however

calculate width for every column

probably.

vindarel avatar Jun 01 '20 11:06 vindarel

Having an automatic column width calculation is a nice feature. Cl-ASCII-TABLE does this.

svetlyak40wt avatar Jun 01 '20 11:06 svetlyak40wt