java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java
branchv_0
changeset 40 a9db7fb3ce65
parent 37 9e6f8e5d5f98
child 55 f5ed7c4efacc
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java	Mon Dec 23 12:16:22 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java	Mon Dec 23 16:14:03 2013 +0100
     1.3 @@ -92,6 +92,75 @@
     1.4  		return array;
     1.5  	}
     1.6  
     1.7 +	/**
     1.8 +	 * Print (usually audible) bell code (\007, \a, ^G)
     1.9 +	 */
    1.10 +	public void bell() {
    1.11 +		print("\007");
    1.12 +	}
    1.13 +
    1.14 +	/**
    1.15 +	 * Eat the last character
    1.16 +	 */
    1.17 +	public void backspace() {
    1.18 +		print("\b");
    1.19 +	}
    1.20 +
    1.21 +	/**
    1.22 +	 * Eat n last characters
    1.23 +	 *
    1.24 +	 * @param count n
    1.25 +	 */
    1.26 +	public void backspace(int count) {
    1.27 +		for (int i = 0; i < count; i++) {
    1.28 +			backspace();
    1.29 +		}
    1.30 +	}
    1.31 +
    1.32 +	/**
    1.33 +	 * With 100 ms delay and all colors.
    1.34 +	 *
    1.35 +	 * @see #printRainbow(java.lang.String, int,
    1.36 +	 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[])
    1.37 +	 */
    1.38 +	public void printRainbow(String string) {
    1.39 +		printRainbow(string, 100);
    1.40 +	}
    1.41 +
    1.42 +	/**
    1.43 +	 * With all colors.
    1.44 +	 *
    1.45 +	 * @see #printRainbow(java.lang.String, int,
    1.46 +	 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[])
    1.47 +	 */
    1.48 +	public void printRainbow(String string, int delay) {
    1.49 +		printRainbow(string, delay, TerminalColor.values());
    1.50 +	}
    1.51 +
    1.52 +	/**
    1.53 +	 * Prints rainbow text – (re)writes same text subsequently in given colors and then in default
    1.54 +	 * color.
    1.55 +	 *
    1.56 +	 * @param string text to be printed, should not contain \n new line (then rainbow does not work
    1.57 +	 * – use println() after printRainbow() instead)
    1.58 +	 * @param delay delay between rewrites
    1.59 +	 * @param colors list of colors to be used
    1.60 +	 */
    1.61 +	public void printRainbow(String string, int delay, TerminalColor... colors) {
    1.62 +		for (TerminalColor c : colors) {
    1.63 +			print(c, string);
    1.64 +			try {
    1.65 +				Thread.sleep(delay);
    1.66 +			} catch (InterruptedException e) {
    1.67 +				// no time to sleep
    1.68 +				break;
    1.69 +			}
    1.70 +			backspace(string.length());
    1.71 +			flush();
    1.72 +		}
    1.73 +		print(string);
    1.74 +	}
    1.75 +
    1.76  	public void setForegroundColor(TerminalColor color) {
    1.77  		printCodes(color.getForegroundCode());
    1.78  	}