aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2008-12-12 18:31:49 +0000
committerKenny Root <kenny@the-b.org>2008-12-12 18:31:49 +0000
commit5d8c2880c73c8d4dada456b43f34f8982992143e (patch)
tree91ae200c3f05ed3b043231bbd037d02a3073b082 /src
parent68d6453fe846e44a22be2ecbaed0b31755f5e9eb (diff)
downloadconnectbot-5d8c2880c73c8d4dada456b43f34f8982992143e.tar.gz
connectbot-5d8c2880c73c8d4dada456b43f34f8982992143e.tar.bz2
connectbot-5d8c2880c73c8d4dada456b43f34f8982992143e.zip
* Support more xterm attributes ESC [90m - 97m and 100m - 107m
* Move onus of color tracking to VDUDisplay implementors * Fix some indentation to match mud.de style * Add color resets to "ESC c" functionality
Diffstat (limited to 'src')
-rw-r--r--src/de/mud/terminal/VDUDisplay.java3
-rw-r--r--src/de/mud/terminal/vt320.java68
-rw-r--r--src/org/connectbot/service/TerminalBridge.java118
3 files changed, 129 insertions, 60 deletions
diff --git a/src/de/mud/terminal/VDUDisplay.java b/src/de/mud/terminal/VDUDisplay.java
index 4323465..bb4a7b8 100644
--- a/src/de/mud/terminal/VDUDisplay.java
+++ b/src/de/mud/terminal/VDUDisplay.java
@@ -34,4 +34,7 @@ public interface VDUDisplay {
public void setVDUBuffer(VDUBuffer buffer);
public VDUBuffer getVDUBuffer();
+
+ public void setColor(int index, int red, int green, int blue);
+ public void resetColors();
}
diff --git a/src/de/mud/terminal/vt320.java b/src/de/mud/terminal/vt320.java
index 147c8e0..3e1b7cc 100644
--- a/src/de/mud/terminal/vt320.java
+++ b/src/de/mud/terminal/vt320.java
@@ -45,9 +45,6 @@ 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
@@ -1078,22 +1075,19 @@ public abstract class vt320 extends VDUBuffer implements VDUInput {
// Define color palette
String[] colorData = osc.split(";");
- String[] rgb = new String[3];
try {
- int colorIndex = Integer.parseInt(colorData[1]) - 16;
+ int colorIndex = Integer.parseInt(colorData[1]);
if ("rgb:".equals(colorData[2].substring(0, 4))) {
- rgb = colorData[2].substring(4).split("/");
+ String[] 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);
+ int red = Integer.parseInt(rgb[0].substring(0, 2), 16) & 0xFF;
+ int green = Integer.parseInt(rgb[1].substring(0, 2), 16) & 0xFF;
+ int blue = Integer.parseInt(rgb[2].substring(0, 2), 16) & 0xFF;
+ display.setColor(colorIndex, red, green, blue);
}
} 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();
+ System.out.println("OSC: invalid color sequence encountered: " + osc);
}
} else
System.out.println("OSC: " + osc);
@@ -1704,6 +1698,7 @@ public abstract class vt320 extends VDUBuffer implements VDUInput {
setMargins(0, rows);
C = R = 0;
_SetCursor(0, 0);
+ display.resetColors();
showCursor(true);
/*FIXME:*/
break;
@@ -2704,9 +2699,9 @@ public abstract class vt320 extends VDUBuffer implements VDUInput {
break;
case 38:
if (DCEvars[i+1] == 5) {
- attributes &= ~COLOR_FG;
- attributes |= ((DCEvars[i+2]) & 0xff) << COLOR_FG_SHIFT;
- i+=2;
+ attributes &= ~COLOR_FG;
+ attributes |= ((DCEvars[i+2]) & 0xff) << COLOR_FG_SHIFT;
+ i+=2;
}
break;
case 39:
@@ -2724,16 +2719,38 @@ public abstract class vt320 extends VDUBuffer implements VDUInput {
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;
+ if (DCEvars[i+1] == 5) {
+ attributes &= ~COLOR_BG;
+ attributes |= (DCEvars[i+2]) << COLOR_BG_SHIFT;
+ i+=2;
+ }
+ break;
case 49:
attributes &= ~COLOR_BG;
break;
-
+ case 90:
+ case 91:
+ case 92:
+ case 93:
+ case 94:
+ case 95:
+ case 96:
+ case 97:
+ attributes &= ~COLOR_FG;
+ attributes |= (DCEvars[i] - 82) << COLOR_FG_SHIFT;
+ break;
+ case 100:
+ case 101:
+ case 102:
+ case 103:
+ case 104:
+ case 105:
+ case 106:
+ case 107:
+ attributes &= ~COLOR_BG;
+ attributes |= (DCEvars[i] - 92) << COLOR_BG_SHIFT;
+ break;
+
default:
System.out.println("ESC [ " + DCEvars[i] + " m unknown...");
break;
@@ -2791,12 +2808,9 @@ public abstract class vt320 extends VDUBuffer implements VDUInput {
setMargins(0, getRows());
C = R = 0;
_SetCursor(0, 0);
+ display.resetColors();
showCursor(true);
/*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 2dc1b27..2e46628 100644
--- a/src/org/connectbot/service/TerminalBridge.java
+++ b/src/org/connectbot/service/TerminalBridge.java
@@ -91,25 +91,8 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
private List<PortForwardBean> portForwards = new LinkedList<PortForwardBean>();
- 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 int color[];
+
public final static int COLOR_FG_STD = 7;
public final static int COLOR_BG_STD = 0;
@@ -292,6 +275,7 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
};
buffer.setBufferSize(scrollback);
+ resetColors();
buffer.setDisplay(this);
// TODO Change this when hosts are beans as well
@@ -1026,22 +1010,12 @@ 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 = (currAttr & VDUBuffer.COLOR_FG) >> VDUBuffer.COLOR_FG_SHIFT;
- if (fg < 16)
- fg = color[fg];
- else
- fg = ((vt320) buffer).getColor(fg - 16);
- }
+ if ((currAttr & VDUBuffer.COLOR_FG) != 0)
+ fg = color[(currAttr & VDUBuffer.COLOR_FG) >> VDUBuffer.COLOR_FG_SHIFT];
// check if background color attribute is set
- 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);
- }
+ if ((currAttr & VDUBuffer.COLOR_BG) != 0)
+ bg = color[(currAttr & VDUBuffer.COLOR_BG) >> VDUBuffer.COLOR_BG_SHIFT];
// support character inversion by swapping background and foreground color
if ((currAttr & VDUBuffer.INVERT) != 0) {
@@ -1346,4 +1320,82 @@ public class TerminalBridge implements VDUDisplay, OnKeyListener, InteractiveCal
public boolean isDisconnected() {
return disconnected;
}
+
+ /* (non-Javadoc)
+ * @see de.mud.terminal.VDUDisplay#setColor(byte, byte, byte, byte)
+ */
+ public void setColor(int index, int red, int green, int blue) {
+ // Don't allow the system colors to be overwritten for now. May violate specs.
+ if (index < color.length && index >= 16)
+ color[index] = 0xff000000 | red << 16 | green << 8 | blue;
+ }
+
+ public void resetColors() {
+ color = new int[] {
+ 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
+ 0xff000000, 0xff00005f, 0xff000087, 0xff0000af, 0xff0000d7,
+ 0xff0000ff, 0xff005f00, 0xff005f5f, 0xff005f87, 0xff005faf,
+ 0xff005fd7, 0xff005fff, 0xff008700, 0xff00875f, 0xff008787,
+ 0xff0087af, 0xff0087d7, 0xff0087ff, 0xff00af00, 0xff00af5f,
+ 0xff00af87, 0xff00afaf, 0xff00afd7, 0xff00afff, 0xff00d700,
+ 0xff00d75f, 0xff00d787, 0xff00d7af, 0xff00d7d7, 0xff00d7ff,
+ 0xff00ff00, 0xff00ff5f, 0xff00ff87, 0xff00ffaf, 0xff00ffd7,
+ 0xff00ffff, 0xff5f0000, 0xff5f005f, 0xff5f0087, 0xff5f00af,
+ 0xff5f00d7, 0xff5f00ff, 0xff5f5f00, 0xff5f5f5f, 0xff5f5f87,
+ 0xff5f5faf, 0xff5f5fd7, 0xff5f5fff, 0xff5f8700, 0xff5f875f,
+ 0xff5f8787, 0xff5f87af, 0xff5f87d7, 0xff5f87ff, 0xff5faf00,
+ 0xff5faf5f, 0xff5faf87, 0xff5fafaf, 0xff5fafd7, 0xff5fafff,
+ 0xff5fd700, 0xff5fd75f, 0xff5fd787, 0xff5fd7af, 0xff5fd7d7,
+ 0xff5fd7ff, 0xff5fff00, 0xff5fff5f, 0xff5fff87, 0xff5fffaf,
+ 0xff5fffd7, 0xff5fffff, 0xff870000, 0xff87005f, 0xff870087,
+ 0xff8700af, 0xff8700d7, 0xff8700ff, 0xff875f00, 0xff875f5f,
+ 0xff875f87, 0xff875faf, 0xff875fd7, 0xff875fff, 0xff878700,
+ 0xff87875f, 0xff878787, 0xff8787af, 0xff8787d7, 0xff8787ff,
+ 0xff87af00, 0xff87af5f, 0xff87af87, 0xff87afaf, 0xff87afd7,
+ 0xff87afff, 0xff87d700, 0xff87d75f, 0xff87d787, 0xff87d7af,
+ 0xff87d7d7, 0xff87d7ff, 0xff87ff00, 0xff87ff5f, 0xff87ff87,
+ 0xff87ffaf, 0xff87ffd7, 0xff87ffff, 0xffaf0000, 0xffaf005f,
+ 0xffaf0087, 0xffaf00af, 0xffaf00d7, 0xffaf00ff, 0xffaf5f00,
+ 0xffaf5f5f, 0xffaf5f87, 0xffaf5faf, 0xffaf5fd7, 0xffaf5fff,
+ 0xffaf8700, 0xffaf875f, 0xffaf8787, 0xffaf87af, 0xffaf87d7,
+ 0xffaf87ff, 0xffafaf00, 0xffafaf5f, 0xffafaf87, 0xffafafaf,
+ 0xffafafd7, 0xffafafff, 0xffafd700, 0xffafd75f, 0xffafd787,
+ 0xffafd7af, 0xffafd7d7, 0xffafd7ff, 0xffafff00, 0xffafff5f,
+ 0xffafff87, 0xffafffaf, 0xffafffd7, 0xffafffff, 0xffd70000,
+ 0xffd7005f, 0xffd70087, 0xffd700af, 0xffd700d7, 0xffd700ff,
+ 0xffd75f00, 0xffd75f5f, 0xffd75f87, 0xffd75faf, 0xffd75fd7,
+ 0xffd75fff, 0xffd78700, 0xffd7875f, 0xffd78787, 0xffd787af,
+ 0xffd787d7, 0xffd787ff, 0xffd7af00, 0xffd7af5f, 0xffd7af87,
+ 0xffd7afaf, 0xffd7afd7, 0xffd7afff, 0xffd7d700, 0xffd7d75f,
+ 0xffd7d787, 0xffd7d7af, 0xffd7d7d7, 0xffd7d7ff, 0xffd7ff00,
+ 0xffd7ff5f, 0xffd7ff87, 0xffd7ffaf, 0xffd7ffd7, 0xffd7ffff,
+ 0xffff0000, 0xffff005f, 0xffff0087, 0xffff00af, 0xffff00d7,
+ 0xffff00ff, 0xffff5f00, 0xffff5f5f, 0xffff5f87, 0xffff5faf,
+ 0xffff5fd7, 0xffff5fff, 0xffff8700, 0xffff875f, 0xffff8787,
+ 0xffff87af, 0xffff87d7, 0xffff87ff, 0xffffaf00, 0xffffaf5f,
+ 0xffffaf87, 0xffffafaf, 0xffffafd7, 0xffffafff, 0xffffd700,
+ 0xffffd75f, 0xffffd787, 0xffffd7af, 0xffffd7d7, 0xffffd7ff,
+ 0xffffff00, 0xffffff5f, 0xffffff87, 0xffffffaf, 0xffffffd7,
+ 0xffffffff, 0xff080808, 0xff121212, 0xff1c1c1c, 0xff262626,
+ 0xff303030, 0xff3a3a3a, 0xff444444, 0xff4e4e4e, 0xff585858,
+ 0xff626262, 0xff6c6c6c, 0xff767676, 0xff808080, 0xff8a8a8a,
+ 0xff949494, 0xff9e9e9e, 0xffa8a8a8, 0xffb2b2b2, 0xffbcbcbc,
+ 0xffc6c6c6, 0xffd0d0d0, 0xffdadada, 0xffe4e4e4, 0xffeeeeee,
+ };
+ }
}