format-table: add an explicit "vertical" mode
authorLennart Poettering <lennart@poettering.net>
Thu, 10 Nov 2022 11:52:08 +0000 (12:52 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 10 Nov 2022 22:09:18 +0000 (23:09 +0100)
commitc6bf9dff3a6e6a071b55755b57f8d44bbefe9cca
treea5d8420f9a1149f5f282f161c6c294ff90b08909
parent251dc2f14ba423f7c27dcafb6eb2c06bc94c840d
format-table: add an explicit "vertical" mode

Originally, the table formatting code was written to display a number of
records, one per line, and within each line multiple fields of the same
record. The first line contains the column names.

It was then started to be used in a "vertical" mode however,
i.e. with field names on the left instead of the top. Let's support such
a mode explicitly, so that we can provide systematic styling, and can
properly convert this mode to JSON.

A new constructor "table_new_vertical()" is added creating such
"vertical" tables. Internally, this is a table with two columns: "key"
and "value". When outputting this as JSON we'll output a single JSON
object, with key/value as fields. (Which is different from the
traditional output where we'd use the first line as JSON field names,
and output an array of objects).

A new cell type TABLE_FIELD is added for specifically marking the
"field" cells, i.e. the cells in the first column. We'll automatically
suffic ":" to these fields on output.
src/shared/format-table.c
src/shared/format-table.h
src/test/test-format-table.c