# HG changeset patch # User František Kučera # Date 1442165136 -7200 # Node ID 0094319a274a4d77fb0c41b4581d1631c3949f06 # Parent b40153eb771677c5ec250f594112b1051e8e4454 headerTypes: new option to hide column types in tabular headers diff -r b40153eb7716 -r 0094319a274a java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java --- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java Sun Sep 06 21:48:54 2015 +0200 +++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java Sun Sep 13 19:25:36 2015 +0200 @@ -45,6 +45,7 @@ @PropertyDeclaration(name = COLORFUL, defaultValue = "true", type = Boolean.class, description = COLORFUL_DESCRIPTION) @PropertyDeclaration(name = TabularFormatter.PROPERTY_ASCII, defaultValue = "false", type = Boolean.class, description = "whether to use ASCII table borders instead of unicode ones") @PropertyDeclaration(name = TabularFormatter.PROPERTY_TRIM, defaultValue = "false", type = Boolean.class, description = "whether to trim the values to fit the column width") +@PropertyDeclaration(name = TabularFormatter.PROPERTY_HEADER_TYPE, defaultValue = "true", type = Boolean.class, description = "whether to print data types in column headers") public class TabularFormatter extends AbstractFormatter { public static final String NAME = "tabular"; // bash-completion:formatter @@ -52,6 +53,7 @@ private static final String HEADER_TYPE_SUFFIX = ")"; public static final String PROPERTY_ASCII = "ascii"; public static final String PROPERTY_TRIM = "trim"; + public static final String PROPERTY_HEADER_TYPE = "headerTypes"; protected ColorfulPrintWriter out; private boolean firstResult = true; private int[] columnWidth; @@ -63,12 +65,17 @@ * Trim values if they are longer than cell size */ private final boolean trimValues; + /** + * Print data type of each column in the header + */ + private final boolean printHeaderTypes; public TabularFormatter(FormatterContext formatterContext) { super(formatterContext); out = new ColorfulPrintWriter(formatterContext.getOutputStream()); asciiNostalgia = formatterContext.getProperties().getBoolean(PROPERTY_ASCII, false); trimValues = formatterContext.getProperties().getBoolean(PROPERTY_TRIM, false); + printHeaderTypes = formatterContext.getProperties().getBoolean(PROPERTY_HEADER_TYPE, true); out.setColorful(formatterContext.getProperties().getBoolean(COLORFUL, true)); } @@ -86,7 +93,7 @@ for (ColumnDescriptor cd : columnDescriptors) { // padding: make header cell at least same width as data cells in this column - int typeWidth = cd.getTypeName().length() + HEADER_TYPE_PREFIX.length() + HEADER_TYPE_SUFFIX.length(); + int typeWidth = printHeaderTypes ? cd.getTypeName().length() + HEADER_TYPE_PREFIX.length() + HEADER_TYPE_SUFFIX.length() : 0; cd.setLabel(rpad(cd.getLabel(), getColumnWidth(cd.getColumnNumber()) - typeWidth)); updateColumnWidth(cd.getColumnNumber(), cd.getLabel().length() + typeWidth); @@ -106,9 +113,11 @@ printTableBorder(" │ "); } out.print(TerminalStyle.Bright, cd.getLabel()); - out.print(HEADER_TYPE_PREFIX); - out.print(cd.getTypeName()); - out.print(HEADER_TYPE_SUFFIX); + if (printHeaderTypes) { + out.print(HEADER_TYPE_PREFIX); + out.print(cd.getTypeName()); + out.print(HEADER_TYPE_SUFFIX); + } if (cd.isLastColumn()) { printTableBorder(" │"); }