+ String color(final boolean bold, final Color color,
+ final boolean foreground) {
+ return color(color, foreground, true) +
+ rgbColor(bold, color, foreground);
+ }
+
+ /**
+ * Create a T.416 RGB parameter sequence for a single color change.
+ *
+ * @param bold if true, set bold
+ * @param color one of the Color.WHITE, Color.BLUE, etc. constants
+ * @param foreground if true, this is a foreground color
+ * @return the string to emit to an xterm terminal with RGB support,
+ * e.g. "\033[38;2;RR;GG;BBm"
+ */
+ private String rgbColor(final boolean bold, final Color color,
+ final boolean foreground) {
+ if (doRgbColor == false) {
+ return "";
+ }
+ StringBuilder sb = new StringBuilder("\033[");
+ if (bold) {
+ // Bold implies foreground only
+ sb.append("38;2;");
+ if (color.equals(Color.BLACK)) {
+ sb.append("116;116;116");
+ } else if (color.equals(Color.RED)) {
+ sb.append("252;116;116");
+ } else if (color.equals(Color.GREEN)) {
+ sb.append("116;252;116");
+ } else if (color.equals(Color.YELLOW)) {
+ sb.append("252;252;116");
+ } else if (color.equals(Color.BLUE)) {
+ sb.append("116;116;252");
+ } else if (color.equals(Color.MAGENTA)) {
+ sb.append("252;116;252");
+ } else if (color.equals(Color.CYAN)) {
+ sb.append("116;252;252");
+ } else if (color.equals(Color.WHITE)) {
+ sb.append("252;252;252");
+ }
+ } else {
+ if (foreground) {
+ sb.append("38;2;");
+ } else {
+ sb.append("48;2;");
+ }
+ if (color.equals(Color.BLACK)) {
+ sb.append("0;0;0");
+ } else if (color.equals(Color.RED)) {
+ sb.append("168;0;0");
+ } else if (color.equals(Color.GREEN)) {
+ sb.append("0;168;0");
+ } else if (color.equals(Color.YELLOW)) {
+ sb.append("168;116;0");
+ } else if (color.equals(Color.BLUE)) {
+ sb.append("0;0;168");
+ } else if (color.equals(Color.MAGENTA)) {
+ sb.append("168;0;168");
+ } else if (color.equals(Color.CYAN)) {
+ sb.append("0;168;168");
+ } else if (color.equals(Color.WHITE)) {
+ sb.append("168;168;168");
+ }
+ }
+ sb.append("m");
+ return sb.toString();
+ }
+
+ /**
+ * Create a T.416 RGB parameter sequence for both foreground and
+ * background color change.
+ *
+ * @param bold if true, set bold
+ * @param foreColor one of the Color.WHITE, Color.BLUE, etc. constants
+ * @param backColor one of the Color.WHITE, Color.BLUE, etc. constants
+ * @return the string to emit to an xterm terminal with RGB support,
+ * e.g. "\033[38;2;RR;GG;BB;48;2;RR;GG;BBm"
+ */
+ private String rgbColor(final boolean bold, final Color foreColor,
+ final Color backColor) {
+ if (doRgbColor == false) {
+ return "";
+ }
+
+ return rgbColor(bold, foreColor, true) +
+ rgbColor(false, backColor, false);