From 809123f03100ee9ed90d31424304c22ba28e842c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 28 Oct 2020 10:47:32 +0200 Subject: Pad config report to maximum name length --- libbuild2/file.cxx | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'libbuild2/file.cxx') diff --git a/libbuild2/file.cxx b/libbuild2/file.cxx index 1bd5068..701367f 100644 --- a/libbuild2/file.cxx +++ b/libbuild2/file.cxx @@ -1495,7 +1495,6 @@ namespace build2 bool he (exists (hd)); bool fe (exists (f)); - // Reuse the parser to accumulate the configuration variable information. // parser p (ctx, load_stage::root); @@ -1519,13 +1518,6 @@ namespace build2 // // - Should we be printing NULL values? Maybe make this configurable? // - Quoted printing format (single/double)? - // - - // Use the special `config` module name (which doesn't have its own - // report) for project configuration. - // - diag_record dr (text); - dr << "config " << proj << '@' << root; // Printing the whole variable name would add too much noise with all // the repetitive config.. So we are only going to print the @@ -1540,6 +1532,36 @@ namespace build2 // string stem (!proj.empty () ? '.' + proj.variable () + '.' : string ()); + // Calculate max name length. + // + size_t pad (10); + for (const pair& lf: p.config_report) + { + lookup l (lf.first); + + size_t n; + if (l.value == nullptr) + { + n = l.var->name.size (); + } + else + { + size_t p (!stem.empty () + ? l.var->name.find (stem) + stem.size () + : 7); // "config." + n = l.var->name.size () - p; + } + + if (n > pad) + pad = n; + } + + // Use the special `config` module name (which doesn't have its own + // report) for project configuration. + // + diag_record dr (text); + dr << "config " << proj << '@' << root; + names storage; for (const pair& lf: p.config_report) { @@ -1577,10 +1599,10 @@ namespace build2 dr << "\n " << n; } else - dr << left << setw (10) << n << ' ' << ns; + dr << left << setw (static_cast (pad)) << n << ' ' << ns; } else - dr << left << setw (10) << n << " [null]"; + dr << left << setw (static_cast (pad)) << n << " [null]"; } } } -- cgit v1.1