aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2008-12-12 00:06:35 +0000
committerKenny Root <kenny@the-b.org>2008-12-12 00:06:35 +0000
commit68d6453fe846e44a22be2ecbaed0b31755f5e9eb (patch)
treef20a1b335d6425c5ae365763378cb8a77dfd8dc0 /src
parent7cf1f4248c9a1600a0a2fa5f842c123c72be2a51 (diff)
downloadconnectbot-68d6453fe846e44a22be2ecbaed0b31755f5e9eb.tar.gz
connectbot-68d6453fe846e44a22be2ecbaed0b31755f5e9eb.tar.bz2
connectbot-68d6453fe846e44a22be2ecbaed0b31755f5e9eb.zip
Add in xterm-style 256 color support
Diffstat (limited to 'src')
-rw-r--r--src/de/mud/terminal/VDUBuffer.java12
-rw-r--r--src/de/mud/terminal/vt320.java49
-rw-r--r--src/org/connectbot/service/TerminalBridge.java56
3 files changed, 87 insertions, 30 deletions
diff --git a/src/de/mud/terminal/VDUBuffer.java b/src/de/mud/terminal/VDUBuffer.java
index 35dbb49..445d9f9 100644
--- a/src/de/mud/terminal/VDUBuffer.java
+++ b/src/de/mud/terminal/VDUBuffer.java
@@ -1,7 +1,7 @@
/*
* This file is part of "JTA - Telnet/SSH for the JAVA(tm) platform".
*
- * (c) Matthias L. Jugel, Marcus Mei§ner 1996-2005. All Rights Reserved.
+ * (c) Matthias L. Jugel, Marcus Mei�ner 1996-2005. All Rights Reserved.
*
* Please visit http://javatelnet.org/ for updates and contact.
*
@@ -32,7 +32,7 @@ import java.util.Arrays;
* all methods to manipulate the buffer that stores characters and their
* attributes as well as the regions displayed.
*
- * @author Matthias L. Jugel, Marcus Mei§ner
+ * @author Matthias L. Jugel, Marcus Mei�ner
* @version $Id: VDUBuffer.java 503 2005-10-24 07:34:13Z marcus $
*/
public class VDUBuffer {
@@ -81,13 +81,13 @@ public class VDUBuffer {
/** how much to left shift the foreground color */
public final static int COLOR_FG_SHIFT = 5;
/** how much to left shift the background color */
- public final static int COLOR_BG_SHIFT = 9;
+ public final static int COLOR_BG_SHIFT = 13;
/** color mask */
- public final static int COLOR = 0x1fe0;
+ public final static int COLOR = 0x1fffe0;
/** foreground color mask */
- public final static int COLOR_FG = 0x1e0;
+ public final static int COLOR_FG = 0x1fe0;
/** background color mask */
- public final static int COLOR_BG = 0x1e00;
+ public final static int COLOR_BG = 0x1fe000;
/**
* Create a new video display buffer with the passed width and height in
diff --git a/src/de/mud/terminal/vt320.java b/src/de/mud/terminal/vt320.java
index bf8e392..147c8e0 100644
--- a/src/de/mud/terminal/vt320.java
+++ b/src/de/mud/terminal/vt320.java
@@ -46,6 +46,9 @@ public abstract class vt320 extends VDUBuffer implements VDUInput {
/** the debug level */
private final static int debug = 0;
+ // Color palette for xterm 256-color
+ private int[] colorPalette = new int[240];
+
/**
* Write an answer back to the remote host. This is needed to be able to
* send terminal answers requests like status and type information.
@@ -1071,7 +1074,29 @@ public abstract class vt320 extends VDUBuffer implements VDUInput {
}
private void handle_osc(String osc) {
- System.out.println("OSC: " + osc);
+ if (osc.substring(0, 2).equals("4;")) {
+ // Define color palette
+ String[] colorData = osc.split(";");
+
+ String[] rgb = new String[3];
+ try {
+ int colorIndex = Integer.parseInt(colorData[1]) - 16;
+
+ if ("rgb:".equals(colorData[2].substring(0, 4))) {
+ rgb = colorData[2].substring(4).split("/");
+
+ colorPalette[colorIndex] = 0xFF000000
+ | (Integer.parseInt(rgb[0].substring(0, 2), 16) & 0xFF) << 16
+ | (Integer.parseInt(rgb[1].substring(0, 2), 16) & 0xFF) << 8
+ | (Integer.parseInt(rgb[2].substring(0, 2), 16) & 0xFF);
+ }
+ } catch (Exception e) {
+ System.out.println("OSC: invalid color sequence encountered");
+ System.out.println(String.format("R:%s, G:%s, B:%s, remain:%s", rgb[0], rgb[1], rgb[2], colorData[2].substring(4)));
+ e.printStackTrace();
+ }
+ } else
+ System.out.println("OSC: " + osc);
}
private final static char unimap[] = {
@@ -2675,7 +2700,14 @@ public abstract class vt320 extends VDUBuffer implements VDUInput {
case 36:
case 37:
attributes &= ~COLOR_FG;
- attributes |= ((DCEvars[i] - 30) + 1) << COLOR_FG_SHIFT;
+ attributes |= (DCEvars[i] - 30) << COLOR_FG_SHIFT;
+ break;
+ case 38:
+ if (DCEvars[i+1] == 5) {
+ attributes &= ~COLOR_FG;
+ attributes |= ((DCEvars[i+2]) & 0xff) << COLOR_FG_SHIFT;
+ i+=2;
+ }
break;
case 39:
attributes &= ~COLOR_FG;
@@ -2689,8 +2721,15 @@ public abstract class vt320 extends VDUBuffer implements VDUInput {
case 46:
case 47:
attributes &= ~COLOR_BG;
- attributes |= ((DCEvars[i] - 40) + 1) << COLOR_BG_SHIFT;
+ attributes |= (DCEvars[i] - 40) << COLOR_BG_SHIFT;
break;
+ case 48:
+ if (DCEvars[i+1] == 5) {
+ attributes &= ~COLOR_BG;
+ attributes |= (DCEvars[i+2]) << COLOR_BG_SHIFT;
+ i+=2;
+ }
+ break;
case 49:
attributes &= ~COLOR_BG;
break;
@@ -2756,4 +2795,8 @@ public abstract class vt320 extends VDUBuffer implements VDUInput {
/*FIXME:*/
term_state = TSTATE_DATA;
}
+
+ public int getColor(int colorIndex) {
+ return colorPalette[colorIndex];
+ }
}
diff --git a/src/org/connectbot/service/TerminalBridge.java b/src/org/connectbot/service/TerminalBridge.java
index bbd811e..2dc1b27 100644
--- a/src/org/connectbot/service/TerminalBridge.java
+++ b/src/org/connectbot/service/TerminalBridge.java
@@ -89,21 +89,27 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
protected final static int AUTH_TRIES = 20;
- private int darken(int color) {
- return Color.argb(0xFF,
- (int)(Color.red(color) * 0.8),
- (int)(Color.green(color) * 0.8),
- (int)(Color.blue(color) * 0.8)
- );
- }
-
private List<PortForwardBean> portForwards = new LinkedList<PortForwardBean>();
- public int color[] = { Color.BLACK, Color.RED, Color.GREEN, Color.YELLOW,
- Color.BLUE, Color.MAGENTA, Color.CYAN, Color.WHITE, };
-
- private int darkerColor[] = new int[color.length];
-
+ public int color[] = {
+ 0xff000000, // black
+ 0xffcc0000, // red
+ 0xff00cc00, // green
+ 0xffcccc00, // brown
+ 0xff0000cc, // blue
+ 0xffcc00cc, // purple
+ 0xff00cccc, // cyan
+ 0xffcccccc, // light grey
+ 0xff444444, // dark grey
+ 0xffff4444, // light red
+ 0xff44ff44, // light green
+ 0xffffff44, // yellow
+ 0xff4444ff, // light blue
+ 0xffff44ff, // light purple
+ 0xff44ffff, // light cyan
+ 0xffffffff, // white
+ };
+
public final static int COLOR_FG_STD = 7;
public final static int COLOR_BG_STD = 0;
@@ -263,10 +269,6 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
localOutput = new LinkedList<String>();
setFontSize(DEFAULT_FONT_SIZE);
-
- // prepare our "darker" colors
- for(int i = 0; i < color.length; i++)
- darkerColor[i] = darken(color[i]);
// create terminal buffer and handle outgoing data
// this is probably status reply information
@@ -1024,12 +1026,22 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
bg = color[COLOR_BG_STD];
// check if foreground color attribute is set
- if((currAttr & VDUBuffer.COLOR_FG) != 0)
- fg = color[((currAttr & VDUBuffer.COLOR_FG) >> VDUBuffer.COLOR_FG_SHIFT) - 1];
+ if ((currAttr & VDUBuffer.COLOR_FG) != 0) {
+ fg = (currAttr & VDUBuffer.COLOR_FG) >> VDUBuffer.COLOR_FG_SHIFT;
+ if (fg < 16)
+ fg = color[fg];
+ else
+ fg = ((vt320) buffer).getColor(fg - 16);
+ }
// check if background color attribute is set
- if((currAttr & VDUBuffer.COLOR_BG) != 0)
- bg = darkerColor[((currAttr & VDUBuffer.COLOR_BG) >> VDUBuffer.COLOR_BG_SHIFT) - 1];
+ if ((currAttr & VDUBuffer.COLOR_BG) != 0) {
+ bg = (currAttr & VDUBuffer.COLOR_BG) >> VDUBuffer.COLOR_BG_SHIFT;
+ if (bg < 16)
+ bg = color[bg];
+ else
+ bg = ((vt320) buffer).getColor(bg - 16);
+ }
// support character inversion by swapping background and foreground color
if ((currAttr & VDUBuffer.INVERT) != 0) {
@@ -1039,8 +1051,10 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
}
// if black-on-black, try correcting to grey
+ /*
if(fg == Color.BLACK && bg == Color.BLACK)
fg = Color.GRAY;
+ */
// correctly set bold and underlined attributes if requested
defaultPaint.setFakeBoldText((currAttr & VDUBuffer.BOLD) != 0);