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

Already on GitHub? Sign in to your account

Print compact tables with no decorations #24

merged 4 commits into from Jun 22, 2013


None yet
3 participants

em- commented Mar 17, 2013

I wanted to be able to use cli-table to print columned data in a ultra-compact mode with no decorations whatsoever.

To accomplish this, I wrote some patches adding the following capabilities to cli-table:

  1. have a vertical cell separator different from the right border
  2. completely omit vertical decoration lines if empty, instead of printing '\n'

I've added some test to prevent the most obvious breackage.

Let me know if there's any change you'd like to see applied.


em- added some commits Mar 17, 2013

Customize the vertical cell separator separately from the right one
WARNING: this breaks compatibility if you rely on setting
options.chars.right to set the vertical cell separator too.

Given the following table:
 │ foo    │ bar    │ baz    │

it's now possible to double the outer border only:
 ║ foo    │ bar    │ baz    ║

just set the appropriate chars, using the new 'middle' property:
 var table = new Table({
   , style: {
       chars: {
         'top': '═'
       , 'top-mid': '╤'
       , 'top-left': '╔'
       , 'top-right': '╗'
       , 'bottom': '═'
       , 'bottom-mid': '╧'
       , 'bottom-left': '╚'
       , 'bottom-right': '╝'
       , 'left': '║'
       , 'left-mid': '╟'
       , 'mid': '─'
       , 'mid-mid': '┼'
       , 'right': '║'
       , 'right-mid': '╢'
       , 'middle': '│'
Make line() return the generated string instead of appending it to ret
This makes reasoning about the newly created line easier, to eg. skip
empty lines.

rauchg commented Mar 17, 2013

This looks pretty awesome. Would you mind documenting in the README? It would also be nice to include the different examples we use in the tests in the README, they look sweet!

Omit horizontal decoration lines if empty
This allows for more flexible compact layouts: even the compact mode can
be redefined in terms of 'chars' settings by using the empty string for all the
horizontal 'mid' characters.

By using the following configuration:
 var table = new Table({
   chars: {
       'mid': ''
     , 'left-mid': ''
     , 'mid-mid': ''
     , 'right-mid': ''
   style: {
       head: []
     , border: []

it's now possible to get results like this (note the lack of the horizontal
line between rows):
 │ foo        │ bar │ baz  │
 │ frobnicate │ bar │ quuz │

By setting all chars to empty with the exception of 'middle' being set to a
single space and by setting padding to zero, it's possible to get the
most compact layout with no decorations:
 foo        bar baz
 frobnicate bar quuz

em- commented Mar 19, 2013

Examples added to the README. Let me know!


em- commented Apr 11, 2013

Any news about the patch?


em- commented May 2, 2013

Is the patch ok to be merged?

Would be nice to see these...


em- commented Jun 10, 2013

@guille do you have some other comments about the patches?

rauchg added a commit that referenced this pull request Jun 22, 2013

Merge pull request #24 from em-/no-decoration
Print compact tables with no decorations

@rauchg rauchg merged commit 7660ebf into Automattic:master Jun 22, 2013


rauchg commented Jun 22, 2013

Thanks a lot @em- – sorry about the awful delay


em- commented Jun 22, 2013

No worries @guille and thanks for merging this stuff! :D

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