3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 17:59:25 +01:00

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.
This commit is contained in:
James Prestwood 2022-06-29 12:27:08 -07:00 committed by Denis Kenzior
parent 5b58390b8d
commit 2c92a5e137
2 changed files with 21 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -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,