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[128];
695 readBuffer
= new byte[128];
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();
3462 newCell
.setChar('E');
3463 for (DisplayLine line
: display
) {
3464 for (int i
= 0; i
< line
.length(); i
++) {
3465 line
.replace(i
, newCell
);
3471 * DECSCL - Compatibility level.
3473 private void decscl() {
3474 int i
= getCsiParam(0, 0);
3475 int j
= getCsiParam(1, 0);
3479 currentState
.g0Charset
= CharacterSet
.US
;
3480 currentState
.g1Charset
= CharacterSet
.DRAWING
;
3482 } else if (i
== 62) {
3484 if ((j
== 0) || (j
== 2)) {
3486 } else if (j
== 1) {
3493 * CUD - Cursor down.
3495 private void cud() {
3496 cursorDown(getCsiParam(0, 1, 1, height
), true);
3500 * CUF - Cursor forward.
3502 private void cuf() {
3503 cursorRight(getCsiParam(0, 1, 1, rightMargin
+ 1), true);
3507 * CUB - Cursor backward.
3509 private void cub() {
3510 cursorLeft(getCsiParam(0, 1, 1, currentState
.cursorX
+ 1), true);
3516 private void cuu() {
3517 cursorUp(getCsiParam(0, 1, 1, currentState
.cursorY
+ 1), true);
3521 * CUP - Cursor position.
3523 private void cup() {
3524 cursorPosition(getCsiParam(0, 1, 1, height
) - 1,
3525 getCsiParam(1, 1, 1, rightMargin
+ 1) - 1);
3529 * CNL - Cursor down and to column 1.
3531 private void cnl() {
3532 cursorDown(getCsiParam(0, 1, 1, height
), true);
3534 cursorLeft(currentState
.cursorX
, true);
3538 * CPL - Cursor up and to column 1.
3540 private void cpl() {
3541 cursorUp(getCsiParam(0, 1, 1, currentState
.cursorY
+ 1), true);
3543 cursorLeft(currentState
.cursorX
, true);
3547 * CHA - Cursor to column # in current row.
3549 private void cha() {
3550 cursorPosition(currentState
.cursorY
,
3551 getCsiParam(0, 1, 1, rightMargin
+ 1) - 1);
3555 * VPA - Cursor to row #, same column.
3557 private void vpa() {
3558 cursorPosition(getCsiParam(0, 1, 1, height
) - 1,
3559 currentState
.cursorX
);
3563 * ED - Erase in display.
3566 boolean honorProtected
= false;
3567 boolean decPrivateModeFlag
= false;
3569 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
3570 if (collectBuffer
.charAt(i
) == '?') {
3571 decPrivateModeFlag
= true;
3576 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
3577 && (decPrivateModeFlag
== true)
3579 honorProtected
= true;
3582 int i
= getCsiParam(0, 0);
3585 // Erase from here to end of screen
3586 if (currentState
.cursorY
< height
- 1) {
3587 eraseScreen(currentState
.cursorY
+ 1, 0, height
- 1, width
- 1,
3590 eraseLine(currentState
.cursorX
, width
- 1, honorProtected
);
3591 } else if (i
== 1) {
3592 // Erase from beginning of screen to here
3593 eraseScreen(0, 0, currentState
.cursorY
- 1, width
- 1,
3595 eraseLine(0, currentState
.cursorX
, honorProtected
);
3596 } else if (i
== 2) {
3597 // Erase entire screen
3598 eraseScreen(0, 0, height
- 1, width
- 1, honorProtected
);
3603 * EL - Erase in line.
3606 boolean honorProtected
= false;
3607 boolean decPrivateModeFlag
= false;
3609 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
3610 if (collectBuffer
.charAt(i
) == '?') {
3611 decPrivateModeFlag
= true;
3616 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
3617 && (decPrivateModeFlag
== true)
3619 honorProtected
= true;
3622 int i
= getCsiParam(0, 0);
3625 // Erase from here to end of line
3626 eraseLine(currentState
.cursorX
, width
- 1, honorProtected
);
3627 } else if (i
== 1) {
3628 // Erase from beginning of line to here
3629 eraseLine(0, currentState
.cursorX
, honorProtected
);
3630 } else if (i
== 2) {
3631 // Erase entire line
3632 eraseLine(0, width
- 1, honorProtected
);
3637 * ECH - Erase # of characters in current row.
3639 private void ech() {
3640 int i
= getCsiParam(0, 1, 1, width
);
3642 // Erase from here to i characters
3643 eraseLine(currentState
.cursorX
, currentState
.cursorX
+ i
- 1, false);
3650 int i
= getCsiParam(0, 1);
3652 if ((currentState
.cursorY
>= scrollRegionTop
)
3653 && (currentState
.cursorY
<= scrollRegionBottom
)
3656 // I can get the same effect with a scroll-down
3657 scrollingRegionScrollDown(currentState
.cursorY
,
3658 scrollRegionBottom
, i
);
3663 * DCH - Delete char.
3665 private void dch() {
3666 int n
= getCsiParam(0, 1);
3667 DisplayLine line
= display
.get(currentState
.cursorY
);
3668 Cell blank
= new Cell();
3669 for (int i
= 0; i
< n
; i
++) {
3670 line
.delete(currentState
.cursorX
, blank
);
3675 * ICH - Insert blank char at cursor.
3677 private void ich() {
3678 int n
= getCsiParam(0, 1);
3679 DisplayLine line
= display
.get(currentState
.cursorY
);
3680 Cell blank
= new Cell();
3681 for (int i
= 0; i
< n
; i
++) {
3682 line
.insert(currentState
.cursorX
, blank
);
3690 int i
= getCsiParam(0, 1);
3692 if ((currentState
.cursorY
>= scrollRegionTop
)
3693 && (currentState
.cursorY
<= scrollRegionBottom
)) {
3695 // I can get the same effect with a scroll-down
3696 scrollingRegionScrollUp(currentState
.cursorY
,
3697 scrollRegionBottom
, i
);
3702 * HVP - Horizontal and vertical position.
3704 private void hvp() {
3709 * REP - Repeat character.
3711 private void rep() {
3712 int n
= getCsiParam(0, 1);
3713 for (int i
= 0; i
< n
; i
++) {
3714 printCharacter(repCh
);
3722 scrollingRegionScrollUp(scrollRegionTop
, scrollRegionBottom
,
3723 getCsiParam(0, 1, 1, height
));
3730 scrollingRegionScrollDown(scrollRegionTop
, scrollRegionBottom
,
3731 getCsiParam(0, 1, 1, height
));
3735 * CBT - Go back X tab stops.
3737 private void cbt() {
3738 int tabsToMove
= getCsiParam(0, 1);
3741 for (int i
= 0; i
< tabsToMove
; i
++) {
3742 int j
= currentState
.cursorX
;
3743 for (tabI
= 0; tabI
< tabStops
.size(); tabI
++) {
3744 if (tabStops
.get(tabI
) >= currentState
.cursorX
) {
3752 j
= tabStops
.get(tabI
);
3754 cursorPosition(currentState
.cursorY
, j
);
3759 * CHT - Advance X tab stops.
3761 private void cht() {
3762 int n
= getCsiParam(0, 1);
3763 for (int i
= 0; i
< n
; i
++) {
3764 advanceToNextTabStop();
3769 * SGR - Select graphics rendition.
3771 private void sgr() {
3773 if (csiParams
.size() == 0) {
3774 currentState
.attr
.reset();
3778 int sgrColorMode
= -1;
3779 boolean idx88Color
= false;
3780 boolean rgbColor
= false;
3784 for (Integer i
: csiParams
) {
3786 if ((sgrColorMode
== 38) || (sgrColorMode
== 48)) {
3788 assert (type
== DeviceType
.XTERM
);
3792 * Indexed color mode, we now have the index number.
3794 if (sgrColorMode
== 38) {
3795 currentState
.attr
.setForeColorRGB(get88Color(i
));
3797 assert (sgrColorMode
== 48);
3798 currentState
.attr
.setBackColorRGB(get88Color(i
));
3807 * RGB color mode, we are collecting tokens.
3811 } else if (rgbGreen
== -1) {
3812 rgbGreen
= i
& 0xFF;
3814 int rgb
= rgbRed
<< 16;
3815 rgb
|= rgbGreen
<< 8;
3818 // System.err.printf("RGB: %08x\n", rgb);
3820 if (sgrColorMode
== 38) {
3821 currentState
.attr
.setForeColorRGB(rgb
);
3823 assert (sgrColorMode
== 48);
3824 currentState
.attr
.setBackColorRGB(rgb
);
3845 * Indexed color mode.
3852 * This is neither indexed nor RGB color. Bail out.
3857 } // if ((sgrColorMode == 38) || (sgrColorMode == 48))
3863 currentState
.attr
.reset();
3868 currentState
.attr
.setBold(true);
3873 currentState
.attr
.setUnderline(true);
3878 currentState
.attr
.setBlink(true);
3883 currentState
.attr
.setReverse(true);
3890 if (type
== DeviceType
.XTERM
) {
3900 // Set black foreground
3901 currentState
.attr
.setForeColorRGB(get88Color(8));
3904 // Set red foreground
3905 currentState
.attr
.setForeColorRGB(get88Color(9));
3908 // Set green foreground
3909 currentState
.attr
.setForeColorRGB(get88Color(10));
3912 // Set yellow foreground
3913 currentState
.attr
.setForeColorRGB(get88Color(11));
3916 // Set blue foreground
3917 currentState
.attr
.setForeColorRGB(get88Color(12));
3920 // Set magenta foreground
3921 currentState
.attr
.setForeColorRGB(get88Color(13));
3924 // Set cyan foreground
3925 currentState
.attr
.setForeColorRGB(get88Color(14));
3928 // Set white foreground
3929 currentState
.attr
.setForeColorRGB(get88Color(15));
3933 // Set black background
3934 currentState
.attr
.setBackColorRGB(get88Color(8));
3937 // Set red background
3938 currentState
.attr
.setBackColorRGB(get88Color(9));
3941 // Set green background
3942 currentState
.attr
.setBackColorRGB(get88Color(10));
3945 // Set yellow background
3946 currentState
.attr
.setBackColorRGB(get88Color(11));
3949 // Set blue background
3950 currentState
.attr
.setBackColorRGB(get88Color(12));
3953 // Set magenta background
3954 currentState
.attr
.setBackColorRGB(get88Color(13));
3957 // Set cyan background
3958 currentState
.attr
.setBackColorRGB(get88Color(14));
3961 // Set white background
3962 currentState
.attr
.setBackColorRGB(get88Color(15));
3970 if ((type
== DeviceType
.VT220
)
3971 || (type
== DeviceType
.XTERM
)) {
3977 currentState
.attr
.setBold(false);
3982 currentState
.attr
.setUnderline(false);
3987 currentState
.attr
.setBlink(false);
3992 currentState
.attr
.setReverse(false);
4000 // A true VT100/102/220 does not support color, however everyone
4001 // is used to their terminal emulator supporting color so we will
4002 // unconditionally support color for all DeviceType's.
4007 // Set black foreground
4008 currentState
.attr
.setForeColor(Color
.BLACK
);
4009 currentState
.attr
.setForeColorRGB(-1);
4012 // Set red foreground
4013 currentState
.attr
.setForeColor(Color
.RED
);
4014 currentState
.attr
.setForeColorRGB(-1);
4017 // Set green foreground
4018 currentState
.attr
.setForeColor(Color
.GREEN
);
4019 currentState
.attr
.setForeColorRGB(-1);
4022 // Set yellow foreground
4023 currentState
.attr
.setForeColor(Color
.YELLOW
);
4024 currentState
.attr
.setForeColorRGB(-1);
4027 // Set blue foreground
4028 currentState
.attr
.setForeColor(Color
.BLUE
);
4029 currentState
.attr
.setForeColorRGB(-1);
4032 // Set magenta foreground
4033 currentState
.attr
.setForeColor(Color
.MAGENTA
);
4034 currentState
.attr
.setForeColorRGB(-1);
4037 // Set cyan foreground
4038 currentState
.attr
.setForeColor(Color
.CYAN
);
4039 currentState
.attr
.setForeColorRGB(-1);
4042 // Set white foreground
4043 currentState
.attr
.setForeColor(Color
.WHITE
);
4044 currentState
.attr
.setForeColorRGB(-1);
4047 if (type
== DeviceType
.XTERM
) {
4049 * Xterm supports T.416 / ISO-8613-3 codes to select
4050 * either an indexed color or an RGB value. (It also
4051 * permits these ISO-8613-3 SGR sequences to be separated
4052 * by colons rather than semicolons.)
4054 * We will support only the following:
4056 * 1. Indexed color mode (88- or 256-color modes).
4060 * These cover most of the use cases in the real world.
4062 * HOWEVER, note that this is an awful broken "standard",
4063 * with no way to do it "right". See
4064 * http://invisible-island.net/ncurses/ncurses.faq.html#xterm_16MegaColors
4065 * for a detailed discussion of the current state of RGB
4066 * in various terminals, the point of which is that none
4067 * of them really do the same thing despite all appearing
4071 * https://bugs.kde.org/show_bug.cgi?id=107487#c3 .
4072 * where it is assumed that supporting just the "indexed
4073 * mode" of these sequences (which could align easily
4074 * with existing SGR colors) is assumed to mean full
4075 * support of 24-bit RGB. So it is all or nothing.
4077 * Finally, these sequences break the assumptions of
4078 * standard ECMA-48 style parsers as pointed out at
4079 * https://bugs.kde.org/show_bug.cgi?id=107487#c11 .
4080 * Therefore in order to keep a clean display, we cannot
4081 * parse anything else in this sequence.
4086 // Underscore on, default foreground color
4087 currentState
.attr
.setUnderline(true);
4088 currentState
.attr
.setForeColor(Color
.WHITE
);
4092 // Underscore off, default foreground color
4093 currentState
.attr
.setUnderline(false);
4094 currentState
.attr
.setForeColor(Color
.WHITE
);
4095 currentState
.attr
.setForeColorRGB(-1);
4098 // Set black background
4099 currentState
.attr
.setBackColor(Color
.BLACK
);
4100 currentState
.attr
.setBackColorRGB(-1);
4103 // Set red background
4104 currentState
.attr
.setBackColor(Color
.RED
);
4105 currentState
.attr
.setBackColorRGB(-1);
4108 // Set green background
4109 currentState
.attr
.setBackColor(Color
.GREEN
);
4110 currentState
.attr
.setBackColorRGB(-1);
4113 // Set yellow background
4114 currentState
.attr
.setBackColor(Color
.YELLOW
);
4115 currentState
.attr
.setBackColorRGB(-1);
4118 // Set blue background
4119 currentState
.attr
.setBackColor(Color
.BLUE
);
4120 currentState
.attr
.setBackColorRGB(-1);
4123 // Set magenta background
4124 currentState
.attr
.setBackColor(Color
.MAGENTA
);
4125 currentState
.attr
.setBackColorRGB(-1);
4128 // Set cyan background
4129 currentState
.attr
.setBackColor(Color
.CYAN
);
4130 currentState
.attr
.setBackColorRGB(-1);
4133 // Set white background
4134 currentState
.attr
.setBackColor(Color
.WHITE
);
4135 currentState
.attr
.setBackColorRGB(-1);
4138 if (type
== DeviceType
.XTERM
) {
4140 * Xterm supports T.416 / ISO-8613-3 codes to select
4141 * either an indexed color or an RGB value. (It also
4142 * permits these ISO-8613-3 SGR sequences to be separated
4143 * by colons rather than semicolons.)
4145 * We will support only the following:
4147 * 1. Indexed color mode (88- or 256-color modes).
4151 * These cover most of the use cases in the real world.
4153 * HOWEVER, note that this is an awful broken "standard",
4154 * with no way to do it "right". See
4155 * http://invisible-island.net/ncurses/ncurses.faq.html#xterm_16MegaColors
4156 * for a detailed discussion of the current state of RGB
4157 * in various terminals, the point of which is that none
4158 * of them really do the same thing despite all appearing
4162 * https://bugs.kde.org/show_bug.cgi?id=107487#c3 .
4163 * where it is assumed that supporting just the "indexed
4164 * mode" of these sequences (which could align easily
4165 * with existing SGR colors) is assumed to mean full
4166 * support of 24-bit RGB. So it is all or nothing.
4168 * Finally, these sequences break the assumptions of
4169 * standard ECMA-48 style parsers as pointed out at
4170 * https://bugs.kde.org/show_bug.cgi?id=107487#c11 .
4171 * Therefore in order to keep a clean display, we cannot
4172 * parse anything else in this sequence.
4179 // Default background
4180 currentState
.attr
.setBackColor(Color
.BLACK
);
4181 currentState
.attr
.setBackColorRGB(-1);
4191 * DA - Device attributes.
4194 int extendedFlag
= 0;
4196 if (collectBuffer
.length() > 0) {
4197 String args
= collectBuffer
.substring(1);
4198 if (collectBuffer
.charAt(0) == '>') {
4200 if (collectBuffer
.length() >= 2) {
4201 i
= Integer
.parseInt(args
);
4203 } else if (collectBuffer
.charAt(0) == '=') {
4205 if (collectBuffer
.length() >= 2) {
4206 i
= Integer
.parseInt(args
);
4209 // Unknown code, bail out
4214 if ((i
!= 0) && (i
!= 1)) {
4218 if ((extendedFlag
== 0) && (i
== 0)) {
4219 // Send string directly to remote side
4220 writeRemote(deviceTypeResponse());
4224 if ((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
)) {
4226 if ((extendedFlag
== 1) && (i
== 0)) {
4228 * Request "What type of terminal are you, what is your
4229 * firmware version, and what hardware options do you have
4232 * Respond: "I am a VT220 (identification code of 1), my
4233 * firmware version is _____ (Pv), and I have _____ Po
4234 * options installed."
4240 if (s8c1t
== true) {
4241 writeRemote("\u009b>1;10;0c");
4243 writeRemote("\033[>1;10;0c");
4249 if ((extendedFlag
== 2) && (i
== 0)) {
4252 * Request "What is your unit ID?"
4254 * Respond: "I was manufactured at site 00 and have a unique ID
4258 writeRemote("\033P!|00010203\033\\");
4263 * DECSTBM - Set top and bottom margins.
4265 private void decstbm() {
4266 boolean decPrivateModeFlag
= false;
4268 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4269 if (collectBuffer
.charAt(i
) == '?') {
4270 decPrivateModeFlag
= true;
4274 if (decPrivateModeFlag
) {
4275 // This could be restore DEC private mode values.
4279 int top
= getCsiParam(0, 1, 1, height
) - 1;
4280 int bottom
= getCsiParam(1, height
, 1, height
) - 1;
4285 scrollRegionTop
= top
;
4286 scrollRegionBottom
= bottom
;
4289 cursorPosition(0, 0);
4294 * DECREQTPARM - Request terminal parameters.
4296 private void decreqtparm() {
4297 int i
= getCsiParam(0, 0);
4299 if ((i
!= 0) && (i
!= 1)) {
4306 * Request terminal parameters.
4310 * Parity NONE, 8 bits, xmitspeed 38400, recvspeed 38400.
4311 * (CLoCk MULtiplier = 1, STP option flags = 0)
4315 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4318 str
= String
.format("\u009b%d;1;1;128;128;1;0x", i
+ 2);
4320 str
= String
.format("\033[%d;1;1;128;128;1;0x", i
+ 2);
4326 * DECSCA - Select Character Attributes.
4328 private void decsca() {
4329 int i
= getCsiParam(0, 0);
4331 if ((i
== 0) || (i
== 2)) {
4333 currentState
.attr
.setProtect(false);
4337 currentState
.attr
.setProtect(true);
4342 * DECSTR - Soft Terminal Reset.
4344 private void decstr() {
4345 // Do exactly like RIS - Reset to initial state
4347 // Do I clear screen too? I think so...
4348 eraseScreen(0, 0, height
- 1, width
- 1, false);
4349 cursorPosition(0, 0);
4353 * DSR - Device status report.
4355 private void dsr() {
4356 boolean decPrivateModeFlag
= false;
4357 int row
= currentState
.cursorY
;
4359 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4360 if (collectBuffer
.charAt(i
) == '?') {
4361 decPrivateModeFlag
= true;
4366 int i
= getCsiParam(0, 0);
4371 // Request status report. Respond with "OK, no malfunction."
4373 // Send string directly to remote side
4374 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4377 writeRemote("\u009b0n");
4379 writeRemote("\033[0n");
4384 // Request cursor position. Respond with current position.
4385 if (currentState
.originMode
== true) {
4386 row
-= scrollRegionTop
;
4389 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4392 str
= String
.format("\u009b%d;%dR", row
+ 1,
4393 currentState
.cursorX
+ 1);
4395 str
= String
.format("\033[%d;%dR", row
+ 1,
4396 currentState
.cursorX
+ 1);
4399 // Send string directly to remote side
4404 if (decPrivateModeFlag
== true) {
4406 // Request printer status report. Respond with "Printer not
4409 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4410 && (s8c1t
== true)) {
4411 writeRemote("\u009b?13n");
4413 writeRemote("\033[?13n");
4419 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4420 && (decPrivateModeFlag
== true)
4423 // Request user-defined keys are locked or unlocked. Respond
4424 // with "User-defined keys are locked."
4426 if (s8c1t
== true) {
4427 writeRemote("\u009b?21n");
4429 writeRemote("\033[?21n");
4435 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4436 && (decPrivateModeFlag
== true)
4439 // Request keyboard language. Respond with "Keyboard
4440 // language is North American."
4442 if (s8c1t
== true) {
4443 writeRemote("\u009b?27;1n");
4445 writeRemote("\033[?27;1n");
4452 // Some other option, ignore
4458 * TBC - Tabulation clear.
4460 private void tbc() {
4461 int i
= getCsiParam(0, 0);
4463 List
<Integer
> newStops
= new ArrayList
<Integer
>();
4464 for (Integer stop
: tabStops
) {
4465 if (stop
== currentState
.cursorX
) {
4470 tabStops
= newStops
;
4478 * Erase the characters in the current line from the start column to the
4479 * end column, inclusive.
4481 * @param start starting column to erase (between 0 and width - 1)
4482 * @param end ending column to erase (between 0 and width - 1)
4483 * @param honorProtected if true, do not erase characters with the
4484 * protected attribute set
4486 private void eraseLine(int start
, int end
, final boolean honorProtected
) {
4491 if (end
> width
- 1) {
4498 for (int i
= start
; i
<= end
; i
++) {
4499 DisplayLine line
= display
.get(currentState
.cursorY
);
4500 if ((!honorProtected
)
4501 || ((honorProtected
) && (!line
.charAt(i
).isProtect()))) {
4508 * From the VT102 manual:
4510 * Erasing a character also erases any character
4511 * attribute of the character.
4517 * Erase with the current color a.k.a. back-color erase
4520 line
.setChar(i
, ' ');
4521 line
.setAttr(i
, currentState
.attr
);
4529 * Erase a rectangular section of the screen, inclusive. end column,
4532 * @param startRow starting row to erase (between 0 and height - 1)
4533 * @param startCol starting column to erase (between 0 and width - 1)
4534 * @param endRow ending row to erase (between 0 and height - 1)
4535 * @param endCol ending column to erase (between 0 and width - 1)
4536 * @param honorProtected if true, do not erase characters with the
4537 * protected attribute set
4539 private void eraseScreen(final int startRow
, final int startCol
,
4540 final int endRow
, final int endCol
, final boolean honorProtected
) {
4548 || (endRow
< startRow
)
4549 || (endCol
< startCol
)
4554 oldCursorY
= currentState
.cursorY
;
4555 for (int i
= startRow
; i
<= endRow
; i
++) {
4556 currentState
.cursorY
= i
;
4557 eraseLine(startCol
, endCol
, honorProtected
);
4559 // Erase display clears the double attributes
4560 display
.get(i
).setDoubleWidth(false);
4561 display
.get(i
).setDoubleHeight(0);
4563 currentState
.cursorY
= oldCursorY
;
4567 * VT220 printer functions. All of these are parsed, but won't do
4570 private void printerFunctions() {
4571 boolean decPrivateModeFlag
= false;
4572 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4573 if (collectBuffer
.charAt(i
) == '?') {
4574 decPrivateModeFlag
= true;
4579 int i
= getCsiParam(0, 0);
4584 if (decPrivateModeFlag
== false) {
4590 if (decPrivateModeFlag
== true) {
4591 // Print cursor line
4596 if (decPrivateModeFlag
== true) {
4597 // Auto print mode OFF
4599 // Printer controller OFF
4601 // Characters re-appear on the screen
4602 printerControllerMode
= false;
4607 if (decPrivateModeFlag
== true) {
4611 // Printer controller
4613 // Characters get sucked into oblivion
4614 printerControllerMode
= true;
4625 * Handle the SCAN_OSC_STRING state. Handle this in VT100 because lots
4626 * of remote systems will send an XTerm title sequence even if TERM isn't
4629 * @param xtermChar the character received from the remote side
4631 private void oscPut(final char xtermChar
) {
4632 // System.err.println("oscPut: " + xtermChar);
4635 collectBuffer
.append(xtermChar
);
4638 if ((xtermChar
== 0x07)
4639 || (collectBuffer
.toString().endsWith("\033\\"))
4642 if (xtermChar
== 0x07) {
4643 args
= collectBuffer
.substring(0, collectBuffer
.length() - 1);
4645 args
= collectBuffer
.substring(0, collectBuffer
.length() - 2);
4648 String
[] p
= args
.split(";");
4650 if ((p
[0].equals("0")) || (p
[0].equals("2"))) {
4657 if (p
[0].equals("4")) {
4658 for (int i
= 1; i
+ 1 < p
.length
; i
+= 2) {
4659 // Set a color index value
4661 set88Color(Integer
.parseInt(p
[i
]), p
[i
+ 1]);
4662 } catch (NumberFormatException e
) {
4669 // Go to SCAN_GROUND state
4676 * Handle the SCAN_SOSPMAPC_STRING state. This is currently only used by
4677 * Jexer ECMA48Terminal to talk to ECMA48.
4679 * @param pmChar the character received from the remote side
4681 private void pmPut(final char pmChar
) {
4682 // System.err.println("pmPut: " + pmChar);
4685 collectBuffer
.append(pmChar
);
4688 if (collectBuffer
.toString().endsWith("\033\\")) {
4690 arg
= collectBuffer
.substring(0, collectBuffer
.length() - 2);
4692 // System.err.println("arg: '" + arg + "'");
4694 if (arg
.equals("hideMousePointer")) {
4695 hideMousePointer
= true;
4697 if (arg
.equals("showMousePointer")) {
4698 hideMousePointer
= false;
4701 // Go to SCAN_GROUND state
4708 * Perform xterm window operations.
4710 private void xtermWindowOps() {
4711 boolean xtermPrivateModeFlag
= false;
4713 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4714 if (collectBuffer
.charAt(i
) == '?') {
4715 xtermPrivateModeFlag
= true;
4720 int i
= getCsiParam(0, 0);
4722 if (!xtermPrivateModeFlag
) {
4724 // Report xterm window in pixels as CSI 4 ; height ; width t
4725 writeRemote(String
.format("\033[4;%d;%dt", textHeight
* height
,
4726 textWidth
* width
));
4732 * Run this input character through the ECMA48 state machine.
4734 * @param ch character from the remote side
4736 private void consume(char ch
) {
4739 // System.err.printf("%c STATE = %s\n", ch, scanState);
4741 // Special case for VT10x: 7-bit characters only
4742 if ((type
== DeviceType
.VT100
) || (type
== DeviceType
.VT102
)) {
4743 ch
= (char)(ch
& 0x7F);
4746 // Special "anywhere" states
4748 // 18, 1A --> execute, then switch to SCAN_GROUND
4749 if ((ch
== 0x18) || (ch
== 0x1A)) {
4750 // CAN and SUB abort escape sequences
4755 // 80-8F, 91-97, 99, 9A, 9C --> execute, then switch to SCAN_GROUND
4759 if ((type
== DeviceType
.XTERM
)
4760 && ((scanState
== ScanState
.OSC_STRING
)
4761 || (scanState
== ScanState
.DCS_SIXEL
)
4762 || (scanState
== ScanState
.SOSPMAPC_STRING
))
4764 // Xterm can pass ESCAPE to its OSC sequence.
4765 // Xterm can pass ESCAPE to its DCS sequence.
4766 // Jexer can pass ESCAPE to its PM sequence.
4767 } else if ((scanState
!= ScanState
.DCS_ENTRY
)
4768 && (scanState
!= ScanState
.DCS_INTERMEDIATE
)
4769 && (scanState
!= ScanState
.DCS_IGNORE
)
4770 && (scanState
!= ScanState
.DCS_PARAM
)
4771 && (scanState
!= ScanState
.DCS_PASSTHROUGH
)
4773 scanState
= ScanState
.ESCAPE
;
4778 // 0x9B == CSI 8-bit sequence
4780 scanState
= ScanState
.CSI_ENTRY
;
4784 // 0x9D goes to ScanState.OSC_STRING
4786 scanState
= ScanState
.OSC_STRING
;
4790 // 0x90 goes to DCS_ENTRY
4792 scanState
= ScanState
.DCS_ENTRY
;
4796 // 0x98, 0x9E, and 0x9F go to SOSPMAPC_STRING
4797 if ((ch
== 0x98) || (ch
== 0x9E) || (ch
== 0x9F)) {
4798 scanState
= ScanState
.SOSPMAPC_STRING
;
4802 // 0x7F (DEL) is always discarded
4807 switch (scanState
) {
4810 // 00-17, 19, 1C-1F --> execute
4811 // 80-8F, 91-9A, 9C --> execute
4812 if ((ch
<= 0x1F) || ((ch
>= 0x80) && (ch
<= 0x9F))) {
4813 handleControlChar(ch
);
4817 if (((ch
>= 0x20) && (ch
<= 0x7F))
4821 // VT220 printer --> trash bin
4822 if (((type
== DeviceType
.VT220
)
4823 || (type
== DeviceType
.XTERM
))
4824 && (printerControllerMode
== true)
4829 // Hang onto this character
4830 repCh
= mapCharacter(ch
);
4832 // Print this character
4833 printCharacter(repCh
);
4838 // 00-17, 19, 1C-1F --> execute
4840 handleControlChar(ch
);
4844 // 20-2F --> collect, then switch to ESCAPE_INTERMEDIATE
4845 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
4847 scanState
= ScanState
.ESCAPE_INTERMEDIATE
;
4851 // 30-4F, 51-57, 59, 5A, 5C, 60-7E --> dispatch, then switch to GROUND
4852 if ((ch
>= 0x30) && (ch
<= 0x4F)) {
4863 // DECSC - Save cursor
4864 // Note this code overlaps both ANSI and VT52 mode
4869 // DECRC - Restore cursor
4870 // Note this code overlaps both ANSI and VT52 mode
4879 if (vt52Mode
== true) {
4880 // DECANM - Enter ANSI mode
4882 arrowKeyMode
= ArrowKeyMode
.VT100
;
4885 * From the VT102 docs: "You use ANSI mode to select
4886 * most terminal features; the terminal uses the same
4887 * features when it switches to VT52 mode. You
4888 * cannot, however, change most of these features in
4891 * In other words, do not reset any other attributes
4892 * when switching between VT52 submode and ANSI.
4896 currentState
.g0Charset
= CharacterSet
.US
;
4897 currentState
.g1Charset
= CharacterSet
.DRAWING
;
4899 singleshift
= Singleshift
.NONE
;
4900 currentState
.glLockshift
= LockshiftMode
.NONE
;
4901 currentState
.grLockshift
= LockshiftMode
.NONE
;
4905 // DECKPAM - Keypad application mode
4906 // Note this code overlaps both ANSI and VT52 mode
4910 // DECKPNM - Keypad numeric mode
4911 // Note this code overlaps both ANSI and VT52 mode
4918 if (vt52Mode
== true) {
4919 // Cursor up, and stop at the top without scrolling
4924 if (vt52Mode
== true) {
4925 // Cursor down, and stop at the bottom without scrolling
4926 cursorDown(1, false);
4930 if (vt52Mode
== true) {
4931 // Cursor right, and stop at the right without scrolling
4932 cursorRight(1, false);
4936 if (vt52Mode
== true) {
4937 // Cursor left, and stop at the left without scrolling
4938 cursorLeft(1, false);
4945 if (vt52Mode
== true) {
4953 if (vt52Mode
== true) {
4954 // G0 --> Special graphics
4955 currentState
.g0Charset
= CharacterSet
.VT52_GRAPHICS
;
4959 if (vt52Mode
== true) {
4961 currentState
.g0Charset
= CharacterSet
.US
;
4965 if (vt52Mode
== true) {
4967 cursorPosition(0, 0);
4969 // HTS - Horizontal tabulation set
4974 if (vt52Mode
== true) {
4975 // Reverse line feed. Same as RI.
4980 if (vt52Mode
== true) {
4981 // Erase to end of screen
4982 eraseLine(currentState
.cursorX
, width
- 1, false);
4983 eraseScreen(currentState
.cursorY
+ 1, 0, height
- 1,
4988 if (vt52Mode
== true) {
4989 // Erase to end of line
4990 eraseLine(currentState
.cursorX
, width
- 1, false);
4996 if (vt52Mode
== true) {
4999 // RI - Reverse index
5004 if (vt52Mode
== false) {
5006 singleshift
= Singleshift
.SS2
;
5010 if (vt52Mode
== false) {
5012 singleshift
= Singleshift
.SS3
;
5019 if ((ch
>= 0x51) && (ch
<= 0x57)) {
5035 if (vt52Mode
== true) {
5036 scanState
= ScanState
.VT52_DIRECT_CURSOR_ADDRESS
;
5044 if (vt52Mode
== true) {
5046 // Send string directly to remote side
5047 writeRemote("\033/Z");
5050 // Send string directly to remote side
5051 writeRemote(deviceTypeResponse());
5062 // VT52 cannot get to any of these other states
5063 if (vt52Mode
== true) {
5068 if ((ch
>= 0x60) && (ch
<= 0x7E)) {
5075 // RIS - Reset to initial state
5077 // Do I clear screen too? I think so...
5078 eraseScreen(0, 0, height
- 1, width
- 1, false);
5079 cursorPosition(0, 0);
5093 if ((type
== DeviceType
.VT220
)
5094 || (type
== DeviceType
.XTERM
)) {
5096 // VT220 lockshift G2 into GL
5097 currentState
.glLockshift
= LockshiftMode
.G2_GL
;
5102 if ((type
== DeviceType
.VT220
)
5103 || (type
== DeviceType
.XTERM
)) {
5105 // VT220 lockshift G3 into GL
5106 currentState
.glLockshift
= LockshiftMode
.G3_GL
;
5124 if ((type
== DeviceType
.VT220
)
5125 || (type
== DeviceType
.XTERM
)) {
5127 // VT220 lockshift G3 into GR
5128 currentState
.grLockshift
= LockshiftMode
.G3_GR
;
5133 if ((type
== DeviceType
.VT220
)
5134 || (type
== DeviceType
.XTERM
)) {
5136 // VT220 lockshift G2 into GR
5137 currentState
.grLockshift
= LockshiftMode
.G2_GR
;
5143 if ((type
== DeviceType
.VT220
)
5144 || (type
== DeviceType
.XTERM
)) {
5146 // VT220 lockshift G1 into GR
5147 currentState
.grLockshift
= LockshiftMode
.G1_GR
;
5157 // 0x5B goes to CSI_ENTRY
5159 scanState
= ScanState
.CSI_ENTRY
;
5162 // 0x5D goes to OSC_STRING
5164 scanState
= ScanState
.OSC_STRING
;
5167 // 0x50 goes to DCS_ENTRY
5169 scanState
= ScanState
.DCS_ENTRY
;
5172 // 0x58, 0x5E, and 0x5F go to SOSPMAPC_STRING
5173 if ((ch
== 0x58) || (ch
== 0x5E) || (ch
== 0x5F)) {
5174 scanState
= ScanState
.SOSPMAPC_STRING
;
5179 case ESCAPE_INTERMEDIATE
:
5180 // 00-17, 19, 1C-1F --> execute
5182 handleControlChar(ch
);
5185 // 20-2F --> collect
5186 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
5190 // 30-7E --> dispatch, then switch to GROUND
5191 if ((ch
>= 0x30) && (ch
<= 0x7E)) {
5194 if ((collectBuffer
.length() == 1)
5195 && (collectBuffer
.charAt(0) == '(')) {
5196 // G0 --> Special graphics
5197 currentState
.g0Charset
= CharacterSet
.DRAWING
;
5199 if ((collectBuffer
.length() == 1)
5200 && (collectBuffer
.charAt(0) == ')')) {
5201 // G1 --> Special graphics
5202 currentState
.g1Charset
= CharacterSet
.DRAWING
;
5204 if ((type
== DeviceType
.VT220
)
5205 || (type
== DeviceType
.XTERM
)) {
5207 if ((collectBuffer
.length() == 1)
5208 && (collectBuffer
.charAt(0) == '*')) {
5209 // G2 --> Special graphics
5210 currentState
.g2Charset
= CharacterSet
.DRAWING
;
5212 if ((collectBuffer
.length() == 1)
5213 && (collectBuffer
.charAt(0) == '+')) {
5214 // G3 --> Special graphics
5215 currentState
.g3Charset
= CharacterSet
.DRAWING
;
5220 if ((collectBuffer
.length() == 1)
5221 && (collectBuffer
.charAt(0) == '(')) {
5222 // G0 --> Alternate character ROM standard character set
5223 currentState
.g0Charset
= CharacterSet
.ROM
;
5225 if ((collectBuffer
.length() == 1)
5226 && (collectBuffer
.charAt(0) == ')')) {
5227 // G1 --> Alternate character ROM standard character set
5228 currentState
.g1Charset
= CharacterSet
.ROM
;
5232 if ((collectBuffer
.length() == 1)
5233 && (collectBuffer
.charAt(0) == '(')) {
5234 // G0 --> Alternate character ROM special graphics
5235 currentState
.g0Charset
= CharacterSet
.ROM_SPECIAL
;
5237 if ((collectBuffer
.length() == 1)
5238 && (collectBuffer
.charAt(0) == ')')) {
5239 // G1 --> Alternate character ROM special graphics
5240 currentState
.g1Charset
= CharacterSet
.ROM_SPECIAL
;
5244 if ((collectBuffer
.length() == 1)
5245 && (collectBuffer
.charAt(0) == '#')) {
5246 // DECDHL - Double-height line (top half)
5251 if ((collectBuffer
.length() == 1)
5252 && (collectBuffer
.charAt(0) == '#')) {
5253 // DECDHL - Double-height line (bottom half)
5256 if ((type
== DeviceType
.VT220
)
5257 || (type
== DeviceType
.XTERM
)) {
5259 if ((collectBuffer
.length() == 1)
5260 && (collectBuffer
.charAt(0) == '(')) {
5262 currentState
.g0Charset
= CharacterSet
.NRC_DUTCH
;
5264 if ((collectBuffer
.length() == 1)
5265 && (collectBuffer
.charAt(0) == ')')) {
5267 currentState
.g1Charset
= CharacterSet
.NRC_DUTCH
;
5269 if ((collectBuffer
.length() == 1)
5270 && (collectBuffer
.charAt(0) == '*')) {
5272 currentState
.g2Charset
= CharacterSet
.NRC_DUTCH
;
5274 if ((collectBuffer
.length() == 1)
5275 && (collectBuffer
.charAt(0) == '+')) {
5277 currentState
.g3Charset
= CharacterSet
.NRC_DUTCH
;
5282 if ((collectBuffer
.length() == 1)
5283 && (collectBuffer
.charAt(0) == '#')) {
5284 // DECSWL - Single-width line
5287 if ((type
== DeviceType
.VT220
)
5288 || (type
== DeviceType
.XTERM
)) {
5290 if ((collectBuffer
.length() == 1)
5291 && (collectBuffer
.charAt(0) == '(')) {
5293 currentState
.g0Charset
= CharacterSet
.NRC_FINNISH
;
5295 if ((collectBuffer
.length() == 1)
5296 && (collectBuffer
.charAt(0) == ')')) {
5298 currentState
.g1Charset
= CharacterSet
.NRC_FINNISH
;
5300 if ((collectBuffer
.length() == 1)
5301 && (collectBuffer
.charAt(0) == '*')) {
5303 currentState
.g2Charset
= CharacterSet
.NRC_FINNISH
;
5305 if ((collectBuffer
.length() == 1)
5306 && (collectBuffer
.charAt(0) == '+')) {
5308 currentState
.g3Charset
= CharacterSet
.NRC_FINNISH
;
5313 if ((collectBuffer
.length() == 1)
5314 && (collectBuffer
.charAt(0) == '#')) {
5315 // DECDWL - Double-width line
5318 if ((type
== DeviceType
.VT220
)
5319 || (type
== DeviceType
.XTERM
)) {
5321 if ((collectBuffer
.length() == 1)
5322 && (collectBuffer
.charAt(0) == '(')) {
5324 currentState
.g0Charset
= CharacterSet
.NRC_NORWEGIAN
;
5326 if ((collectBuffer
.length() == 1)
5327 && (collectBuffer
.charAt(0) == ')')) {
5329 currentState
.g1Charset
= CharacterSet
.NRC_NORWEGIAN
;
5331 if ((collectBuffer
.length() == 1)
5332 && (collectBuffer
.charAt(0) == '*')) {
5334 currentState
.g2Charset
= CharacterSet
.NRC_NORWEGIAN
;
5336 if ((collectBuffer
.length() == 1)
5337 && (collectBuffer
.charAt(0) == '+')) {
5339 currentState
.g3Charset
= CharacterSet
.NRC_NORWEGIAN
;
5344 if ((type
== DeviceType
.VT220
)
5345 || (type
== DeviceType
.XTERM
)) {
5347 if ((collectBuffer
.length() == 1)
5348 && (collectBuffer
.charAt(0) == '(')) {
5350 currentState
.g0Charset
= CharacterSet
.NRC_SWEDISH
;
5352 if ((collectBuffer
.length() == 1)
5353 && (collectBuffer
.charAt(0) == ')')) {
5355 currentState
.g1Charset
= CharacterSet
.NRC_SWEDISH
;
5357 if ((collectBuffer
.length() == 1)
5358 && (collectBuffer
.charAt(0) == '*')) {
5360 currentState
.g2Charset
= CharacterSet
.NRC_SWEDISH
;
5362 if ((collectBuffer
.length() == 1)
5363 && (collectBuffer
.charAt(0) == '+')) {
5365 currentState
.g3Charset
= CharacterSet
.NRC_SWEDISH
;
5370 if ((collectBuffer
.length() == 1)
5371 && (collectBuffer
.charAt(0) == '#')) {
5372 // DECALN - Screen alignment display
5381 if ((type
== DeviceType
.VT220
)
5382 || (type
== DeviceType
.XTERM
)) {
5384 if ((collectBuffer
.length() == 1)
5385 && (collectBuffer
.charAt(0) == '(')) {
5386 // G0 --> DEC_SUPPLEMENTAL
5387 currentState
.g0Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5389 if ((collectBuffer
.length() == 1)
5390 && (collectBuffer
.charAt(0) == ')')) {
5391 // G1 --> DEC_SUPPLEMENTAL
5392 currentState
.g1Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5394 if ((collectBuffer
.length() == 1)
5395 && (collectBuffer
.charAt(0) == '*')) {
5396 // G2 --> DEC_SUPPLEMENTAL
5397 currentState
.g2Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5399 if ((collectBuffer
.length() == 1)
5400 && (collectBuffer
.charAt(0) == '+')) {
5401 // G3 --> DEC_SUPPLEMENTAL
5402 currentState
.g3Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5407 if ((type
== DeviceType
.VT220
)
5408 || (type
== DeviceType
.XTERM
)) {
5410 if ((collectBuffer
.length() == 1)
5411 && (collectBuffer
.charAt(0) == '(')) {
5413 currentState
.g0Charset
= CharacterSet
.NRC_SWISS
;
5415 if ((collectBuffer
.length() == 1)
5416 && (collectBuffer
.charAt(0) == ')')) {
5418 currentState
.g1Charset
= CharacterSet
.NRC_SWISS
;
5420 if ((collectBuffer
.length() == 1)
5421 && (collectBuffer
.charAt(0) == '*')) {
5423 currentState
.g2Charset
= CharacterSet
.NRC_SWISS
;
5425 if ((collectBuffer
.length() == 1)
5426 && (collectBuffer
.charAt(0) == '+')) {
5428 currentState
.g3Charset
= CharacterSet
.NRC_SWISS
;
5437 if ((collectBuffer
.length() == 1)
5438 && (collectBuffer
.charAt(0) == '(')) {
5439 // G0 --> United Kingdom set
5440 currentState
.g0Charset
= CharacterSet
.UK
;
5442 if ((collectBuffer
.length() == 1)
5443 && (collectBuffer
.charAt(0) == ')')) {
5444 // G1 --> United Kingdom set
5445 currentState
.g1Charset
= CharacterSet
.UK
;
5447 if ((type
== DeviceType
.VT220
)
5448 || (type
== DeviceType
.XTERM
)) {
5450 if ((collectBuffer
.length() == 1)
5451 && (collectBuffer
.charAt(0) == '*')) {
5452 // G2 --> United Kingdom set
5453 currentState
.g2Charset
= CharacterSet
.UK
;
5455 if ((collectBuffer
.length() == 1)
5456 && (collectBuffer
.charAt(0) == '+')) {
5457 // G3 --> United Kingdom set
5458 currentState
.g3Charset
= CharacterSet
.UK
;
5463 if ((collectBuffer
.length() == 1)
5464 && (collectBuffer
.charAt(0) == '(')) {
5466 currentState
.g0Charset
= CharacterSet
.US
;
5468 if ((collectBuffer
.length() == 1)
5469 && (collectBuffer
.charAt(0) == ')')) {
5471 currentState
.g1Charset
= CharacterSet
.US
;
5473 if ((type
== DeviceType
.VT220
)
5474 || (type
== DeviceType
.XTERM
)) {
5476 if ((collectBuffer
.length() == 1)
5477 && (collectBuffer
.charAt(0) == '*')) {
5479 currentState
.g2Charset
= CharacterSet
.US
;
5481 if ((collectBuffer
.length() == 1)
5482 && (collectBuffer
.charAt(0) == '+')) {
5484 currentState
.g3Charset
= CharacterSet
.US
;
5489 if ((type
== DeviceType
.VT220
)
5490 || (type
== DeviceType
.XTERM
)) {
5492 if ((collectBuffer
.length() == 1)
5493 && (collectBuffer
.charAt(0) == '(')) {
5495 currentState
.g0Charset
= CharacterSet
.NRC_FINNISH
;
5497 if ((collectBuffer
.length() == 1)
5498 && (collectBuffer
.charAt(0) == ')')) {
5500 currentState
.g1Charset
= CharacterSet
.NRC_FINNISH
;
5502 if ((collectBuffer
.length() == 1)
5503 && (collectBuffer
.charAt(0) == '*')) {
5505 currentState
.g2Charset
= CharacterSet
.NRC_FINNISH
;
5507 if ((collectBuffer
.length() == 1)
5508 && (collectBuffer
.charAt(0) == '+')) {
5510 currentState
.g3Charset
= CharacterSet
.NRC_FINNISH
;
5517 if ((type
== DeviceType
.VT220
)
5518 || (type
== DeviceType
.XTERM
)) {
5520 if ((collectBuffer
.length() == 1)
5521 && (collectBuffer
.charAt(0) == '(')) {
5523 currentState
.g0Charset
= CharacterSet
.NRC_NORWEGIAN
;
5525 if ((collectBuffer
.length() == 1)
5526 && (collectBuffer
.charAt(0) == ')')) {
5528 currentState
.g1Charset
= CharacterSet
.NRC_NORWEGIAN
;
5530 if ((collectBuffer
.length() == 1)
5531 && (collectBuffer
.charAt(0) == '*')) {
5533 currentState
.g2Charset
= CharacterSet
.NRC_NORWEGIAN
;
5535 if ((collectBuffer
.length() == 1)
5536 && (collectBuffer
.charAt(0) == '+')) {
5538 currentState
.g3Charset
= CharacterSet
.NRC_NORWEGIAN
;
5543 if ((type
== DeviceType
.VT220
)
5544 || (type
== DeviceType
.XTERM
)) {
5546 if ((collectBuffer
.length() == 1)
5547 && (collectBuffer
.charAt(0) == ' ')) {
5554 if ((type
== DeviceType
.VT220
)
5555 || (type
== DeviceType
.XTERM
)) {
5557 if ((collectBuffer
.length() == 1)
5558 && (collectBuffer
.charAt(0) == ' ')) {
5565 if ((type
== DeviceType
.VT220
)
5566 || (type
== DeviceType
.XTERM
)) {
5568 if ((collectBuffer
.length() == 1)
5569 && (collectBuffer
.charAt(0) == '(')) {
5571 currentState
.g0Charset
= CharacterSet
.NRC_SWEDISH
;
5573 if ((collectBuffer
.length() == 1)
5574 && (collectBuffer
.charAt(0) == ')')) {
5576 currentState
.g1Charset
= CharacterSet
.NRC_SWEDISH
;
5578 if ((collectBuffer
.length() == 1)
5579 && (collectBuffer
.charAt(0) == '*')) {
5581 currentState
.g2Charset
= CharacterSet
.NRC_SWEDISH
;
5583 if ((collectBuffer
.length() == 1)
5584 && (collectBuffer
.charAt(0) == '+')) {
5586 currentState
.g3Charset
= CharacterSet
.NRC_SWEDISH
;
5594 if ((type
== DeviceType
.VT220
)
5595 || (type
== DeviceType
.XTERM
)) {
5597 if ((collectBuffer
.length() == 1)
5598 && (collectBuffer
.charAt(0) == '(')) {
5600 currentState
.g0Charset
= CharacterSet
.NRC_GERMAN
;
5602 if ((collectBuffer
.length() == 1)
5603 && (collectBuffer
.charAt(0) == ')')) {
5605 currentState
.g1Charset
= CharacterSet
.NRC_GERMAN
;
5607 if ((collectBuffer
.length() == 1)
5608 && (collectBuffer
.charAt(0) == '*')) {
5610 currentState
.g2Charset
= CharacterSet
.NRC_GERMAN
;
5612 if ((collectBuffer
.length() == 1)
5613 && (collectBuffer
.charAt(0) == '+')) {
5615 currentState
.g3Charset
= CharacterSet
.NRC_GERMAN
;
5626 if ((type
== DeviceType
.VT220
)
5627 || (type
== DeviceType
.XTERM
)) {
5629 if ((collectBuffer
.length() == 1)
5630 && (collectBuffer
.charAt(0) == '(')) {
5632 currentState
.g0Charset
= CharacterSet
.NRC_FRENCH_CA
;
5634 if ((collectBuffer
.length() == 1)
5635 && (collectBuffer
.charAt(0) == ')')) {
5637 currentState
.g1Charset
= CharacterSet
.NRC_FRENCH_CA
;
5639 if ((collectBuffer
.length() == 1)
5640 && (collectBuffer
.charAt(0) == '*')) {
5642 currentState
.g2Charset
= CharacterSet
.NRC_FRENCH_CA
;
5644 if ((collectBuffer
.length() == 1)
5645 && (collectBuffer
.charAt(0) == '+')) {
5647 currentState
.g3Charset
= CharacterSet
.NRC_FRENCH_CA
;
5652 if ((type
== DeviceType
.VT220
)
5653 || (type
== DeviceType
.XTERM
)) {
5655 if ((collectBuffer
.length() == 1)
5656 && (collectBuffer
.charAt(0) == '(')) {
5658 currentState
.g0Charset
= CharacterSet
.NRC_FRENCH
;
5660 if ((collectBuffer
.length() == 1)
5661 && (collectBuffer
.charAt(0) == ')')) {
5663 currentState
.g1Charset
= CharacterSet
.NRC_FRENCH
;
5665 if ((collectBuffer
.length() == 1)
5666 && (collectBuffer
.charAt(0) == '*')) {
5668 currentState
.g2Charset
= CharacterSet
.NRC_FRENCH
;
5670 if ((collectBuffer
.length() == 1)
5671 && (collectBuffer
.charAt(0) == '+')) {
5673 currentState
.g3Charset
= CharacterSet
.NRC_FRENCH
;
5685 if ((type
== DeviceType
.VT220
)
5686 || (type
== DeviceType
.XTERM
)) {
5688 if ((collectBuffer
.length() == 1)
5689 && (collectBuffer
.charAt(0) == '(')) {
5691 currentState
.g0Charset
= CharacterSet
.NRC_ITALIAN
;
5693 if ((collectBuffer
.length() == 1)
5694 && (collectBuffer
.charAt(0) == ')')) {
5696 currentState
.g1Charset
= CharacterSet
.NRC_ITALIAN
;
5698 if ((collectBuffer
.length() == 1)
5699 && (collectBuffer
.charAt(0) == '*')) {
5701 currentState
.g2Charset
= CharacterSet
.NRC_ITALIAN
;
5703 if ((collectBuffer
.length() == 1)
5704 && (collectBuffer
.charAt(0) == '+')) {
5706 currentState
.g3Charset
= CharacterSet
.NRC_ITALIAN
;
5711 if ((type
== DeviceType
.VT220
)
5712 || (type
== DeviceType
.XTERM
)) {
5714 if ((collectBuffer
.length() == 1)
5715 && (collectBuffer
.charAt(0) == '(')) {
5717 currentState
.g0Charset
= CharacterSet
.NRC_SPANISH
;
5719 if ((collectBuffer
.length() == 1)
5720 && (collectBuffer
.charAt(0) == ')')) {
5722 currentState
.g1Charset
= CharacterSet
.NRC_SPANISH
;
5724 if ((collectBuffer
.length() == 1)
5725 && (collectBuffer
.charAt(0) == '*')) {
5727 currentState
.g2Charset
= CharacterSet
.NRC_SPANISH
;
5729 if ((collectBuffer
.length() == 1)
5730 && (collectBuffer
.charAt(0) == '+')) {
5732 currentState
.g3Charset
= CharacterSet
.NRC_SPANISH
;
5779 // 0x9C goes to GROUND
5787 // 00-17, 19, 1C-1F --> execute
5789 handleControlChar(ch
);
5792 // 20-2F --> collect, then switch to CSI_INTERMEDIATE
5793 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
5795 scanState
= ScanState
.CSI_INTERMEDIATE
;
5798 // 30-39, 3B --> param, then switch to CSI_PARAM
5799 if ((ch
>= '0') && (ch
<= '9')) {
5801 scanState
= ScanState
.CSI_PARAM
;
5805 scanState
= ScanState
.CSI_PARAM
;
5808 // 3C-3F --> collect, then switch to CSI_PARAM
5809 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
5811 scanState
= ScanState
.CSI_PARAM
;
5814 // 40-7E --> dispatch, then switch to GROUND
5815 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
5818 // ICH - Insert character
5826 // CUD - Cursor down
5830 // CUF - Cursor forward
5834 // CUB - Cursor backward
5838 // CNL - Cursor down and to column 1
5839 if (type
== DeviceType
.XTERM
) {
5844 // CPL - Cursor up and to column 1
5845 if (type
== DeviceType
.XTERM
) {
5850 // CHA - Cursor to column # in current row
5851 if (type
== DeviceType
.XTERM
) {
5856 // CUP - Cursor position
5860 // CHT - Cursor forward X tab stops (default 1)
5861 if (type
== DeviceType
.XTERM
) {
5866 // ED - Erase in display
5870 // EL - Erase in line
5885 // DCH - Delete character
5892 // Scroll up X lines (default 1)
5893 if (type
== DeviceType
.XTERM
) {
5898 // Scroll down X lines (default 1)
5899 if (type
== DeviceType
.XTERM
) {
5908 if ((type
== DeviceType
.VT220
)
5909 || (type
== DeviceType
.XTERM
)) {
5911 // ECH - Erase character
5918 // CBT - Cursor backward X tab stops (default 1)
5919 if (type
== DeviceType
.XTERM
) {
5930 // HPA - Cursor to column # in current row. Same as CHA
5931 if (type
== DeviceType
.XTERM
) {
5936 // HPR - Cursor right. Same as CUF
5937 if (type
== DeviceType
.XTERM
) {
5942 // REP - Repeat last char X times
5943 if (type
== DeviceType
.XTERM
) {
5948 // DA - Device attributes
5952 // VPA - Cursor to row, current column.
5953 if (type
== DeviceType
.XTERM
) {
5958 // VPR - Cursor down. Same as CUD
5959 if (type
== DeviceType
.XTERM
) {
5964 // HVP - Horizontal and vertical position
5968 // TBC - Tabulation clear
5972 // Sets an ANSI or DEC private toggle
5976 if ((type
== DeviceType
.VT220
)
5977 || (type
== DeviceType
.XTERM
)) {
5979 // Printer functions
5987 // Sets an ANSI or DEC private toggle
5991 // SGR - Select graphics rendition
5995 // DSR - Device status report
6002 // DECLL - Load leds
6006 // DECSTBM - Set top and bottom margins
6010 // Save cursor (ANSI.SYS)
6011 if (type
== DeviceType
.XTERM
) {
6012 savedState
.cursorX
= currentState
.cursorX
;
6013 savedState
.cursorY
= currentState
.cursorY
;
6017 if (type
== DeviceType
.XTERM
) {
6018 // Window operations
6023 // Restore cursor (ANSI.SYS)
6024 if (type
== DeviceType
.XTERM
) {
6025 cursorPosition(savedState
.cursorY
, savedState
.cursorX
);
6032 // DECREQTPARM - Request terminal parameters
6048 // 0x9C goes to GROUND
6053 // 0x3A goes to CSI_IGNORE
6055 scanState
= ScanState
.CSI_IGNORE
;
6060 // 00-17, 19, 1C-1F --> execute
6062 handleControlChar(ch
);
6065 // 20-2F --> collect, then switch to CSI_INTERMEDIATE
6066 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6068 scanState
= ScanState
.CSI_INTERMEDIATE
;
6071 // 30-39, 3B --> param
6072 if ((ch
>= '0') && (ch
<= '9')) {
6079 // 0x3A goes to CSI_IGNORE
6081 scanState
= ScanState
.CSI_IGNORE
;
6083 // 0x3C-3F goes to CSI_IGNORE
6084 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
6085 scanState
= ScanState
.CSI_IGNORE
;
6088 // 40-7E --> dispatch, then switch to GROUND
6089 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6092 // ICH - Insert character
6100 // CUD - Cursor down
6104 // CUF - Cursor forward
6108 // CUB - Cursor backward
6112 // CNL - Cursor down and to column 1
6113 if (type
== DeviceType
.XTERM
) {
6118 // CPL - Cursor up and to column 1
6119 if (type
== DeviceType
.XTERM
) {
6124 // CHA - Cursor to column # in current row
6125 if (type
== DeviceType
.XTERM
) {
6130 // CUP - Cursor position
6134 // CHT - Cursor forward X tab stops (default 1)
6135 if (type
== DeviceType
.XTERM
) {
6140 // ED - Erase in display
6144 // EL - Erase in line
6159 // DCH - Delete character
6166 // Scroll up X lines (default 1)
6167 if (type
== DeviceType
.XTERM
) {
6172 // Scroll down X lines (default 1)
6173 if (type
== DeviceType
.XTERM
) {
6182 if ((type
== DeviceType
.VT220
)
6183 || (type
== DeviceType
.XTERM
)) {
6185 // ECH - Erase character
6192 // CBT - Cursor backward X tab stops (default 1)
6193 if (type
== DeviceType
.XTERM
) {
6204 // HPA - Cursor to column # in current row. Same as CHA
6205 if (type
== DeviceType
.XTERM
) {
6210 // HPR - Cursor right. Same as CUF
6211 if (type
== DeviceType
.XTERM
) {
6216 // REP - Repeat last char X times
6217 if (type
== DeviceType
.XTERM
) {
6222 // DA - Device attributes
6226 // VPA - Cursor to row, current column.
6227 if (type
== DeviceType
.XTERM
) {
6232 // VPR - Cursor down. Same as CUD
6233 if (type
== DeviceType
.XTERM
) {
6238 // HVP - Horizontal and vertical position
6242 // TBC - Tabulation clear
6246 // Sets an ANSI or DEC private toggle
6250 if ((type
== DeviceType
.VT220
)
6251 || (type
== DeviceType
.XTERM
)) {
6253 // Printer functions
6261 // Sets an ANSI or DEC private toggle
6265 // SGR - Select graphics rendition
6269 // DSR - Device status report
6276 // DECLL - Load leds
6280 // DECSTBM - Set top and bottom margins
6286 if (type
== DeviceType
.XTERM
) {
6287 // Window operations
6296 // DECREQTPARM - Request terminal parameters
6313 case CSI_INTERMEDIATE
:
6314 // 00-17, 19, 1C-1F --> execute
6316 handleControlChar(ch
);
6319 // 20-2F --> collect
6320 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6324 // 0x30-3F goes to CSI_IGNORE
6325 if ((ch
>= 0x30) && (ch
<= 0x3F)) {
6326 scanState
= ScanState
.CSI_IGNORE
;
6329 // 40-7E --> dispatch, then switch to GROUND
6330 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6382 if (((type
== DeviceType
.VT220
)
6383 || (type
== DeviceType
.XTERM
))
6384 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == '\"')
6386 // DECSCL - compatibility level
6389 if ((type
== DeviceType
.XTERM
)
6390 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == '!')
6392 // DECSTR - Soft terminal reset
6397 if (((type
== DeviceType
.VT220
)
6398 || (type
== DeviceType
.XTERM
))
6399 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == '\"')
6427 // 00-17, 19, 1C-1F --> execute
6429 handleControlChar(ch
);
6432 // 20-2F --> collect
6433 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6437 // 40-7E --> ignore, then switch to GROUND
6438 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6442 // 20-3F, 7F --> ignore
6448 // 0x9C goes to GROUND
6453 // 0x1B 0x5C goes to GROUND
6458 if ((collectBuffer
.length() > 0)
6459 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6465 // 20-2F --> collect, then switch to DCS_INTERMEDIATE
6466 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6468 scanState
= ScanState
.DCS_INTERMEDIATE
;
6471 // 30-39, 3B --> param, then switch to DCS_PARAM
6472 if ((ch
>= '0') && (ch
<= '9')) {
6474 scanState
= ScanState
.DCS_PARAM
;
6478 scanState
= ScanState
.DCS_PARAM
;
6481 // 3C-3F --> collect, then switch to DCS_PARAM
6482 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
6484 scanState
= ScanState
.DCS_PARAM
;
6487 // 00-17, 19, 1C-1F, 7F --> ignore
6489 // 0x3A goes to DCS_IGNORE
6491 scanState
= ScanState
.DCS_IGNORE
;
6494 // 0x71 goes to DCS_SIXEL
6496 sixelParseBuffer
= new StringBuilder();
6497 scanState
= ScanState
.DCS_SIXEL
;
6498 } else if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6499 // 0x40-7E goes to DCS_PASSTHROUGH
6500 scanState
= ScanState
.DCS_PASSTHROUGH
;
6504 case DCS_INTERMEDIATE
:
6506 // 0x9C goes to GROUND
6511 // 0x1B 0x5C goes to GROUND
6516 if ((collectBuffer
.length() > 0)
6517 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6523 // 0x30-3F goes to DCS_IGNORE
6524 if ((ch
>= 0x30) && (ch
<= 0x3F)) {
6525 scanState
= ScanState
.DCS_IGNORE
;
6528 // 0x40-7E goes to DCS_PASSTHROUGH
6529 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6530 scanState
= ScanState
.DCS_PASSTHROUGH
;
6533 // 00-17, 19, 1C-1F, 7F --> ignore
6538 // 0x9C goes to GROUND
6543 // 0x1B 0x5C goes to GROUND
6548 if ((collectBuffer
.length() > 0)
6549 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6555 // 20-2F --> collect, then switch to DCS_INTERMEDIATE
6556 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6558 scanState
= ScanState
.DCS_INTERMEDIATE
;
6561 // 30-39, 3B --> param
6562 if ((ch
>= '0') && (ch
<= '9')) {
6569 // 00-17, 19, 1C-1F, 7F --> ignore
6571 // 0x3A, 3C-3F goes to DCS_IGNORE
6573 scanState
= ScanState
.DCS_IGNORE
;
6575 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
6576 scanState
= ScanState
.DCS_IGNORE
;
6579 // 0x71 goes to DCS_SIXEL
6581 sixelParseBuffer
= new StringBuilder();
6582 scanState
= ScanState
.DCS_SIXEL
;
6583 } else if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6584 // 0x40-7E goes to DCS_PASSTHROUGH
6585 scanState
= ScanState
.DCS_PASSTHROUGH
;
6589 case DCS_PASSTHROUGH
:
6590 // 0x9C goes to GROUND
6595 // 0x1B 0x5C goes to GROUND
6600 if ((collectBuffer
.length() > 0)
6601 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6607 // 00-17, 19, 1C-1F, 20-7E --> put
6615 if ((ch
>= 0x1C) && (ch
<= 0x1F)) {
6618 if ((ch
>= 0x20) && (ch
<= 0x7E)) {
6627 // 00-17, 19, 1C-1F, 20-7F --> ignore
6629 // 0x9C goes to GROUND
6637 // 0x9C goes to GROUND
6643 // 0x1B 0x5C goes to GROUND
6648 if ((collectBuffer
.length() > 0)
6649 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6656 // 00-17, 19, 1C-1F, 20-7E --> put
6658 sixelParseBuffer
.append(ch
);
6662 sixelParseBuffer
.append(ch
);
6665 if ((ch
>= 0x1C) && (ch
<= 0x1F)) {
6666 sixelParseBuffer
.append(ch
);
6669 if ((ch
>= 0x20) && (ch
<= 0x7E)) {
6670 sixelParseBuffer
.append(ch
);
6678 case SOSPMAPC_STRING
:
6679 // 00-17, 19, 1C-1F, 20-7F --> ignore
6681 // Special case for Jexer: PM can pass one control character
6686 if ((ch
>= 0x20) && (ch
<= 0x7F)) {
6690 // 0x9C goes to GROUND
6698 // Special case for Xterm: OSC can pass control characters
6699 if ((ch
== 0x9C) || (ch
== 0x07) || (ch
== 0x1B)) {
6703 // 00-17, 19, 1C-1F --> ignore
6705 // 20-7F --> osc_put
6706 if ((ch
>= 0x20) && (ch
<= 0x7F)) {
6710 // 0x9C goes to GROUND
6717 case VT52_DIRECT_CURSOR_ADDRESS
:
6718 // This is a special case for the VT52 sequence "ESC Y l c"
6719 if (collectBuffer
.length() == 0) {
6721 } else if (collectBuffer
.length() == 1) {
6722 // We've got the two characters, one in the buffer and the
6724 cursorPosition(collectBuffer
.charAt(0) - '\040', ch
- '\040');
6733 * Expose current cursor X to outside world.
6735 * @return current cursor X
6737 public final int getCursorX() {
6738 if (display
.get(currentState
.cursorY
).isDoubleWidth()) {
6739 return currentState
.cursorX
* 2;
6741 return currentState
.cursorX
;
6745 * Expose current cursor Y to outside world.
6747 * @return current cursor Y
6749 public final int getCursorY() {
6750 return currentState
.cursorY
;
6754 * Returns true if this terminal has requested the mouse pointer be
6757 * @return true if this terminal has requested the mouse pointer be
6760 public final boolean hasHiddenMousePointer() {
6761 return hideMousePointer
;
6765 * Get the mouse protocol.
6767 * @return MouseProtocol.OFF, MouseProtocol.X10, etc.
6769 public MouseProtocol
getMouseProtocol() {
6770 return mouseProtocol
;
6773 // ------------------------------------------------------------------------
6774 // Sixel support ----------------------------------------------------------
6775 // ------------------------------------------------------------------------
6778 * Set the width of a character cell in pixels.
6780 * @param textWidth the width in pixels of a character cell
6782 public void setTextWidth(final int textWidth
) {
6783 this.textWidth
= textWidth
;
6787 * Set the height of a character cell in pixels.
6789 * @param textHeight the height in pixels of a character cell
6791 public void setTextHeight(final int textHeight
) {
6792 this.textHeight
= textHeight
;
6796 * Parse a sixel string into a bitmap image, and overlay that image onto
6799 private void parseSixel() {
6802 System.err.println("parseSixel(): '" + sixelParseBuffer.toString()
6806 Sixel sixel
= new Sixel(sixelParseBuffer
.toString());
6807 BufferedImage image
= sixel
.getImage();
6809 // System.err.println("parseSixel(): image " + image);
6811 if (image
== null) {
6812 // Sixel data was malformed in some way, bail out.
6819 * Break up the image into text cell sized pieces as a new array of
6822 * Note original column position x0.
6826 * 1. Advance (printCharacter(' ')) for horizontal increment, or
6827 * index (linefeed() + cursorPosition(y, x0)) for vertical
6830 * 2. Set (x, y) cell image data.
6832 * 3. For the right and bottom edges:
6834 * a. Render the text to pixels using Terminus font.
6836 * b. Blit the image on top of the text, using alpha channel.
6838 int cellColumns
= image
.getWidth() / textWidth
;
6839 if (cellColumns
* textWidth
< image
.getWidth()) {
6842 int cellRows
= image
.getHeight() / textHeight
;
6843 if (cellRows
* textHeight
< image
.getHeight()) {
6847 // Break the image up into an array of cells.
6848 Cell
[][] cells
= new Cell
[cellColumns
][cellRows
];
6850 for (int x
= 0; x
< cellColumns
; x
++) {
6851 for (int y
= 0; y
< cellRows
; y
++) {
6853 int width
= textWidth
;
6854 if ((x
+ 1) * textWidth
> image
.getWidth()) {
6855 width
= image
.getWidth() - (x
* textWidth
);
6857 int height
= textHeight
;
6858 if ((y
+ 1) * textHeight
> image
.getHeight()) {
6859 height
= image
.getHeight() - (y
* textHeight
);
6862 Cell cell
= new Cell();
6863 cell
.setImage(image
.getSubimage(x
* textWidth
,
6864 y
* textHeight
, width
, height
));
6870 int x0
= currentState
.cursorX
;
6871 for (int y
= 0; y
< cellRows
; y
++) {
6872 for (int x
= 0; x
< cellColumns
; x
++) {
6873 printCharacter(' ');
6874 cursorLeft(1, false);
6875 if ((x
== cellColumns
- 1) || (y
== cellRows
- 1)) {
6876 // TODO: render text of current cell first, then image
6877 // over it. For now, just copy the cell.
6878 DisplayLine line
= display
.get(currentState
.cursorY
);
6879 line
.replace(currentState
.cursorX
, cells
[x
][y
]);
6881 // Copy the image cell into the display.
6882 DisplayLine line
= display
.get(currentState
.cursorY
);
6883 line
.replace(currentState
.cursorX
, cells
[x
][y
]);
6885 cursorRight(1, false);
6888 cursorPosition(currentState
.cursorY
, x0
);
6894 * Draw the left and right cells of a two-cell-wide (full-width) glyph.
6896 * @param leftX the x position to draw the left half to
6897 * @param leftY the y position to draw the left half to
6898 * @param rightX the x position to draw the right half to
6899 * @param rightY the y position to draw the right half to
6900 * @param ch the character to draw
6902 private void drawHalves(final int leftX
, final int leftY
,
6903 final int rightX
, final int rightY
, final char ch
) {
6905 // System.err.println("drawHalves(): " + Integer.toHexString(ch));
6907 if (lastTextHeight
!= textHeight
) {
6908 glyphMaker
= GlyphMaker
.getInstance(textHeight
);
6909 lastTextHeight
= textHeight
;
6912 Cell cell
= new Cell(ch
);
6913 cell
.setAttr(currentState
.attr
);
6914 BufferedImage image
= glyphMaker
.getImage(cell
, textWidth
* 2,
6916 BufferedImage leftImage
= image
.getSubimage(0, 0, textWidth
,
6918 BufferedImage rightImage
= image
.getSubimage(textWidth
, 0, textWidth
,
6921 Cell left
= new Cell();
6923 left
.setImage(leftImage
);
6924 left
.setWidth(Cell
.Width
.LEFT
);
6925 display
.get(leftY
).replace(leftX
, left
);
6927 Cell right
= new Cell();
6929 right
.setImage(rightImage
);
6930 right
.setWidth(Cell
.Width
.RIGHT
);
6931 display
.get(rightY
).replace(rightX
, right
);