From bcacbff096224ebba1d91a5865f399d5eba481de Mon Sep 17 00:00:00 2001 From: Andrew Raines Date: Thu, 4 Jul 2013 15:39:20 -0500 Subject: [PATCH] Don't consider header width if not printed. --- .../rest/action/support/RestTable.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/elasticsearch/rest/action/support/RestTable.java b/src/main/java/org/elasticsearch/rest/action/support/RestTable.java index 09cdc490db7..2ccc9903bca 100644 --- a/src/main/java/org/elasticsearch/rest/action/support/RestTable.java +++ b/src/main/java/org/elasticsearch/rest/action/support/RestTable.java @@ -66,10 +66,10 @@ public class RestTable { } public static RestResponse buildTextPlainResponse(Table table, RestRequest request, RestChannel channel) { - int[] width = buildWidths(table, request); + boolean verbose = request.paramAsBoolean("v", true); + int[] width = buildWidths(table, request, verbose); Set displayHeaders = buildDisplayHeaders(table, request); - boolean verbose = request.paramAsBoolean("v", true); StringBuilder out = new StringBuilder(); if (verbose) { // print the headers @@ -113,13 +113,16 @@ public class RestTable { return display; } - private static int[] buildWidths(Table table, RestRequest request) { + private static int[] buildWidths(Table table, RestRequest request, boolean verbose) { int[] width = new int[table.getHeaders().size()]; - for (int col = 0; col < width.length; col++) { - String v = renderValue(request, table.getHeaders().get(col).value); - int vWidth = v == null ? 0 : v.length(); - if (width[col] < vWidth) { - width[col] = vWidth; + + if (verbose) { + for (int col = 0; col < width.length; col++) { + String v = renderValue(request, table.getHeaders().get(col).value); + int vWidth = v == null ? 0 : v.length(); + if (width[col] < vWidth) { + width[col] = vWidth; + } } }