java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 04 Jan 2014 19:38:20 +0100
branchv_0
changeset 126 2357a9d08660
parent 59 5f745ae795a8
child 155 eb3676c6929b
permissions -rw-r--r--
Colors can be definitively turned off in constructor
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
/**
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
 *
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
 * @author Ing. František Kučera (frantovo.cz)
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
 */
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
public class ColorfulPrintWriter extends PrintWriter {
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
	public enum TerminalColor {
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
		Black(30, 40),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
		Red(31, 41),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
		Green(32, 42),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
		Yellow(33, 43),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		Blue(34, 44),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		Magenta(35, 45),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
		Cyan(36, 46),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		White(37, 47);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		private final int foregroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		private final int backgroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		private TerminalColor(int foregroundCode, int backgroundCode) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
			this.foregroundCode = foregroundCode;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
			this.backgroundCode = 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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		public int getForegroundCode() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
			return foregroundCode;
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 getBackgroundCode() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
			return backgroundCode;
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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	public enum TerminalStyle {
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
		Reset(0),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
		Bright(1),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
		Dim(2),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
		Underscore(4),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
		Blink(5),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
		Reverse(7),
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
		Hidden(8);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
		private int code;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
		private TerminalStyle(int code) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
			this.code = code;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
		}
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
		public int getCode() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
			return 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
	}
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
    80
	private final boolean COLOR_ENABLED;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
	private boolean colorful = true;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
59
5f745ae795a8 logging: print stacktraces if level is less than INFO
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    83
	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
    84
		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
    85
	}
5f745ae795a8 logging: print stacktraces if level is less than INFO
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    86
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
	public void setStyle(EnumSet<TerminalStyle> styles) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
		printCodes(getStyleCodes(styles));
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
	private static int[] getStyleCodes(EnumSet<TerminalStyle> styles) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
		int[] array = new int[styles.size()];
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
		int i = 0;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
		for (TerminalStyle s : styles) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
			array[i++] = s.getCode();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
		}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
		return array;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    99
40
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   100
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   101
	 * 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
   102
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   103
	public void bell() {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   104
		print("\007");
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   105
	}
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
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   108
	 * Eat the last character
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
	public void backspace() {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   111
		print("\b");
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   112
	}
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
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   115
	 * Eat n last characters
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
	 * @param count n
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
	public void backspace(int count) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   120
		for (int i = 0; i < count; i++) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   121
			backspace();
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
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   124
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   125
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   126
	 * With 100 ms delay and all colors.
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
	 * @see #printRainbow(java.lang.String, int,
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   129
	 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[])
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   130
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   131
	public void printRainbow(String string) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   132
		printRainbow(string, 100);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   133
	}
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
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   136
	 * With all colors.
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
	 * @see #printRainbow(java.lang.String, int,
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   139
	 * info.globalcode.sql.dk.ColorfulPrintWriter.TerminalColor[])
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   140
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   141
	public void printRainbow(String string, int delay) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   142
		printRainbow(string, delay, TerminalColor.values());
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   143
	}
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
	/**
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   146
	 * 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
   147
	 * color.
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
	 * @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
   150
	 * – use println() after printRainbow() instead)
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   151
	 * @param delay delay between rewrites
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   152
	 * @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
   153
	 */
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   154
	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
   155
		for (TerminalColor c : colors) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   156
			print(c, string);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   157
			try {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   158
				Thread.sleep(delay);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   159
			} catch (InterruptedException e) {
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   160
				// no time to sleep
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   161
				break;
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   162
			}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   163
			backspace(string.length());
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   164
			flush();
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   165
		}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   166
		print(string);
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   167
	}
a9db7fb3ce65 TabularFormatter: print colorful tables\!
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
   168
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   169
	public void setForegroundColor(TerminalColor color) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   170
		printCodes(color.getForegroundCode());
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   171
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   172
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   173
	public void setBackgroundColor(TerminalColor color) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   174
		printCodes(color.getBackgroundCode());
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 print(TerminalColor foregroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   178
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   179
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   180
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   181
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   182
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   183
	public void println(TerminalColor foregroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   184
		print(foregroundColor, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   185
		println();
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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   188
	public void print(TerminalColor foregroundColor, TerminalColor backgroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   189
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   190
		setBackgroundColor(backgroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   191
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   192
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   193
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   194
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   195
	public void println(TerminalColor foregroundColor, TerminalColor backgroundColor, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   196
		print(foregroundColor, backgroundColor, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   197
		println();
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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   200
	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
   201
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   202
		setBackgroundColor(backgroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   203
		setStyle(styles);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   204
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   205
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   206
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   207
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   208
	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
   209
		print(foregroundColor, backgroundColor, styles, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   210
		println();
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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   213
	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
   214
		print(foregroundColor, backgroundColor, EnumSet.of(style), string);
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 println(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, style, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   219
		println();
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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   222
	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
   223
		setForegroundColor(foregroundColor);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   224
		setStyle(styles);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   225
		print(string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   226
		resetAll();
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   227
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   228
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   229
	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
   230
		print(foregroundColor, styles, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   231
		println();
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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   234
	public void print(TerminalColor foregroundColor, TerminalStyle style, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   235
		print(foregroundColor, EnumSet.of(style), string);
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 println(TerminalColor foregroundColor, TerminalStyle style, String string) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   239
		print(foregroundColor, style, string);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   240
		println();
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
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
   243
	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
   244
		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
   245
		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
   246
		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
   247
	}
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
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
	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
   250
		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
   251
		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
   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
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
	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
   255
		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
   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 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
   259
		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
   260
		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
   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
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   263
	public void resetAll() {
55
f5ed7c4efacc colorful logging
František Kučera <franta-hg@frantovo.cz>
parents: 40
diff changeset
   264
		printCodes(TerminalStyle.Reset.code);
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   265
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   266
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   267
	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
   268
		if (COLOR_ENABLED && colorful) {
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   269
			print("\033[");
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   270
			for (int i = 0; i < codes.length; i++) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   271
				print(codes[i]);
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   272
				if (i < codes.length - 1 && codes.length > 1) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   273
					print(";");
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   274
				}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   275
			}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   276
			print("m");
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   277
		}
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
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   280
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   281
	 * 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
   282
	 *
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   283
	 * @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
   284
	 * @see #isColorEnabled()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   285
	 */
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   286
	public boolean isColorful() {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   287
		return colorful;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   288
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   289
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   290
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   291
	 * 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
   292
	 * 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
   293
	 *
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   294
	 * @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
   295
	 * @see #isColorful()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   296
	 */
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   297
	public boolean isColorEnabled() {
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   298
		return COLOR_ENABLED;
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   299
	}
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
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   302
	 * @see #isColorful()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   303
	 * @see #isColorEnabled()
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   304
	 */
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   305
	public void setColorful(boolean colorful) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   306
		this.colorful = colorful;
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   307
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   308
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   309
	public ColorfulPrintWriter(File file) throws FileNotFoundException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   310
		super(file);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   311
		COLOR_ENABLED = true;
31
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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   314
	public ColorfulPrintWriter(OutputStream out) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   315
		super(out);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   316
		COLOR_ENABLED = true;
31
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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   319
	public ColorfulPrintWriter(String fileName) throws FileNotFoundException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   320
		super(fileName);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   321
		COLOR_ENABLED = true;
31
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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   324
	public ColorfulPrintWriter(Writer out) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   325
		super(out);
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   326
		COLOR_ENABLED = true;
31
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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   329
	public ColorfulPrintWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   330
		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
   331
		COLOR_ENABLED = true;
31
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
126
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   334
	/**
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   335
	 * @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
   336
	 * 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
   337
	 * 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
   338
	 * 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
   339
	 */
2357a9d08660 Colors can be definitively turned off in constructor
František Kučera <franta-hg@frantovo.cz>
parents: 59
diff changeset
   340
	public ColorfulPrintWriter(OutputStream out, boolean autoFlush, boolean colorEnabled) {
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   341
		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
   342
		COLOR_ENABLED = colorEnabled;
31
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   343
	}
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   344
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   345
	public ColorfulPrintWriter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   346
		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
   347
		COLOR_ENABLED = true;
31
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
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   350
	public ColorfulPrintWriter(Writer out, boolean autoFlush) {
ef2fdb55e8ec ColorfulPrintWriter: colorz, wow
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   351
		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
   352
		COLOR_ENABLED = true;
31
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
}