java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java
branchv_0
changeset 87 03bf24449c7a
parent 79 e19a13ed19a9
child 88 102ba0fcb07f
--- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Fri Dec 27 19:33:46 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Fri Dec 27 21:26:30 2013 +0100
@@ -35,7 +35,14 @@
 	private ColorfulPrintWriter out;
 	private boolean firstResult = true;
 	private int[] columnWidth;
+	/**
+	 * use ASCII borders instead of unicode ones
+	 */
 	private final boolean asciiNostalgia = false;
+	/**
+	 * Trim values if they are longer than cell size
+	 */
+	private final boolean trimValues = false;
 
 	public TabularFormatter(FormatterContext formatterContext) {
 		super(formatterContext);
@@ -135,12 +142,19 @@
 	@Override
 	protected String toString(Object value) {
 		final int width = getColumnWidth(getCurrentColumnsCount());
+		String result;
 		if (value instanceof Number || value instanceof Boolean) {
-			return lpad(super.toString(value), width);
+			result = lpad(super.toString(value), width);
 		} else {
-			return rpad(super.toString(value), width);
+			result = rpad(super.toString(value), width);
 		}
 		// ?	value = (boolean) value ? "✔" : "✗";
+
+		if (trimValues && result.length() > width) {
+			result = result.substring(0, width - 1) + "…";
+		}
+
+		return result;
 	}
 
 	@Override
@@ -208,7 +222,7 @@
 			border = border.replaceAll("│", "|");
 			border = border.replaceAll("[╭┬╮├┼┤╰┴╯]", "+");
 		}
-		
+
 		out.print(TerminalColor.Green, border);
 	}