From: Peter Krempa <pkrempa@redhat.com> After recent addition of 'available' field the hardcoded alignments no longer match: $ virsh nodememstats total : 63393452 KiB free : 4046756 KiB available: 35747628 KiB buffers: 2291748 KiB cached : 24086464 KiB To address the issue switch to use dynamicaly aligned columns via vshTable infrastructure: $ virsh nodememstats total : 63393452 KiB free : 3888776 KiB available: 35640268 KiB buffers : 2291768 KiB cached : 24089916 KiB Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tools/virsh-host.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index dd98917fa8..ef91e22fed 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -33,6 +33,7 @@ #include "virfile.h" #include "virenum.h" #include "virsh-util.h" +#include "vsh-table.h" /* * "capabilities" command @@ -889,6 +890,8 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) int cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS; g_autofree virNodeMemoryStatsPtr params = NULL; virshControl *priv = ctl->privData; + g_autoptr(vshTable) table = vshTableNew("field", ":", "value", NULL); + g_autofree char *tblstr = NULL; if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0) return false; @@ -912,8 +915,18 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) return false; } - for (i = 0; i < nparams; i++) - vshPrint(ctl, "%-7s: %20llu KiB\n", params[i].field, params[i].value); + for (i = 0; i < nparams; i++) { + g_autofree char *val = g_strdup_printf("%llu KiB", params[i].value); + + vshTableRowAppendFlags(table, + VSH_TABLE_CELL_SKIP_LEADING | VSH_TABLE_CELL_SKIP_TRAILING, params[i].field, + VSH_TABLE_CELL_SKIP_LEADING, ":", + VSH_TABLE_CELL_ALIGN_RIGHT, val, + 0, NULL); + } + + tblstr = vshTablePrintToString(table, false); + vshPrint(ctl, "%s", tblstr); return true; } -- 2.53.0