cli tableau
Horizontal Tables
var Table = ; var table = head: 'TH 1 label' 'TH 2 label' colWidths: 100 200 borders: false; table; console;
Vertical Tables
var Table = ;var table = ; table; console;
Cross Tables
Cross tables are very similar to vertical tables, with two key differences:
- They require a
head
setting when instantiated that has an empty string as the first header - The individual rows take the general form of { "Header": ["Row", "Values"] }
var Table = ;var table = head: "" "Top Header 1" "Top Header 2" ; table; console;
Custom styles
The chars
property controls how the table is drawn:
var table = 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': '│' ; table; console;// Outputs:////╔══════╤═════╤══════╗//║ foo │ bar │ baz ║//╟──────┼─────┼──────╢//║ frob │ bar │ quuz ║//╚══════╧═════╧══════╝
Empty decoration lines will be skipped, to avoid vertical separator rows just set the 'mid', 'left-mid', 'mid-mid', 'right-mid' to the empty string:
var table = chars: 'mid': '' 'left-mid': '' 'mid-mid': '' 'right-mid': '' ;table; console;// Outputs: (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:
var table = 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': ' ' style: 'padding-left': 0 'padding-right': 0 ; table; console;// Outputs://foo bar baz//frobnicate bar quuz
Credits
- Guillermo Rauch <guillermo@learnboost.com> (Guille)