diff options
Diffstat (limited to 'src/de/mud')
-rw-r--r-- | src/de/mud/terminal/VDUBuffer.java | 12 | ||||
-rw-r--r-- | src/de/mud/terminal/vt320.java | 49 |
2 files changed, 52 insertions, 9 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]; + } } |