rocdev-foundation / medera

Is a chat bot the new "Hello, World"?
GNU General Public License v3.0
1 stars 2 forks source link

Table formatting #28

Open geowa4 opened 7 years ago

geowa4 commented 7 years ago

Formatting objects as JSON is often sufficient, especially for a bot like this, but tables are nice too. In the skill definition, add "table" to possible values to the "format" option.

description: foo
verb: get
noun: bar
command: ls
format: table

Since we're working with a text interface, an ASCII table is sufficient. The first row must display the names of each property in all of the objects. The table shall be bordered using +, =, -, and | characters. The corners of each cell shall be rendered with a +. All vertical lines shall be rendered with a |. The horizontal lines above and below the header row shall be rendered with =. All other horizontal lines will be rendered with a -. Place a single space on each side of the value in the cell. The width of each column is therefore two spaces wider than the widest element.

Assuming a skill's JSON output as [{"name":"asdf","foo":111,"bar":"one"},{"name":"asdf","foo":222,"bar":"two"}], the following must be the output.

+======+=====+=====+
| name | foo | bar |
+======+=====+=====+
| asdf | 111 | one |
+------+-----+-----+
| fasd | 222 | two |
+------+-----+-----+