From 2c92a5e137a85fab1b986c780be516d912ad6639 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Wed, 29 Jun 2022 12:27:08 -0700 Subject: [PATCH] client: support multi-line print for long values The generic proxy property display was limited to a width for names/value which makes the output look nice and uniform, but will cut off any values which are longer than this limit. This patch adds some logic to detect this, and continue displaying the value on the next line. The width arguments were also updated to be unsigned, which allows checking the length without a cast. --- client/dbus-proxy.c | 21 +++++++++++++++++++-- client/dbus-proxy.h | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/client/dbus-proxy.c b/client/dbus-proxy.c index 624ce4aa..9f05c0e7 100644 --- a/client/dbus-proxy.c +++ b/client/dbus-proxy.c @@ -49,7 +49,8 @@ static struct l_queue *proxy_interface_types; void proxy_properties_display(const struct proxy_interface *proxy, const char *caption, const char *margin, - int name_column_width, int value_column_width) + unsigned int name_column_width, + unsigned int value_column_width) { const void *data; const struct proxy_interface_property *properties; @@ -67,14 +68,30 @@ void proxy_properties_display(const struct proxy_interface *proxy, properties = proxy->type->properties; for (i = 0; properties[i].name; i++) { + const char *str; + size_t len; + size_t j; + if (!properties[i].tostr) continue; + str = properties[i].tostr(data); + len = str ? strlen(str) : 0; + display("%s%*s %-*s%-.*s\n", margin, 8, properties[i].is_read_write ? COLOR_BOLDGRAY " *" COLOR_OFF : "", name_column_width, properties[i].name, - value_column_width, properties[i].tostr(data) ? : ""); + value_column_width, str ? : ""); + + if (len <= value_column_width) + continue; + + /* Display remaining data */ + for (j = value_column_width; j < len; j += value_column_width) + display("%s%*s %-*s%-.*s\n", margin, 8, "", + name_column_width, "", value_column_width, + str + j); } } diff --git a/client/dbus-proxy.h b/client/dbus-proxy.h index 1d6af5de..34917e82 100644 --- a/client/dbus-proxy.h +++ b/client/dbus-proxy.h @@ -89,7 +89,8 @@ bool proxy_interface_method_call(const struct proxy_interface *proxy, void proxy_properties_display(const struct proxy_interface *proxy, const char *caption, const char *margin, - int name_column_width, int value_column_width); + unsigned int name_column_width, + unsigned int value_column_width); char *proxy_property_str_completion(const struct proxy_interface_type *type, proxy_property_match_func_t function,