Lennart Poettering
10d7126365
json: add new json format flag for disabling JSON output
...
This adds a new flag JSON_FORMAT_OFF that is a marker for "no JSON
output please!".
Of course, this flag sounds pointless in a JSON implementation, however
this is useful in code that can generate JSON output, but also more
human friendly output (for example our table formatters).
With this in place various tools that so far maintained one boolean
field "arg_json" that controlled whether JSON output was requested at
all and another field "arg_json_format_flags" for selecing the precise
json output flags may merge them into one, simplifying code a bit.
2021-01-09 17:35:58 +01:00
Yu Watanabe
db9ecf0501
license: LGPL-2.1+ -> LGPL-2.1-or-later
2020-11-09 13:23:58 +09:00
Zbigniew Jędrzejewski-Szmek
b0e3d79989
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.
2020-10-22 13:20:40 +02:00
Zbigniew Jędrzejewski-Szmek
6f8ca84c9b
format-table: reduce scope of iterator variables
2020-10-20 19:58:37 +02:00
Luca Boccassi
7b3eb5c97e
basic/time-util: add function to format timestamps with different styles
...
Instead of a multiple fixed format helper functions, add an enum and
a single helper, so that it's easier to extend in the future.
2020-08-19 15:30:13 +01:00
наб
2f665f2437
networkctl: use uint64_t for link speed throughout
...
format-table used size_t/uint64_t interchangeably for TABLE_BPS,
and ethtool-util used SIZE_MAX to indicate SPEED_UNKNOWN,
which worked only on ABIs with 64-bit pointers.
For example, the tg3 driver returns SPEED_UNKNOWN with no link (cf.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/broadcom/tg3.c?id=3eb2efbea193789397c36f52b17d8692ac79bf68#n12190 )
which on x32 (and other 32-bit ABIs, presumably) caused
"networkctl status" to mark it with "Speed: 4Gbps":
nabijaczleweli@szarotka:~$ networkctl --version
systemd 245 (245.5-2)
nabijaczleweli@szarotka:~$ file $(which networkctl)
/bin/networkctl: ELF 32-bit LSB shared object, x86-64, version 1 (SYSV),
dynamically linked, interpreter /libx32/ld-linux-x32.so.2,
BuildID[sha1]=36d684cb1fc8fb5060050d32b969e5aa172fa607, for GNU/Linux
3.4.0, stripped
nabijaczleweli@szarotka:~$ networkctl status onboard1
● 4: onboard1
Driver: tg3
Model: NetXtreme BCM5755 Gigabit Ethernet PCI Express
Speed: 4Gbps
Whereas on 64-bit-pointer ABIs (here: amd64):
nabijaczleweli@szarotka:~$ networkctl --version
systemd 245 (245.5-2)
nabijaczleweli@szarotka:~$ file $(which networkctl)
/bin/networkctl: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2,
BuildID[sha1]=7a3e406e54968d7774ad467fc3f6a9d35ff7aea2, for GNU/Linux
3.2.0, stripped
nabijaczleweli@szarotka:~$ networkctl status onboard1
● 4: onboard1
Driver: tg3
Model: NetXtreme BCM5755 Gigabit Ethernet PCI Express
Speed: n/a
With this patch, networkctl returns, for x32:
nabijaczleweli@szarotka:~$ networkctl --version
systemd 245 (245.5-2.1~networkctl-4g-v2)
nabijaczleweli@szarotka:~$ file $(which networkctl)
/bin/networkctl: ELF 32-bit LSB shared object, x86-64, version 1 (SYSV),
dynamically linked, interpreter /libx32/ld-linux-x32.so.2,
BuildID[sha1]=36d684cb1fc8fb5060050d32b969e5aa172fa607, for GNU/Linux
3.4.0, stripped
nabijaczleweli@szarotka:~$ networkctl status onboard1
● 4: onboard1
Driver: tg3
Model: NetXtreme BCM5755 Gigabit Ethernet PCI Express
Speed: n/a
And for amd64:
nabijaczleweli@szarotka:~$ file $(which networkctl)
/bin/networkctl: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2,
BuildID[sha1]=7a3e406e54968d7774ad467fc3f6a9d35ff7aea2, for GNU/Linux
3.2.0, stripped
nabijaczleweli@szarotka:~$ networkctl status onboard1
● 4: onboard1
Driver: tg3
Model: NetXtreme BCM5755 Gigabit Ethernet PCI Express
Speed: n/a
2020-05-09 08:49:31 +02:00
Lennart Poettering
b0395c1176
format-table: support coloring the gap right of each cell individually
...
This is useful for underlining a whole row of cells: previously we
couldn't underline the gap. Now we can.
2020-05-06 15:40:15 +02:00
Lennart Poettering
557b0841b7
format-table: display an empty strv cell the same way as an empty cell
...
An empty list conceptually is very close to null, hence let's show it
the same way, i.e. using the defined "empty" string, and greyed out.
2020-05-06 15:40:15 +02:00
Lennart Poettering
e21b76cd68
format-table: generate better JSON field names
...
Let's try to mangle table contents a bit to make them more suitable as
JSON field names. Specifically when we see "foo bar" convert this to
"foo_bar" as field name, as variable/field names are generally assumed
to be without spaces.
2020-05-05 08:13:58 +02:00
Zbigniew Jędrzejewski-Szmek
162392b75a
tree-wide: spellcheck using codespell
...
Fixes #15436 .
2020-04-16 18:00:40 +02:00
Frantisek Sumsal
0080964cc8
format-table: allow hiding a specific column
...
without having to specify the whole display map
2020-03-11 14:43:52 +01:00
Lennart Poettering
137688dff4
format-table: add support for formatting uuids/id128 values
2020-01-20 17:42:03 +01:00
Yu Watanabe
4618660d10
format-table: introduce TABLE_STRV
2020-01-15 11:52:40 +09:00
Lennart Poettering
d91614e717
format-table: natively support multiline cells
...
This adds native support for multiline cells.
2020-01-13 16:38:28 +01:00
Lennart Poettering
bcf00b6c0a
format-table: allow forcing arbitrary width tables
...
Useful for implementing systemctl's --full.
See #14470
2020-01-10 11:53:28 +09:00
Yu Watanabe
f93d876c80
format-table: introduce TABLE_PATH
2020-01-09 20:16:03 +09:00
Zbigniew Jędrzejewski-Szmek
0db41a8f1f
shared/format-table: disable ellipsization when piped
...
Fixes #13461 .
Before:
$ systemd-inhibit --no-pager
WHO UID USER PID COMM WHAT WHY MODE
ModemManager 0 root 1093 ModemManager sleep ModemManage… delay
NetworkManager 0 root 1400 NetworkManager sleep NetworkMana… delay
UPower 0 root 5141 upowerd sleep Pause devic… delay
zbyszek 1000 zbyszek 10036 gsd-power handle-lid-switch External mo… block
zbyszek 1000 zbyszek 10035 gsd-media-keys handle-power-key:handle-suspend-key:… GNOME handl… block
zbyszek 1000 zbyszek 10035 gsd-media-keys sleep GNOME handl… delay
zbyszek 1000 zbyszek 10036 gsd-power sleep GNOME needs… delay
7 inhibitors listed.
$ systemd-inhibit --no-pager|grep suspend
$ systemd-inhibit --no-pager|cat
WHO UID USER PID COMM WHAT WHY MODE
ModemManager 0 root 1093 ModemManager sleep Mode… delay
NetworkManager 0 root 1400 NetworkManager sleep Netw… delay
UPower 0 root 5141 upowerd sleep Paus… delay
zbyszek 1000 zbyszek 10036 gsd-power handle-lid-switch Exte… block
zbyszek 1000 zbyszek 10035 gsd-media-keys handle-power-key:h… GNOM… block
zbyszek 1000 zbyszek 10035 gsd-media-keys sleep GNOM… delay
zbyszek 1000 zbyszek 10036 gsd-power sleep GNOM… delay
After:
$ build/systemd-inhibit --no-pager
(same as above)
$ build/systemd-inhibit --no-pager|grep suspend
zbyszek 1000 zbyszek 10035 gsd-media-keys handle-power-key:handle-suspend-key:handle-hibernate-key GNOME handling keypresses block
$ build/systemd-inhibit --no-pager|cat
WHO UID USER PID COMM WHAT WHY MODE
ModemManager 0 root 1093 ModemManager sleep ModemManager needs to reset devices delay
NetworkManager 0 root 1400 NetworkManager sleep NetworkManager needs to turn off networks delay
UPower 0 root 5141 upowerd sleep Pause device polling delay
zbyszek 1000 zbyszek 10036 gsd-power handle-lid-switch External monitor attached or configuration changed recently block
zbyszek 1000 zbyszek 10035 gsd-media-keys handle-power-key:handle-suspend-key:handle-hibernate-key GNOME handling keypresses block
zbyszek 1000 zbyszek 10035 gsd-media-keys sleep GNOME handling keypresses delay
zbyszek 1000 zbyszek 10036 gsd-power sleep GNOME needs to lock the screen delay
7 inhibitors listed.
Note that this affect all tools that use format-table.c: machinectl, busctl,
loginctl, systemd-analyze, networkctl, portablectl.
2019-11-05 17:50:09 +01:00
Lennart Poettering
cd2d52d34f
Merge pull request #13216 from poettering/busctl-format-table
...
port "busctl list" to format-table.h
2019-07-29 20:44:54 +02:00
Lennart Poettering
2cb86a3e16
format-table: automatically show empty cells in grey
2019-07-29 18:48:38 +02:00
Lennart Poettering
728a22d3b1
format-table: add table_fill_empty() to fill in empty cells until the specified column is reached
2019-07-29 18:48:28 +02:00
Lennart Poettering
4ea710eaf4
format-table: if NULL is spcified as data, let's patch to an empty cell
...
This should make various calls easier that currently generate either an
empty cell or a regular cell depending on whether they have data to
show.
2019-07-29 18:48:25 +02:00
Lennart Poettering
7a9b4bb050
format-table: optionally show a specific string in empty cells
...
For some cases it might make sense to show "-" instead of just spaces
for empty cells.
2019-07-29 18:48:08 +02:00
Yu Watanabe
57894dc989
table: add missing NULL initialization
2019-07-29 23:30:32 +09:00
Yu Watanabe
e74294c30a
table: add TABLE_UINT8 or friends
2019-07-29 23:27:56 +09:00
Yu Watanabe
a7a257cdda
table: add TABLE_IN_ADDR and TABLE_IN6_ADDR
2019-07-29 23:22:14 +09:00
Lennart Poettering
c1b71f3a61
Merge pull request #13074 from poettering/format-tree-many
...
table_add_many() improvements
2019-07-16 16:03:54 +02:00
Lennart Poettering
6268974f88
format-table: add ability to set cell attributes within table_add_many()
...
table_add_many() is so much shorter and easier to read than
table_add_cell() with its accessors. Let's teach table_add_many() more
tricks, so that reverting to table_add_cell() is not needed that often
anymore.
2019-07-16 12:43:46 +02:00
Yu Watanabe
c5bbb2b5be
format-table: add TABLE_TIMESTAMP_UTC and _RELATIVE
2019-07-16 00:44:14 +09:00
Yu Watanabe
ba99f19c0d
format-table: add TABLE_TIMESPAN_MSEC
2019-07-16 00:09:39 +09:00
Yu Watanabe
9ff27e6413
table: introduce FORMAT_BPS type
2019-06-19 23:15:19 +09:00
Yu Watanabe
518a66ec08
tree-wide: replace if_indextoname() with format_ifname()
2019-05-29 14:21:19 +09:00
Yu Watanabe
8390d39165
table: add TABLE_IFINDEX type
2019-05-29 14:21:19 +09:00
Yu Watanabe
d553832698
table: add more basic types
2019-05-29 14:21:19 +09:00
Yu Watanabe
5896e03c6f
table: add teble_add_string_cell()
2019-05-29 14:21:19 +09:00
Ben Boeckel
5238e95759
codespell: fix spelling errors
2019-04-29 16:47:18 +02:00
Zbigniew Jędrzejewski-Szmek
2fe21124a6
Add open_memstream_unlocked() wrapper
2019-04-12 11:44:57 +02:00
Zbigniew Jędrzejewski-Szmek
ca78ad1de9
headers: remove unneeded includes from util.h
...
This means we need to include many more headers in various files that simply
included util.h before, but it seems cleaner to do it this way.
2019-03-27 11:53:12 +01:00
Lennart Poettering
760877e90c
util: split out sorting related calls to new sort-util.[ch]
2019-03-13 12:16:43 +01:00
Lennart Poettering
0a9707187b
util: split out memcmp()/memset() related calls into memory-util.[ch]
...
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Lennart Poettering
94a80afed4
format-table: never try to reuse cells that have color/url/uppercase set
...
The table cell reusing code is supposed to be an internal memory
optimization, and not more. This means behaviour should be the same as
if we wouldn't reuse cells.
2018-12-03 22:42:38 +01:00
Lennart Poettering
359abf6dd0
format-table: add option to uppercase cells on display
...
This adds a per-cell option for uppercasing displayed strings.
Implicitly turn this on for the header row. The fact that we format the
table header in uppercase is a formatting thing after all, hence should
be applied by the formatter, i.e. the table display code.
Moreover, this provides us with the benefit that we can more nicely
reuse the specified table headers as JSON field names, like we already
do: json field names are usually not uppercase.
2018-12-03 22:42:38 +01:00
Lennart Poettering
31ac235771
format-table: optionally covert/output table to JSON
2018-12-03 22:42:38 +01:00
Lennart Poettering
c93d372d7c
format-table: use right field for display
...
Since .timespan and .timestamp are unionized on top of each other this
doesn't actually matter, but it is still more correct to address it
under it's correct name.
2018-12-03 22:42:38 +01:00
Lennart Poettering
88db94fa57
format-table: make sure we never call memcmp() with NULL parameters
2018-11-30 16:46:10 +01:00
Lennart Poettering
62d99b3970
format-table: add calls to query the data in a specific cell
2018-11-30 16:46:10 +01:00
Lennart Poettering
30d98de00c
format-table: always underline header line
2018-11-30 16:46:10 +01:00
Lennart Poettering
9314ead785
format-table: add an API for getting the cell at a specific row/column
2018-11-30 16:46:10 +01:00
Lennart Poettering
27e730e6d0
format-table: add table_update() to update existing entries
2018-11-30 16:46:10 +01:00
Lennart Poettering
a2c73e2d38
format-table: optionally allow reversing the sort order for a column
2018-11-30 16:46:10 +01:00
Lennart Poettering
a4661181fa
format-table: add option to store/format percent and uint64_t values in cells
2018-11-30 16:46:10 +01:00