java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java
branchv_0
changeset 40 a9db7fb3ce65
parent 37 9e6f8e5d5f98
child 55 f5ed7c4efacc
--- a/java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java	Mon Dec 23 12:16:22 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java	Mon Dec 23 16:14:03 2013 +0100
@@ -92,6 +92,75 @@
 		return array;
 	}
 
+	/**
+	 * Print (usually audible) bell code (\007, \a, ^G)
+	 */
+	public void bell() {
+		print("\007");
+	}
+
+	/**
+	 * Eat the last character
+	 */
+	public void backspace() {
+		print("\b");
+	}
+
+	/**
+	 * Eat n last characters
+	 *
+	 * @param count n
+	 */
+	public void backspace(int count) {
+		for (int i = 0; i < count; i++) {
+			backspace();
+		}
+	}
+
+	/**
+	 * With 100 ms delay and all colors.
+	 *
+	 * @see #printRainbow(java.lang.String, int,
+	 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[])
+	 */
+	public void printRainbow(String string) {
+		printRainbow(string, 100);
+	}
+
+	/**
+	 * With all colors.
+	 *
+	 * @see #printRainbow(java.lang.String, int,
+	 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[])
+	 */
+	public void printRainbow(String string, int delay) {
+		printRainbow(string, delay, TerminalColor.values());
+	}
+
+	/**
+	 * Prints rainbow text – (re)writes same text subsequently in given colors and then in default
+	 * color.
+	 *
+	 * @param string text to be printed, should not contain \n new line (then rainbow does not work
+	 * – use println() after printRainbow() instead)
+	 * @param delay delay between rewrites
+	 * @param colors list of colors to be used
+	 */
+	public void printRainbow(String string, int delay, TerminalColor... colors) {
+		for (TerminalColor c : colors) {
+			print(c, string);
+			try {
+				Thread.sleep(delay);
+			} catch (InterruptedException e) {
+				// no time to sleep
+				break;
+			}
+			backspace(string.length());
+			flush();
+		}
+		print(string);
+	}
+
 	public void setForegroundColor(TerminalColor color) {
 		printCodes(color.getForegroundCode());
 	}