Tabular formatter: fix problem with CR (carriage return). v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 01 Feb 2015 00:03:40 +0100
branchv_0
changeset 185 087d8ec75109
parent 184 53fb05ce504c
child 186 6c6a7904b22a
Tabular formatter: fix problem with CR (carriage return). Less command or orher programs shows it as ^M (two characters) and it breaks the table layout – so we need to translate it to a single symbol.
java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java
--- a/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Sat Jan 31 23:40:31 2015 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/formatting/TabularFormatter.java	Sun Feb 01 00:03:40 2015 +0100
@@ -27,10 +27,14 @@
 import java.util.regex.Pattern;
 
 /**
- * <p>Prints human-readable output – tables of result sets and text messages with update counts.</p>
+ * <p>
+ * Prints human-readable output – tables of result sets and text messages with update counts.
+ * </p>
  *
- * <p>Longer values might break the table – overflow the cells – see alternative tabular formatters
- * and the {@linkplain #PROPERTY_TRIM} property.</p>
+ * <p>
+ * Longer values might break the table – overflow the cells – see alternative tabular formatters
+ * and the {@linkplain #PROPERTY_TRIM} property.
+ * </p>
  *
  * @author Ing. František Kučera (frantovo.cz)
  * @see TabularPrefetchingFormatter
@@ -45,7 +49,7 @@
 	public static final String PROPERTY_COLORFUL = "color";
 	public static final String PROPERTY_TRIM = "trim";
 	private static final String NBSP = " ";
-	private static final Pattern whitespaceToReplace = Pattern.compile("\\n|\\t|" + NBSP);
+	private static final Pattern whitespaceToReplace = Pattern.compile("\\n|\\r|\\t|" + NBSP);
 	protected ColorfulPrintWriter out;
 	private boolean firstResult = true;
 	private int[] columnWidth;
@@ -282,6 +286,9 @@
 				case "\n":
 					out.print(TerminalColor.Red, "↲");
 					break;
+				case "\r":
+					out.print(TerminalColor.Red, "⏎");
+					break;
 				case "\t":
 					out.print(TerminalColor.Red, "↹");
 					break;