2 * This file is part of lanterna (http://code.google.com/p/lanterna/).
4 * lanterna is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) 2010-2015 Martin
20 package com
.googlecode
.lanterna
.terminal
.swing
;
22 import com
.googlecode
.lanterna
.TextColor
;
23 import java
.awt
.Color
;
26 * This class specifies the palette of colors the terminal will use for the normally available 8 + 1 ANSI colors but
27 * also their 'bright' versions with are normally enabled through bold mode. There are several palettes available, all
28 * based on popular terminal emulators. All colors are defined in the AWT format.
31 @SuppressWarnings("WeakerAccess")
32 public class TerminalEmulatorPalette
{
34 * Values taken from gnome-terminal on Ubuntu
36 public static final TerminalEmulatorPalette GNOME_TERMINAL
=
37 new TerminalEmulatorPalette(
38 new java
.awt
.Color(211, 215, 207),
39 new java
.awt
.Color(238, 238, 236),
40 new java
.awt
.Color(46, 52, 54),
41 new java
.awt
.Color(46, 52, 54),
42 new java
.awt
.Color(85, 87, 83),
43 new java
.awt
.Color(204, 0, 0),
44 new java
.awt
.Color(239, 41, 41),
45 new java
.awt
.Color(78, 154, 6),
46 new java
.awt
.Color(138, 226, 52),
47 new java
.awt
.Color(196, 160, 0),
48 new java
.awt
.Color(252, 233, 79),
49 new java
.awt
.Color(52, 101, 164),
50 new java
.awt
.Color(114, 159, 207),
51 new java
.awt
.Color(117, 80, 123),
52 new java
.awt
.Color(173, 127, 168),
53 new java
.awt
.Color(6, 152, 154),
54 new java
.awt
.Color(52, 226, 226),
55 new java
.awt
.Color(211, 215, 207),
56 new java
.awt
.Color(238, 238, 236));
59 * Values taken from <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">
60 * wikipedia</a>, these are supposed to be the standard VGA palette.
62 public static final TerminalEmulatorPalette STANDARD_VGA
=
63 new TerminalEmulatorPalette(
64 new java
.awt
.Color(170, 170, 170),
65 new java
.awt
.Color(255, 255, 255),
66 new java
.awt
.Color(0, 0, 0),
67 new java
.awt
.Color(0, 0, 0),
68 new java
.awt
.Color(85, 85, 85),
69 new java
.awt
.Color(170, 0, 0),
70 new java
.awt
.Color(255, 85, 85),
71 new java
.awt
.Color(0, 170, 0),
72 new java
.awt
.Color(85, 255, 85),
73 new java
.awt
.Color(170, 85, 0),
74 new java
.awt
.Color(255, 255, 85),
75 new java
.awt
.Color(0, 0, 170),
76 new java
.awt
.Color(85, 85, 255),
77 new java
.awt
.Color(170, 0, 170),
78 new java
.awt
.Color(255, 85, 255),
79 new java
.awt
.Color(0, 170, 170),
80 new java
.awt
.Color(85, 255, 255),
81 new java
.awt
.Color(170, 170, 170),
82 new java
.awt
.Color(255, 255, 255));
85 * Values taken from <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">
86 * wikipedia</a>, these are supposed to be what Windows XP cmd is using.
88 public static final TerminalEmulatorPalette WINDOWS_XP_COMMAND_PROMPT
=
89 new TerminalEmulatorPalette(
90 new java
.awt
.Color(192, 192, 192),
91 new java
.awt
.Color(255, 255, 255),
92 new java
.awt
.Color(0, 0, 0),
93 new java
.awt
.Color(0, 0, 0),
94 new java
.awt
.Color(128, 128, 128),
95 new java
.awt
.Color(128, 0, 0),
96 new java
.awt
.Color(255, 0, 0),
97 new java
.awt
.Color(0, 128, 0),
98 new java
.awt
.Color(0, 255, 0),
99 new java
.awt
.Color(128, 128, 0),
100 new java
.awt
.Color(255, 255, 0),
101 new java
.awt
.Color(0, 0, 128),
102 new java
.awt
.Color(0, 0, 255),
103 new java
.awt
.Color(128, 0, 128),
104 new java
.awt
.Color(255, 0, 255),
105 new java
.awt
.Color(0, 128, 128),
106 new java
.awt
.Color(0, 255, 255),
107 new java
.awt
.Color(192, 192, 192),
108 new java
.awt
.Color(255, 255, 255));
111 * Values taken from <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">
112 * wikipedia</a>, these are supposed to be what terminal.app on MacOSX is using.
114 public static final TerminalEmulatorPalette MAC_OS_X_TERMINAL_APP
=
115 new TerminalEmulatorPalette(
116 new java
.awt
.Color(203, 204, 205),
117 new java
.awt
.Color(233, 235, 235),
118 new java
.awt
.Color(0, 0, 0),
119 new java
.awt
.Color(0, 0, 0),
120 new java
.awt
.Color(129, 131, 131),
121 new java
.awt
.Color(194, 54, 33),
122 new java
.awt
.Color(252,57,31),
123 new java
.awt
.Color(37, 188, 36),
124 new java
.awt
.Color(49, 231, 34),
125 new java
.awt
.Color(173, 173, 39),
126 new java
.awt
.Color(234, 236, 35),
127 new java
.awt
.Color(73, 46, 225),
128 new java
.awt
.Color(88, 51, 255),
129 new java
.awt
.Color(211, 56, 211),
130 new java
.awt
.Color(249, 53, 248),
131 new java
.awt
.Color(51, 187, 200),
132 new java
.awt
.Color(20, 240, 240),
133 new java
.awt
.Color(203, 204, 205),
134 new java
.awt
.Color(233, 235, 235));
137 * Values taken from <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">
138 * wikipedia</a>, these are supposed to be what putty is using.
140 public static final TerminalEmulatorPalette PUTTY
=
141 new TerminalEmulatorPalette(
142 new java
.awt
.Color(187, 187, 187),
143 new java
.awt
.Color(255, 255, 255),
144 new java
.awt
.Color(0, 0, 0),
145 new java
.awt
.Color(0, 0, 0),
146 new java
.awt
.Color(85, 85, 85),
147 new java
.awt
.Color(187, 0, 0),
148 new java
.awt
.Color(255, 85, 85),
149 new java
.awt
.Color(0, 187, 0),
150 new java
.awt
.Color(85, 255, 85),
151 new java
.awt
.Color(187, 187, 0),
152 new java
.awt
.Color(255, 255, 85),
153 new java
.awt
.Color(0, 0, 187),
154 new java
.awt
.Color(85, 85, 255),
155 new java
.awt
.Color(187, 0, 187),
156 new java
.awt
.Color(255, 85, 255),
157 new java
.awt
.Color(0, 187, 187),
158 new java
.awt
.Color(85, 255, 255),
159 new java
.awt
.Color(187, 187, 187),
160 new java
.awt
.Color(255, 255, 255));
163 * Values taken from <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">
164 * wikipedia</a>, these are supposed to be what xterm is using.
166 public static final TerminalEmulatorPalette XTERM
=
167 new TerminalEmulatorPalette(
168 new java
.awt
.Color(229, 229, 229),
169 new java
.awt
.Color(255, 255, 255),
170 new java
.awt
.Color(0, 0, 0),
171 new java
.awt
.Color(0, 0, 0),
172 new java
.awt
.Color(127, 127, 127),
173 new java
.awt
.Color(205, 0, 0),
174 new java
.awt
.Color(255, 0, 0),
175 new java
.awt
.Color(0, 205, 0),
176 new java
.awt
.Color(0, 255, 0),
177 new java
.awt
.Color(205, 205, 0),
178 new java
.awt
.Color(255, 255, 0),
179 new java
.awt
.Color(0, 0, 238),
180 new java
.awt
.Color(92, 92, 255),
181 new java
.awt
.Color(205, 0, 205),
182 new java
.awt
.Color(255, 0, 255),
183 new java
.awt
.Color(0, 205, 205),
184 new java
.awt
.Color(0, 255, 255),
185 new java
.awt
.Color(229, 229, 229),
186 new java
.awt
.Color(255, 255, 255));
189 * Default colors the SwingTerminal is using if you don't specify anything
191 public static final TerminalEmulatorPalette DEFAULT
= GNOME_TERMINAL
;
193 private final Color defaultColor
;
194 private final Color defaultBrightColor
;
195 private final Color defaultBackgroundColor
;
196 private final Color normalBlack
;
197 private final Color brightBlack
;
198 private final Color normalRed
;
199 private final Color brightRed
;
200 private final Color normalGreen
;
201 private final Color brightGreen
;
202 private final Color normalYellow
;
203 private final Color brightYellow
;
204 private final Color normalBlue
;
205 private final Color brightBlue
;
206 private final Color normalMagenta
;
207 private final Color brightMagenta
;
208 private final Color normalCyan
;
209 private final Color brightCyan
;
210 private final Color normalWhite
;
211 private final Color brightWhite
;
214 * Creates a new palette with all colors specified up-front
215 * @param defaultColor Default color which no specific color has been selected
216 * @param defaultBrightColor Default color which no specific color has been selected but bold is enabled
217 * @param defaultBackgroundColor Default color to use for the background when no specific color has been selected
218 * @param normalBlack Color for normal black
219 * @param brightBlack Color for bright black
220 * @param normalRed Color for normal red
221 * @param brightRed Color for bright red
222 * @param normalGreen Color for normal green
223 * @param brightGreen Color for bright green
224 * @param normalYellow Color for normal yellow
225 * @param brightYellow Color for bright yellow
226 * @param normalBlue Color for normal blue
227 * @param brightBlue Color for bright blue
228 * @param normalMagenta Color for normal magenta
229 * @param brightMagenta Color for bright magenta
230 * @param normalCyan Color for normal cyan
231 * @param brightCyan Color for bright cyan
232 * @param normalWhite Color for normal white
233 * @param brightWhite Color for bright white
235 public TerminalEmulatorPalette(
237 Color defaultBrightColor
,
238 Color defaultBackgroundColor
,
255 this.defaultColor
= defaultColor
;
256 this.defaultBrightColor
= defaultBrightColor
;
257 this.defaultBackgroundColor
= defaultBackgroundColor
;
258 this.normalBlack
= normalBlack
;
259 this.brightBlack
= brightBlack
;
260 this.normalRed
= normalRed
;
261 this.brightRed
= brightRed
;
262 this.normalGreen
= normalGreen
;
263 this.brightGreen
= brightGreen
;
264 this.normalYellow
= normalYellow
;
265 this.brightYellow
= brightYellow
;
266 this.normalBlue
= normalBlue
;
267 this.brightBlue
= brightBlue
;
268 this.normalMagenta
= normalMagenta
;
269 this.brightMagenta
= brightMagenta
;
270 this.normalCyan
= normalCyan
;
271 this.brightCyan
= brightCyan
;
272 this.normalWhite
= normalWhite
;
273 this.brightWhite
= brightWhite
;
277 * Returns the AWT color from this palette given an ANSI color and two hints for if we are looking for a background
278 * color and if we want to use the bright version.
279 * @param color Which ANSI color we want to extract
280 * @param isForeground Is this color we extract going to be used as a background color?
281 * @param useBrightTones If true, we should return the bright version of the color
282 * @return AWT color extracted from this palette for the input parameters
284 public Color
get(TextColor
.ANSI color
, boolean isForeground
, boolean useBrightTones
) {
294 return isForeground ? defaultBrightColor
: defaultBackgroundColor
;
298 return brightMagenta
;
316 return isForeground ? defaultColor
: defaultBackgroundColor
;
320 return normalMagenta
;
329 throw new IllegalArgumentException("Unknown text color " + color
);
332 @SuppressWarnings({"SimplifiableIfStatement", "ConstantConditions"})
334 public boolean equals(Object obj
) {
338 if(getClass() != obj
.getClass()) {
341 final TerminalEmulatorPalette other
= (TerminalEmulatorPalette
) obj
;
342 if(this.defaultColor
!= other
.defaultColor
&& (this.defaultColor
== null || !this.defaultColor
.equals(other
.defaultColor
))) {
345 if(this.defaultBrightColor
!= other
.defaultBrightColor
&& (this.defaultBrightColor
== null || !this.defaultBrightColor
.equals(other
.defaultBrightColor
))) {
348 if(this.defaultBackgroundColor
!= other
.defaultBackgroundColor
&& (this.defaultBackgroundColor
== null || !this.defaultBackgroundColor
.equals(other
.defaultBackgroundColor
))) {
351 if(this.normalBlack
!= other
.normalBlack
&& (this.normalBlack
== null || !this.normalBlack
.equals(other
.normalBlack
))) {
354 if(this.brightBlack
!= other
.brightBlack
&& (this.brightBlack
== null || !this.brightBlack
.equals(other
.brightBlack
))) {
357 if(this.normalRed
!= other
.normalRed
&& (this.normalRed
== null || !this.normalRed
.equals(other
.normalRed
))) {
360 if(this.brightRed
!= other
.brightRed
&& (this.brightRed
== null || !this.brightRed
.equals(other
.brightRed
))) {
363 if(this.normalGreen
!= other
.normalGreen
&& (this.normalGreen
== null || !this.normalGreen
.equals(other
.normalGreen
))) {
366 if(this.brightGreen
!= other
.brightGreen
&& (this.brightGreen
== null || !this.brightGreen
.equals(other
.brightGreen
))) {
369 if(this.normalYellow
!= other
.normalYellow
&& (this.normalYellow
== null || !this.normalYellow
.equals(other
.normalYellow
))) {
372 if(this.brightYellow
!= other
.brightYellow
&& (this.brightYellow
== null || !this.brightYellow
.equals(other
.brightYellow
))) {
375 if(this.normalBlue
!= other
.normalBlue
&& (this.normalBlue
== null || !this.normalBlue
.equals(other
.normalBlue
))) {
378 if(this.brightBlue
!= other
.brightBlue
&& (this.brightBlue
== null || !this.brightBlue
.equals(other
.brightBlue
))) {
381 if(this.normalMagenta
!= other
.normalMagenta
&& (this.normalMagenta
== null || !this.normalMagenta
.equals(other
.normalMagenta
))) {
384 if(this.brightMagenta
!= other
.brightMagenta
&& (this.brightMagenta
== null || !this.brightMagenta
.equals(other
.brightMagenta
))) {
387 if(this.normalCyan
!= other
.normalCyan
&& (this.normalCyan
== null || !this.normalCyan
.equals(other
.normalCyan
))) {
390 if(this.brightCyan
!= other
.brightCyan
&& (this.brightCyan
== null || !this.brightCyan
.equals(other
.brightCyan
))) {
393 if(this.normalWhite
!= other
.normalWhite
&& (this.normalWhite
== null || !this.normalWhite
.equals(other
.normalWhite
))) {
396 return !(this.brightWhite
!= other
.brightWhite
&& (this.brightWhite
== null || !this.brightWhite
.equals(other
.brightWhite
)));
399 @SuppressWarnings("ConstantConditions")
401 public int hashCode() {
403 hash
= 47 * hash
+ (this.defaultColor
!= null ?
this.defaultColor
.hashCode() : 0);
404 hash
= 47 * hash
+ (this.defaultBrightColor
!= null ?
this.defaultBrightColor
.hashCode() : 0);
405 hash
= 47 * hash
+ (this.defaultBackgroundColor
!= null ?
this.defaultBackgroundColor
.hashCode() : 0);
406 hash
= 47 * hash
+ (this.normalBlack
!= null ?
this.normalBlack
.hashCode() : 0);
407 hash
= 47 * hash
+ (this.brightBlack
!= null ?
this.brightBlack
.hashCode() : 0);
408 hash
= 47 * hash
+ (this.normalRed
!= null ?
this.normalRed
.hashCode() : 0);
409 hash
= 47 * hash
+ (this.brightRed
!= null ?
this.brightRed
.hashCode() : 0);
410 hash
= 47 * hash
+ (this.normalGreen
!= null ?
this.normalGreen
.hashCode() : 0);
411 hash
= 47 * hash
+ (this.brightGreen
!= null ?
this.brightGreen
.hashCode() : 0);
412 hash
= 47 * hash
+ (this.normalYellow
!= null ?
this.normalYellow
.hashCode() : 0);
413 hash
= 47 * hash
+ (this.brightYellow
!= null ?
this.brightYellow
.hashCode() : 0);
414 hash
= 47 * hash
+ (this.normalBlue
!= null ?
this.normalBlue
.hashCode() : 0);
415 hash
= 47 * hash
+ (this.brightBlue
!= null ?
this.brightBlue
.hashCode() : 0);
416 hash
= 47 * hash
+ (this.normalMagenta
!= null ?
this.normalMagenta
.hashCode() : 0);
417 hash
= 47 * hash
+ (this.brightMagenta
!= null ?
this.brightMagenta
.hashCode() : 0);
418 hash
= 47 * hash
+ (this.normalCyan
!= null ?
this.normalCyan
.hashCode() : 0);
419 hash
= 47 * hash
+ (this.brightCyan
!= null ?
this.brightCyan
.hashCode() : 0);
420 hash
= 47 * hash
+ (this.normalWhite
!= null ?
this.normalWhite
.hashCode() : 0);
421 hash
= 47 * hash
+ (this.brightWhite
!= null ?
this.brightWhite
.hashCode() : 0);
426 public String
toString() {
427 return "SwingTerminalPalette{" +
428 "defaultColor=" + defaultColor
+
429 ", defaultBrightColor=" + defaultBrightColor
+
430 ", defaultBackgroundColor=" + defaultBackgroundColor
+
431 ", normalBlack=" + normalBlack
+
432 ", brightBlack=" + brightBlack
+
433 ", normalRed=" + normalRed
+
434 ", brightRed=" + brightRed
+
435 ", normalGreen=" + normalGreen
+
436 ", brightGreen=" + brightGreen
+
437 ", normalYellow=" + normalYellow
+
438 ", brightYellow=" + brightYellow
+
439 ", normalBlue=" + normalBlue
+
440 ", brightBlue=" + brightBlue
+
441 ", normalMagenta=" + normalMagenta
+
442 ", brightMagenta=" + brightMagenta
+
443 ", normalCyan=" + normalCyan
+
444 ", brightCyan=" + brightCyan
+
445 ", normalWhite=" + normalWhite
+
446 ", brightWhite=" + brightWhite
+ '}';