From a531f185872495afa49f52ac84c1d3929113a692 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Fri, 3 Jun 2016 12:30:21 +0200 Subject: info: size name column according to longest name --- bin/tools/info.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/tools/info.c b/bin/tools/info.c index 42e73f0..ec264cd 100644 --- a/bin/tools/info.c +++ b/bin/tools/info.c @@ -16,6 +16,7 @@ Franklin St, Fifth Floor, Boston, MA 02110, USA */ #include +#include #include "uca-plugin-manager.h" #include "uca-camera.h" @@ -60,11 +61,18 @@ print_properties (UcaCamera *camera) { GObjectClass *oclass; GParamSpec **pspecs; + gchar *fmt_string; guint n_props; + guint max_length = 0; oclass = G_OBJECT_GET_CLASS (camera); pspecs = g_object_class_list_properties (oclass, &n_props); + for (guint i = 0; i < n_props; i++) + max_length = MAX (max_length, strlen (g_param_spec_get_name (pspecs[i]))); + + fmt_string = g_strdup_printf (" %%s | %%-%us | %%s\n", max_length); + for (guint i = 0; i < n_props; i++) { GParamSpec *pspec; GValue value= { 0, { { 0 } } }; @@ -78,12 +86,13 @@ print_properties (UcaCamera *camera) g_object_get_property (G_OBJECT (camera), name, &value); value_string = g_strdup_value_contents (&value); - g_print (" %s | %-26s | %s\n", get_flags_description (pspec), name, value_string); + g_print (fmt_string, get_flags_description (pspec), name, value_string); g_free (value_string); g_value_unset (&value); } + g_free (fmt_string); g_free (pspecs); } -- cgit v1.2.3