2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 package jexer
.tterminal
;
31 import java
.awt
.Graphics2D
;
32 import java
.awt
.image
.BufferedImage
;
33 import java
.io
.BufferedOutputStream
;
34 import java
.io
.CharArrayWriter
;
35 import java
.io
.InputStream
;
36 import java
.io
.InputStreamReader
;
37 import java
.io
.IOException
;
38 import java
.io
.OutputStream
;
39 import java
.io
.OutputStreamWriter
;
40 import java
.io
.PrintWriter
;
41 import java
.io
.Reader
;
42 import java
.io
.UnsupportedEncodingException
;
43 import java
.io
.Writer
;
44 import java
.util
.ArrayList
;
45 import java
.util
.Collections
;
46 import java
.util
.HashMap
;
47 import java
.util
.List
;
49 import jexer
.TKeypress
;
50 import jexer
.backend
.GlyphMaker
;
51 import jexer
.bits
.Color
;
52 import jexer
.bits
.Cell
;
53 import jexer
.bits
.CellAttributes
;
54 import jexer
.bits
.StringUtils
;
55 import jexer
.event
.TInputEvent
;
56 import jexer
.event
.TKeypressEvent
;
57 import jexer
.event
.TMouseEvent
;
58 import jexer
.io
.ReadTimeoutException
;
59 import jexer
.io
.TimeoutInputStream
;
60 import static jexer
.TKeypress
.*;
63 * This implements a complex ECMA-48/ISO 6429/ANSI X3.64 type console,
64 * including a scrollback buffer.
67 * It currently implements VT100, VT102, VT220, and XTERM with the following
71 * - The vttest scenario for VT220 8-bit controls (11.1.2.3) reports a
72 * failure with XTERM. This is due to vttest failing to decode the UTF-8
76 * - Smooth scrolling, printing, keyboard locking, keyboard leds, and tests
77 * from VT100 are not supported.
80 * - User-defined keys (DECUDK), downloadable fonts (DECDLD), and VT100/ANSI
81 * compatibility mode (DECSCL) from VT220 are not supported. (Also,
82 * because DECSCL is not supported, it will fail the last part of the
83 * vttest "Test of VT52 mode" if DeviceType is set to VT220.)
86 * - Numeric/application keys from the number pad are not supported because
87 * they are not exposed from the TKeypress API.
90 * - VT52 HOLD SCREEN mode is not supported.
93 * - In VT52 graphics mode, the 3/, 5/, and 7/ characters (fraction
94 * numerators) are not rendered correctly.
97 * - All data meant for the 'printer' (CSI Pc ? i) is discarded.
99 public class ECMA48
implements Runnable
{
101 // ------------------------------------------------------------------------
102 // Constants --------------------------------------------------------------
103 // ------------------------------------------------------------------------
106 * The emulator can emulate several kinds of terminals.
108 public enum DeviceType
{
110 * DEC VT100 but also including the three VT102 functions.
131 * Parser character scan states.
133 private enum ScanState
{
149 VT52_DIRECT_CURSOR_ADDRESS
153 * The selected number pad mode (DECKPAM, DECKPNM). We record this, but
154 * can't really use it in keypress() because we do not see number pad
155 * events from TKeypress.
157 private enum KeypadMode
{
163 * Arrow keys can emit three different sequences (DECCKM or VT52
166 private enum ArrowKeyMode
{
173 * Available character sets for GL, GR, G0, G1, G2, G3.
175 private enum CharacterSet
{
196 * Single-shift states used by the C1 control characters SS2 (0x8E) and
199 private enum Singleshift
{
206 * VT220+ lockshift states.
208 private enum LockshiftMode
{
218 * XTERM mouse reporting protocols.
220 public enum MouseProtocol
{
229 * XTERM mouse reporting encodings.
231 private enum MouseEncoding
{
237 // ------------------------------------------------------------------------
238 // Variables --------------------------------------------------------------
239 // ------------------------------------------------------------------------
242 * The enclosing listening object.
244 private DisplayListener displayListener
;
247 * When true, the reader thread is expected to exit.
249 private volatile boolean stopReaderThread
= false;
254 private Thread readerThread
= null;
257 * The type of emulator to be.
259 private DeviceType type
= DeviceType
.VT102
;
262 * The scrollback buffer characters + attributes.
264 private volatile ArrayList
<DisplayLine
> scrollback
;
267 * The raw display buffer characters + attributes.
269 private volatile ArrayList
<DisplayLine
> display
;
272 * The maximum number of lines in the scrollback buffer.
274 private int maxScrollback
= 10000;
277 * The terminal's input. For type == XTERM, this is an InputStreamReader
278 * with UTF-8 encoding.
280 private Reader input
;
283 * The terminal's raw InputStream. This is used for type != XTERM.
285 private volatile TimeoutInputStream inputStream
;
288 * The terminal's output. For type == XTERM, this wraps an
289 * OutputStreamWriter with UTF-8 encoding.
291 private Writer output
;
294 * The terminal's raw OutputStream. This is used for type != XTERM.
296 private OutputStream outputStream
;
299 * Current scanning state.
301 private ScanState scanState
;
304 * Which mouse protocol is active.
306 private MouseProtocol mouseProtocol
= MouseProtocol
.OFF
;
309 * Which mouse encoding is active.
311 private MouseEncoding mouseEncoding
= MouseEncoding
.X10
;
314 * A terminal may request that the mouse pointer be hidden using a
315 * Privacy Message containing either "hideMousePointer" or
316 * "showMousePointer". This is currently only used within Jexer by
317 * TTerminalWindow so that only the bottom-most instance of nested
318 * Jexer's draws the mouse within its application window.
320 private boolean hideMousePointer
= false;
323 * Physical display width. We start at 80x24, but the user can resize us
329 * Physical display height. We start at 80x24, but the user can resize
335 * Top margin of the scrolling region.
337 private int scrollRegionTop
;
340 * Bottom margin of the scrolling region.
342 private int scrollRegionBottom
;
345 * Right margin column number. This can be selected by the remote side
346 * to be 80/132 (rightMargin values 79/131), or it can be (width - 1).
348 private int rightMargin
;
351 * Last character printed.
356 * VT100-style line wrapping: a character is placed in column 80 (or
357 * 132), but the line does NOT wrap until another character is written to
358 * column 1 of the next line, after which the cursor moves to column 2.
360 private boolean wrapLineFlag
;
363 * VT220 single shift flag.
365 private Singleshift singleshift
= Singleshift
.NONE
;
368 * true = insert characters, false = overwrite.
370 private boolean insertMode
= false;
373 * VT52 mode as selected by DECANM. True means VT52, false means
374 * ANSI. Default is ANSI.
376 private boolean vt52Mode
= false;
379 * Visible cursor (DECTCEM).
381 private boolean cursorVisible
= true;
384 * Screen title as set by the xterm OSC sequence. Lots of applications
385 * send a screenTitle regardless of whether it is an xterm client or not.
387 private String screenTitle
= "";
390 * Parameter characters being collected.
392 private List
<Integer
> csiParams
;
395 * Non-csi collect buffer.
397 private StringBuilder collectBuffer
;
400 * When true, use the G1 character set.
402 private boolean shiftOut
= false;
405 * Horizontal tab stop locations.
407 private List
<Integer
> tabStops
;
410 * S8C1T. True means 8bit controls, false means 7bit controls.
412 private boolean s8c1t
= false;
415 * Printer mode. True means send all output to printer, which discards
418 private boolean printerControllerMode
= false;
421 * LMN line mode. If true, linefeed() puts the cursor on the first
422 * column of the next line. If false, linefeed() puts the cursor one
423 * line down on the current line. The default is false.
425 private boolean newLineMode
= false;
428 * Whether arrow keys send ANSI, VT100, or VT52 sequences.
430 private ArrowKeyMode arrowKeyMode
;
433 * Whether number pad keys send VT100 or VT52, application or numeric
436 @SuppressWarnings("unused")
437 private KeypadMode keypadMode
;
440 * When true, the terminal is in 132-column mode (DECCOLM).
442 private boolean columns132
= false;
445 * true = reverse video. Set by DECSCNM.
447 private boolean reverseVideo
= false;
450 * false = echo characters locally.
452 private boolean fullDuplex
= true;
455 * The current terminal state.
457 private SaveableState currentState
;
460 * The last saved terminal state.
462 private SaveableState savedState
;
465 * The 88- or 256-color support RGB colors.
467 private List
<Integer
> colors88
;
470 * Sixel collection buffer.
472 private StringBuilder sixelParseBuffer
;
475 * The width of a character cell in pixels.
477 private int textWidth
= 16;
480 * The height of a character cell in pixels.
482 private int textHeight
= 20;
485 * The last used height of a character cell in pixels, only used for
488 private int lastTextHeight
= -1;
491 * The glyph drawer for full-width chars.
493 private GlyphMaker glyphMaker
= null;
496 * Input queue for keystrokes and mouse events to send to the remote
499 private ArrayList
<TInputEvent
> userQueue
= new ArrayList
<TInputEvent
>();
502 * DECSC/DECRC save/restore a subset of the total state. This class
503 * encapsulates those specific flags/modes.
505 private class SaveableState
{
508 * When true, cursor positions are relative to the scrolling region.
510 public boolean originMode
= false;
513 * The current editing X position.
515 public int cursorX
= 0;
518 * The current editing Y position.
520 public int cursorY
= 0;
523 * Which character set is currently selected in G0.
525 public CharacterSet g0Charset
= CharacterSet
.US
;
528 * Which character set is currently selected in G1.
530 public CharacterSet g1Charset
= CharacterSet
.DRAWING
;
533 * Which character set is currently selected in G2.
535 public CharacterSet g2Charset
= CharacterSet
.US
;
538 * Which character set is currently selected in G3.
540 public CharacterSet g3Charset
= CharacterSet
.US
;
543 * Which character set is currently selected in GR.
545 public CharacterSet grCharset
= CharacterSet
.DRAWING
;
548 * The current drawing attributes.
550 public CellAttributes attr
;
555 public LockshiftMode glLockshift
= LockshiftMode
.NONE
;
560 public LockshiftMode grLockshift
= LockshiftMode
.NONE
;
565 public boolean lineWrap
= true;
570 public void reset() {
574 g0Charset
= CharacterSet
.US
;
575 g1Charset
= CharacterSet
.DRAWING
;
576 g2Charset
= CharacterSet
.US
;
577 g3Charset
= CharacterSet
.US
;
578 grCharset
= CharacterSet
.DRAWING
;
579 attr
= new CellAttributes();
580 glLockshift
= LockshiftMode
.NONE
;
581 grLockshift
= LockshiftMode
.NONE
;
586 * Copy attributes from another instance.
588 * @param that the other instance to match
590 public void setTo(final SaveableState that
) {
591 this.originMode
= that
.originMode
;
592 this.cursorX
= that
.cursorX
;
593 this.cursorY
= that
.cursorY
;
594 this.g0Charset
= that
.g0Charset
;
595 this.g1Charset
= that
.g1Charset
;
596 this.g2Charset
= that
.g2Charset
;
597 this.g3Charset
= that
.g3Charset
;
598 this.grCharset
= that
.grCharset
;
599 this.attr
= new CellAttributes();
600 this.attr
.setTo(that
.attr
);
601 this.glLockshift
= that
.glLockshift
;
602 this.grLockshift
= that
.grLockshift
;
603 this.lineWrap
= that
.lineWrap
;
607 * Public constructor.
609 public SaveableState() {
614 // ------------------------------------------------------------------------
615 // Constructors -----------------------------------------------------------
616 // ------------------------------------------------------------------------
619 * Public constructor.
621 * @param type one of the DeviceType constants to select VT100, VT102,
623 * @param inputStream an InputStream connected to the remote side. For
624 * type == XTERM, inputStream is converted to a Reader with UTF-8
626 * @param outputStream an OutputStream connected to the remote user. For
627 * type == XTERM, outputStream is converted to a Writer with UTF-8
629 * @param displayListener a callback to the outer display, or null for
630 * default VT100 behavior
631 * @throws UnsupportedEncodingException if an exception is thrown when
632 * creating the InputStreamReader
634 public ECMA48(final DeviceType type
, final InputStream inputStream
,
635 final OutputStream outputStream
, final DisplayListener displayListener
)
636 throws UnsupportedEncodingException
{
638 assert (inputStream
!= null);
639 assert (outputStream
!= null);
641 csiParams
= new ArrayList
<Integer
>();
642 tabStops
= new ArrayList
<Integer
>();
643 scrollback
= new ArrayList
<DisplayLine
>();
644 display
= new ArrayList
<DisplayLine
>();
647 if (inputStream
instanceof TimeoutInputStream
) {
648 this.inputStream
= (TimeoutInputStream
)inputStream
;
650 this.inputStream
= new TimeoutInputStream(inputStream
, 2000);
652 if (type
== DeviceType
.XTERM
) {
653 this.input
= new InputStreamReader(this.inputStream
, "UTF-8");
654 this.output
= new OutputStreamWriter(new
655 BufferedOutputStream(outputStream
), "UTF-8");
656 this.outputStream
= null;
659 this.outputStream
= new BufferedOutputStream(outputStream
);
661 this.displayListener
= displayListener
;
664 for (int i
= 0; i
< height
; i
++) {
665 display
.add(new DisplayLine(currentState
.attr
));
668 // Spin up the input reader
669 readerThread
= new Thread(this);
670 readerThread
.start();
673 // ------------------------------------------------------------------------
674 // Runnable ---------------------------------------------------------------
675 // ------------------------------------------------------------------------
678 * Read function runs on a separate thread.
680 public final void run() {
681 boolean utf8
= false;
682 boolean done
= false;
684 if (type
== DeviceType
.XTERM
) {
688 // available() will often return > 1, so we need to read in chunks to
690 char [] readBufferUTF8
= null;
691 byte [] readBuffer
= null;
693 readBufferUTF8
= new char[2048];
695 readBuffer
= new byte[2048];
698 while (!done
&& !stopReaderThread
) {
699 synchronized (userQueue
) {
700 while (userQueue
.size() > 0) {
701 handleUserEvent(userQueue
.remove(0));
706 int n
= inputStream
.available();
708 // System.err.printf("available() %d\n", n); System.err.flush();
710 if (readBufferUTF8
.length
< n
) {
711 // The buffer wasn't big enough, make it huger
712 int newSizeHalf
= Math
.max(readBufferUTF8
.length
,
715 readBufferUTF8
= new char[newSizeHalf
* 2];
718 if (readBuffer
.length
< n
) {
719 // The buffer wasn't big enough, make it huger
720 int newSizeHalf
= Math
.max(readBuffer
.length
, n
);
721 readBuffer
= new byte[newSizeHalf
* 2];
727 } catch (InterruptedException e
) {
736 rc
= input
.read(readBufferUTF8
, 0,
737 readBufferUTF8
.length
);
739 rc
= inputStream
.read(readBuffer
, 0,
742 } catch (ReadTimeoutException e
) {
746 // System.err.printf("read() %d\n", rc); System.err.flush();
751 // Don't step on UI events
752 synchronized (this) {
753 for (int i
= 0; i
< rc
; i
++) {
756 ch
= readBufferUTF8
[i
];
764 // Permit my enclosing UI to know that I updated.
765 if (displayListener
!= null) {
766 displayListener
.displayChanged();
769 // System.err.println("end while loop"); System.err.flush();
770 } catch (IOException e
) {
773 // This is an unusual case. We want to see the stack trace,
774 // but it is related to the spawned process rather than the
775 // actual UI. We will generate the stack trace, and consume
776 // it as though it was emitted by the shell.
777 CharArrayWriter writer
= new CharArrayWriter();
778 // Send a ST and RIS to clear the emulator state.
780 writer
.write("\033\\\033c");
781 writer
.write("\n-----------------------------------\n");
782 e
.printStackTrace(new PrintWriter(writer
));
783 writer
.write("\n-----------------------------------\n");
784 } catch (IOException e2
) {
787 char [] stackTrace
= writer
.toCharArray();
788 for (int i
= 0; i
< stackTrace
.length
; i
++) {
789 if (stackTrace
[i
] == '\n') {
792 consume(stackTrace
[i
]);
796 } // while ((done == false) && (stopReaderThread == false))
798 // Let the rest of the world know that I am done.
799 stopReaderThread
= true;
802 inputStream
.cancelRead();
805 } catch (IOException e
) {
811 } catch (IOException e
) {
815 // Permit my enclosing UI to know that I updated.
816 if (displayListener
!= null) {
817 displayListener
.displayChanged();
820 // System.err.println("*** run() exiting..."); System.err.flush();
823 // ------------------------------------------------------------------------
824 // ECMA48 -----------------------------------------------------------------
825 // ------------------------------------------------------------------------
828 * Process keyboard and mouse events from the user.
830 * @param event the input event to consume
832 private void handleUserEvent(final TInputEvent event
) {
833 if (event
instanceof TKeypressEvent
) {
834 keypress(((TKeypressEvent
) event
).getKey());
836 if (event
instanceof TMouseEvent
) {
837 mouse((TMouseEvent
) event
);
842 * Add a keyboard and mouse event from the user to the queue.
844 * @param event the input event to consume
846 public void addUserEvent(final TInputEvent event
) {
847 synchronized (userQueue
) {
848 userQueue
.add(event
);
853 * Return the proper primary Device Attributes string.
855 * @return string to send to remote side that is appropriate for the
858 private String
deviceTypeResponse() {
861 // "I am a VT100 with advanced video option" (often VT102)
870 // "I am a VT220" - 7 bit version
872 return "\033[?62;1;6c";
874 // "I am a VT220" - 8 bit version
875 return "\u009b?62;1;6c";
877 throw new IllegalArgumentException("Invalid device type: " + type
);
882 * Return the proper TERM environment variable for this device type.
884 * @param deviceType DeviceType.VT100, DeviceType, XTERM, etc.
885 * @return "vt100", "xterm", etc.
887 public static String
deviceTypeTerm(final DeviceType deviceType
) {
888 switch (deviceType
) {
902 throw new IllegalArgumentException("Invalid device type: "
908 * Return the proper LANG for this device type. Only XTERM devices know
909 * about UTF-8, the others are defined by their standard to be either
910 * 7-bit or 8-bit characters only.
912 * @param deviceType DeviceType.VT100, DeviceType, XTERM, etc.
913 * @param baseLang a base language without UTF-8 flag such as "C" or
915 * @return "en_US", "en_US.UTF-8", etc.
917 public static String
deviceTypeLang(final DeviceType deviceType
,
918 final String baseLang
) {
920 switch (deviceType
) {
928 return baseLang
+ ".UTF-8";
931 throw new IllegalArgumentException("Invalid device type: "
937 * Write a string directly to the remote side.
939 * @param str string to send
941 public void writeRemote(final String str
) {
942 if (stopReaderThread
) {
943 // Reader hit EOF, bail out now.
948 // System.err.printf("writeRemote() '%s'\n", str);
954 if (outputStream
== null) {
958 outputStream
.flush();
959 for (int i
= 0; i
< str
.length(); i
++) {
960 outputStream
.write(str
.charAt(i
));
962 outputStream
.flush();
963 } catch (IOException e
) {
969 if (output
== null) {
976 } catch (IOException e
) {
982 throw new IllegalArgumentException("Invalid device type: " + type
);
987 * Close the input and output streams and stop the reader thread. Note
988 * that it is safe to call this multiple times.
990 public final void close() {
992 // Tell the reader thread to stop looking at input. It will close
993 // the input streams.
994 if (stopReaderThread
== false) {
995 stopReaderThread
= true;
997 readerThread
.join(1000);
998 } catch (InterruptedException e
) {
1003 // Now close the output stream.
1008 if (outputStream
!= null) {
1010 outputStream
.close();
1011 } catch (IOException e
) {
1014 outputStream
= null;
1018 if (outputStream
!= null) {
1020 outputStream
.close();
1021 } catch (IOException e
) {
1024 outputStream
= null;
1026 if (output
!= null) {
1029 } catch (IOException e
) {
1036 throw new IllegalArgumentException("Invalid device type: " +
1042 * See if the reader thread is still running.
1044 * @return if true, we are still connected to / reading from the remote
1047 public final boolean isReading() {
1048 return (!stopReaderThread
);
1052 * Obtain a new blank display line for an external user
1053 * (e.g. TTerminalWindow).
1055 * @return new blank line
1057 public final DisplayLine
getBlankDisplayLine() {
1058 return new DisplayLine(currentState
.attr
);
1062 * Get the scrollback buffer.
1064 * @return the scrollback buffer
1066 public final List
<DisplayLine
> getScrollbackBuffer() {
1071 * Get the display buffer.
1073 * @return the display buffer
1075 public final List
<DisplayLine
> getDisplayBuffer() {
1080 * Get the display width.
1082 * @return the width (usually 80 or 132)
1084 public final int getWidth() {
1089 * Set the display width.
1091 * @param width the new width
1093 public final void setWidth(final int width
) {
1095 rightMargin
= width
- 1;
1096 if (currentState
.cursorX
>= width
) {
1097 currentState
.cursorX
= width
- 1;
1099 if (savedState
.cursorX
>= width
) {
1100 savedState
.cursorX
= width
- 1;
1105 * Get the display height.
1107 * @return the height (usually 24)
1109 public final int getHeight() {
1114 * Set the display height.
1116 * @param height the new height
1118 public final void setHeight(final int height
) {
1119 int delta
= height
- this.height
;
1120 this.height
= height
;
1121 scrollRegionBottom
+= delta
;
1122 if (scrollRegionBottom
< 0) {
1123 scrollRegionBottom
= height
;
1125 if (scrollRegionTop
>= scrollRegionBottom
) {
1126 scrollRegionTop
= 0;
1128 if (currentState
.cursorY
>= height
) {
1129 currentState
.cursorY
= height
- 1;
1131 if (savedState
.cursorY
>= height
) {
1132 savedState
.cursorY
= height
- 1;
1134 while (display
.size() < height
) {
1135 DisplayLine line
= new DisplayLine(currentState
.attr
);
1136 line
.setReverseColor(reverseVideo
);
1139 while (display
.size() > height
) {
1140 scrollback
.add(display
.remove(0));
1145 * Get visible cursor flag.
1147 * @return if true, the cursor is visible
1149 public final boolean isCursorVisible() {
1150 return cursorVisible
;
1154 * Get the screen title as set by the xterm OSC sequence. Lots of
1155 * applications send a screenTitle regardless of whether it is an xterm
1158 * @return screen title
1160 public final String
getScreenTitle() {
1165 * Get 132 columns value.
1167 * @return if true, the terminal is in 132 column mode
1169 public final boolean isColumns132() {
1174 * Clear the CSI parameters and flags.
1176 private void toGround() {
1178 collectBuffer
= new StringBuilder(8);
1179 scanState
= ScanState
.GROUND
;
1183 * Reset the tab stops list.
1185 private void resetTabStops() {
1187 for (int i
= 0; (i
* 8) <= rightMargin
; i
++) {
1188 tabStops
.add(Integer
.valueOf(i
* 8));
1193 * Reset the 88- or 256-colors.
1195 private void resetColors() {
1196 colors88
= new ArrayList
<Integer
>(256);
1197 for (int i
= 0; i
< 256; i
++) {
1201 // Set default system colors.
1202 colors88
.set(0, 0x00000000);
1203 colors88
.set(1, 0x00a80000);
1204 colors88
.set(2, 0x0000a800);
1205 colors88
.set(3, 0x00a85400);
1206 colors88
.set(4, 0x000000a8);
1207 colors88
.set(5, 0x00a800a8);
1208 colors88
.set(6, 0x0000a8a8);
1209 colors88
.set(7, 0x00a8a8a8);
1211 colors88
.set(8, 0x00545454);
1212 colors88
.set(9, 0x00fc5454);
1213 colors88
.set(10, 0x0054fc54);
1214 colors88
.set(11, 0x00fcfc54);
1215 colors88
.set(12, 0x005454fc);
1216 colors88
.set(13, 0x00fc54fc);
1217 colors88
.set(14, 0x0054fcfc);
1218 colors88
.set(15, 0x00fcfcfc);
1222 * Get the RGB value of one of the indexed colors.
1224 * @param index the color index
1225 * @return the RGB value
1227 private int get88Color(final int index
) {
1228 // System.err.print("get88Color: " + index);
1229 if ((index
< 0) || (index
> colors88
.size())) {
1230 // System.err.println(" -- UNKNOWN");
1233 // System.err.printf(" %08x\n", colors88.get(index));
1234 return colors88
.get(index
);
1238 * Set one of the indexed colors to a color specification.
1240 * @param index the color index
1241 * @param spec the specification, typically something like "rgb:aa/bb/cc"
1243 private void set88Color(final int index
, final String spec
) {
1244 // System.err.println("set88Color: " + index + " '" + spec + "'");
1246 if ((index
< 0) || (index
> colors88
.size())) {
1249 if (spec
.startsWith("rgb:")) {
1250 String
[] rgbTokens
= spec
.substring(4).split("/");
1251 if (rgbTokens
.length
== 3) {
1253 int rgb
= (Integer
.parseInt(rgbTokens
[0], 16) << 16);
1254 rgb
|= Integer
.parseInt(rgbTokens
[1], 16) << 8;
1255 rgb
|= Integer
.parseInt(rgbTokens
[2], 16);
1256 // System.err.printf(" set to %08x\n", rgb);
1257 colors88
.set(index
, rgb
);
1258 } catch (NumberFormatException e
) {
1265 if (spec
.toLowerCase().equals("black")) {
1266 colors88
.set(index
, 0x00000000);
1267 } else if (spec
.toLowerCase().equals("red")) {
1268 colors88
.set(index
, 0x00a80000);
1269 } else if (spec
.toLowerCase().equals("green")) {
1270 colors88
.set(index
, 0x0000a800);
1271 } else if (spec
.toLowerCase().equals("yellow")) {
1272 colors88
.set(index
, 0x00a85400);
1273 } else if (spec
.toLowerCase().equals("blue")) {
1274 colors88
.set(index
, 0x000000a8);
1275 } else if (spec
.toLowerCase().equals("magenta")) {
1276 colors88
.set(index
, 0x00a800a8);
1277 } else if (spec
.toLowerCase().equals("cyan")) {
1278 colors88
.set(index
, 0x0000a8a8);
1279 } else if (spec
.toLowerCase().equals("white")) {
1280 colors88
.set(index
, 0x00a8a8a8);
1286 * Reset the emulation state.
1288 private void reset() {
1290 currentState
= new SaveableState();
1291 savedState
= new SaveableState();
1292 scanState
= ScanState
.GROUND
;
1295 scrollRegionTop
= 0;
1296 scrollRegionBottom
= height
- 1;
1297 rightMargin
= width
- 1;
1298 newLineMode
= false;
1299 arrowKeyMode
= ArrowKeyMode
.ANSI
;
1300 keypadMode
= KeypadMode
.Numeric
;
1301 wrapLineFlag
= false;
1302 if (displayListener
!= null) {
1303 width
= displayListener
.getDisplayWidth();
1304 height
= displayListener
.getDisplayHeight();
1305 rightMargin
= width
- 1;
1313 newLineMode
= false;
1314 reverseVideo
= false;
1316 cursorVisible
= true;
1319 singleshift
= Singleshift
.NONE
;
1321 printerControllerMode
= false;
1324 mouseProtocol
= MouseProtocol
.OFF
;
1325 mouseEncoding
= MouseEncoding
.X10
;
1330 // Reset extra colors
1338 * Append a new line to the bottom of the display, adding lines off the
1339 * top to the scrollback buffer.
1341 private void newDisplayLine() {
1342 // Scroll the top line off into the scrollback buffer
1343 scrollback
.add(display
.get(0));
1344 if (scrollback
.size() > maxScrollback
) {
1345 scrollback
.remove(0);
1346 scrollback
.trimToSize();
1349 display
.trimToSize();
1350 DisplayLine line
= new DisplayLine(currentState
.attr
);
1351 line
.setReverseColor(reverseVideo
);
1356 * Wraps the current line.
1358 private void wrapCurrentLine() {
1359 if (currentState
.cursorY
== height
- 1) {
1362 if (currentState
.cursorY
< height
- 1) {
1363 currentState
.cursorY
++;
1365 currentState
.cursorX
= 0;
1369 * Handle a carriage return.
1371 private void carriageReturn() {
1372 currentState
.cursorX
= 0;
1373 wrapLineFlag
= false;
1377 * Reverse the color of the visible display.
1379 private void invertDisplayColors() {
1380 for (DisplayLine line
: display
) {
1381 line
.setReverseColor(!line
.isReverseColor());
1386 * Handle a linefeed.
1388 private void linefeed() {
1390 if (currentState
.cursorY
< scrollRegionBottom
) {
1391 // Increment screen y
1392 currentState
.cursorY
++;
1395 // Screen y does not increment
1398 * Two cases: either we're inside a scrolling region or not. If
1399 * the scrolling region bottom is the bottom of the screen, then
1400 * push the top line into the buffer. Else scroll the scrolling
1403 if ((scrollRegionBottom
== height
- 1) && (scrollRegionTop
== 0)) {
1405 // We're at the bottom of the scroll region, AND the scroll
1406 // region is the entire screen.
1412 // We're at the bottom of the scroll region, AND the scroll
1413 // region is NOT the entire screen.
1414 scrollingRegionScrollUp(scrollRegionTop
, scrollRegionBottom
, 1);
1419 currentState
.cursorX
= 0;
1421 wrapLineFlag
= false;
1425 * Prints one character to the display buffer.
1427 * @param ch character to display
1429 private void printCharacter(final char ch
) {
1430 int rightMargin
= this.rightMargin
;
1432 if (StringUtils
.width(ch
) == 2) {
1433 // This is a full-width character. Save two spaces, and then
1434 // draw the character as two image halves.
1435 int x0
= currentState
.cursorX
;
1436 int y0
= currentState
.cursorY
;
1437 printCharacter(' ');
1438 printCharacter(' ');
1439 if ((currentState
.cursorX
== x0
+ 2)
1440 && (currentState
.cursorY
== y0
)
1442 // We can draw both halves of the character.
1443 drawHalves(x0
, y0
, x0
+ 1, y0
, ch
);
1444 } else if ((currentState
.cursorX
== x0
+ 1)
1445 && (currentState
.cursorY
== y0
)
1447 // VT100 line wrap behavior: we should be at the right
1448 // margin. We can draw both halves of the character.
1449 drawHalves(x0
, y0
, x0
+ 1, y0
, ch
);
1451 // The character splits across the line. Draw the entire
1452 // character on the new line, giving one more space for it.
1453 x0
= currentState
.cursorX
- 1;
1454 y0
= currentState
.cursorY
;
1455 printCharacter(' ');
1456 drawHalves(x0
, y0
, x0
+ 1, y0
, ch
);
1461 // Check if we have double-width, and if so chop at 40/66 instead of
1463 if (display
.get(currentState
.cursorY
).isDoubleWidth()) {
1464 rightMargin
= ((rightMargin
+ 1) / 2) - 1;
1467 // Check the unusually-complicated line wrapping conditions...
1468 if (currentState
.cursorX
== rightMargin
) {
1470 if (currentState
.lineWrap
== true) {
1472 * This case happens when: the cursor was already on the
1473 * right margin (either through printing or by an explicit
1474 * placement command), and a character was printed.
1476 * The line wraps only when a new character arrives AND the
1477 * cursor is already on the right margin AND has placed a
1478 * character in its cell. Easier to see than to explain.
1480 if (wrapLineFlag
== false) {
1482 * This block marks the case that we are in the margin
1483 * and the first character has been received and printed.
1485 wrapLineFlag
= true;
1488 * This block marks the case that we are in the margin
1489 * and the second character has been received and
1492 wrapLineFlag
= false;
1496 } else if (currentState
.cursorX
<= rightMargin
) {
1498 * This is the normal case: a character came in and was printed
1499 * to the left of the right margin column.
1502 // Turn off VT100 special-case flag
1503 wrapLineFlag
= false;
1506 // "Print" the character
1507 Cell newCell
= new Cell(ch
);
1508 CellAttributes newCellAttributes
= (CellAttributes
) newCell
;
1509 newCellAttributes
.setTo(currentState
.attr
);
1510 DisplayLine line
= display
.get(currentState
.cursorY
);
1512 if (StringUtils
.width(ch
) == 1) {
1513 // Insert mode special case
1514 if (insertMode
== true) {
1515 line
.insert(currentState
.cursorX
, newCell
);
1517 // Replace an existing character
1518 line
.replace(currentState
.cursorX
, newCell
);
1521 // Increment horizontal
1522 if (wrapLineFlag
== false) {
1523 currentState
.cursorX
++;
1524 if (currentState
.cursorX
> rightMargin
) {
1525 currentState
.cursorX
--;
1532 * Translate the mouse event to a VT100, VT220, or XTERM sequence and
1533 * send to the remote side.
1535 * @param mouse mouse event received from the local user
1537 private void mouse(final TMouseEvent mouse
) {
1540 System.err.printf("mouse(): protocol %s encoding %s mouse %s\n",
1541 mouseProtocol, mouseEncoding, mouse);
1544 if (mouseEncoding
== MouseEncoding
.X10
) {
1545 // We will support X10 but only for (160,94) and smaller.
1546 if ((mouse
.getX() >= 160) || (mouse
.getY() >= 94)) {
1551 switch (mouseProtocol
) {
1558 // Only report button presses
1559 if (mouse
.getType() != TMouseEvent
.Type
.MOUSE_DOWN
) {
1565 // Only report button presses and releases
1566 if ((mouse
.getType() != TMouseEvent
.Type
.MOUSE_DOWN
)
1567 && (mouse
.getType() != TMouseEvent
.Type
.MOUSE_UP
)
1575 * Only report button presses, button releases, and motions that
1576 * have a button down (i.e. drag-and-drop).
1578 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1579 if (!mouse
.isMouse1()
1580 && !mouse
.isMouse2()
1581 && !mouse
.isMouse3()
1582 && !mouse
.isMouseWheelUp()
1583 && !mouse
.isMouseWheelDown()
1591 // Report everything
1595 // Now encode the event
1596 StringBuilder sb
= new StringBuilder(6);
1597 if (mouseEncoding
== MouseEncoding
.SGR
) {
1598 sb
.append((char) 0x1B);
1601 if (mouse
.isMouse1()) {
1602 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1607 } else if (mouse
.isMouse2()) {
1608 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1613 } else if (mouse
.isMouse3()) {
1614 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1619 } else if (mouse
.isMouseWheelUp()) {
1621 } else if (mouse
.isMouseWheelDown()) {
1624 // This is motion with no buttons down.
1628 sb
.append(String
.format("%d;%d", mouse
.getX() + 1,
1631 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_UP
) {
1638 // X10 and UTF8 encodings
1639 sb
.append((char) 0x1B);
1642 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_UP
) {
1643 sb
.append((char) (0x03 + 32));
1644 } else if (mouse
.isMouse1()) {
1645 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1646 sb
.append((char) (0x00 + 32 + 32));
1648 sb
.append((char) (0x00 + 32));
1650 } else if (mouse
.isMouse2()) {
1651 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1652 sb
.append((char) (0x01 + 32 + 32));
1654 sb
.append((char) (0x01 + 32));
1656 } else if (mouse
.isMouse3()) {
1657 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1658 sb
.append((char) (0x02 + 32 + 32));
1660 sb
.append((char) (0x02 + 32));
1662 } else if (mouse
.isMouseWheelUp()) {
1663 sb
.append((char) (0x04 + 64));
1664 } else if (mouse
.isMouseWheelDown()) {
1665 sb
.append((char) (0x05 + 64));
1667 // This is motion with no buttons down.
1668 sb
.append((char) (0x03 + 32));
1671 sb
.append((char) (mouse
.getX() + 33));
1672 sb
.append((char) (mouse
.getY() + 33));
1675 // System.err.printf("Would write: \'%s\'\n", sb.toString());
1676 writeRemote(sb
.toString());
1680 * Translate the keyboard press to a VT100, VT220, or XTERM sequence and
1681 * send to the remote side.
1683 * @param keypress keypress received from the local user
1685 private void keypress(final TKeypress keypress
) {
1686 writeRemote(keypressToString(keypress
));
1690 * Build one of the complex xterm keystroke sequences, storing the result in
1691 * xterm_keystroke_buffer.
1693 * @param ss3 the prefix to use based on VT100 state.
1694 * @param first the first character, usually a number.
1695 * @param first the last character, one of the following: ~ A B C D F H
1696 * @param ctrl whether or not ctrl is down
1697 * @param alt whether or not alt is down
1698 * @param shift whether or not shift is down
1699 * @return the buffer with the full key sequence
1701 private String
xtermBuildKeySequence(final String ss3
, final char first
,
1702 final char last
, boolean ctrl
, boolean alt
, boolean shift
) {
1704 StringBuilder sb
= new StringBuilder(ss3
);
1705 if ((last
== '~') || (ctrl
== true) || (alt
== true)
1709 if ( (ctrl
== false) && (alt
== false) && (shift
== true)) {
1711 } else if ((ctrl
== false) && (alt
== true) && (shift
== false)) {
1713 } else if ((ctrl
== false) && (alt
== true) && (shift
== true)) {
1715 } else if ((ctrl
== true) && (alt
== false) && (shift
== false)) {
1717 } else if ((ctrl
== true) && (alt
== false) && (shift
== true)) {
1719 } else if ((ctrl
== true) && (alt
== true) && (shift
== false)) {
1721 } else if ((ctrl
== true) && (alt
== true) && (shift
== true)) {
1726 return sb
.toString();
1730 * Translate the keyboard press to a VT100, VT220, or XTERM sequence.
1732 * @param keypress keypress received from the local user
1733 * @return string to transmit to the remote side
1735 @SuppressWarnings("fallthrough")
1736 private String
keypressToString(final TKeypress keypress
) {
1738 if ((fullDuplex
== false) && (!keypress
.isFnKey())) {
1740 * If this is a control character, process it like it came from
1743 if (keypress
.getChar() < 0x20) {
1744 handleControlChar(keypress
.getChar());
1746 // Local echo for everything else
1747 printCharacter(keypress
.getChar());
1751 if ((newLineMode
== true) && (keypress
.equals(kbEnter
))) {
1756 // Handle control characters
1757 if ((keypress
.isCtrl()) && (!keypress
.isFnKey())) {
1758 StringBuilder sb
= new StringBuilder();
1759 char ch
= keypress
.getChar();
1762 return sb
.toString();
1765 // Handle alt characters
1766 if ((keypress
.isAlt()) && (!keypress
.isFnKey())) {
1767 StringBuilder sb
= new StringBuilder("\033");
1768 char ch
= keypress
.getChar();
1770 return sb
.toString();
1773 if (keypress
.equals(kbBackspaceDel
)) {
1786 if (keypress
.equalsWithoutModifiers(kbLeft
)) {
1789 switch (arrowKeyMode
) {
1791 return xtermBuildKeySequence("\033[", '1', 'D',
1792 keypress
.isCtrl(), keypress
.isAlt(),
1793 keypress
.isShift());
1795 return xtermBuildKeySequence("\033", '1', 'D',
1796 keypress
.isCtrl(), keypress
.isAlt(),
1797 keypress
.isShift());
1799 return xtermBuildKeySequence("\033O", '1', 'D',
1800 keypress
.isCtrl(), keypress
.isAlt(),
1801 keypress
.isShift());
1804 switch (arrowKeyMode
) {
1815 if (keypress
.equalsWithoutModifiers(kbRight
)) {
1818 switch (arrowKeyMode
) {
1820 return xtermBuildKeySequence("\033[", '1', 'C',
1821 keypress
.isCtrl(), keypress
.isAlt(),
1822 keypress
.isShift());
1824 return xtermBuildKeySequence("\033", '1', 'C',
1825 keypress
.isCtrl(), keypress
.isAlt(),
1826 keypress
.isShift());
1828 return xtermBuildKeySequence("\033O", '1', 'C',
1829 keypress
.isCtrl(), keypress
.isAlt(),
1830 keypress
.isShift());
1833 switch (arrowKeyMode
) {
1844 if (keypress
.equalsWithoutModifiers(kbUp
)) {
1847 switch (arrowKeyMode
) {
1849 return xtermBuildKeySequence("\033[", '1', 'A',
1850 keypress
.isCtrl(), keypress
.isAlt(),
1851 keypress
.isShift());
1853 return xtermBuildKeySequence("\033", '1', 'A',
1854 keypress
.isCtrl(), keypress
.isAlt(),
1855 keypress
.isShift());
1857 return xtermBuildKeySequence("\033O", '1', 'A',
1858 keypress
.isCtrl(), keypress
.isAlt(),
1859 keypress
.isShift());
1862 switch (arrowKeyMode
) {
1873 if (keypress
.equalsWithoutModifiers(kbDown
)) {
1876 switch (arrowKeyMode
) {
1878 return xtermBuildKeySequence("\033[", '1', 'B',
1879 keypress
.isCtrl(), keypress
.isAlt(),
1880 keypress
.isShift());
1882 return xtermBuildKeySequence("\033", '1', 'B',
1883 keypress
.isCtrl(), keypress
.isAlt(),
1884 keypress
.isShift());
1886 return xtermBuildKeySequence("\033O", '1', 'B',
1887 keypress
.isCtrl(), keypress
.isAlt(),
1888 keypress
.isShift());
1891 switch (arrowKeyMode
) {
1902 if (keypress
.equalsWithoutModifiers(kbHome
)) {
1905 switch (arrowKeyMode
) {
1907 return xtermBuildKeySequence("\033[", '1', 'H',
1908 keypress
.isCtrl(), keypress
.isAlt(),
1909 keypress
.isShift());
1911 return xtermBuildKeySequence("\033", '1', 'H',
1912 keypress
.isCtrl(), keypress
.isAlt(),
1913 keypress
.isShift());
1915 return xtermBuildKeySequence("\033O", '1', 'H',
1916 keypress
.isCtrl(), keypress
.isAlt(),
1917 keypress
.isShift());
1920 switch (arrowKeyMode
) {
1931 if (keypress
.equalsWithoutModifiers(kbEnd
)) {
1934 switch (arrowKeyMode
) {
1936 return xtermBuildKeySequence("\033[", '1', 'F',
1937 keypress
.isCtrl(), keypress
.isAlt(),
1938 keypress
.isShift());
1940 return xtermBuildKeySequence("\033", '1', 'F',
1941 keypress
.isCtrl(), keypress
.isAlt(),
1942 keypress
.isShift());
1944 return xtermBuildKeySequence("\033O", '1', 'F',
1945 keypress
.isCtrl(), keypress
.isAlt(),
1946 keypress
.isShift());
1949 switch (arrowKeyMode
) {
1960 if (keypress
.equals(kbF1
)) {
1968 if (keypress
.equals(kbF2
)) {
1976 if (keypress
.equals(kbF3
)) {
1984 if (keypress
.equals(kbF4
)) {
1992 if (keypress
.equals(kbF5
)) {
2005 if (keypress
.equals(kbF6
)) {
2018 if (keypress
.equals(kbF7
)) {
2031 if (keypress
.equals(kbF8
)) {
2044 if (keypress
.equals(kbF9
)) {
2057 if (keypress
.equals(kbF10
)) {
2070 if (keypress
.equals(kbF11
)) {
2074 if (keypress
.equals(kbF12
)) {
2078 if (keypress
.equals(kbShiftF1
)) {
2083 if (type
== DeviceType
.XTERM
) {
2089 if (keypress
.equals(kbShiftF2
)) {
2094 if (type
== DeviceType
.XTERM
) {
2100 if (keypress
.equals(kbShiftF3
)) {
2105 if (type
== DeviceType
.XTERM
) {
2111 if (keypress
.equals(kbShiftF4
)) {
2116 if (type
== DeviceType
.XTERM
) {
2122 if (keypress
.equals(kbShiftF5
)) {
2124 return "\033[15;2~";
2127 if (keypress
.equals(kbShiftF6
)) {
2129 return "\033[17;2~";
2132 if (keypress
.equals(kbShiftF7
)) {
2134 return "\033[18;2~";
2137 if (keypress
.equals(kbShiftF8
)) {
2139 return "\033[19;2~";
2142 if (keypress
.equals(kbShiftF9
)) {
2144 return "\033[20;2~";
2147 if (keypress
.equals(kbShiftF10
)) {
2149 return "\033[21;2~";
2152 if (keypress
.equals(kbShiftF11
)) {
2154 return "\033[23;2~";
2157 if (keypress
.equals(kbShiftF12
)) {
2159 return "\033[24;2~";
2162 if (keypress
.equals(kbCtrlF1
)) {
2167 if (type
== DeviceType
.XTERM
) {
2173 if (keypress
.equals(kbCtrlF2
)) {
2178 if (type
== DeviceType
.XTERM
) {
2184 if (keypress
.equals(kbCtrlF3
)) {
2189 if (type
== DeviceType
.XTERM
) {
2195 if (keypress
.equals(kbCtrlF4
)) {
2200 if (type
== DeviceType
.XTERM
) {
2206 if (keypress
.equals(kbCtrlF5
)) {
2208 return "\033[15;5~";
2211 if (keypress
.equals(kbCtrlF6
)) {
2213 return "\033[17;5~";
2216 if (keypress
.equals(kbCtrlF7
)) {
2218 return "\033[18;5~";
2221 if (keypress
.equals(kbCtrlF8
)) {
2223 return "\033[19;5~";
2226 if (keypress
.equals(kbCtrlF9
)) {
2228 return "\033[20;5~";
2231 if (keypress
.equals(kbCtrlF10
)) {
2233 return "\033[21;5~";
2236 if (keypress
.equals(kbCtrlF11
)) {
2238 return "\033[23;5~";
2241 if (keypress
.equals(kbCtrlF12
)) {
2243 return "\033[24;5~";
2246 if (keypress
.equalsWithoutModifiers(kbPgUp
)) {
2249 return xtermBuildKeySequence("\033[", '5', '~',
2250 keypress
.isCtrl(), keypress
.isAlt(),
2251 keypress
.isShift());
2257 if (keypress
.equalsWithoutModifiers(kbPgDn
)) {
2260 return xtermBuildKeySequence("\033[", '6', '~',
2261 keypress
.isCtrl(), keypress
.isAlt(),
2262 keypress
.isShift());
2268 if (keypress
.equalsWithoutModifiers(kbIns
)) {
2271 return xtermBuildKeySequence("\033[", '2', '~',
2272 keypress
.isCtrl(), keypress
.isAlt(),
2273 keypress
.isShift());
2279 if (keypress
.equalsWithoutModifiers(kbDel
)) {
2282 return xtermBuildKeySequence("\033[", '3', '~',
2283 keypress
.isCtrl(), keypress
.isAlt(),
2284 keypress
.isShift());
2286 // Delete sends real delete for VTxxx
2291 if (keypress
.equals(kbEnter
)) {
2295 if (keypress
.equals(kbEsc
)) {
2299 if (keypress
.equals(kbAltEsc
)) {
2303 if (keypress
.equals(kbTab
)) {
2307 if ((keypress
.equalsWithoutModifiers(kbBackTab
)) ||
2308 (keypress
.equals(kbShiftTab
))
2318 // Non-alt, non-ctrl characters
2319 if (!keypress
.isFnKey()) {
2320 StringBuilder sb
= new StringBuilder();
2321 sb
.append(keypress
.getChar());
2322 return sb
.toString();
2328 * Map a symbol in any one of the VT100/VT220 character sets to a Unicode
2331 * @param ch 8-bit character from the remote side
2332 * @param charsetGl character set defined for GL
2333 * @param charsetGr character set defined for GR
2334 * @return character to display on the screen
2336 private char mapCharacterCharset(final char ch
,
2337 final CharacterSet charsetGl
,
2338 final CharacterSet charsetGr
) {
2340 int lookupChar
= ch
;
2341 CharacterSet lookupCharset
= charsetGl
;
2344 assert ((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
));
2345 lookupCharset
= charsetGr
;
2349 switch (lookupCharset
) {
2352 return DECCharacterSets
.SPECIAL_GRAPHICS
[lookupChar
];
2355 return DECCharacterSets
.UK
[lookupChar
];
2358 return DECCharacterSets
.US_ASCII
[lookupChar
];
2361 return DECCharacterSets
.NL
[lookupChar
];
2364 return DECCharacterSets
.FI
[lookupChar
];
2367 return DECCharacterSets
.FR
[lookupChar
];
2370 return DECCharacterSets
.FR_CA
[lookupChar
];
2373 return DECCharacterSets
.DE
[lookupChar
];
2376 return DECCharacterSets
.IT
[lookupChar
];
2379 return DECCharacterSets
.NO
[lookupChar
];
2382 return DECCharacterSets
.ES
[lookupChar
];
2385 return DECCharacterSets
.SV
[lookupChar
];
2388 return DECCharacterSets
.SWISS
[lookupChar
];
2390 case DEC_SUPPLEMENTAL
:
2391 return DECCharacterSets
.DEC_SUPPLEMENTAL
[lookupChar
];
2394 return DECCharacterSets
.VT52_SPECIAL_GRAPHICS
[lookupChar
];
2397 return DECCharacterSets
.US_ASCII
[lookupChar
];
2400 return DECCharacterSets
.US_ASCII
[lookupChar
];
2403 throw new IllegalArgumentException("Invalid character set value: "
2409 * Map an 8-bit byte into a printable character.
2411 * @param ch either 8-bit or Unicode character from the remote side
2412 * @return character to display on the screen
2414 private char mapCharacter(final char ch
) {
2416 // Unicode character, just return it
2420 CharacterSet charsetGl
= currentState
.g0Charset
;
2421 CharacterSet charsetGr
= currentState
.grCharset
;
2423 if (vt52Mode
== true) {
2424 if (shiftOut
== true) {
2425 // Shifted out character, pull from VT52 graphics
2426 charsetGl
= currentState
.g1Charset
;
2427 charsetGr
= CharacterSet
.US
;
2430 charsetGl
= currentState
.g0Charset
;
2431 charsetGr
= CharacterSet
.US
;
2434 // Pull the character
2435 return mapCharacterCharset(ch
, charsetGl
, charsetGr
);
2439 if (shiftOut
== true) {
2440 // Shifted out character, pull from G1
2441 charsetGl
= currentState
.g1Charset
;
2442 charsetGr
= currentState
.grCharset
;
2444 // Pull the character
2445 return mapCharacterCharset(ch
, charsetGl
, charsetGr
);
2449 if (singleshift
== Singleshift
.SS2
) {
2451 singleshift
= Singleshift
.NONE
;
2453 // Shifted out character, pull from G2
2454 charsetGl
= currentState
.g2Charset
;
2455 charsetGr
= currentState
.grCharset
;
2459 if (singleshift
== Singleshift
.SS3
) {
2461 singleshift
= Singleshift
.NONE
;
2463 // Shifted out character, pull from G3
2464 charsetGl
= currentState
.g3Charset
;
2465 charsetGr
= currentState
.grCharset
;
2468 if ((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
)) {
2469 // Check for locking shift
2471 switch (currentState
.glLockshift
) {
2474 throw new IllegalArgumentException("programming bug");
2477 throw new IllegalArgumentException("programming bug");
2480 throw new IllegalArgumentException("programming bug");
2484 charsetGl
= currentState
.g2Charset
;
2489 charsetGl
= currentState
.g3Charset
;
2494 charsetGl
= currentState
.g0Charset
;
2498 switch (currentState
.grLockshift
) {
2501 throw new IllegalArgumentException("programming bug");
2504 throw new IllegalArgumentException("programming bug");
2508 charsetGr
= currentState
.g1Charset
;
2513 charsetGr
= currentState
.g2Charset
;
2518 charsetGr
= currentState
.g3Charset
;
2523 charsetGr
= CharacterSet
.DEC_SUPPLEMENTAL
;
2530 // Pull the character
2531 return mapCharacterCharset(ch
, charsetGl
, charsetGr
);
2535 * Scroll the text within a scrolling region up n lines.
2537 * @param regionTop top row of the scrolling region
2538 * @param regionBottom bottom row of the scrolling region
2539 * @param n number of lines to scroll
2541 private void scrollingRegionScrollUp(final int regionTop
,
2542 final int regionBottom
, final int n
) {
2544 if (regionTop
>= regionBottom
) {
2548 // Sanity check: see if there will be any characters left after the
2550 if (regionBottom
+ 1 - regionTop
<= n
) {
2551 // There won't be anything left in the region, so just call
2552 // eraseScreen() and return.
2553 eraseScreen(regionTop
, 0, regionBottom
, width
- 1, false);
2557 int remaining
= regionBottom
+ 1 - regionTop
- n
;
2558 List
<DisplayLine
> displayTop
= display
.subList(0, regionTop
);
2559 List
<DisplayLine
> displayBottom
= display
.subList(regionBottom
+ 1,
2561 List
<DisplayLine
> displayMiddle
= display
.subList(regionBottom
+ 1
2562 - remaining
, regionBottom
+ 1);
2563 display
= new ArrayList
<DisplayLine
>(displayTop
);
2564 display
.addAll(displayMiddle
);
2565 for (int i
= 0; i
< n
; i
++) {
2566 DisplayLine line
= new DisplayLine(currentState
.attr
);
2567 line
.setReverseColor(reverseVideo
);
2570 display
.addAll(displayBottom
);
2572 assert (display
.size() == height
);
2576 * Scroll the text within a scrolling region down n lines.
2578 * @param regionTop top row of the scrolling region
2579 * @param regionBottom bottom row of the scrolling region
2580 * @param n number of lines to scroll
2582 private void scrollingRegionScrollDown(final int regionTop
,
2583 final int regionBottom
, final int n
) {
2585 if (regionTop
>= regionBottom
) {
2589 // Sanity check: see if there will be any characters left after the
2591 if (regionBottom
+ 1 - regionTop
<= n
) {
2592 // There won't be anything left in the region, so just call
2593 // eraseScreen() and return.
2594 eraseScreen(regionTop
, 0, regionBottom
, width
- 1, false);
2598 int remaining
= regionBottom
+ 1 - regionTop
- n
;
2599 List
<DisplayLine
> displayTop
= display
.subList(0, regionTop
);
2600 List
<DisplayLine
> displayBottom
= display
.subList(regionBottom
+ 1,
2602 List
<DisplayLine
> displayMiddle
= display
.subList(regionTop
,
2603 regionTop
+ remaining
);
2604 display
= new ArrayList
<DisplayLine
>(displayTop
);
2605 for (int i
= 0; i
< n
; i
++) {
2606 DisplayLine line
= new DisplayLine(currentState
.attr
);
2607 line
.setReverseColor(reverseVideo
);
2610 display
.addAll(displayMiddle
);
2611 display
.addAll(displayBottom
);
2613 assert (display
.size() == height
);
2617 * Process a control character.
2619 * @param ch 8-bit character from the remote side
2621 private void handleControlChar(final char ch
) {
2622 assert ((ch
<= 0x1F) || ((ch
>= 0x7F) && (ch
<= 0x9F)));
2633 // Transmit the answerback message.
2644 cursorLeft(1, false);
2649 advanceToNextTabStop();
2675 currentState
.glLockshift
= LockshiftMode
.NONE
;
2681 currentState
.glLockshift
= LockshiftMode
.NONE
;
2706 singleshift
= Singleshift
.SS2
;
2711 singleshift
= Singleshift
.SS3
;
2721 * Advance the cursor to the next tab stop.
2723 private void advanceToNextTabStop() {
2724 if (tabStops
.size() == 0) {
2725 // Go to the rightmost column
2726 cursorRight(rightMargin
- currentState
.cursorX
, false);
2729 for (Integer stop
: tabStops
) {
2730 if (stop
> currentState
.cursorX
) {
2731 cursorRight(stop
- currentState
.cursorX
, false);
2736 * We got here, meaning there isn't a tab stop beyond the current
2737 * cursor position. Place the cursor of the right-most edge of the
2740 cursorRight(rightMargin
- currentState
.cursorX
, false);
2744 * Save a character into the collect buffer.
2746 * @param ch character to save
2748 private void collect(final char ch
) {
2749 collectBuffer
.append(ch
);
2753 * Save a byte into the CSI parameters buffer.
2755 * @param ch byte to save
2757 private void param(final byte ch
) {
2758 if (csiParams
.size() == 0) {
2759 csiParams
.add(Integer
.valueOf(0));
2761 Integer x
= csiParams
.get(csiParams
.size() - 1);
2762 if ((ch
>= '0') && (ch
<= '9')) {
2765 csiParams
.set(csiParams
.size() - 1, x
);
2768 if ((ch
== ';') && (csiParams
.size() < 16)) {
2769 csiParams
.add(Integer
.valueOf(0));
2774 * Get a CSI parameter value, with a default.
2776 * @param position parameter index. 0 is the first parameter.
2777 * @param defaultValue value to use if csiParams[position] doesn't exist
2778 * @return parameter value
2780 private int getCsiParam(final int position
, final int defaultValue
) {
2781 if (csiParams
.size() < position
+ 1) {
2782 return defaultValue
;
2784 return csiParams
.get(position
).intValue();
2788 * Get a CSI parameter value, clamped to within min/max.
2790 * @param position parameter index. 0 is the first parameter.
2791 * @param defaultValue value to use if csiParams[position] doesn't exist
2792 * @param minValue minimum value inclusive
2793 * @param maxValue maximum value inclusive
2794 * @return parameter value
2796 private int getCsiParam(final int position
, final int defaultValue
,
2797 final int minValue
, final int maxValue
) {
2799 assert (minValue
<= maxValue
);
2800 int value
= getCsiParam(position
, defaultValue
);
2801 if (value
< minValue
) {
2804 if (value
> maxValue
) {
2811 * Set or unset a toggle.
2813 * @param value true for set ('h'), false for reset ('l')
2815 private void setToggle(final boolean value
) {
2816 boolean decPrivateModeFlag
= false;
2817 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
2818 if (collectBuffer
.charAt(i
) == '?') {
2819 decPrivateModeFlag
= true;
2824 for (Integer i
: csiParams
) {
2829 if (decPrivateModeFlag
== true) {
2831 if (value
== true) {
2832 // Use application arrow keys
2833 arrowKeyMode
= ArrowKeyMode
.VT100
;
2835 // Use ANSI arrow keys
2836 arrowKeyMode
= ArrowKeyMode
.ANSI
;
2841 if (decPrivateModeFlag
== true) {
2842 if (value
== false) {
2846 arrowKeyMode
= ArrowKeyMode
.VT52
;
2849 * From the VT102 docs: "You use ANSI mode to select
2850 * most terminal features; the terminal uses the same
2851 * features when it switches to VT52 mode. You
2852 * cannot, however, change most of these features in
2855 * In other words, do not reset any other attributes
2856 * when switching between VT52 submode and ANSI.
2858 * HOWEVER, the real vt100 does switch the character
2859 * set according to Usenet.
2861 currentState
.g0Charset
= CharacterSet
.US
;
2862 currentState
.g1Charset
= CharacterSet
.DRAWING
;
2865 if ((type
== DeviceType
.VT220
)
2866 || (type
== DeviceType
.XTERM
)) {
2868 // VT52 mode is explicitly 7-bit
2870 singleshift
= Singleshift
.NONE
;
2875 if (value
== true) {
2876 // Turn off keyboard
2885 if (decPrivateModeFlag
== true) {
2887 if (value
== true) {
2894 if ((displayListener
!= null)
2895 && (type
== DeviceType
.XTERM
)
2897 // For xterms, reset to the actual width, not 80
2899 width
= displayListener
.getDisplayWidth();
2900 rightMargin
= width
- 1;
2903 width
= rightMargin
+ 1;
2906 // Entire screen is cleared, and scrolling region is
2908 eraseScreen(0, 0, height
- 1, width
- 1, false);
2909 scrollRegionTop
= 0;
2910 scrollRegionBottom
= height
- 1;
2911 // Also home the cursor
2912 cursorPosition(0, 0);
2916 if (decPrivateModeFlag
== true) {
2918 if (value
== true) {
2927 if (value
== true) {
2935 if (decPrivateModeFlag
== true) {
2937 if (value
== true) {
2939 * Set selects reverse screen, a white screen
2940 * background with black characters.
2942 if (reverseVideo
!= true) {
2944 * If in normal video, switch it back
2946 invertDisplayColors();
2948 reverseVideo
= true;
2951 * Reset selects normal screen, a black screen
2952 * background with white characters.
2954 if (reverseVideo
== true) {
2956 * If in reverse video already, switch it back
2958 invertDisplayColors();
2960 reverseVideo
= false;
2965 if (decPrivateModeFlag
== true) {
2967 if (value
== true) {
2968 // Origin is relative to scroll region cursor.
2969 // Cursor can NEVER leave scrolling region.
2970 currentState
.originMode
= true;
2971 cursorPosition(0, 0);
2973 // Origin is absolute to entire screen. Cursor can
2974 // leave the scrolling region via cup() and hvp().
2975 currentState
.originMode
= false;
2976 cursorPosition(0, 0);
2981 if (decPrivateModeFlag
== true) {
2983 if (value
== true) {
2985 currentState
.lineWrap
= true;
2987 // Turn linewrap off
2988 currentState
.lineWrap
= false;
2993 if (decPrivateModeFlag
== true) {
2995 if (value
== true) {
2996 // Keyboard auto-repeat on
2999 // Keyboard auto-repeat off
3005 if (decPrivateModeFlag
== false) {
3007 if (value
== true) {
3017 if (decPrivateModeFlag
== true) {
3023 if (decPrivateModeFlag
== true) {
3029 if (decPrivateModeFlag
== false) {
3031 if (value
== true) {
3033 * Set causes a received linefeed, form feed, or
3034 * vertical tab to move cursor to first column of
3035 * next line. RETURN transmits both a carriage return
3036 * and linefeed. This selection is also called new
3042 * Reset causes a received linefeed, form feed, or
3043 * vertical tab to move cursor to next line in
3044 * current column. RETURN transmits a carriage
3047 newLineMode
= false;
3053 if ((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
)) {
3054 if (decPrivateModeFlag
== true) {
3056 if (value
== true) {
3058 cursorVisible
= true;
3061 cursorVisible
= false;
3068 if ((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
)) {
3069 if (decPrivateModeFlag
== true) {
3071 if (value
== true) {
3072 // Select national mode NRC
3075 // Select multi-national mode
3084 if ((type
== DeviceType
.XTERM
)
3085 && (decPrivateModeFlag
== true)
3087 // Mouse: normal tracking mode
3088 if (value
== true) {
3089 mouseProtocol
= MouseProtocol
.NORMAL
;
3091 mouseProtocol
= MouseProtocol
.OFF
;
3097 if ((type
== DeviceType
.XTERM
)
3098 && (decPrivateModeFlag
== true)
3100 // Mouse: normal tracking mode
3101 if (value
== true) {
3102 mouseProtocol
= MouseProtocol
.BUTTONEVENT
;
3104 mouseProtocol
= MouseProtocol
.OFF
;
3110 if ((type
== DeviceType
.XTERM
)
3111 && (decPrivateModeFlag
== true)
3113 // Mouse: Any-event tracking mode
3114 if (value
== true) {
3115 mouseProtocol
= MouseProtocol
.ANYEVENT
;
3117 mouseProtocol
= MouseProtocol
.OFF
;
3123 if ((type
== DeviceType
.XTERM
)
3124 && (decPrivateModeFlag
== true)
3126 // Mouse: UTF-8 coordinates
3127 if (value
== true) {
3128 mouseEncoding
= MouseEncoding
.UTF8
;
3130 mouseEncoding
= MouseEncoding
.X10
;
3136 if ((type
== DeviceType
.XTERM
)
3137 && (decPrivateModeFlag
== true)
3139 // Mouse: SGR coordinates
3140 if (value
== true) {
3141 mouseEncoding
= MouseEncoding
.SGR
;
3143 mouseEncoding
= MouseEncoding
.X10
;
3156 * DECSC - Save cursor.
3158 private void decsc() {
3159 savedState
.setTo(currentState
);
3163 * DECRC - Restore cursor.
3165 private void decrc() {
3166 currentState
.setTo(savedState
);
3172 private void ind() {
3173 // Move the cursor and scroll if necessary. If at the bottom line
3174 // already, a scroll up is supposed to be performed.
3175 if (currentState
.cursorY
== scrollRegionBottom
) {
3176 scrollingRegionScrollUp(scrollRegionTop
, scrollRegionBottom
, 1);
3178 cursorDown(1, true);
3182 * RI - Reverse index.
3185 // Move the cursor and scroll if necessary. If at the top line
3186 // already, a scroll down is supposed to be performed.
3187 if (currentState
.cursorY
== scrollRegionTop
) {
3188 scrollingRegionScrollDown(scrollRegionTop
, scrollRegionBottom
, 1);
3196 private void nel() {
3197 // Move the cursor and scroll if necessary. If at the bottom line
3198 // already, a scroll up is supposed to be performed.
3199 if (currentState
.cursorY
== scrollRegionBottom
) {
3200 scrollingRegionScrollUp(scrollRegionTop
, scrollRegionBottom
, 1);
3202 cursorDown(1, true);
3204 // Reset to the beginning of the next line
3205 currentState
.cursorX
= 0;
3209 * DECKPAM - Keypad application mode.
3211 private void deckpam() {
3212 keypadMode
= KeypadMode
.Application
;
3216 * DECKPNM - Keypad numeric mode.
3218 private void deckpnm() {
3219 keypadMode
= KeypadMode
.Numeric
;
3225 * @param n number of spaces to move
3226 * @param honorScrollRegion if true, then do nothing if the cursor is
3227 * outside the scrolling region
3229 private void cursorUp(final int n
, final boolean honorScrollRegion
) {
3233 * Special case: if a user moves the cursor from the right margin, we
3234 * have to reset the VT100 right margin flag.
3237 wrapLineFlag
= false;
3240 for (int i
= 0; i
< n
; i
++) {
3241 if (honorScrollRegion
== true) {
3242 // Honor the scrolling region
3243 if ((currentState
.cursorY
< scrollRegionTop
)
3244 || (currentState
.cursorY
> scrollRegionBottom
)
3246 // Outside region, do nothing
3249 // Inside region, go up
3250 top
= scrollRegionTop
;
3252 // Non-scrolling case
3256 if (currentState
.cursorY
> top
) {
3257 currentState
.cursorY
--;
3263 * Move down n spaces.
3265 * @param n number of spaces to move
3266 * @param honorScrollRegion if true, then do nothing if the cursor is
3267 * outside the scrolling region
3269 private void cursorDown(final int n
, final boolean honorScrollRegion
) {
3273 * Special case: if a user moves the cursor from the right margin, we
3274 * have to reset the VT100 right margin flag.
3277 wrapLineFlag
= false;
3280 for (int i
= 0; i
< n
; i
++) {
3282 if (honorScrollRegion
== true) {
3283 // Honor the scrolling region
3284 if (currentState
.cursorY
> scrollRegionBottom
) {
3285 // Outside region, do nothing
3288 // Inside region, go down
3289 bottom
= scrollRegionBottom
;
3291 // Non-scrolling case
3292 bottom
= height
- 1;
3295 if (currentState
.cursorY
< bottom
) {
3296 currentState
.cursorY
++;
3302 * Move left n spaces.
3304 * @param n number of spaces to move
3305 * @param honorScrollRegion if true, then do nothing if the cursor is
3306 * outside the scrolling region
3308 private void cursorLeft(final int n
, final boolean honorScrollRegion
) {
3310 * Special case: if a user moves the cursor from the right margin, we
3311 * have to reset the VT100 right margin flag.
3314 wrapLineFlag
= false;
3317 for (int i
= 0; i
< n
; i
++) {
3318 if (honorScrollRegion
== true) {
3319 // Honor the scrolling region
3320 if ((currentState
.cursorY
< scrollRegionTop
)
3321 || (currentState
.cursorY
> scrollRegionBottom
)
3323 // Outside region, do nothing
3328 if (currentState
.cursorX
> 0) {
3329 currentState
.cursorX
--;
3335 * Move right n spaces.
3337 * @param n number of spaces to move
3338 * @param honorScrollRegion if true, then do nothing if the cursor is
3339 * outside the scrolling region
3341 private void cursorRight(final int n
, final boolean honorScrollRegion
) {
3342 int rightMargin
= this.rightMargin
;
3345 * Special case: if a user moves the cursor from the right margin, we
3346 * have to reset the VT100 right margin flag.
3349 wrapLineFlag
= false;
3352 if (display
.get(currentState
.cursorY
).isDoubleWidth()) {
3353 rightMargin
= ((rightMargin
+ 1) / 2) - 1;
3356 for (int i
= 0; i
< n
; i
++) {
3357 if (honorScrollRegion
== true) {
3358 // Honor the scrolling region
3359 if ((currentState
.cursorY
< scrollRegionTop
)
3360 || (currentState
.cursorY
> scrollRegionBottom
)
3362 // Outside region, do nothing
3367 if (currentState
.cursorX
< rightMargin
) {
3368 currentState
.cursorX
++;
3374 * Move cursor to (col, row) where (0, 0) is the top-left corner.
3376 * @param row row to move to
3377 * @param col column to move to
3379 private void cursorPosition(int row
, final int col
) {
3380 int rightMargin
= this.rightMargin
;
3385 if (display
.get(currentState
.cursorY
).isDoubleWidth()) {
3386 rightMargin
= ((rightMargin
+ 1) / 2) - 1;
3389 // Set column number
3390 currentState
.cursorX
= col
;
3392 // Sanity check, bring column back to margin.
3393 if (currentState
.cursorX
> rightMargin
) {
3394 currentState
.cursorX
= rightMargin
;
3398 if (currentState
.originMode
== true) {
3399 row
+= scrollRegionTop
;
3401 if (currentState
.cursorY
< row
) {
3402 cursorDown(row
- currentState
.cursorY
, false);
3403 } else if (currentState
.cursorY
> row
) {
3404 cursorUp(currentState
.cursorY
- row
, false);
3407 wrapLineFlag
= false;
3411 * HTS - Horizontal tabulation set.
3413 private void hts() {
3414 for (Integer stop
: tabStops
) {
3415 if (stop
== currentState
.cursorX
) {
3416 // Already have a tab stop here
3421 // Append a tab stop to the end of the array and resort them
3422 tabStops
.add(currentState
.cursorX
);
3423 Collections
.sort(tabStops
);
3427 * DECSWL - Single-width line.
3429 private void decswl() {
3430 display
.get(currentState
.cursorY
).setDoubleWidth(false);
3431 display
.get(currentState
.cursorY
).setDoubleHeight(0);
3435 * DECDWL - Double-width line.
3437 private void decdwl() {
3438 display
.get(currentState
.cursorY
).setDoubleWidth(true);
3439 display
.get(currentState
.cursorY
).setDoubleHeight(0);
3443 * DECHDL - Double-height + double-width line.
3445 * @param topHalf if true, this sets the row to be the top half row of a
3448 private void dechdl(final boolean topHalf
) {
3449 display
.get(currentState
.cursorY
).setDoubleWidth(true);
3450 if (topHalf
== true) {
3451 display
.get(currentState
.cursorY
).setDoubleHeight(1);
3453 display
.get(currentState
.cursorY
).setDoubleHeight(2);
3458 * DECALN - Screen alignment display.
3460 private void decaln() {
3461 Cell newCell
= new Cell('E');
3462 for (DisplayLine line
: display
) {
3463 for (int i
= 0; i
< line
.length(); i
++) {
3464 line
.replace(i
, newCell
);
3470 * DECSCL - Compatibility level.
3472 private void decscl() {
3473 int i
= getCsiParam(0, 0);
3474 int j
= getCsiParam(1, 0);
3478 currentState
.g0Charset
= CharacterSet
.US
;
3479 currentState
.g1Charset
= CharacterSet
.DRAWING
;
3481 } else if (i
== 62) {
3483 if ((j
== 0) || (j
== 2)) {
3485 } else if (j
== 1) {
3492 * CUD - Cursor down.
3494 private void cud() {
3495 cursorDown(getCsiParam(0, 1, 1, height
), true);
3499 * CUF - Cursor forward.
3501 private void cuf() {
3502 cursorRight(getCsiParam(0, 1, 1, rightMargin
+ 1), true);
3506 * CUB - Cursor backward.
3508 private void cub() {
3509 cursorLeft(getCsiParam(0, 1, 1, currentState
.cursorX
+ 1), true);
3515 private void cuu() {
3516 cursorUp(getCsiParam(0, 1, 1, currentState
.cursorY
+ 1), true);
3520 * CUP - Cursor position.
3522 private void cup() {
3523 cursorPosition(getCsiParam(0, 1, 1, height
) - 1,
3524 getCsiParam(1, 1, 1, rightMargin
+ 1) - 1);
3528 * CNL - Cursor down and to column 1.
3530 private void cnl() {
3531 cursorDown(getCsiParam(0, 1, 1, height
), true);
3533 cursorLeft(currentState
.cursorX
, true);
3537 * CPL - Cursor up and to column 1.
3539 private void cpl() {
3540 cursorUp(getCsiParam(0, 1, 1, currentState
.cursorY
+ 1), true);
3542 cursorLeft(currentState
.cursorX
, true);
3546 * CHA - Cursor to column # in current row.
3548 private void cha() {
3549 cursorPosition(currentState
.cursorY
,
3550 getCsiParam(0, 1, 1, rightMargin
+ 1) - 1);
3554 * VPA - Cursor to row #, same column.
3556 private void vpa() {
3557 cursorPosition(getCsiParam(0, 1, 1, height
) - 1,
3558 currentState
.cursorX
);
3562 * ED - Erase in display.
3565 boolean honorProtected
= false;
3566 boolean decPrivateModeFlag
= false;
3568 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
3569 if (collectBuffer
.charAt(i
) == '?') {
3570 decPrivateModeFlag
= true;
3575 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
3576 && (decPrivateModeFlag
== true)
3578 honorProtected
= true;
3581 int i
= getCsiParam(0, 0);
3584 // Erase from here to end of screen
3585 if (currentState
.cursorY
< height
- 1) {
3586 eraseScreen(currentState
.cursorY
+ 1, 0, height
- 1, width
- 1,
3589 eraseLine(currentState
.cursorX
, width
- 1, honorProtected
);
3590 } else if (i
== 1) {
3591 // Erase from beginning of screen to here
3592 eraseScreen(0, 0, currentState
.cursorY
- 1, width
- 1,
3594 eraseLine(0, currentState
.cursorX
, honorProtected
);
3595 } else if (i
== 2) {
3596 // Erase entire screen
3597 eraseScreen(0, 0, height
- 1, width
- 1, honorProtected
);
3602 * EL - Erase in line.
3605 boolean honorProtected
= false;
3606 boolean decPrivateModeFlag
= false;
3608 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
3609 if (collectBuffer
.charAt(i
) == '?') {
3610 decPrivateModeFlag
= true;
3615 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
3616 && (decPrivateModeFlag
== true)
3618 honorProtected
= true;
3621 int i
= getCsiParam(0, 0);
3624 // Erase from here to end of line
3625 eraseLine(currentState
.cursorX
, width
- 1, honorProtected
);
3626 } else if (i
== 1) {
3627 // Erase from beginning of line to here
3628 eraseLine(0, currentState
.cursorX
, honorProtected
);
3629 } else if (i
== 2) {
3630 // Erase entire line
3631 eraseLine(0, width
- 1, honorProtected
);
3636 * ECH - Erase # of characters in current row.
3638 private void ech() {
3639 int i
= getCsiParam(0, 1, 1, width
);
3641 // Erase from here to i characters
3642 eraseLine(currentState
.cursorX
, currentState
.cursorX
+ i
- 1, false);
3649 int i
= getCsiParam(0, 1);
3651 if ((currentState
.cursorY
>= scrollRegionTop
)
3652 && (currentState
.cursorY
<= scrollRegionBottom
)
3655 // I can get the same effect with a scroll-down
3656 scrollingRegionScrollDown(currentState
.cursorY
,
3657 scrollRegionBottom
, i
);
3662 * DCH - Delete char.
3664 private void dch() {
3665 int n
= getCsiParam(0, 1);
3666 DisplayLine line
= display
.get(currentState
.cursorY
);
3667 Cell blank
= new Cell();
3668 for (int i
= 0; i
< n
; i
++) {
3669 line
.delete(currentState
.cursorX
, blank
);
3674 * ICH - Insert blank char at cursor.
3676 private void ich() {
3677 int n
= getCsiParam(0, 1);
3678 DisplayLine line
= display
.get(currentState
.cursorY
);
3679 Cell blank
= new Cell();
3680 for (int i
= 0; i
< n
; i
++) {
3681 line
.insert(currentState
.cursorX
, blank
);
3689 int i
= getCsiParam(0, 1);
3691 if ((currentState
.cursorY
>= scrollRegionTop
)
3692 && (currentState
.cursorY
<= scrollRegionBottom
)) {
3694 // I can get the same effect with a scroll-down
3695 scrollingRegionScrollUp(currentState
.cursorY
,
3696 scrollRegionBottom
, i
);
3701 * HVP - Horizontal and vertical position.
3703 private void hvp() {
3708 * REP - Repeat character.
3710 private void rep() {
3711 int n
= getCsiParam(0, 1);
3712 for (int i
= 0; i
< n
; i
++) {
3713 printCharacter(repCh
);
3721 scrollingRegionScrollUp(scrollRegionTop
, scrollRegionBottom
,
3722 getCsiParam(0, 1, 1, height
));
3729 scrollingRegionScrollDown(scrollRegionTop
, scrollRegionBottom
,
3730 getCsiParam(0, 1, 1, height
));
3734 * CBT - Go back X tab stops.
3736 private void cbt() {
3737 int tabsToMove
= getCsiParam(0, 1);
3740 for (int i
= 0; i
< tabsToMove
; i
++) {
3741 int j
= currentState
.cursorX
;
3742 for (tabI
= 0; tabI
< tabStops
.size(); tabI
++) {
3743 if (tabStops
.get(tabI
) >= currentState
.cursorX
) {
3751 j
= tabStops
.get(tabI
);
3753 cursorPosition(currentState
.cursorY
, j
);
3758 * CHT - Advance X tab stops.
3760 private void cht() {
3761 int n
= getCsiParam(0, 1);
3762 for (int i
= 0; i
< n
; i
++) {
3763 advanceToNextTabStop();
3768 * SGR - Select graphics rendition.
3770 private void sgr() {
3772 if (csiParams
.size() == 0) {
3773 currentState
.attr
.reset();
3777 int sgrColorMode
= -1;
3778 boolean idx88Color
= false;
3779 boolean rgbColor
= false;
3783 for (Integer i
: csiParams
) {
3785 if ((sgrColorMode
== 38) || (sgrColorMode
== 48)) {
3787 assert (type
== DeviceType
.XTERM
);
3791 * Indexed color mode, we now have the index number.
3793 if (sgrColorMode
== 38) {
3794 currentState
.attr
.setForeColorRGB(get88Color(i
));
3796 assert (sgrColorMode
== 48);
3797 currentState
.attr
.setBackColorRGB(get88Color(i
));
3806 * RGB color mode, we are collecting tokens.
3810 } else if (rgbGreen
== -1) {
3811 rgbGreen
= i
& 0xFF;
3813 int rgb
= rgbRed
<< 16;
3814 rgb
|= rgbGreen
<< 8;
3817 // System.err.printf("RGB: %08x\n", rgb);
3819 if (sgrColorMode
== 38) {
3820 currentState
.attr
.setForeColorRGB(rgb
);
3822 assert (sgrColorMode
== 48);
3823 currentState
.attr
.setBackColorRGB(rgb
);
3844 * Indexed color mode.
3851 * This is neither indexed nor RGB color. Bail out.
3856 } // if ((sgrColorMode == 38) || (sgrColorMode == 48))
3862 currentState
.attr
.reset();
3867 currentState
.attr
.setBold(true);
3872 currentState
.attr
.setUnderline(true);
3877 currentState
.attr
.setBlink(true);
3882 currentState
.attr
.setReverse(true);
3889 if (type
== DeviceType
.XTERM
) {
3899 // Set black foreground
3900 currentState
.attr
.setForeColorRGB(get88Color(8));
3903 // Set red foreground
3904 currentState
.attr
.setForeColorRGB(get88Color(9));
3907 // Set green foreground
3908 currentState
.attr
.setForeColorRGB(get88Color(10));
3911 // Set yellow foreground
3912 currentState
.attr
.setForeColorRGB(get88Color(11));
3915 // Set blue foreground
3916 currentState
.attr
.setForeColorRGB(get88Color(12));
3919 // Set magenta foreground
3920 currentState
.attr
.setForeColorRGB(get88Color(13));
3923 // Set cyan foreground
3924 currentState
.attr
.setForeColorRGB(get88Color(14));
3927 // Set white foreground
3928 currentState
.attr
.setForeColorRGB(get88Color(15));
3932 // Set black background
3933 currentState
.attr
.setBackColorRGB(get88Color(8));
3936 // Set red background
3937 currentState
.attr
.setBackColorRGB(get88Color(9));
3940 // Set green background
3941 currentState
.attr
.setBackColorRGB(get88Color(10));
3944 // Set yellow background
3945 currentState
.attr
.setBackColorRGB(get88Color(11));
3948 // Set blue background
3949 currentState
.attr
.setBackColorRGB(get88Color(12));
3952 // Set magenta background
3953 currentState
.attr
.setBackColorRGB(get88Color(13));
3956 // Set cyan background
3957 currentState
.attr
.setBackColorRGB(get88Color(14));
3960 // Set white background
3961 currentState
.attr
.setBackColorRGB(get88Color(15));
3969 if ((type
== DeviceType
.VT220
)
3970 || (type
== DeviceType
.XTERM
)) {
3976 currentState
.attr
.setBold(false);
3981 currentState
.attr
.setUnderline(false);
3986 currentState
.attr
.setBlink(false);
3991 currentState
.attr
.setReverse(false);
3999 // A true VT100/102/220 does not support color, however everyone
4000 // is used to their terminal emulator supporting color so we will
4001 // unconditionally support color for all DeviceType's.
4006 // Set black foreground
4007 currentState
.attr
.setForeColor(Color
.BLACK
);
4008 currentState
.attr
.setForeColorRGB(-1);
4011 // Set red foreground
4012 currentState
.attr
.setForeColor(Color
.RED
);
4013 currentState
.attr
.setForeColorRGB(-1);
4016 // Set green foreground
4017 currentState
.attr
.setForeColor(Color
.GREEN
);
4018 currentState
.attr
.setForeColorRGB(-1);
4021 // Set yellow foreground
4022 currentState
.attr
.setForeColor(Color
.YELLOW
);
4023 currentState
.attr
.setForeColorRGB(-1);
4026 // Set blue foreground
4027 currentState
.attr
.setForeColor(Color
.BLUE
);
4028 currentState
.attr
.setForeColorRGB(-1);
4031 // Set magenta foreground
4032 currentState
.attr
.setForeColor(Color
.MAGENTA
);
4033 currentState
.attr
.setForeColorRGB(-1);
4036 // Set cyan foreground
4037 currentState
.attr
.setForeColor(Color
.CYAN
);
4038 currentState
.attr
.setForeColorRGB(-1);
4041 // Set white foreground
4042 currentState
.attr
.setForeColor(Color
.WHITE
);
4043 currentState
.attr
.setForeColorRGB(-1);
4046 if (type
== DeviceType
.XTERM
) {
4048 * Xterm supports T.416 / ISO-8613-3 codes to select
4049 * either an indexed color or an RGB value. (It also
4050 * permits these ISO-8613-3 SGR sequences to be separated
4051 * by colons rather than semicolons.)
4053 * We will support only the following:
4055 * 1. Indexed color mode (88- or 256-color modes).
4059 * These cover most of the use cases in the real world.
4061 * HOWEVER, note that this is an awful broken "standard",
4062 * with no way to do it "right". See
4063 * http://invisible-island.net/ncurses/ncurses.faq.html#xterm_16MegaColors
4064 * for a detailed discussion of the current state of RGB
4065 * in various terminals, the point of which is that none
4066 * of them really do the same thing despite all appearing
4070 * https://bugs.kde.org/show_bug.cgi?id=107487#c3 .
4071 * where it is assumed that supporting just the "indexed
4072 * mode" of these sequences (which could align easily
4073 * with existing SGR colors) is assumed to mean full
4074 * support of 24-bit RGB. So it is all or nothing.
4076 * Finally, these sequences break the assumptions of
4077 * standard ECMA-48 style parsers as pointed out at
4078 * https://bugs.kde.org/show_bug.cgi?id=107487#c11 .
4079 * Therefore in order to keep a clean display, we cannot
4080 * parse anything else in this sequence.
4085 // Underscore on, default foreground color
4086 currentState
.attr
.setUnderline(true);
4087 currentState
.attr
.setForeColor(Color
.WHITE
);
4091 // Underscore off, default foreground color
4092 currentState
.attr
.setUnderline(false);
4093 currentState
.attr
.setForeColor(Color
.WHITE
);
4094 currentState
.attr
.setForeColorRGB(-1);
4097 // Set black background
4098 currentState
.attr
.setBackColor(Color
.BLACK
);
4099 currentState
.attr
.setBackColorRGB(-1);
4102 // Set red background
4103 currentState
.attr
.setBackColor(Color
.RED
);
4104 currentState
.attr
.setBackColorRGB(-1);
4107 // Set green background
4108 currentState
.attr
.setBackColor(Color
.GREEN
);
4109 currentState
.attr
.setBackColorRGB(-1);
4112 // Set yellow background
4113 currentState
.attr
.setBackColor(Color
.YELLOW
);
4114 currentState
.attr
.setBackColorRGB(-1);
4117 // Set blue background
4118 currentState
.attr
.setBackColor(Color
.BLUE
);
4119 currentState
.attr
.setBackColorRGB(-1);
4122 // Set magenta background
4123 currentState
.attr
.setBackColor(Color
.MAGENTA
);
4124 currentState
.attr
.setBackColorRGB(-1);
4127 // Set cyan background
4128 currentState
.attr
.setBackColor(Color
.CYAN
);
4129 currentState
.attr
.setBackColorRGB(-1);
4132 // Set white background
4133 currentState
.attr
.setBackColor(Color
.WHITE
);
4134 currentState
.attr
.setBackColorRGB(-1);
4137 if (type
== DeviceType
.XTERM
) {
4139 * Xterm supports T.416 / ISO-8613-3 codes to select
4140 * either an indexed color or an RGB value. (It also
4141 * permits these ISO-8613-3 SGR sequences to be separated
4142 * by colons rather than semicolons.)
4144 * We will support only the following:
4146 * 1. Indexed color mode (88- or 256-color modes).
4150 * These cover most of the use cases in the real world.
4152 * HOWEVER, note that this is an awful broken "standard",
4153 * with no way to do it "right". See
4154 * http://invisible-island.net/ncurses/ncurses.faq.html#xterm_16MegaColors
4155 * for a detailed discussion of the current state of RGB
4156 * in various terminals, the point of which is that none
4157 * of them really do the same thing despite all appearing
4161 * https://bugs.kde.org/show_bug.cgi?id=107487#c3 .
4162 * where it is assumed that supporting just the "indexed
4163 * mode" of these sequences (which could align easily
4164 * with existing SGR colors) is assumed to mean full
4165 * support of 24-bit RGB. So it is all or nothing.
4167 * Finally, these sequences break the assumptions of
4168 * standard ECMA-48 style parsers as pointed out at
4169 * https://bugs.kde.org/show_bug.cgi?id=107487#c11 .
4170 * Therefore in order to keep a clean display, we cannot
4171 * parse anything else in this sequence.
4178 // Default background
4179 currentState
.attr
.setBackColor(Color
.BLACK
);
4180 currentState
.attr
.setBackColorRGB(-1);
4190 * DA - Device attributes.
4193 int extendedFlag
= 0;
4195 if (collectBuffer
.length() > 0) {
4196 String args
= collectBuffer
.substring(1);
4197 if (collectBuffer
.charAt(0) == '>') {
4199 if (collectBuffer
.length() >= 2) {
4200 i
= Integer
.parseInt(args
);
4202 } else if (collectBuffer
.charAt(0) == '=') {
4204 if (collectBuffer
.length() >= 2) {
4205 i
= Integer
.parseInt(args
);
4208 // Unknown code, bail out
4213 if ((i
!= 0) && (i
!= 1)) {
4217 if ((extendedFlag
== 0) && (i
== 0)) {
4218 // Send string directly to remote side
4219 writeRemote(deviceTypeResponse());
4223 if ((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
)) {
4225 if ((extendedFlag
== 1) && (i
== 0)) {
4227 * Request "What type of terminal are you, what is your
4228 * firmware version, and what hardware options do you have
4231 * Respond: "I am a VT220 (identification code of 1), my
4232 * firmware version is _____ (Pv), and I have _____ Po
4233 * options installed."
4239 if (s8c1t
== true) {
4240 writeRemote("\u009b>1;10;0c");
4242 writeRemote("\033[>1;10;0c");
4248 if ((extendedFlag
== 2) && (i
== 0)) {
4251 * Request "What is your unit ID?"
4253 * Respond: "I was manufactured at site 00 and have a unique ID
4257 writeRemote("\033P!|00010203\033\\");
4262 * DECSTBM - Set top and bottom margins.
4264 private void decstbm() {
4265 boolean decPrivateModeFlag
= false;
4267 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4268 if (collectBuffer
.charAt(i
) == '?') {
4269 decPrivateModeFlag
= true;
4273 if (decPrivateModeFlag
) {
4274 // This could be restore DEC private mode values.
4278 int top
= getCsiParam(0, 1, 1, height
) - 1;
4279 int bottom
= getCsiParam(1, height
, 1, height
) - 1;
4284 scrollRegionTop
= top
;
4285 scrollRegionBottom
= bottom
;
4288 cursorPosition(0, 0);
4293 * DECREQTPARM - Request terminal parameters.
4295 private void decreqtparm() {
4296 int i
= getCsiParam(0, 0);
4298 if ((i
!= 0) && (i
!= 1)) {
4305 * Request terminal parameters.
4309 * Parity NONE, 8 bits, xmitspeed 38400, recvspeed 38400.
4310 * (CLoCk MULtiplier = 1, STP option flags = 0)
4314 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4317 str
= String
.format("\u009b%d;1;1;128;128;1;0x", i
+ 2);
4319 str
= String
.format("\033[%d;1;1;128;128;1;0x", i
+ 2);
4325 * DECSCA - Select Character Attributes.
4327 private void decsca() {
4328 int i
= getCsiParam(0, 0);
4330 if ((i
== 0) || (i
== 2)) {
4332 currentState
.attr
.setProtect(false);
4336 currentState
.attr
.setProtect(true);
4341 * DECSTR - Soft Terminal Reset.
4343 private void decstr() {
4344 // Do exactly like RIS - Reset to initial state
4346 // Do I clear screen too? I think so...
4347 eraseScreen(0, 0, height
- 1, width
- 1, false);
4348 cursorPosition(0, 0);
4352 * DSR - Device status report.
4354 private void dsr() {
4355 boolean decPrivateModeFlag
= false;
4356 int row
= currentState
.cursorY
;
4358 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4359 if (collectBuffer
.charAt(i
) == '?') {
4360 decPrivateModeFlag
= true;
4365 int i
= getCsiParam(0, 0);
4370 // Request status report. Respond with "OK, no malfunction."
4372 // Send string directly to remote side
4373 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4376 writeRemote("\u009b0n");
4378 writeRemote("\033[0n");
4383 // Request cursor position. Respond with current position.
4384 if (currentState
.originMode
== true) {
4385 row
-= scrollRegionTop
;
4388 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4391 str
= String
.format("\u009b%d;%dR", row
+ 1,
4392 currentState
.cursorX
+ 1);
4394 str
= String
.format("\033[%d;%dR", row
+ 1,
4395 currentState
.cursorX
+ 1);
4398 // Send string directly to remote side
4403 if (decPrivateModeFlag
== true) {
4405 // Request printer status report. Respond with "Printer not
4408 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4409 && (s8c1t
== true)) {
4410 writeRemote("\u009b?13n");
4412 writeRemote("\033[?13n");
4418 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4419 && (decPrivateModeFlag
== true)
4422 // Request user-defined keys are locked or unlocked. Respond
4423 // with "User-defined keys are locked."
4425 if (s8c1t
== true) {
4426 writeRemote("\u009b?21n");
4428 writeRemote("\033[?21n");
4434 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4435 && (decPrivateModeFlag
== true)
4438 // Request keyboard language. Respond with "Keyboard
4439 // language is North American."
4441 if (s8c1t
== true) {
4442 writeRemote("\u009b?27;1n");
4444 writeRemote("\033[?27;1n");
4451 // Some other option, ignore
4457 * TBC - Tabulation clear.
4459 private void tbc() {
4460 int i
= getCsiParam(0, 0);
4462 List
<Integer
> newStops
= new ArrayList
<Integer
>();
4463 for (Integer stop
: tabStops
) {
4464 if (stop
== currentState
.cursorX
) {
4469 tabStops
= newStops
;
4477 * Erase the characters in the current line from the start column to the
4478 * end column, inclusive.
4480 * @param start starting column to erase (between 0 and width - 1)
4481 * @param end ending column to erase (between 0 and width - 1)
4482 * @param honorProtected if true, do not erase characters with the
4483 * protected attribute set
4485 private void eraseLine(int start
, int end
, final boolean honorProtected
) {
4490 if (end
> width
- 1) {
4497 for (int i
= start
; i
<= end
; i
++) {
4498 DisplayLine line
= display
.get(currentState
.cursorY
);
4499 if ((!honorProtected
)
4500 || ((honorProtected
) && (!line
.charAt(i
).isProtect()))) {
4507 * From the VT102 manual:
4509 * Erasing a character also erases any character
4510 * attribute of the character.
4516 * Erase with the current color a.k.a. back-color erase
4519 line
.setChar(i
, ' ');
4520 line
.setAttr(i
, currentState
.attr
);
4528 * Erase a rectangular section of the screen, inclusive. end column,
4531 * @param startRow starting row to erase (between 0 and height - 1)
4532 * @param startCol starting column to erase (between 0 and width - 1)
4533 * @param endRow ending row to erase (between 0 and height - 1)
4534 * @param endCol ending column to erase (between 0 and width - 1)
4535 * @param honorProtected if true, do not erase characters with the
4536 * protected attribute set
4538 private void eraseScreen(final int startRow
, final int startCol
,
4539 final int endRow
, final int endCol
, final boolean honorProtected
) {
4547 || (endRow
< startRow
)
4548 || (endCol
< startCol
)
4553 oldCursorY
= currentState
.cursorY
;
4554 for (int i
= startRow
; i
<= endRow
; i
++) {
4555 currentState
.cursorY
= i
;
4556 eraseLine(startCol
, endCol
, honorProtected
);
4558 // Erase display clears the double attributes
4559 display
.get(i
).setDoubleWidth(false);
4560 display
.get(i
).setDoubleHeight(0);
4562 currentState
.cursorY
= oldCursorY
;
4566 * VT220 printer functions. All of these are parsed, but won't do
4569 private void printerFunctions() {
4570 boolean decPrivateModeFlag
= false;
4571 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4572 if (collectBuffer
.charAt(i
) == '?') {
4573 decPrivateModeFlag
= true;
4578 int i
= getCsiParam(0, 0);
4583 if (decPrivateModeFlag
== false) {
4589 if (decPrivateModeFlag
== true) {
4590 // Print cursor line
4595 if (decPrivateModeFlag
== true) {
4596 // Auto print mode OFF
4598 // Printer controller OFF
4600 // Characters re-appear on the screen
4601 printerControllerMode
= false;
4606 if (decPrivateModeFlag
== true) {
4610 // Printer controller
4612 // Characters get sucked into oblivion
4613 printerControllerMode
= true;
4624 * Handle the SCAN_OSC_STRING state. Handle this in VT100 because lots
4625 * of remote systems will send an XTerm title sequence even if TERM isn't
4628 * @param xtermChar the character received from the remote side
4630 private void oscPut(final char xtermChar
) {
4631 // System.err.println("oscPut: " + xtermChar);
4634 collectBuffer
.append(xtermChar
);
4637 if ((xtermChar
== 0x07)
4638 || (collectBuffer
.toString().endsWith("\033\\"))
4641 if (xtermChar
== 0x07) {
4642 args
= collectBuffer
.substring(0, collectBuffer
.length() - 1);
4644 args
= collectBuffer
.substring(0, collectBuffer
.length() - 2);
4647 String
[] p
= args
.split(";");
4649 if ((p
[0].equals("0")) || (p
[0].equals("2"))) {
4656 if (p
[0].equals("4")) {
4657 for (int i
= 1; i
+ 1 < p
.length
; i
+= 2) {
4658 // Set a color index value
4660 set88Color(Integer
.parseInt(p
[i
]), p
[i
+ 1]);
4661 } catch (NumberFormatException e
) {
4668 // Go to SCAN_GROUND state
4675 * Handle the SCAN_SOSPMAPC_STRING state. This is currently only used by
4676 * Jexer ECMA48Terminal to talk to ECMA48.
4678 * @param pmChar the character received from the remote side
4680 private void pmPut(final char pmChar
) {
4681 // System.err.println("pmPut: " + pmChar);
4684 collectBuffer
.append(pmChar
);
4687 if (collectBuffer
.toString().endsWith("\033\\")) {
4689 arg
= collectBuffer
.substring(0, collectBuffer
.length() - 2);
4691 // System.err.println("arg: '" + arg + "'");
4693 if (arg
.equals("hideMousePointer")) {
4694 hideMousePointer
= true;
4696 if (arg
.equals("showMousePointer")) {
4697 hideMousePointer
= false;
4700 // Go to SCAN_GROUND state
4707 * Perform xterm window operations.
4709 private void xtermWindowOps() {
4710 boolean xtermPrivateModeFlag
= false;
4712 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4713 if (collectBuffer
.charAt(i
) == '?') {
4714 xtermPrivateModeFlag
= true;
4719 int i
= getCsiParam(0, 0);
4721 if (!xtermPrivateModeFlag
) {
4723 // Report xterm window in pixels as CSI 4 ; height ; width t
4724 writeRemote(String
.format("\033[4;%d;%dt", textHeight
* height
,
4725 textWidth
* width
));
4731 * Run this input character through the ECMA48 state machine.
4733 * @param ch character from the remote side
4735 private void consume(char ch
) {
4738 // System.err.printf("%c STATE = %s\n", ch, scanState);
4740 // Special case for VT10x: 7-bit characters only
4741 if ((type
== DeviceType
.VT100
) || (type
== DeviceType
.VT102
)) {
4742 ch
= (char)(ch
& 0x7F);
4745 // Special "anywhere" states
4747 // 18, 1A --> execute, then switch to SCAN_GROUND
4748 if ((ch
== 0x18) || (ch
== 0x1A)) {
4749 // CAN and SUB abort escape sequences
4754 // 80-8F, 91-97, 99, 9A, 9C --> execute, then switch to SCAN_GROUND
4758 if ((type
== DeviceType
.XTERM
)
4759 && ((scanState
== ScanState
.OSC_STRING
)
4760 || (scanState
== ScanState
.DCS_SIXEL
)
4761 || (scanState
== ScanState
.SOSPMAPC_STRING
))
4763 // Xterm can pass ESCAPE to its OSC sequence.
4764 // Xterm can pass ESCAPE to its DCS sequence.
4765 // Jexer can pass ESCAPE to its PM sequence.
4766 } else if ((scanState
!= ScanState
.DCS_ENTRY
)
4767 && (scanState
!= ScanState
.DCS_INTERMEDIATE
)
4768 && (scanState
!= ScanState
.DCS_IGNORE
)
4769 && (scanState
!= ScanState
.DCS_PARAM
)
4770 && (scanState
!= ScanState
.DCS_PASSTHROUGH
)
4772 scanState
= ScanState
.ESCAPE
;
4777 // 0x9B == CSI 8-bit sequence
4779 scanState
= ScanState
.CSI_ENTRY
;
4783 // 0x9D goes to ScanState.OSC_STRING
4785 scanState
= ScanState
.OSC_STRING
;
4789 // 0x90 goes to DCS_ENTRY
4791 scanState
= ScanState
.DCS_ENTRY
;
4795 // 0x98, 0x9E, and 0x9F go to SOSPMAPC_STRING
4796 if ((ch
== 0x98) || (ch
== 0x9E) || (ch
== 0x9F)) {
4797 scanState
= ScanState
.SOSPMAPC_STRING
;
4801 // 0x7F (DEL) is always discarded
4806 switch (scanState
) {
4809 // 00-17, 19, 1C-1F --> execute
4810 // 80-8F, 91-9A, 9C --> execute
4811 if ((ch
<= 0x1F) || ((ch
>= 0x80) && (ch
<= 0x9F))) {
4812 handleControlChar(ch
);
4816 if (((ch
>= 0x20) && (ch
<= 0x7F))
4820 // VT220 printer --> trash bin
4821 if (((type
== DeviceType
.VT220
)
4822 || (type
== DeviceType
.XTERM
))
4823 && (printerControllerMode
== true)
4828 // Hang onto this character
4829 repCh
= mapCharacter(ch
);
4831 // Print this character
4832 printCharacter(repCh
);
4837 // 00-17, 19, 1C-1F --> execute
4839 handleControlChar(ch
);
4843 // 20-2F --> collect, then switch to ESCAPE_INTERMEDIATE
4844 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
4846 scanState
= ScanState
.ESCAPE_INTERMEDIATE
;
4850 // 30-4F, 51-57, 59, 5A, 5C, 60-7E --> dispatch, then switch to GROUND
4851 if ((ch
>= 0x30) && (ch
<= 0x4F)) {
4862 // DECSC - Save cursor
4863 // Note this code overlaps both ANSI and VT52 mode
4868 // DECRC - Restore cursor
4869 // Note this code overlaps both ANSI and VT52 mode
4878 if (vt52Mode
== true) {
4879 // DECANM - Enter ANSI mode
4881 arrowKeyMode
= ArrowKeyMode
.VT100
;
4884 * From the VT102 docs: "You use ANSI mode to select
4885 * most terminal features; the terminal uses the same
4886 * features when it switches to VT52 mode. You
4887 * cannot, however, change most of these features in
4890 * In other words, do not reset any other attributes
4891 * when switching between VT52 submode and ANSI.
4895 currentState
.g0Charset
= CharacterSet
.US
;
4896 currentState
.g1Charset
= CharacterSet
.DRAWING
;
4898 singleshift
= Singleshift
.NONE
;
4899 currentState
.glLockshift
= LockshiftMode
.NONE
;
4900 currentState
.grLockshift
= LockshiftMode
.NONE
;
4904 // DECKPAM - Keypad application mode
4905 // Note this code overlaps both ANSI and VT52 mode
4909 // DECKPNM - Keypad numeric mode
4910 // Note this code overlaps both ANSI and VT52 mode
4917 if (vt52Mode
== true) {
4918 // Cursor up, and stop at the top without scrolling
4923 if (vt52Mode
== true) {
4924 // Cursor down, and stop at the bottom without scrolling
4925 cursorDown(1, false);
4929 if (vt52Mode
== true) {
4930 // Cursor right, and stop at the right without scrolling
4931 cursorRight(1, false);
4935 if (vt52Mode
== true) {
4936 // Cursor left, and stop at the left without scrolling
4937 cursorLeft(1, false);
4944 if (vt52Mode
== true) {
4952 if (vt52Mode
== true) {
4953 // G0 --> Special graphics
4954 currentState
.g0Charset
= CharacterSet
.VT52_GRAPHICS
;
4958 if (vt52Mode
== true) {
4960 currentState
.g0Charset
= CharacterSet
.US
;
4964 if (vt52Mode
== true) {
4966 cursorPosition(0, 0);
4968 // HTS - Horizontal tabulation set
4973 if (vt52Mode
== true) {
4974 // Reverse line feed. Same as RI.
4979 if (vt52Mode
== true) {
4980 // Erase to end of screen
4981 eraseLine(currentState
.cursorX
, width
- 1, false);
4982 eraseScreen(currentState
.cursorY
+ 1, 0, height
- 1,
4987 if (vt52Mode
== true) {
4988 // Erase to end of line
4989 eraseLine(currentState
.cursorX
, width
- 1, false);
4995 if (vt52Mode
== true) {
4998 // RI - Reverse index
5003 if (vt52Mode
== false) {
5005 singleshift
= Singleshift
.SS2
;
5009 if (vt52Mode
== false) {
5011 singleshift
= Singleshift
.SS3
;
5018 if ((ch
>= 0x51) && (ch
<= 0x57)) {
5034 if (vt52Mode
== true) {
5035 scanState
= ScanState
.VT52_DIRECT_CURSOR_ADDRESS
;
5043 if (vt52Mode
== true) {
5045 // Send string directly to remote side
5046 writeRemote("\033/Z");
5049 // Send string directly to remote side
5050 writeRemote(deviceTypeResponse());
5061 // VT52 cannot get to any of these other states
5062 if (vt52Mode
== true) {
5067 if ((ch
>= 0x60) && (ch
<= 0x7E)) {
5074 // RIS - Reset to initial state
5076 // Do I clear screen too? I think so...
5077 eraseScreen(0, 0, height
- 1, width
- 1, false);
5078 cursorPosition(0, 0);
5092 if ((type
== DeviceType
.VT220
)
5093 || (type
== DeviceType
.XTERM
)) {
5095 // VT220 lockshift G2 into GL
5096 currentState
.glLockshift
= LockshiftMode
.G2_GL
;
5101 if ((type
== DeviceType
.VT220
)
5102 || (type
== DeviceType
.XTERM
)) {
5104 // VT220 lockshift G3 into GL
5105 currentState
.glLockshift
= LockshiftMode
.G3_GL
;
5123 if ((type
== DeviceType
.VT220
)
5124 || (type
== DeviceType
.XTERM
)) {
5126 // VT220 lockshift G3 into GR
5127 currentState
.grLockshift
= LockshiftMode
.G3_GR
;
5132 if ((type
== DeviceType
.VT220
)
5133 || (type
== DeviceType
.XTERM
)) {
5135 // VT220 lockshift G2 into GR
5136 currentState
.grLockshift
= LockshiftMode
.G2_GR
;
5142 if ((type
== DeviceType
.VT220
)
5143 || (type
== DeviceType
.XTERM
)) {
5145 // VT220 lockshift G1 into GR
5146 currentState
.grLockshift
= LockshiftMode
.G1_GR
;
5156 // 0x5B goes to CSI_ENTRY
5158 scanState
= ScanState
.CSI_ENTRY
;
5161 // 0x5D goes to OSC_STRING
5163 scanState
= ScanState
.OSC_STRING
;
5166 // 0x50 goes to DCS_ENTRY
5168 scanState
= ScanState
.DCS_ENTRY
;
5171 // 0x58, 0x5E, and 0x5F go to SOSPMAPC_STRING
5172 if ((ch
== 0x58) || (ch
== 0x5E) || (ch
== 0x5F)) {
5173 scanState
= ScanState
.SOSPMAPC_STRING
;
5178 case ESCAPE_INTERMEDIATE
:
5179 // 00-17, 19, 1C-1F --> execute
5181 handleControlChar(ch
);
5184 // 20-2F --> collect
5185 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
5189 // 30-7E --> dispatch, then switch to GROUND
5190 if ((ch
>= 0x30) && (ch
<= 0x7E)) {
5193 if ((collectBuffer
.length() == 1)
5194 && (collectBuffer
.charAt(0) == '(')) {
5195 // G0 --> Special graphics
5196 currentState
.g0Charset
= CharacterSet
.DRAWING
;
5198 if ((collectBuffer
.length() == 1)
5199 && (collectBuffer
.charAt(0) == ')')) {
5200 // G1 --> Special graphics
5201 currentState
.g1Charset
= CharacterSet
.DRAWING
;
5203 if ((type
== DeviceType
.VT220
)
5204 || (type
== DeviceType
.XTERM
)) {
5206 if ((collectBuffer
.length() == 1)
5207 && (collectBuffer
.charAt(0) == '*')) {
5208 // G2 --> Special graphics
5209 currentState
.g2Charset
= CharacterSet
.DRAWING
;
5211 if ((collectBuffer
.length() == 1)
5212 && (collectBuffer
.charAt(0) == '+')) {
5213 // G3 --> Special graphics
5214 currentState
.g3Charset
= CharacterSet
.DRAWING
;
5219 if ((collectBuffer
.length() == 1)
5220 && (collectBuffer
.charAt(0) == '(')) {
5221 // G0 --> Alternate character ROM standard character set
5222 currentState
.g0Charset
= CharacterSet
.ROM
;
5224 if ((collectBuffer
.length() == 1)
5225 && (collectBuffer
.charAt(0) == ')')) {
5226 // G1 --> Alternate character ROM standard character set
5227 currentState
.g1Charset
= CharacterSet
.ROM
;
5231 if ((collectBuffer
.length() == 1)
5232 && (collectBuffer
.charAt(0) == '(')) {
5233 // G0 --> Alternate character ROM special graphics
5234 currentState
.g0Charset
= CharacterSet
.ROM_SPECIAL
;
5236 if ((collectBuffer
.length() == 1)
5237 && (collectBuffer
.charAt(0) == ')')) {
5238 // G1 --> Alternate character ROM special graphics
5239 currentState
.g1Charset
= CharacterSet
.ROM_SPECIAL
;
5243 if ((collectBuffer
.length() == 1)
5244 && (collectBuffer
.charAt(0) == '#')) {
5245 // DECDHL - Double-height line (top half)
5250 if ((collectBuffer
.length() == 1)
5251 && (collectBuffer
.charAt(0) == '#')) {
5252 // DECDHL - Double-height line (bottom half)
5255 if ((type
== DeviceType
.VT220
)
5256 || (type
== DeviceType
.XTERM
)) {
5258 if ((collectBuffer
.length() == 1)
5259 && (collectBuffer
.charAt(0) == '(')) {
5261 currentState
.g0Charset
= CharacterSet
.NRC_DUTCH
;
5263 if ((collectBuffer
.length() == 1)
5264 && (collectBuffer
.charAt(0) == ')')) {
5266 currentState
.g1Charset
= CharacterSet
.NRC_DUTCH
;
5268 if ((collectBuffer
.length() == 1)
5269 && (collectBuffer
.charAt(0) == '*')) {
5271 currentState
.g2Charset
= CharacterSet
.NRC_DUTCH
;
5273 if ((collectBuffer
.length() == 1)
5274 && (collectBuffer
.charAt(0) == '+')) {
5276 currentState
.g3Charset
= CharacterSet
.NRC_DUTCH
;
5281 if ((collectBuffer
.length() == 1)
5282 && (collectBuffer
.charAt(0) == '#')) {
5283 // DECSWL - Single-width line
5286 if ((type
== DeviceType
.VT220
)
5287 || (type
== DeviceType
.XTERM
)) {
5289 if ((collectBuffer
.length() == 1)
5290 && (collectBuffer
.charAt(0) == '(')) {
5292 currentState
.g0Charset
= CharacterSet
.NRC_FINNISH
;
5294 if ((collectBuffer
.length() == 1)
5295 && (collectBuffer
.charAt(0) == ')')) {
5297 currentState
.g1Charset
= CharacterSet
.NRC_FINNISH
;
5299 if ((collectBuffer
.length() == 1)
5300 && (collectBuffer
.charAt(0) == '*')) {
5302 currentState
.g2Charset
= CharacterSet
.NRC_FINNISH
;
5304 if ((collectBuffer
.length() == 1)
5305 && (collectBuffer
.charAt(0) == '+')) {
5307 currentState
.g3Charset
= CharacterSet
.NRC_FINNISH
;
5312 if ((collectBuffer
.length() == 1)
5313 && (collectBuffer
.charAt(0) == '#')) {
5314 // DECDWL - Double-width line
5317 if ((type
== DeviceType
.VT220
)
5318 || (type
== DeviceType
.XTERM
)) {
5320 if ((collectBuffer
.length() == 1)
5321 && (collectBuffer
.charAt(0) == '(')) {
5323 currentState
.g0Charset
= CharacterSet
.NRC_NORWEGIAN
;
5325 if ((collectBuffer
.length() == 1)
5326 && (collectBuffer
.charAt(0) == ')')) {
5328 currentState
.g1Charset
= CharacterSet
.NRC_NORWEGIAN
;
5330 if ((collectBuffer
.length() == 1)
5331 && (collectBuffer
.charAt(0) == '*')) {
5333 currentState
.g2Charset
= CharacterSet
.NRC_NORWEGIAN
;
5335 if ((collectBuffer
.length() == 1)
5336 && (collectBuffer
.charAt(0) == '+')) {
5338 currentState
.g3Charset
= CharacterSet
.NRC_NORWEGIAN
;
5343 if ((type
== DeviceType
.VT220
)
5344 || (type
== DeviceType
.XTERM
)) {
5346 if ((collectBuffer
.length() == 1)
5347 && (collectBuffer
.charAt(0) == '(')) {
5349 currentState
.g0Charset
= CharacterSet
.NRC_SWEDISH
;
5351 if ((collectBuffer
.length() == 1)
5352 && (collectBuffer
.charAt(0) == ')')) {
5354 currentState
.g1Charset
= CharacterSet
.NRC_SWEDISH
;
5356 if ((collectBuffer
.length() == 1)
5357 && (collectBuffer
.charAt(0) == '*')) {
5359 currentState
.g2Charset
= CharacterSet
.NRC_SWEDISH
;
5361 if ((collectBuffer
.length() == 1)
5362 && (collectBuffer
.charAt(0) == '+')) {
5364 currentState
.g3Charset
= CharacterSet
.NRC_SWEDISH
;
5369 if ((collectBuffer
.length() == 1)
5370 && (collectBuffer
.charAt(0) == '#')) {
5371 // DECALN - Screen alignment display
5380 if ((type
== DeviceType
.VT220
)
5381 || (type
== DeviceType
.XTERM
)) {
5383 if ((collectBuffer
.length() == 1)
5384 && (collectBuffer
.charAt(0) == '(')) {
5385 // G0 --> DEC_SUPPLEMENTAL
5386 currentState
.g0Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5388 if ((collectBuffer
.length() == 1)
5389 && (collectBuffer
.charAt(0) == ')')) {
5390 // G1 --> DEC_SUPPLEMENTAL
5391 currentState
.g1Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5393 if ((collectBuffer
.length() == 1)
5394 && (collectBuffer
.charAt(0) == '*')) {
5395 // G2 --> DEC_SUPPLEMENTAL
5396 currentState
.g2Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5398 if ((collectBuffer
.length() == 1)
5399 && (collectBuffer
.charAt(0) == '+')) {
5400 // G3 --> DEC_SUPPLEMENTAL
5401 currentState
.g3Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5406 if ((type
== DeviceType
.VT220
)
5407 || (type
== DeviceType
.XTERM
)) {
5409 if ((collectBuffer
.length() == 1)
5410 && (collectBuffer
.charAt(0) == '(')) {
5412 currentState
.g0Charset
= CharacterSet
.NRC_SWISS
;
5414 if ((collectBuffer
.length() == 1)
5415 && (collectBuffer
.charAt(0) == ')')) {
5417 currentState
.g1Charset
= CharacterSet
.NRC_SWISS
;
5419 if ((collectBuffer
.length() == 1)
5420 && (collectBuffer
.charAt(0) == '*')) {
5422 currentState
.g2Charset
= CharacterSet
.NRC_SWISS
;
5424 if ((collectBuffer
.length() == 1)
5425 && (collectBuffer
.charAt(0) == '+')) {
5427 currentState
.g3Charset
= CharacterSet
.NRC_SWISS
;
5436 if ((collectBuffer
.length() == 1)
5437 && (collectBuffer
.charAt(0) == '(')) {
5438 // G0 --> United Kingdom set
5439 currentState
.g0Charset
= CharacterSet
.UK
;
5441 if ((collectBuffer
.length() == 1)
5442 && (collectBuffer
.charAt(0) == ')')) {
5443 // G1 --> United Kingdom set
5444 currentState
.g1Charset
= CharacterSet
.UK
;
5446 if ((type
== DeviceType
.VT220
)
5447 || (type
== DeviceType
.XTERM
)) {
5449 if ((collectBuffer
.length() == 1)
5450 && (collectBuffer
.charAt(0) == '*')) {
5451 // G2 --> United Kingdom set
5452 currentState
.g2Charset
= CharacterSet
.UK
;
5454 if ((collectBuffer
.length() == 1)
5455 && (collectBuffer
.charAt(0) == '+')) {
5456 // G3 --> United Kingdom set
5457 currentState
.g3Charset
= CharacterSet
.UK
;
5462 if ((collectBuffer
.length() == 1)
5463 && (collectBuffer
.charAt(0) == '(')) {
5465 currentState
.g0Charset
= CharacterSet
.US
;
5467 if ((collectBuffer
.length() == 1)
5468 && (collectBuffer
.charAt(0) == ')')) {
5470 currentState
.g1Charset
= CharacterSet
.US
;
5472 if ((type
== DeviceType
.VT220
)
5473 || (type
== DeviceType
.XTERM
)) {
5475 if ((collectBuffer
.length() == 1)
5476 && (collectBuffer
.charAt(0) == '*')) {
5478 currentState
.g2Charset
= CharacterSet
.US
;
5480 if ((collectBuffer
.length() == 1)
5481 && (collectBuffer
.charAt(0) == '+')) {
5483 currentState
.g3Charset
= CharacterSet
.US
;
5488 if ((type
== DeviceType
.VT220
)
5489 || (type
== DeviceType
.XTERM
)) {
5491 if ((collectBuffer
.length() == 1)
5492 && (collectBuffer
.charAt(0) == '(')) {
5494 currentState
.g0Charset
= CharacterSet
.NRC_FINNISH
;
5496 if ((collectBuffer
.length() == 1)
5497 && (collectBuffer
.charAt(0) == ')')) {
5499 currentState
.g1Charset
= CharacterSet
.NRC_FINNISH
;
5501 if ((collectBuffer
.length() == 1)
5502 && (collectBuffer
.charAt(0) == '*')) {
5504 currentState
.g2Charset
= CharacterSet
.NRC_FINNISH
;
5506 if ((collectBuffer
.length() == 1)
5507 && (collectBuffer
.charAt(0) == '+')) {
5509 currentState
.g3Charset
= CharacterSet
.NRC_FINNISH
;
5516 if ((type
== DeviceType
.VT220
)
5517 || (type
== DeviceType
.XTERM
)) {
5519 if ((collectBuffer
.length() == 1)
5520 && (collectBuffer
.charAt(0) == '(')) {
5522 currentState
.g0Charset
= CharacterSet
.NRC_NORWEGIAN
;
5524 if ((collectBuffer
.length() == 1)
5525 && (collectBuffer
.charAt(0) == ')')) {
5527 currentState
.g1Charset
= CharacterSet
.NRC_NORWEGIAN
;
5529 if ((collectBuffer
.length() == 1)
5530 && (collectBuffer
.charAt(0) == '*')) {
5532 currentState
.g2Charset
= CharacterSet
.NRC_NORWEGIAN
;
5534 if ((collectBuffer
.length() == 1)
5535 && (collectBuffer
.charAt(0) == '+')) {
5537 currentState
.g3Charset
= CharacterSet
.NRC_NORWEGIAN
;
5542 if ((type
== DeviceType
.VT220
)
5543 || (type
== DeviceType
.XTERM
)) {
5545 if ((collectBuffer
.length() == 1)
5546 && (collectBuffer
.charAt(0) == ' ')) {
5553 if ((type
== DeviceType
.VT220
)
5554 || (type
== DeviceType
.XTERM
)) {
5556 if ((collectBuffer
.length() == 1)
5557 && (collectBuffer
.charAt(0) == ' ')) {
5564 if ((type
== DeviceType
.VT220
)
5565 || (type
== DeviceType
.XTERM
)) {
5567 if ((collectBuffer
.length() == 1)
5568 && (collectBuffer
.charAt(0) == '(')) {
5570 currentState
.g0Charset
= CharacterSet
.NRC_SWEDISH
;
5572 if ((collectBuffer
.length() == 1)
5573 && (collectBuffer
.charAt(0) == ')')) {
5575 currentState
.g1Charset
= CharacterSet
.NRC_SWEDISH
;
5577 if ((collectBuffer
.length() == 1)
5578 && (collectBuffer
.charAt(0) == '*')) {
5580 currentState
.g2Charset
= CharacterSet
.NRC_SWEDISH
;
5582 if ((collectBuffer
.length() == 1)
5583 && (collectBuffer
.charAt(0) == '+')) {
5585 currentState
.g3Charset
= CharacterSet
.NRC_SWEDISH
;
5593 if ((type
== DeviceType
.VT220
)
5594 || (type
== DeviceType
.XTERM
)) {
5596 if ((collectBuffer
.length() == 1)
5597 && (collectBuffer
.charAt(0) == '(')) {
5599 currentState
.g0Charset
= CharacterSet
.NRC_GERMAN
;
5601 if ((collectBuffer
.length() == 1)
5602 && (collectBuffer
.charAt(0) == ')')) {
5604 currentState
.g1Charset
= CharacterSet
.NRC_GERMAN
;
5606 if ((collectBuffer
.length() == 1)
5607 && (collectBuffer
.charAt(0) == '*')) {
5609 currentState
.g2Charset
= CharacterSet
.NRC_GERMAN
;
5611 if ((collectBuffer
.length() == 1)
5612 && (collectBuffer
.charAt(0) == '+')) {
5614 currentState
.g3Charset
= CharacterSet
.NRC_GERMAN
;
5625 if ((type
== DeviceType
.VT220
)
5626 || (type
== DeviceType
.XTERM
)) {
5628 if ((collectBuffer
.length() == 1)
5629 && (collectBuffer
.charAt(0) == '(')) {
5631 currentState
.g0Charset
= CharacterSet
.NRC_FRENCH_CA
;
5633 if ((collectBuffer
.length() == 1)
5634 && (collectBuffer
.charAt(0) == ')')) {
5636 currentState
.g1Charset
= CharacterSet
.NRC_FRENCH_CA
;
5638 if ((collectBuffer
.length() == 1)
5639 && (collectBuffer
.charAt(0) == '*')) {
5641 currentState
.g2Charset
= CharacterSet
.NRC_FRENCH_CA
;
5643 if ((collectBuffer
.length() == 1)
5644 && (collectBuffer
.charAt(0) == '+')) {
5646 currentState
.g3Charset
= CharacterSet
.NRC_FRENCH_CA
;
5651 if ((type
== DeviceType
.VT220
)
5652 || (type
== DeviceType
.XTERM
)) {
5654 if ((collectBuffer
.length() == 1)
5655 && (collectBuffer
.charAt(0) == '(')) {
5657 currentState
.g0Charset
= CharacterSet
.NRC_FRENCH
;
5659 if ((collectBuffer
.length() == 1)
5660 && (collectBuffer
.charAt(0) == ')')) {
5662 currentState
.g1Charset
= CharacterSet
.NRC_FRENCH
;
5664 if ((collectBuffer
.length() == 1)
5665 && (collectBuffer
.charAt(0) == '*')) {
5667 currentState
.g2Charset
= CharacterSet
.NRC_FRENCH
;
5669 if ((collectBuffer
.length() == 1)
5670 && (collectBuffer
.charAt(0) == '+')) {
5672 currentState
.g3Charset
= CharacterSet
.NRC_FRENCH
;
5684 if ((type
== DeviceType
.VT220
)
5685 || (type
== DeviceType
.XTERM
)) {
5687 if ((collectBuffer
.length() == 1)
5688 && (collectBuffer
.charAt(0) == '(')) {
5690 currentState
.g0Charset
= CharacterSet
.NRC_ITALIAN
;
5692 if ((collectBuffer
.length() == 1)
5693 && (collectBuffer
.charAt(0) == ')')) {
5695 currentState
.g1Charset
= CharacterSet
.NRC_ITALIAN
;
5697 if ((collectBuffer
.length() == 1)
5698 && (collectBuffer
.charAt(0) == '*')) {
5700 currentState
.g2Charset
= CharacterSet
.NRC_ITALIAN
;
5702 if ((collectBuffer
.length() == 1)
5703 && (collectBuffer
.charAt(0) == '+')) {
5705 currentState
.g3Charset
= CharacterSet
.NRC_ITALIAN
;
5710 if ((type
== DeviceType
.VT220
)
5711 || (type
== DeviceType
.XTERM
)) {
5713 if ((collectBuffer
.length() == 1)
5714 && (collectBuffer
.charAt(0) == '(')) {
5716 currentState
.g0Charset
= CharacterSet
.NRC_SPANISH
;
5718 if ((collectBuffer
.length() == 1)
5719 && (collectBuffer
.charAt(0) == ')')) {
5721 currentState
.g1Charset
= CharacterSet
.NRC_SPANISH
;
5723 if ((collectBuffer
.length() == 1)
5724 && (collectBuffer
.charAt(0) == '*')) {
5726 currentState
.g2Charset
= CharacterSet
.NRC_SPANISH
;
5728 if ((collectBuffer
.length() == 1)
5729 && (collectBuffer
.charAt(0) == '+')) {
5731 currentState
.g3Charset
= CharacterSet
.NRC_SPANISH
;
5778 // 0x9C goes to GROUND
5786 // 00-17, 19, 1C-1F --> execute
5788 handleControlChar(ch
);
5791 // 20-2F --> collect, then switch to CSI_INTERMEDIATE
5792 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
5794 scanState
= ScanState
.CSI_INTERMEDIATE
;
5797 // 30-39, 3B --> param, then switch to CSI_PARAM
5798 if ((ch
>= '0') && (ch
<= '9')) {
5800 scanState
= ScanState
.CSI_PARAM
;
5804 scanState
= ScanState
.CSI_PARAM
;
5807 // 3C-3F --> collect, then switch to CSI_PARAM
5808 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
5810 scanState
= ScanState
.CSI_PARAM
;
5813 // 40-7E --> dispatch, then switch to GROUND
5814 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
5817 // ICH - Insert character
5825 // CUD - Cursor down
5829 // CUF - Cursor forward
5833 // CUB - Cursor backward
5837 // CNL - Cursor down and to column 1
5838 if (type
== DeviceType
.XTERM
) {
5843 // CPL - Cursor up and to column 1
5844 if (type
== DeviceType
.XTERM
) {
5849 // CHA - Cursor to column # in current row
5850 if (type
== DeviceType
.XTERM
) {
5855 // CUP - Cursor position
5859 // CHT - Cursor forward X tab stops (default 1)
5860 if (type
== DeviceType
.XTERM
) {
5865 // ED - Erase in display
5869 // EL - Erase in line
5884 // DCH - Delete character
5891 // Scroll up X lines (default 1)
5892 if (type
== DeviceType
.XTERM
) {
5897 // Scroll down X lines (default 1)
5898 if (type
== DeviceType
.XTERM
) {
5907 if ((type
== DeviceType
.VT220
)
5908 || (type
== DeviceType
.XTERM
)) {
5910 // ECH - Erase character
5917 // CBT - Cursor backward X tab stops (default 1)
5918 if (type
== DeviceType
.XTERM
) {
5929 // HPA - Cursor to column # in current row. Same as CHA
5930 if (type
== DeviceType
.XTERM
) {
5935 // HPR - Cursor right. Same as CUF
5936 if (type
== DeviceType
.XTERM
) {
5941 // REP - Repeat last char X times
5942 if (type
== DeviceType
.XTERM
) {
5947 // DA - Device attributes
5951 // VPA - Cursor to row, current column.
5952 if (type
== DeviceType
.XTERM
) {
5957 // VPR - Cursor down. Same as CUD
5958 if (type
== DeviceType
.XTERM
) {
5963 // HVP - Horizontal and vertical position
5967 // TBC - Tabulation clear
5971 // Sets an ANSI or DEC private toggle
5975 if ((type
== DeviceType
.VT220
)
5976 || (type
== DeviceType
.XTERM
)) {
5978 // Printer functions
5986 // Sets an ANSI or DEC private toggle
5990 // SGR - Select graphics rendition
5994 // DSR - Device status report
6001 // DECLL - Load leds
6005 // DECSTBM - Set top and bottom margins
6009 // Save cursor (ANSI.SYS)
6010 if (type
== DeviceType
.XTERM
) {
6011 savedState
.cursorX
= currentState
.cursorX
;
6012 savedState
.cursorY
= currentState
.cursorY
;
6016 if (type
== DeviceType
.XTERM
) {
6017 // Window operations
6022 // Restore cursor (ANSI.SYS)
6023 if (type
== DeviceType
.XTERM
) {
6024 cursorPosition(savedState
.cursorY
, savedState
.cursorX
);
6031 // DECREQTPARM - Request terminal parameters
6047 // 0x9C goes to GROUND
6052 // 0x3A goes to CSI_IGNORE
6054 scanState
= ScanState
.CSI_IGNORE
;
6059 // 00-17, 19, 1C-1F --> execute
6061 handleControlChar(ch
);
6064 // 20-2F --> collect, then switch to CSI_INTERMEDIATE
6065 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6067 scanState
= ScanState
.CSI_INTERMEDIATE
;
6070 // 30-39, 3B --> param
6071 if ((ch
>= '0') && (ch
<= '9')) {
6078 // 0x3A goes to CSI_IGNORE
6080 scanState
= ScanState
.CSI_IGNORE
;
6082 // 0x3C-3F goes to CSI_IGNORE
6083 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
6084 scanState
= ScanState
.CSI_IGNORE
;
6087 // 40-7E --> dispatch, then switch to GROUND
6088 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6091 // ICH - Insert character
6099 // CUD - Cursor down
6103 // CUF - Cursor forward
6107 // CUB - Cursor backward
6111 // CNL - Cursor down and to column 1
6112 if (type
== DeviceType
.XTERM
) {
6117 // CPL - Cursor up and to column 1
6118 if (type
== DeviceType
.XTERM
) {
6123 // CHA - Cursor to column # in current row
6124 if (type
== DeviceType
.XTERM
) {
6129 // CUP - Cursor position
6133 // CHT - Cursor forward X tab stops (default 1)
6134 if (type
== DeviceType
.XTERM
) {
6139 // ED - Erase in display
6143 // EL - Erase in line
6158 // DCH - Delete character
6165 // Scroll up X lines (default 1)
6166 if (type
== DeviceType
.XTERM
) {
6171 // Scroll down X lines (default 1)
6172 if (type
== DeviceType
.XTERM
) {
6181 if ((type
== DeviceType
.VT220
)
6182 || (type
== DeviceType
.XTERM
)) {
6184 // ECH - Erase character
6191 // CBT - Cursor backward X tab stops (default 1)
6192 if (type
== DeviceType
.XTERM
) {
6203 // HPA - Cursor to column # in current row. Same as CHA
6204 if (type
== DeviceType
.XTERM
) {
6209 // HPR - Cursor right. Same as CUF
6210 if (type
== DeviceType
.XTERM
) {
6215 // REP - Repeat last char X times
6216 if (type
== DeviceType
.XTERM
) {
6221 // DA - Device attributes
6225 // VPA - Cursor to row, current column.
6226 if (type
== DeviceType
.XTERM
) {
6231 // VPR - Cursor down. Same as CUD
6232 if (type
== DeviceType
.XTERM
) {
6237 // HVP - Horizontal and vertical position
6241 // TBC - Tabulation clear
6245 // Sets an ANSI or DEC private toggle
6249 if ((type
== DeviceType
.VT220
)
6250 || (type
== DeviceType
.XTERM
)) {
6252 // Printer functions
6260 // Sets an ANSI or DEC private toggle
6264 // SGR - Select graphics rendition
6268 // DSR - Device status report
6275 // DECLL - Load leds
6279 // DECSTBM - Set top and bottom margins
6285 if (type
== DeviceType
.XTERM
) {
6286 // Window operations
6295 // DECREQTPARM - Request terminal parameters
6312 case CSI_INTERMEDIATE
:
6313 // 00-17, 19, 1C-1F --> execute
6315 handleControlChar(ch
);
6318 // 20-2F --> collect
6319 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6323 // 0x30-3F goes to CSI_IGNORE
6324 if ((ch
>= 0x30) && (ch
<= 0x3F)) {
6325 scanState
= ScanState
.CSI_IGNORE
;
6328 // 40-7E --> dispatch, then switch to GROUND
6329 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6381 if (((type
== DeviceType
.VT220
)
6382 || (type
== DeviceType
.XTERM
))
6383 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == '\"')
6385 // DECSCL - compatibility level
6388 if ((type
== DeviceType
.XTERM
)
6389 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == '!')
6391 // DECSTR - Soft terminal reset
6396 if (((type
== DeviceType
.VT220
)
6397 || (type
== DeviceType
.XTERM
))
6398 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == '\"')
6426 // 00-17, 19, 1C-1F --> execute
6428 handleControlChar(ch
);
6431 // 20-2F --> collect
6432 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6436 // 40-7E --> ignore, then switch to GROUND
6437 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6441 // 20-3F, 7F --> ignore
6447 // 0x9C goes to GROUND
6452 // 0x1B 0x5C goes to GROUND
6457 if ((collectBuffer
.length() > 0)
6458 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6464 // 20-2F --> collect, then switch to DCS_INTERMEDIATE
6465 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6467 scanState
= ScanState
.DCS_INTERMEDIATE
;
6470 // 30-39, 3B --> param, then switch to DCS_PARAM
6471 if ((ch
>= '0') && (ch
<= '9')) {
6473 scanState
= ScanState
.DCS_PARAM
;
6477 scanState
= ScanState
.DCS_PARAM
;
6480 // 3C-3F --> collect, then switch to DCS_PARAM
6481 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
6483 scanState
= ScanState
.DCS_PARAM
;
6486 // 00-17, 19, 1C-1F, 7F --> ignore
6488 // 0x3A goes to DCS_IGNORE
6490 scanState
= ScanState
.DCS_IGNORE
;
6493 // 0x71 goes to DCS_SIXEL
6495 sixelParseBuffer
= new StringBuilder();
6496 scanState
= ScanState
.DCS_SIXEL
;
6497 } else if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6498 // 0x40-7E goes to DCS_PASSTHROUGH
6499 scanState
= ScanState
.DCS_PASSTHROUGH
;
6503 case DCS_INTERMEDIATE
:
6505 // 0x9C goes to GROUND
6510 // 0x1B 0x5C goes to GROUND
6515 if ((collectBuffer
.length() > 0)
6516 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6522 // 0x30-3F goes to DCS_IGNORE
6523 if ((ch
>= 0x30) && (ch
<= 0x3F)) {
6524 scanState
= ScanState
.DCS_IGNORE
;
6527 // 0x40-7E goes to DCS_PASSTHROUGH
6528 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6529 scanState
= ScanState
.DCS_PASSTHROUGH
;
6532 // 00-17, 19, 1C-1F, 7F --> ignore
6537 // 0x9C goes to GROUND
6542 // 0x1B 0x5C goes to GROUND
6547 if ((collectBuffer
.length() > 0)
6548 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6554 // 20-2F --> collect, then switch to DCS_INTERMEDIATE
6555 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6557 scanState
= ScanState
.DCS_INTERMEDIATE
;
6560 // 30-39, 3B --> param
6561 if ((ch
>= '0') && (ch
<= '9')) {
6568 // 00-17, 19, 1C-1F, 7F --> ignore
6570 // 0x3A, 3C-3F goes to DCS_IGNORE
6572 scanState
= ScanState
.DCS_IGNORE
;
6574 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
6575 scanState
= ScanState
.DCS_IGNORE
;
6578 // 0x71 goes to DCS_SIXEL
6580 sixelParseBuffer
= new StringBuilder();
6581 scanState
= ScanState
.DCS_SIXEL
;
6582 } else if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6583 // 0x40-7E goes to DCS_PASSTHROUGH
6584 scanState
= ScanState
.DCS_PASSTHROUGH
;
6588 case DCS_PASSTHROUGH
:
6589 // 0x9C goes to GROUND
6594 // 0x1B 0x5C goes to GROUND
6599 if ((collectBuffer
.length() > 0)
6600 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6606 // 00-17, 19, 1C-1F, 20-7E --> put
6614 if ((ch
>= 0x1C) && (ch
<= 0x1F)) {
6617 if ((ch
>= 0x20) && (ch
<= 0x7E)) {
6626 // 00-17, 19, 1C-1F, 20-7F --> ignore
6628 // 0x9C goes to GROUND
6636 // 0x9C goes to GROUND
6642 // 0x1B 0x5C goes to GROUND
6647 if ((collectBuffer
.length() > 0)
6648 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6655 // 00-17, 19, 1C-1F, 20-7E --> put
6657 sixelParseBuffer
.append(ch
);
6661 sixelParseBuffer
.append(ch
);
6664 if ((ch
>= 0x1C) && (ch
<= 0x1F)) {
6665 sixelParseBuffer
.append(ch
);
6668 if ((ch
>= 0x20) && (ch
<= 0x7E)) {
6669 sixelParseBuffer
.append(ch
);
6677 case SOSPMAPC_STRING
:
6678 // 00-17, 19, 1C-1F, 20-7F --> ignore
6680 // Special case for Jexer: PM can pass one control character
6685 if ((ch
>= 0x20) && (ch
<= 0x7F)) {
6689 // 0x9C goes to GROUND
6697 // Special case for Xterm: OSC can pass control characters
6698 if ((ch
== 0x9C) || (ch
== 0x07) || (ch
== 0x1B)) {
6702 // 00-17, 19, 1C-1F --> ignore
6704 // 20-7F --> osc_put
6705 if ((ch
>= 0x20) && (ch
<= 0x7F)) {
6709 // 0x9C goes to GROUND
6716 case VT52_DIRECT_CURSOR_ADDRESS
:
6717 // This is a special case for the VT52 sequence "ESC Y l c"
6718 if (collectBuffer
.length() == 0) {
6720 } else if (collectBuffer
.length() == 1) {
6721 // We've got the two characters, one in the buffer and the
6723 cursorPosition(collectBuffer
.charAt(0) - '\040', ch
- '\040');
6732 * Expose current cursor X to outside world.
6734 * @return current cursor X
6736 public final int getCursorX() {
6737 if (display
.get(currentState
.cursorY
).isDoubleWidth()) {
6738 return currentState
.cursorX
* 2;
6740 return currentState
.cursorX
;
6744 * Expose current cursor Y to outside world.
6746 * @return current cursor Y
6748 public final int getCursorY() {
6749 return currentState
.cursorY
;
6753 * Returns true if this terminal has requested the mouse pointer be
6756 * @return true if this terminal has requested the mouse pointer be
6759 public final boolean hasHiddenMousePointer() {
6760 return hideMousePointer
;
6764 * Get the mouse protocol.
6766 * @return MouseProtocol.OFF, MouseProtocol.X10, etc.
6768 public MouseProtocol
getMouseProtocol() {
6769 return mouseProtocol
;
6772 // ------------------------------------------------------------------------
6773 // Sixel support ----------------------------------------------------------
6774 // ------------------------------------------------------------------------
6777 * Set the width of a character cell in pixels.
6779 * @param textWidth the width in pixels of a character cell
6781 public void setTextWidth(final int textWidth
) {
6782 this.textWidth
= textWidth
;
6786 * Set the height of a character cell in pixels.
6788 * @param textHeight the height in pixels of a character cell
6790 public void setTextHeight(final int textHeight
) {
6791 this.textHeight
= textHeight
;
6795 * Parse a sixel string into a bitmap image, and overlay that image onto
6798 private void parseSixel() {
6801 System.err.println("parseSixel(): '" + sixelParseBuffer.toString()
6805 Sixel sixel
= new Sixel(sixelParseBuffer
.toString());
6806 BufferedImage image
= sixel
.getImage();
6808 // System.err.println("parseSixel(): image " + image);
6810 if (image
== null) {
6811 // Sixel data was malformed in some way, bail out.
6818 * Break up the image into text cell sized pieces as a new array of
6821 * Note original column position x0.
6825 * 1. Advance (printCharacter(' ')) for horizontal increment, or
6826 * index (linefeed() + cursorPosition(y, x0)) for vertical
6829 * 2. Set (x, y) cell image data.
6831 * 3. For the right and bottom edges:
6833 * a. Render the text to pixels using Terminus font.
6835 * b. Blit the image on top of the text, using alpha channel.
6837 int cellColumns
= image
.getWidth() / textWidth
;
6838 if (cellColumns
* textWidth
< image
.getWidth()) {
6841 int cellRows
= image
.getHeight() / textHeight
;
6842 if (cellRows
* textHeight
< image
.getHeight()) {
6846 // Break the image up into an array of cells.
6847 Cell
[][] cells
= new Cell
[cellColumns
][cellRows
];
6849 for (int x
= 0; x
< cellColumns
; x
++) {
6850 for (int y
= 0; y
< cellRows
; y
++) {
6852 int width
= textWidth
;
6853 if ((x
+ 1) * textWidth
> image
.getWidth()) {
6854 width
= image
.getWidth() - (x
* textWidth
);
6856 int height
= textHeight
;
6857 if ((y
+ 1) * textHeight
> image
.getHeight()) {
6858 height
= image
.getHeight() - (y
* textHeight
);
6861 Cell cell
= new Cell();
6862 cell
.setImage(image
.getSubimage(x
* textWidth
,
6863 y
* textHeight
, width
, height
));
6869 int x0
= currentState
.cursorX
;
6870 for (int y
= 0; y
< cellRows
; y
++) {
6871 for (int x
= 0; x
< cellColumns
; x
++) {
6872 printCharacter(' ');
6873 cursorLeft(1, false);
6874 if ((x
== cellColumns
- 1) || (y
== cellRows
- 1)) {
6875 // TODO: render text of current cell first, then image
6876 // over it. For now, just copy the cell.
6877 DisplayLine line
= display
.get(currentState
.cursorY
);
6878 line
.replace(currentState
.cursorX
, cells
[x
][y
]);
6880 // Copy the image cell into the display.
6881 DisplayLine line
= display
.get(currentState
.cursorY
);
6882 line
.replace(currentState
.cursorX
, cells
[x
][y
]);
6884 cursorRight(1, false);
6887 cursorPosition(currentState
.cursorY
, x0
);
6893 * Draw the left and right cells of a two-cell-wide (full-width) glyph.
6895 * @param leftX the x position to draw the left half to
6896 * @param leftY the y position to draw the left half to
6897 * @param rightX the x position to draw the right half to
6898 * @param rightY the y position to draw the right half to
6899 * @param ch the character to draw
6901 private void drawHalves(final int leftX
, final int leftY
,
6902 final int rightX
, final int rightY
, final char ch
) {
6904 // System.err.println("drawHalves(): " + Integer.toHexString(ch));
6906 if (lastTextHeight
!= textHeight
) {
6907 glyphMaker
= GlyphMaker
.getInstance(textHeight
);
6908 lastTextHeight
= textHeight
;
6911 Cell cell
= new Cell(ch
, currentState
.attr
);
6912 BufferedImage image
= glyphMaker
.getImage(cell
, textWidth
* 2,
6914 BufferedImage leftImage
= image
.getSubimage(0, 0, textWidth
,
6916 BufferedImage rightImage
= image
.getSubimage(textWidth
, 0, textWidth
,
6919 Cell left
= new Cell(cell
);
6920 left
.setImage(leftImage
);
6921 left
.setWidth(Cell
.Width
.LEFT
);
6922 display
.get(leftY
).replace(leftX
, left
);
6924 Cell right
= new Cell(cell
);
6925 right
.setImage(rightImage
);
6926 right
.setWidth(Cell
.Width
.RIGHT
);
6927 display
.get(rightY
).replace(rightX
, right
);