java/sql-dk/src/main/java/info/globalcode/sql/dk/ColorfulPrintWriter.java
author František Kučera <franta-hg@frantovo.cz>
Mon, 04 Mar 2019 20:15:24 +0100
branchv_0
changeset 238 4a1864c3e867
parent 155 java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java@eb3676c6929b
child 250 aae5009bd0af
permissions -rw-r--r--
mavenized: sql-dk
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * SQL-DK
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2013 František Kučera (frantovo.cz)
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 * (at your option) any later version.
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * GNU General Public License for more details.
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 *
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
 */
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
package info.globalcode.sql.dk;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
import java.io.File;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
import java.io.FileNotFoundException;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
import java.io.OutputStream;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
import java.io.PrintWriter;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
import java.io.UnsupportedEncodingException;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
import java.io.Writer;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
import java.util.EnumSet;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
/**
155
eb3676c6929b more JavaDoc
František Kučera <franta-hg@frantovo.cz>
parents: 126
diff changeset
    29
 * PrintWriter with convenience methods for printing color and formatted text.
eb3676c6929b more JavaDoc
František Kučera <franta-hg@frantovo.cz>
parents: 126
diff changeset
    30
 *
eb3676c6929b more JavaDoc
František Kučera <franta-hg@frantovo.cz>
parents: 126
diff changeset
    31
 * Uses ANSI Escape Sequences.
eb3676c6929b more JavaDoc
František Kučera <franta-hg@frantovo.cz>
parents: 126
diff changeset
    32
 * See: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
 *
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
 * @author Ing. František Kučera (frantovo.cz)
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
 */
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
public class ColorfulPrintWriter extends PrintWriter {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	public enum TerminalColor {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		Black(30, 40),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		Red(31, 41),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
		Green(32, 42),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		Yellow(33, 43),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		Blue(34, 44),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		Magenta(35, 45),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		Cyan(36, 46),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		White(37, 47);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		private final int foregroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		private final int backgroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		private TerminalColor(int foregroundCode, int backgroundCode) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
			this.foregroundCode = foregroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
			this.backgroundCode = backgroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		public int getForegroundCode() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
			return foregroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
		public int getBackgroundCode() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
			return backgroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
	public enum TerminalStyle {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
		Reset(0),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
		Bright(1),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
		Dim(2),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
		Underscore(4),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
		Blink(5),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
		Reverse(7),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
		Hidden(8);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
		private int code;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
		private TerminalStyle(int code) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
			this.code = code;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
		public int getCode() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
			return code;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
	}
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
    84
	private final boolean COLOR_ENABLED;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
	private boolean colorful = true;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
59
5f745ae795a8 logging: print stacktraces if level is less than INFO
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    87
	public void setStyle(TerminalStyle style) {
5f745ae795a8 logging: print stacktraces if level is less than INFO
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    88
		setStyle(EnumSet.of(style));
5f745ae795a8 logging: print stacktraces if level is less than INFO
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    89
	}
5f745ae795a8 logging: print stacktraces if level is less than INFO
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    90
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
	public void setStyle(EnumSet<TerminalStyle> styles) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
		printCodes(getStyleCodes(styles));
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
	private static int[] getStyleCodes(EnumSet<TerminalStyle> styles) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
		int[] array = new int[styles.size()];
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
		int i = 0;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
		for (TerminalStyle s : styles) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    99
			array[i++] = s.getCode();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   100
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   101
		return array;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   102
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   103
40
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   104
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   105
	 * Print (usually audible) bell code (\007, \a, ^G)
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   106
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   107
	public void bell() {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   108
		print("\007");
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   109
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   110
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   111
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   112
	 * Eat the last character
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   113
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   114
	public void backspace() {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   115
		print("\b");
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   116
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   117
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   118
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   119
	 * Eat n last characters
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   120
	 *
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   121
	 * @param count n
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   122
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   123
	public void backspace(int count) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   124
		for (int i = 0; i < count; i++) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   125
			backspace();
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   126
		}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   127
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   128
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   129
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   130
	 * With 100 ms delay and all colors.
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   131
	 *
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   132
	 * @see #printRainbow(java.lang.String, int,
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   133
	 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[])
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   134
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   135
	public void printRainbow(String string) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   136
		printRainbow(string, 100);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   137
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   138
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   139
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   140
	 * With all colors.
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   141
	 *
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   142
	 * @see #printRainbow(java.lang.String, int,
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   143
	 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[])
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   144
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   145
	public void printRainbow(String string, int delay) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   146
		printRainbow(string, delay, TerminalColor.values());
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   147
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   148
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   149
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   150
	 * Prints rainbow text – (re)writes same text subsequently in given colors and then in default
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   151
	 * color.
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   152
	 *
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   153
	 * @param string text to be printed, should not contain \n new line (then rainbow does not work
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   154
	 * – use println() after printRainbow() instead)
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   155
	 * @param delay delay between rewrites
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   156
	 * @param colors list of colors to be used
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   157
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   158
	public void printRainbow(String string, int delay, TerminalColor... colors) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   159
		for (TerminalColor c : colors) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   160
			print(c, string);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   161
			try {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   162
				Thread.sleep(delay);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   163
			} catch (InterruptedException e) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   164
				// no time to sleep
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   165
				break;
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   166
			}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   167
			backspace(string.length());
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   168
			flush();
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   169
		}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   170
		print(string);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   171
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   172
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   173
	public void setForegroundColor(TerminalColor color) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   174
		printCodes(color.getForegroundCode());
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   175
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   176
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   177
	public void setBackgroundColor(TerminalColor color) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   178
		printCodes(color.getBackgroundCode());
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   179
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   180
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   181
	public void print(TerminalColor foregroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   182
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   183
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   184
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   185
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   186
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   187
	public void println(TerminalColor foregroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   188
		print(foregroundColor, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   189
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   190
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   191
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   192
	public void print(TerminalColor foregroundColor, TerminalColor backgroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   193
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   194
		setBackgroundColor(backgroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   195
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   196
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   197
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   198
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   199
	public void println(TerminalColor foregroundColor, TerminalColor backgroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   200
		print(foregroundColor, backgroundColor, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   201
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   202
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   203
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   204
	public void print(TerminalColor foregroundColor, TerminalColor backgroundColor, EnumSet<TerminalStyle> styles, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   205
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   206
		setBackgroundColor(backgroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   207
		setStyle(styles);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   208
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   209
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   210
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   211
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   212
	public void println(TerminalColor foregroundColor, TerminalColor backgroundColor, EnumSet<TerminalStyle> styles, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   213
		print(foregroundColor, backgroundColor, styles, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   214
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   215
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   216
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   217
	public void print(TerminalColor foregroundColor, TerminalColor backgroundColor, TerminalStyle style, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   218
		print(foregroundColor, backgroundColor, EnumSet.of(style), string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   219
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   220
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   221
	public void println(TerminalColor foregroundColor, TerminalColor backgroundColor, TerminalStyle style, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   222
		print(foregroundColor, backgroundColor, style, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   223
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   224
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   225
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   226
	public void print(TerminalColor foregroundColor, EnumSet<TerminalStyle> styles, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   227
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   228
		setStyle(styles);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   229
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   230
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   231
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   232
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   233
	public void println(TerminalColor foregroundColor, EnumSet<TerminalStyle> styles, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   234
		print(foregroundColor, styles, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   235
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   236
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   237
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   238
	public void print(TerminalColor foregroundColor, TerminalStyle style, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   239
		print(foregroundColor, EnumSet.of(style), string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   240
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   241
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   242
	public void println(TerminalColor foregroundColor, TerminalStyle style, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   243
		print(foregroundColor, style, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   244
		println();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   245
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   246
37
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   247
	public void print(EnumSet<TerminalStyle> styles, String string) {
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   248
		setStyle(styles);
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   249
		print(string);
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   250
		resetAll();
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   251
	}
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   252
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   253
	public void println(EnumSet<TerminalStyle> styles, String string) {
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   254
		print(styles, string);
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   255
		println();
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   256
	}
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   257
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   258
	public void print(TerminalStyle style, String string) {
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   259
		print(EnumSet.of(style), string);
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   260
	}
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   261
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   262
	public void println(TerminalStyle style, String string) {
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   263
		print(style, string);
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   264
		println();
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   265
	}
9e6f8e5d5f98 support SQL commands returning more ResultSets + remove COMMAND_TYPE (type is now derived from result returned from SQL – it is not needed to specify the type on CLI)
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
   266
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   267
	public void resetAll() {
55
f5ed7c4efacc colorful logging
František Kučera <franta-hg@frantovo.cz>
parents: 40
diff changeset
   268
		printCodes(TerminalStyle.Reset.code);
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   269
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   270
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   271
	private void printCodes(int... codes) {
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   272
		if (COLOR_ENABLED && colorful) {
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   273
			print("\033[");
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   274
			for (int i = 0; i < codes.length; i++) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   275
				print(codes[i]);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   276
				if (i < codes.length - 1 && codes.length > 1) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   277
					print(";");
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   278
				}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   279
			}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   280
			print("m");
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   281
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   282
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   283
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   284
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   285
	 * Colors can be switched on/off during usage of this writer.
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   286
	 *
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   287
	 * @return whether colors are currently turned on
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   288
	 * @see #isColorEnabled()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   289
	 */
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   290
	public boolean isColorful() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   291
		return colorful;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   292
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   293
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   294
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   295
	 * Collors might be definitively disabled in constructor. If not, they can be turned on/off
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   296
	 * during usage of this writer by {@linkplain #setColorful(boolean)}
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   297
	 *
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   298
	 * @return whether colors are allowed for this instance of this class
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   299
	 * @see #isColorful()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   300
	 */
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   301
	public boolean isColorEnabled() {
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   302
		return COLOR_ENABLED;
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   303
	}
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   304
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   305
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   306
	 * @see #isColorful()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   307
	 * @see #isColorEnabled()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   308
	 */
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   309
	public void setColorful(boolean colorful) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   310
		this.colorful = colorful;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   311
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   312
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   313
	public ColorfulPrintWriter(File file) throws FileNotFoundException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   314
		super(file);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   315
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   316
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   317
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   318
	public ColorfulPrintWriter(OutputStream out) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   319
		super(out);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   320
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   321
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   322
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   323
	public ColorfulPrintWriter(String fileName) throws FileNotFoundException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   324
		super(fileName);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   325
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   326
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   327
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   328
	public ColorfulPrintWriter(Writer out) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   329
		super(out);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   330
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   331
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   332
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   333
	public ColorfulPrintWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   334
		super(file, csn);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   335
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   336
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   337
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   338
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   339
	 * @param colorEnabled colors might be definitively disabled by this option – this might be more
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   340
	 * optimalizable than dynamic turning off colors by {@linkplain #setColorful(boolean)} which is
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   341
	 * not definitive (colors can be turned on during live of this instance). This might be useful
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   342
	 * if you need an instance of this class but don't need colors at all.
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   343
	 */
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   344
	public ColorfulPrintWriter(OutputStream out, boolean autoFlush, boolean colorEnabled) {
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   345
		super(out, autoFlush);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   346
		COLOR_ENABLED = colorEnabled;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   347
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   348
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   349
	public ColorfulPrintWriter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   350
		super(fileName, csn);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   351
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   352
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   353
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   354
	public ColorfulPrintWriter(Writer out, boolean autoFlush) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   355
		super(out, autoFlush);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   356
		COLOR_ENABLED = true;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   357
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   358
}