]> git.ipfire.org Git - thirdparty/systemd.git/commit
format-table: add TABLE_STRV_WRAPPED
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 12 Oct 2020 11:29:46 +0000 (13:29 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 22 Oct 2020 11:20:40 +0000 (13:20 +0200)
commitb0e3d799891c4633bd2b0d88e4ed2c741bbcd532
tree5a75c03dbd7d29ba9a2e2a5c01739fe3a7dc5a87
parent6f8ca84c9b64c81add286790a7ffcc2eed569b27
format-table: add TABLE_STRV_WRAPPED

The idea is that we have strvs like list of server names or addresses, where
the majority of strings is rather short, but some are long and there can
potentially be many strings. So formattting them either all on one line or all
in separate lines leads to output that is either hard to read or uses way too
many rows. We want to wrap them, but relying on the pager to do the wrapping is
not nice. Normal text has a lot of redundancy, so when the pager wraps a line
in the middle of a word the read can understand what is going on without any
trouble. But for a high-density zero-redundancy text like an IP address it is
much nicer to wrap between words. This also makes c&p easier.

This adds a variant of TABLE_STRV which is wrapped on output (with line breaks
inserted between different strv entries).

The change table_print() is quite ugly. A second pass is added to re-calculate
column widths. Since column size is now "soft", i.e. it can adjust based on
available columns, we need to two passes:
- first we figure out how much space we want
- in the second pass we figure out what the actual wrapped columns
  widths will be.

To avoid unnessary work, the second pass is only done when we actually have
wrappable fields.

A test is added in test-format-table.
src/basic/macro.h
src/resolve/resolvectl.c
src/shared/format-table.c
src/shared/format-table.h
src/test/test-format-table.c