2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 package jexer
.tterminal
;
31 import java
.awt
.Graphics2D
;
32 import java
.awt
.image
.BufferedImage
;
33 import java
.io
.BufferedOutputStream
;
34 import java
.io
.CharArrayWriter
;
35 import java
.io
.InputStream
;
36 import java
.io
.InputStreamReader
;
37 import java
.io
.IOException
;
38 import java
.io
.OutputStream
;
39 import java
.io
.OutputStreamWriter
;
40 import java
.io
.PrintWriter
;
41 import java
.io
.Reader
;
42 import java
.io
.UnsupportedEncodingException
;
43 import java
.io
.Writer
;
44 import java
.util
.ArrayList
;
45 import java
.util
.Collections
;
46 import java
.util
.HashMap
;
47 import java
.util
.List
;
49 import jexer
.TKeypress
;
50 import jexer
.backend
.GlyphMaker
;
51 import jexer
.bits
.Color
;
52 import jexer
.bits
.Cell
;
53 import jexer
.bits
.CellAttributes
;
54 import jexer
.bits
.StringUtils
;
55 import jexer
.event
.TInputEvent
;
56 import jexer
.event
.TKeypressEvent
;
57 import jexer
.event
.TMouseEvent
;
58 import jexer
.io
.ReadTimeoutException
;
59 import jexer
.io
.TimeoutInputStream
;
60 import static jexer
.TKeypress
.*;
63 * This implements a complex ECMA-48/ISO 6429/ANSI X3.64 type console,
64 * including a scrollback buffer.
67 * It currently implements VT100, VT102, VT220, and XTERM with the following
71 * - The vttest scenario for VT220 8-bit controls (11.1.2.3) reports a
72 * failure with XTERM. This is due to vttest failing to decode the UTF-8
76 * - Smooth scrolling, printing, keyboard locking, keyboard leds, and tests
77 * from VT100 are not supported.
80 * - User-defined keys (DECUDK), downloadable fonts (DECDLD), and VT100/ANSI
81 * compatibility mode (DECSCL) from VT220 are not supported. (Also,
82 * because DECSCL is not supported, it will fail the last part of the
83 * vttest "Test of VT52 mode" if DeviceType is set to VT220.)
86 * - Numeric/application keys from the number pad are not supported because
87 * they are not exposed from the TKeypress API.
90 * - VT52 HOLD SCREEN mode is not supported.
93 * - In VT52 graphics mode, the 3/, 5/, and 7/ characters (fraction
94 * numerators) are not rendered correctly.
97 * - All data meant for the 'printer' (CSI Pc ? i) is discarded.
99 public class ECMA48
implements Runnable
{
101 // ------------------------------------------------------------------------
102 // Constants --------------------------------------------------------------
103 // ------------------------------------------------------------------------
106 * The emulator can emulate several kinds of terminals.
108 public enum DeviceType
{
110 * DEC VT100 but also including the three VT102 functions.
131 * Parser character scan states.
133 private enum ScanState
{
149 VT52_DIRECT_CURSOR_ADDRESS
153 * The selected number pad mode (DECKPAM, DECKPNM). We record this, but
154 * can't really use it in keypress() because we do not see number pad
155 * events from TKeypress.
157 private enum KeypadMode
{
163 * Arrow keys can emit three different sequences (DECCKM or VT52
166 private enum ArrowKeyMode
{
173 * Available character sets for GL, GR, G0, G1, G2, G3.
175 private enum CharacterSet
{
196 * Single-shift states used by the C1 control characters SS2 (0x8E) and
199 private enum Singleshift
{
206 * VT220+ lockshift states.
208 private enum LockshiftMode
{
218 * XTERM mouse reporting protocols.
220 public enum MouseProtocol
{
229 * XTERM mouse reporting encodings.
231 private enum MouseEncoding
{
237 // ------------------------------------------------------------------------
238 // Variables --------------------------------------------------------------
239 // ------------------------------------------------------------------------
242 * The enclosing listening object.
244 private DisplayListener displayListener
;
247 * When true, the reader thread is expected to exit.
249 private volatile boolean stopReaderThread
= false;
254 private Thread readerThread
= null;
257 * The type of emulator to be.
259 private DeviceType type
= DeviceType
.VT102
;
262 * The scrollback buffer characters + attributes.
264 private volatile ArrayList
<DisplayLine
> scrollback
;
267 * The raw display buffer characters + attributes.
269 private volatile ArrayList
<DisplayLine
> display
;
272 * The maximum number of lines in the scrollback buffer.
274 private int maxScrollback
= 10000;
277 * The terminal's input. For type == XTERM, this is an InputStreamReader
278 * with UTF-8 encoding.
280 private Reader input
;
283 * The terminal's raw InputStream. This is used for type != XTERM.
285 private volatile TimeoutInputStream inputStream
;
288 * The terminal's output. For type == XTERM, this wraps an
289 * OutputStreamWriter with UTF-8 encoding.
291 private Writer output
;
294 * The terminal's raw OutputStream. This is used for type != XTERM.
296 private OutputStream outputStream
;
299 * Current scanning state.
301 private ScanState scanState
;
304 * Which mouse protocol is active.
306 private MouseProtocol mouseProtocol
= MouseProtocol
.OFF
;
309 * Which mouse encoding is active.
311 private MouseEncoding mouseEncoding
= MouseEncoding
.X10
;
314 * A terminal may request that the mouse pointer be hidden using a
315 * Privacy Message containing either "hideMousePointer" or
316 * "showMousePointer". This is currently only used within Jexer by
317 * TTerminalWindow so that only the bottom-most instance of nested
318 * Jexer's draws the mouse within its application window.
320 private boolean hideMousePointer
= false;
323 * Physical display width. We start at 80x24, but the user can resize us
329 * Physical display height. We start at 80x24, but the user can resize
335 * Top margin of the scrolling region.
337 private int scrollRegionTop
;
340 * Bottom margin of the scrolling region.
342 private int scrollRegionBottom
;
345 * Right margin column number. This can be selected by the remote side
346 * to be 80/132 (rightMargin values 79/131), or it can be (width - 1).
348 private int rightMargin
;
351 * Last character printed.
356 * VT100-style line wrapping: a character is placed in column 80 (or
357 * 132), but the line does NOT wrap until another character is written to
358 * column 1 of the next line, after which the cursor moves to column 2.
360 private boolean wrapLineFlag
;
363 * VT220 single shift flag.
365 private Singleshift singleshift
= Singleshift
.NONE
;
368 * true = insert characters, false = overwrite.
370 private boolean insertMode
= false;
373 * VT52 mode as selected by DECANM. True means VT52, false means
374 * ANSI. Default is ANSI.
376 private boolean vt52Mode
= false;
379 * Visible cursor (DECTCEM).
381 private boolean cursorVisible
= true;
384 * Screen title as set by the xterm OSC sequence. Lots of applications
385 * send a screenTitle regardless of whether it is an xterm client or not.
387 private String screenTitle
= "";
390 * Parameter characters being collected.
392 private List
<Integer
> csiParams
;
395 * Non-csi collect buffer.
397 private StringBuilder collectBuffer
;
400 * When true, use the G1 character set.
402 private boolean shiftOut
= false;
405 * Horizontal tab stop locations.
407 private List
<Integer
> tabStops
;
410 * S8C1T. True means 8bit controls, false means 7bit controls.
412 private boolean s8c1t
= false;
415 * Printer mode. True means send all output to printer, which discards
418 private boolean printerControllerMode
= false;
421 * LMN line mode. If true, linefeed() puts the cursor on the first
422 * column of the next line. If false, linefeed() puts the cursor one
423 * line down on the current line. The default is false.
425 private boolean newLineMode
= false;
428 * Whether arrow keys send ANSI, VT100, or VT52 sequences.
430 private ArrowKeyMode arrowKeyMode
;
433 * Whether number pad keys send VT100 or VT52, application or numeric
436 @SuppressWarnings("unused")
437 private KeypadMode keypadMode
;
440 * When true, the terminal is in 132-column mode (DECCOLM).
442 private boolean columns132
= false;
445 * true = reverse video. Set by DECSCNM.
447 private boolean reverseVideo
= false;
450 * false = echo characters locally.
452 private boolean fullDuplex
= true;
455 * The current terminal state.
457 private SaveableState currentState
;
460 * The last saved terminal state.
462 private SaveableState savedState
;
465 * The 88- or 256-color support RGB colors.
467 private List
<Integer
> colors88
;
470 * Sixel collection buffer.
472 private StringBuilder sixelParseBuffer
;
475 * The width of a character cell in pixels.
477 private int textWidth
= 16;
480 * The height of a character cell in pixels.
482 private int textHeight
= 20;
485 * The last used height of a character cell in pixels, only used for
488 private int lastTextHeight
= -1;
491 * The glyph drawer for full-width chars.
493 private GlyphMaker glyphMaker
= null;
496 * Input queue for keystrokes and mouse events to send to the remote
499 private ArrayList
<TInputEvent
> userQueue
= new ArrayList
<TInputEvent
>();
502 * DECSC/DECRC save/restore a subset of the total state. This class
503 * encapsulates those specific flags/modes.
505 private class SaveableState
{
508 * When true, cursor positions are relative to the scrolling region.
510 public boolean originMode
= false;
513 * The current editing X position.
515 public int cursorX
= 0;
518 * The current editing Y position.
520 public int cursorY
= 0;
523 * Which character set is currently selected in G0.
525 public CharacterSet g0Charset
= CharacterSet
.US
;
528 * Which character set is currently selected in G1.
530 public CharacterSet g1Charset
= CharacterSet
.DRAWING
;
533 * Which character set is currently selected in G2.
535 public CharacterSet g2Charset
= CharacterSet
.US
;
538 * Which character set is currently selected in G3.
540 public CharacterSet g3Charset
= CharacterSet
.US
;
543 * Which character set is currently selected in GR.
545 public CharacterSet grCharset
= CharacterSet
.DRAWING
;
548 * The current drawing attributes.
550 public CellAttributes attr
;
555 public LockshiftMode glLockshift
= LockshiftMode
.NONE
;
560 public LockshiftMode grLockshift
= LockshiftMode
.NONE
;
565 public boolean lineWrap
= true;
570 public void reset() {
574 g0Charset
= CharacterSet
.US
;
575 g1Charset
= CharacterSet
.DRAWING
;
576 g2Charset
= CharacterSet
.US
;
577 g3Charset
= CharacterSet
.US
;
578 grCharset
= CharacterSet
.DRAWING
;
579 attr
= new CellAttributes();
580 glLockshift
= LockshiftMode
.NONE
;
581 grLockshift
= LockshiftMode
.NONE
;
586 * Copy attributes from another instance.
588 * @param that the other instance to match
590 public void setTo(final SaveableState that
) {
591 this.originMode
= that
.originMode
;
592 this.cursorX
= that
.cursorX
;
593 this.cursorY
= that
.cursorY
;
594 this.g0Charset
= that
.g0Charset
;
595 this.g1Charset
= that
.g1Charset
;
596 this.g2Charset
= that
.g2Charset
;
597 this.g3Charset
= that
.g3Charset
;
598 this.grCharset
= that
.grCharset
;
599 this.attr
= new CellAttributes();
600 this.attr
.setTo(that
.attr
);
601 this.glLockshift
= that
.glLockshift
;
602 this.grLockshift
= that
.grLockshift
;
603 this.lineWrap
= that
.lineWrap
;
607 * Public constructor.
609 public SaveableState() {
614 // ------------------------------------------------------------------------
615 // Constructors -----------------------------------------------------------
616 // ------------------------------------------------------------------------
619 * Public constructor.
621 * @param type one of the DeviceType constants to select VT100, VT102,
623 * @param inputStream an InputStream connected to the remote side. For
624 * type == XTERM, inputStream is converted to a Reader with UTF-8
626 * @param outputStream an OutputStream connected to the remote user. For
627 * type == XTERM, outputStream is converted to a Writer with UTF-8
629 * @param displayListener a callback to the outer display, or null for
630 * default VT100 behavior
631 * @throws UnsupportedEncodingException if an exception is thrown when
632 * creating the InputStreamReader
634 public ECMA48(final DeviceType type
, final InputStream inputStream
,
635 final OutputStream outputStream
, final DisplayListener displayListener
)
636 throws UnsupportedEncodingException
{
638 assert (inputStream
!= null);
639 assert (outputStream
!= null);
641 csiParams
= new ArrayList
<Integer
>();
642 tabStops
= new ArrayList
<Integer
>();
643 scrollback
= new ArrayList
<DisplayLine
>();
644 display
= new ArrayList
<DisplayLine
>();
647 if (inputStream
instanceof TimeoutInputStream
) {
648 this.inputStream
= (TimeoutInputStream
)inputStream
;
650 this.inputStream
= new TimeoutInputStream(inputStream
, 2000);
652 if (type
== DeviceType
.XTERM
) {
653 this.input
= new InputStreamReader(this.inputStream
, "UTF-8");
654 this.output
= new OutputStreamWriter(new
655 BufferedOutputStream(outputStream
), "UTF-8");
656 this.outputStream
= null;
659 this.outputStream
= new BufferedOutputStream(outputStream
);
661 this.displayListener
= displayListener
;
664 for (int i
= 0; i
< height
; i
++) {
665 display
.add(new DisplayLine(currentState
.attr
));
668 // Spin up the input reader
669 readerThread
= new Thread(this);
670 readerThread
.start();
673 // ------------------------------------------------------------------------
674 // Runnable ---------------------------------------------------------------
675 // ------------------------------------------------------------------------
678 * Read function runs on a separate thread.
680 public final void run() {
681 boolean utf8
= false;
682 boolean done
= false;
684 if (type
== DeviceType
.XTERM
) {
688 // available() will often return > 1, so we need to read in chunks to
690 char [] readBufferUTF8
= null;
691 byte [] readBuffer
= null;
693 readBufferUTF8
= new char[2048];
695 readBuffer
= new byte[2048];
698 while (!done
&& !stopReaderThread
) {
699 synchronized (userQueue
) {
700 while (userQueue
.size() > 0) {
701 handleUserEvent(userQueue
.remove(0));
706 int n
= inputStream
.available();
708 // System.err.printf("available() %d\n", n); System.err.flush();
710 if (readBufferUTF8
.length
< n
) {
711 // The buffer wasn't big enough, make it huger
712 int newSizeHalf
= Math
.max(readBufferUTF8
.length
,
715 readBufferUTF8
= new char[newSizeHalf
* 2];
718 if (readBuffer
.length
< n
) {
719 // The buffer wasn't big enough, make it huger
720 int newSizeHalf
= Math
.max(readBuffer
.length
, n
);
721 readBuffer
= new byte[newSizeHalf
* 2];
727 } catch (InterruptedException e
) {
736 rc
= input
.read(readBufferUTF8
, 0,
737 readBufferUTF8
.length
);
739 rc
= inputStream
.read(readBuffer
, 0,
742 } catch (ReadTimeoutException e
) {
746 // System.err.printf("read() %d\n", rc); System.err.flush();
751 // Don't step on UI events
752 synchronized (this) {
754 for (int i
= 0; i
< rc
;) {
755 int ch
= Character
.codePointAt(readBufferUTF8
,
757 i
+= Character
.charCount(ch
);
761 for (int i
= 0; i
< rc
; i
++) {
762 consume(readBuffer
[i
]);
766 // Permit my enclosing UI to know that I updated.
767 if (displayListener
!= null) {
768 displayListener
.displayChanged();
771 // System.err.println("end while loop"); System.err.flush();
772 } catch (IOException e
) {
775 // This is an unusual case. We want to see the stack trace,
776 // but it is related to the spawned process rather than the
777 // actual UI. We will generate the stack trace, and consume
778 // it as though it was emitted by the shell.
779 CharArrayWriter writer
= new CharArrayWriter();
780 // Send a ST and RIS to clear the emulator state.
782 writer
.write("\033\\\033c");
783 writer
.write("\n-----------------------------------\n");
784 e
.printStackTrace(new PrintWriter(writer
));
785 writer
.write("\n-----------------------------------\n");
786 } catch (IOException e2
) {
789 char [] stackTrace
= writer
.toCharArray();
790 for (int i
= 0; i
< stackTrace
.length
; i
++) {
791 if (stackTrace
[i
] == '\n') {
794 consume(stackTrace
[i
]);
798 } // while ((done == false) && (stopReaderThread == false))
800 // Let the rest of the world know that I am done.
801 stopReaderThread
= true;
804 inputStream
.cancelRead();
807 } catch (IOException e
) {
813 } catch (IOException e
) {
817 // Permit my enclosing UI to know that I updated.
818 if (displayListener
!= null) {
819 displayListener
.displayChanged();
822 // System.err.println("*** run() exiting..."); System.err.flush();
825 // ------------------------------------------------------------------------
826 // ECMA48 -----------------------------------------------------------------
827 // ------------------------------------------------------------------------
830 * Process keyboard and mouse events from the user.
832 * @param event the input event to consume
834 private void handleUserEvent(final TInputEvent event
) {
835 if (event
instanceof TKeypressEvent
) {
836 keypress(((TKeypressEvent
) event
).getKey());
838 if (event
instanceof TMouseEvent
) {
839 mouse((TMouseEvent
) event
);
844 * Add a keyboard and mouse event from the user to the queue.
846 * @param event the input event to consume
848 public void addUserEvent(final TInputEvent event
) {
849 synchronized (userQueue
) {
850 userQueue
.add(event
);
855 * Return the proper primary Device Attributes string.
857 * @return string to send to remote side that is appropriate for the
860 private String
deviceTypeResponse() {
863 // "I am a VT100 with advanced video option" (often VT102)
872 // "I am a VT220" - 7 bit version
874 return "\033[?62;1;6c";
876 // "I am a VT220" - 8 bit version
877 return "\u009b?62;1;6c";
879 throw new IllegalArgumentException("Invalid device type: " + type
);
884 * Return the proper TERM environment variable for this device type.
886 * @param deviceType DeviceType.VT100, DeviceType, XTERM, etc.
887 * @return "vt100", "xterm", etc.
889 public static String
deviceTypeTerm(final DeviceType deviceType
) {
890 switch (deviceType
) {
904 throw new IllegalArgumentException("Invalid device type: "
910 * Return the proper LANG for this device type. Only XTERM devices know
911 * about UTF-8, the others are defined by their standard to be either
912 * 7-bit or 8-bit characters only.
914 * @param deviceType DeviceType.VT100, DeviceType, XTERM, etc.
915 * @param baseLang a base language without UTF-8 flag such as "C" or
917 * @return "en_US", "en_US.UTF-8", etc.
919 public static String
deviceTypeLang(final DeviceType deviceType
,
920 final String baseLang
) {
922 switch (deviceType
) {
930 return baseLang
+ ".UTF-8";
933 throw new IllegalArgumentException("Invalid device type: "
939 * Write a string directly to the remote side.
941 * @param str string to send
943 public void writeRemote(final String str
) {
944 if (stopReaderThread
) {
945 // Reader hit EOF, bail out now.
950 // System.err.printf("writeRemote() '%s'\n", str);
956 if (outputStream
== null) {
960 outputStream
.flush();
961 for (int i
= 0; i
< str
.length(); i
++) {
962 outputStream
.write(str
.charAt(i
));
964 outputStream
.flush();
965 } catch (IOException e
) {
971 if (output
== null) {
978 } catch (IOException e
) {
984 throw new IllegalArgumentException("Invalid device type: " + type
);
989 * Close the input and output streams and stop the reader thread. Note
990 * that it is safe to call this multiple times.
992 public final void close() {
994 // Tell the reader thread to stop looking at input. It will close
995 // the input streams.
996 if (stopReaderThread
== false) {
997 stopReaderThread
= true;
999 readerThread
.join(1000);
1000 } catch (InterruptedException e
) {
1005 // Now close the output stream.
1010 if (outputStream
!= null) {
1012 outputStream
.close();
1013 } catch (IOException e
) {
1016 outputStream
= null;
1020 if (outputStream
!= null) {
1022 outputStream
.close();
1023 } catch (IOException e
) {
1026 outputStream
= null;
1028 if (output
!= null) {
1031 } catch (IOException e
) {
1038 throw new IllegalArgumentException("Invalid device type: " +
1044 * See if the reader thread is still running.
1046 * @return if true, we are still connected to / reading from the remote
1049 public final boolean isReading() {
1050 return (!stopReaderThread
);
1054 * Obtain a new blank display line for an external user
1055 * (e.g. TTerminalWindow).
1057 * @return new blank line
1059 public final DisplayLine
getBlankDisplayLine() {
1060 return new DisplayLine(currentState
.attr
);
1064 * Get the scrollback buffer.
1066 * @return the scrollback buffer
1068 public final List
<DisplayLine
> getScrollbackBuffer() {
1073 * Get the display buffer.
1075 * @return the display buffer
1077 public final List
<DisplayLine
> getDisplayBuffer() {
1082 * Get the display width.
1084 * @return the width (usually 80 or 132)
1086 public final int getWidth() {
1091 * Set the display width.
1093 * @param width the new width
1095 public final void setWidth(final int width
) {
1097 rightMargin
= width
- 1;
1098 if (currentState
.cursorX
>= width
) {
1099 currentState
.cursorX
= width
- 1;
1101 if (savedState
.cursorX
>= width
) {
1102 savedState
.cursorX
= width
- 1;
1107 * Get the display height.
1109 * @return the height (usually 24)
1111 public final int getHeight() {
1116 * Set the display height.
1118 * @param height the new height
1120 public final void setHeight(final int height
) {
1121 int delta
= height
- this.height
;
1122 this.height
= height
;
1123 scrollRegionBottom
+= delta
;
1124 if (scrollRegionBottom
< 0) {
1125 scrollRegionBottom
= height
;
1127 if (scrollRegionTop
>= scrollRegionBottom
) {
1128 scrollRegionTop
= 0;
1130 if (currentState
.cursorY
>= height
) {
1131 currentState
.cursorY
= height
- 1;
1133 if (savedState
.cursorY
>= height
) {
1134 savedState
.cursorY
= height
- 1;
1136 while (display
.size() < height
) {
1137 DisplayLine line
= new DisplayLine(currentState
.attr
);
1138 line
.setReverseColor(reverseVideo
);
1141 while (display
.size() > height
) {
1142 scrollback
.add(display
.remove(0));
1147 * Get visible cursor flag.
1149 * @return if true, the cursor is visible
1151 public final boolean isCursorVisible() {
1152 return cursorVisible
;
1156 * Get the screen title as set by the xterm OSC sequence. Lots of
1157 * applications send a screenTitle regardless of whether it is an xterm
1160 * @return screen title
1162 public final String
getScreenTitle() {
1167 * Get 132 columns value.
1169 * @return if true, the terminal is in 132 column mode
1171 public final boolean isColumns132() {
1176 * Clear the CSI parameters and flags.
1178 private void toGround() {
1180 collectBuffer
= new StringBuilder(8);
1181 scanState
= ScanState
.GROUND
;
1185 * Reset the tab stops list.
1187 private void resetTabStops() {
1189 for (int i
= 0; (i
* 8) <= rightMargin
; i
++) {
1190 tabStops
.add(Integer
.valueOf(i
* 8));
1195 * Reset the 88- or 256-colors.
1197 private void resetColors() {
1198 colors88
= new ArrayList
<Integer
>(256);
1199 for (int i
= 0; i
< 256; i
++) {
1203 // Set default system colors.
1204 colors88
.set(0, 0x00000000);
1205 colors88
.set(1, 0x00a80000);
1206 colors88
.set(2, 0x0000a800);
1207 colors88
.set(3, 0x00a85400);
1208 colors88
.set(4, 0x000000a8);
1209 colors88
.set(5, 0x00a800a8);
1210 colors88
.set(6, 0x0000a8a8);
1211 colors88
.set(7, 0x00a8a8a8);
1213 colors88
.set(8, 0x00545454);
1214 colors88
.set(9, 0x00fc5454);
1215 colors88
.set(10, 0x0054fc54);
1216 colors88
.set(11, 0x00fcfc54);
1217 colors88
.set(12, 0x005454fc);
1218 colors88
.set(13, 0x00fc54fc);
1219 colors88
.set(14, 0x0054fcfc);
1220 colors88
.set(15, 0x00fcfcfc);
1224 * Get the RGB value of one of the indexed colors.
1226 * @param index the color index
1227 * @return the RGB value
1229 private int get88Color(final int index
) {
1230 // System.err.print("get88Color: " + index);
1231 if ((index
< 0) || (index
> colors88
.size())) {
1232 // System.err.println(" -- UNKNOWN");
1235 // System.err.printf(" %08x\n", colors88.get(index));
1236 return colors88
.get(index
);
1240 * Set one of the indexed colors to a color specification.
1242 * @param index the color index
1243 * @param spec the specification, typically something like "rgb:aa/bb/cc"
1245 private void set88Color(final int index
, final String spec
) {
1246 // System.err.println("set88Color: " + index + " '" + spec + "'");
1248 if ((index
< 0) || (index
> colors88
.size())) {
1251 if (spec
.startsWith("rgb:")) {
1252 String
[] rgbTokens
= spec
.substring(4).split("/");
1253 if (rgbTokens
.length
== 3) {
1255 int rgb
= (Integer
.parseInt(rgbTokens
[0], 16) << 16);
1256 rgb
|= Integer
.parseInt(rgbTokens
[1], 16) << 8;
1257 rgb
|= Integer
.parseInt(rgbTokens
[2], 16);
1258 // System.err.printf(" set to %08x\n", rgb);
1259 colors88
.set(index
, rgb
);
1260 } catch (NumberFormatException e
) {
1267 if (spec
.toLowerCase().equals("black")) {
1268 colors88
.set(index
, 0x00000000);
1269 } else if (spec
.toLowerCase().equals("red")) {
1270 colors88
.set(index
, 0x00a80000);
1271 } else if (spec
.toLowerCase().equals("green")) {
1272 colors88
.set(index
, 0x0000a800);
1273 } else if (spec
.toLowerCase().equals("yellow")) {
1274 colors88
.set(index
, 0x00a85400);
1275 } else if (spec
.toLowerCase().equals("blue")) {
1276 colors88
.set(index
, 0x000000a8);
1277 } else if (spec
.toLowerCase().equals("magenta")) {
1278 colors88
.set(index
, 0x00a800a8);
1279 } else if (spec
.toLowerCase().equals("cyan")) {
1280 colors88
.set(index
, 0x0000a8a8);
1281 } else if (spec
.toLowerCase().equals("white")) {
1282 colors88
.set(index
, 0x00a8a8a8);
1288 * Reset the emulation state.
1290 private void reset() {
1292 currentState
= new SaveableState();
1293 savedState
= new SaveableState();
1294 scanState
= ScanState
.GROUND
;
1297 scrollRegionTop
= 0;
1298 scrollRegionBottom
= height
- 1;
1299 rightMargin
= width
- 1;
1300 newLineMode
= false;
1301 arrowKeyMode
= ArrowKeyMode
.ANSI
;
1302 keypadMode
= KeypadMode
.Numeric
;
1303 wrapLineFlag
= false;
1304 if (displayListener
!= null) {
1305 width
= displayListener
.getDisplayWidth();
1306 height
= displayListener
.getDisplayHeight();
1307 rightMargin
= width
- 1;
1315 newLineMode
= false;
1316 reverseVideo
= false;
1318 cursorVisible
= true;
1321 singleshift
= Singleshift
.NONE
;
1323 printerControllerMode
= false;
1326 mouseProtocol
= MouseProtocol
.OFF
;
1327 mouseEncoding
= MouseEncoding
.X10
;
1332 // Reset extra colors
1340 * Append a new line to the bottom of the display, adding lines off the
1341 * top to the scrollback buffer.
1343 private void newDisplayLine() {
1344 // Scroll the top line off into the scrollback buffer
1345 scrollback
.add(display
.get(0));
1346 if (scrollback
.size() > maxScrollback
) {
1347 scrollback
.remove(0);
1348 scrollback
.trimToSize();
1351 display
.trimToSize();
1352 DisplayLine line
= new DisplayLine(currentState
.attr
);
1353 line
.setReverseColor(reverseVideo
);
1358 * Wraps the current line.
1360 private void wrapCurrentLine() {
1361 if (currentState
.cursorY
== height
- 1) {
1364 if (currentState
.cursorY
< height
- 1) {
1365 currentState
.cursorY
++;
1367 currentState
.cursorX
= 0;
1371 * Handle a carriage return.
1373 private void carriageReturn() {
1374 currentState
.cursorX
= 0;
1375 wrapLineFlag
= false;
1379 * Reverse the color of the visible display.
1381 private void invertDisplayColors() {
1382 for (DisplayLine line
: display
) {
1383 line
.setReverseColor(!line
.isReverseColor());
1388 * Handle a linefeed.
1390 private void linefeed() {
1392 if (currentState
.cursorY
< scrollRegionBottom
) {
1393 // Increment screen y
1394 currentState
.cursorY
++;
1397 // Screen y does not increment
1400 * Two cases: either we're inside a scrolling region or not. If
1401 * the scrolling region bottom is the bottom of the screen, then
1402 * push the top line into the buffer. Else scroll the scrolling
1405 if ((scrollRegionBottom
== height
- 1) && (scrollRegionTop
== 0)) {
1407 // We're at the bottom of the scroll region, AND the scroll
1408 // region is the entire screen.
1414 // We're at the bottom of the scroll region, AND the scroll
1415 // region is NOT the entire screen.
1416 scrollingRegionScrollUp(scrollRegionTop
, scrollRegionBottom
, 1);
1421 currentState
.cursorX
= 0;
1423 wrapLineFlag
= false;
1427 * Prints one character to the display buffer.
1429 * @param ch character to display
1431 private void printCharacter(final int ch
) {
1432 int rightMargin
= this.rightMargin
;
1434 if (StringUtils
.width(ch
) == 2) {
1435 // This is a full-width character. Save two spaces, and then
1436 // draw the character as two image halves.
1437 int x0
= currentState
.cursorX
;
1438 int y0
= currentState
.cursorY
;
1439 printCharacter(' ');
1440 printCharacter(' ');
1441 if ((currentState
.cursorX
== x0
+ 2)
1442 && (currentState
.cursorY
== y0
)
1444 // We can draw both halves of the character.
1445 drawHalves(x0
, y0
, x0
+ 1, y0
, ch
);
1446 } else if ((currentState
.cursorX
== x0
+ 1)
1447 && (currentState
.cursorY
== y0
)
1449 // VT100 line wrap behavior: we should be at the right
1450 // margin. We can draw both halves of the character.
1451 drawHalves(x0
, y0
, x0
+ 1, y0
, ch
);
1453 // The character splits across the line. Draw the entire
1454 // character on the new line, giving one more space for it.
1455 x0
= currentState
.cursorX
- 1;
1456 y0
= currentState
.cursorY
;
1457 printCharacter(' ');
1458 drawHalves(x0
, y0
, x0
+ 1, y0
, ch
);
1463 // Check if we have double-width, and if so chop at 40/66 instead of
1465 if (display
.get(currentState
.cursorY
).isDoubleWidth()) {
1466 rightMargin
= ((rightMargin
+ 1) / 2) - 1;
1469 // Check the unusually-complicated line wrapping conditions...
1470 if (currentState
.cursorX
== rightMargin
) {
1472 if (currentState
.lineWrap
== true) {
1474 * This case happens when: the cursor was already on the
1475 * right margin (either through printing or by an explicit
1476 * placement command), and a character was printed.
1478 * The line wraps only when a new character arrives AND the
1479 * cursor is already on the right margin AND has placed a
1480 * character in its cell. Easier to see than to explain.
1482 if (wrapLineFlag
== false) {
1484 * This block marks the case that we are in the margin
1485 * and the first character has been received and printed.
1487 wrapLineFlag
= true;
1490 * This block marks the case that we are in the margin
1491 * and the second character has been received and
1494 wrapLineFlag
= false;
1498 } else if (currentState
.cursorX
<= rightMargin
) {
1500 * This is the normal case: a character came in and was printed
1501 * to the left of the right margin column.
1504 // Turn off VT100 special-case flag
1505 wrapLineFlag
= false;
1508 // "Print" the character
1509 Cell newCell
= new Cell(ch
);
1510 CellAttributes newCellAttributes
= (CellAttributes
) newCell
;
1511 newCellAttributes
.setTo(currentState
.attr
);
1512 DisplayLine line
= display
.get(currentState
.cursorY
);
1514 if (StringUtils
.width(ch
) == 1) {
1515 // Insert mode special case
1516 if (insertMode
== true) {
1517 line
.insert(currentState
.cursorX
, newCell
);
1519 // Replace an existing character
1520 line
.replace(currentState
.cursorX
, newCell
);
1523 // Increment horizontal
1524 if (wrapLineFlag
== false) {
1525 currentState
.cursorX
++;
1526 if (currentState
.cursorX
> rightMargin
) {
1527 currentState
.cursorX
--;
1534 * Translate the mouse event to a VT100, VT220, or XTERM sequence and
1535 * send to the remote side.
1537 * @param mouse mouse event received from the local user
1539 private void mouse(final TMouseEvent mouse
) {
1542 System.err.printf("mouse(): protocol %s encoding %s mouse %s\n",
1543 mouseProtocol, mouseEncoding, mouse);
1546 if (mouseEncoding
== MouseEncoding
.X10
) {
1547 // We will support X10 but only for (160,94) and smaller.
1548 if ((mouse
.getX() >= 160) || (mouse
.getY() >= 94)) {
1553 switch (mouseProtocol
) {
1560 // Only report button presses
1561 if (mouse
.getType() != TMouseEvent
.Type
.MOUSE_DOWN
) {
1567 // Only report button presses and releases
1568 if ((mouse
.getType() != TMouseEvent
.Type
.MOUSE_DOWN
)
1569 && (mouse
.getType() != TMouseEvent
.Type
.MOUSE_UP
)
1577 * Only report button presses, button releases, and motions that
1578 * have a button down (i.e. drag-and-drop).
1580 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1581 if (!mouse
.isMouse1()
1582 && !mouse
.isMouse2()
1583 && !mouse
.isMouse3()
1584 && !mouse
.isMouseWheelUp()
1585 && !mouse
.isMouseWheelDown()
1593 // Report everything
1597 // Now encode the event
1598 StringBuilder sb
= new StringBuilder(6);
1599 if (mouseEncoding
== MouseEncoding
.SGR
) {
1600 sb
.append((char) 0x1B);
1603 if (mouse
.isMouse1()) {
1604 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1609 } else if (mouse
.isMouse2()) {
1610 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1615 } else if (mouse
.isMouse3()) {
1616 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1621 } else if (mouse
.isMouseWheelUp()) {
1623 } else if (mouse
.isMouseWheelDown()) {
1626 // This is motion with no buttons down.
1630 sb
.append(String
.format("%d;%d", mouse
.getX() + 1,
1633 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_UP
) {
1640 // X10 and UTF8 encodings
1641 sb
.append((char) 0x1B);
1644 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_UP
) {
1645 sb
.append((char) (0x03 + 32));
1646 } else if (mouse
.isMouse1()) {
1647 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1648 sb
.append((char) (0x00 + 32 + 32));
1650 sb
.append((char) (0x00 + 32));
1652 } else if (mouse
.isMouse2()) {
1653 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1654 sb
.append((char) (0x01 + 32 + 32));
1656 sb
.append((char) (0x01 + 32));
1658 } else if (mouse
.isMouse3()) {
1659 if (mouse
.getType() == TMouseEvent
.Type
.MOUSE_MOTION
) {
1660 sb
.append((char) (0x02 + 32 + 32));
1662 sb
.append((char) (0x02 + 32));
1664 } else if (mouse
.isMouseWheelUp()) {
1665 sb
.append((char) (0x04 + 64));
1666 } else if (mouse
.isMouseWheelDown()) {
1667 sb
.append((char) (0x05 + 64));
1669 // This is motion with no buttons down.
1670 sb
.append((char) (0x03 + 32));
1673 sb
.append((char) (mouse
.getX() + 33));
1674 sb
.append((char) (mouse
.getY() + 33));
1677 // System.err.printf("Would write: \'%s\'\n", sb.toString());
1678 writeRemote(sb
.toString());
1682 * Translate the keyboard press to a VT100, VT220, or XTERM sequence and
1683 * send to the remote side.
1685 * @param keypress keypress received from the local user
1687 private void keypress(final TKeypress keypress
) {
1688 writeRemote(keypressToString(keypress
));
1692 * Build one of the complex xterm keystroke sequences, storing the result in
1693 * xterm_keystroke_buffer.
1695 * @param ss3 the prefix to use based on VT100 state.
1696 * @param first the first character, usually a number.
1697 * @param first the last character, one of the following: ~ A B C D F H
1698 * @param ctrl whether or not ctrl is down
1699 * @param alt whether or not alt is down
1700 * @param shift whether or not shift is down
1701 * @return the buffer with the full key sequence
1703 private String
xtermBuildKeySequence(final String ss3
, final char first
,
1704 final char last
, boolean ctrl
, boolean alt
, boolean shift
) {
1706 StringBuilder sb
= new StringBuilder(ss3
);
1707 if ((last
== '~') || (ctrl
== true) || (alt
== true)
1711 if ( (ctrl
== false) && (alt
== false) && (shift
== true)) {
1713 } else if ((ctrl
== false) && (alt
== true) && (shift
== false)) {
1715 } else if ((ctrl
== false) && (alt
== true) && (shift
== true)) {
1717 } else if ((ctrl
== true) && (alt
== false) && (shift
== false)) {
1719 } else if ((ctrl
== true) && (alt
== false) && (shift
== true)) {
1721 } else if ((ctrl
== true) && (alt
== true) && (shift
== false)) {
1723 } else if ((ctrl
== true) && (alt
== true) && (shift
== true)) {
1728 return sb
.toString();
1732 * Translate the keyboard press to a VT100, VT220, or XTERM sequence.
1734 * @param keypress keypress received from the local user
1735 * @return string to transmit to the remote side
1737 @SuppressWarnings("fallthrough")
1738 private String
keypressToString(final TKeypress keypress
) {
1740 if ((fullDuplex
== false) && (!keypress
.isFnKey())) {
1742 * If this is a control character, process it like it came from
1745 if (keypress
.getChar() < 0x20) {
1746 handleControlChar((char) keypress
.getChar());
1748 // Local echo for everything else
1749 printCharacter(keypress
.getChar());
1753 if ((newLineMode
== true) && (keypress
.equals(kbEnter
))) {
1758 // Handle control characters
1759 if ((keypress
.isCtrl()) && (!keypress
.isFnKey())) {
1760 StringBuilder sb
= new StringBuilder();
1761 int ch
= keypress
.getChar();
1763 sb
.append(Character
.toChars(ch
));
1764 return sb
.toString();
1767 // Handle alt characters
1768 if ((keypress
.isAlt()) && (!keypress
.isFnKey())) {
1769 StringBuilder sb
= new StringBuilder("\033");
1770 int ch
= keypress
.getChar();
1771 sb
.append(Character
.toChars(ch
));
1772 return sb
.toString();
1775 if (keypress
.equals(kbBackspaceDel
)) {
1788 if (keypress
.equalsWithoutModifiers(kbLeft
)) {
1791 switch (arrowKeyMode
) {
1793 return xtermBuildKeySequence("\033[", '1', 'D',
1794 keypress
.isCtrl(), keypress
.isAlt(),
1795 keypress
.isShift());
1797 return xtermBuildKeySequence("\033", '1', 'D',
1798 keypress
.isCtrl(), keypress
.isAlt(),
1799 keypress
.isShift());
1801 return xtermBuildKeySequence("\033O", '1', 'D',
1802 keypress
.isCtrl(), keypress
.isAlt(),
1803 keypress
.isShift());
1806 switch (arrowKeyMode
) {
1817 if (keypress
.equalsWithoutModifiers(kbRight
)) {
1820 switch (arrowKeyMode
) {
1822 return xtermBuildKeySequence("\033[", '1', 'C',
1823 keypress
.isCtrl(), keypress
.isAlt(),
1824 keypress
.isShift());
1826 return xtermBuildKeySequence("\033", '1', 'C',
1827 keypress
.isCtrl(), keypress
.isAlt(),
1828 keypress
.isShift());
1830 return xtermBuildKeySequence("\033O", '1', 'C',
1831 keypress
.isCtrl(), keypress
.isAlt(),
1832 keypress
.isShift());
1835 switch (arrowKeyMode
) {
1846 if (keypress
.equalsWithoutModifiers(kbUp
)) {
1849 switch (arrowKeyMode
) {
1851 return xtermBuildKeySequence("\033[", '1', 'A',
1852 keypress
.isCtrl(), keypress
.isAlt(),
1853 keypress
.isShift());
1855 return xtermBuildKeySequence("\033", '1', 'A',
1856 keypress
.isCtrl(), keypress
.isAlt(),
1857 keypress
.isShift());
1859 return xtermBuildKeySequence("\033O", '1', 'A',
1860 keypress
.isCtrl(), keypress
.isAlt(),
1861 keypress
.isShift());
1864 switch (arrowKeyMode
) {
1875 if (keypress
.equalsWithoutModifiers(kbDown
)) {
1878 switch (arrowKeyMode
) {
1880 return xtermBuildKeySequence("\033[", '1', 'B',
1881 keypress
.isCtrl(), keypress
.isAlt(),
1882 keypress
.isShift());
1884 return xtermBuildKeySequence("\033", '1', 'B',
1885 keypress
.isCtrl(), keypress
.isAlt(),
1886 keypress
.isShift());
1888 return xtermBuildKeySequence("\033O", '1', 'B',
1889 keypress
.isCtrl(), keypress
.isAlt(),
1890 keypress
.isShift());
1893 switch (arrowKeyMode
) {
1904 if (keypress
.equalsWithoutModifiers(kbHome
)) {
1907 switch (arrowKeyMode
) {
1909 return xtermBuildKeySequence("\033[", '1', 'H',
1910 keypress
.isCtrl(), keypress
.isAlt(),
1911 keypress
.isShift());
1913 return xtermBuildKeySequence("\033", '1', 'H',
1914 keypress
.isCtrl(), keypress
.isAlt(),
1915 keypress
.isShift());
1917 return xtermBuildKeySequence("\033O", '1', 'H',
1918 keypress
.isCtrl(), keypress
.isAlt(),
1919 keypress
.isShift());
1922 switch (arrowKeyMode
) {
1933 if (keypress
.equalsWithoutModifiers(kbEnd
)) {
1936 switch (arrowKeyMode
) {
1938 return xtermBuildKeySequence("\033[", '1', 'F',
1939 keypress
.isCtrl(), keypress
.isAlt(),
1940 keypress
.isShift());
1942 return xtermBuildKeySequence("\033", '1', 'F',
1943 keypress
.isCtrl(), keypress
.isAlt(),
1944 keypress
.isShift());
1946 return xtermBuildKeySequence("\033O", '1', 'F',
1947 keypress
.isCtrl(), keypress
.isAlt(),
1948 keypress
.isShift());
1951 switch (arrowKeyMode
) {
1962 if (keypress
.equals(kbF1
)) {
1970 if (keypress
.equals(kbF2
)) {
1978 if (keypress
.equals(kbF3
)) {
1986 if (keypress
.equals(kbF4
)) {
1994 if (keypress
.equals(kbF5
)) {
2007 if (keypress
.equals(kbF6
)) {
2020 if (keypress
.equals(kbF7
)) {
2033 if (keypress
.equals(kbF8
)) {
2046 if (keypress
.equals(kbF9
)) {
2059 if (keypress
.equals(kbF10
)) {
2072 if (keypress
.equals(kbF11
)) {
2076 if (keypress
.equals(kbF12
)) {
2080 if (keypress
.equals(kbShiftF1
)) {
2085 if (type
== DeviceType
.XTERM
) {
2091 if (keypress
.equals(kbShiftF2
)) {
2096 if (type
== DeviceType
.XTERM
) {
2102 if (keypress
.equals(kbShiftF3
)) {
2107 if (type
== DeviceType
.XTERM
) {
2113 if (keypress
.equals(kbShiftF4
)) {
2118 if (type
== DeviceType
.XTERM
) {
2124 if (keypress
.equals(kbShiftF5
)) {
2126 return "\033[15;2~";
2129 if (keypress
.equals(kbShiftF6
)) {
2131 return "\033[17;2~";
2134 if (keypress
.equals(kbShiftF7
)) {
2136 return "\033[18;2~";
2139 if (keypress
.equals(kbShiftF8
)) {
2141 return "\033[19;2~";
2144 if (keypress
.equals(kbShiftF9
)) {
2146 return "\033[20;2~";
2149 if (keypress
.equals(kbShiftF10
)) {
2151 return "\033[21;2~";
2154 if (keypress
.equals(kbShiftF11
)) {
2156 return "\033[23;2~";
2159 if (keypress
.equals(kbShiftF12
)) {
2161 return "\033[24;2~";
2164 if (keypress
.equals(kbCtrlF1
)) {
2169 if (type
== DeviceType
.XTERM
) {
2175 if (keypress
.equals(kbCtrlF2
)) {
2180 if (type
== DeviceType
.XTERM
) {
2186 if (keypress
.equals(kbCtrlF3
)) {
2191 if (type
== DeviceType
.XTERM
) {
2197 if (keypress
.equals(kbCtrlF4
)) {
2202 if (type
== DeviceType
.XTERM
) {
2208 if (keypress
.equals(kbCtrlF5
)) {
2210 return "\033[15;5~";
2213 if (keypress
.equals(kbCtrlF6
)) {
2215 return "\033[17;5~";
2218 if (keypress
.equals(kbCtrlF7
)) {
2220 return "\033[18;5~";
2223 if (keypress
.equals(kbCtrlF8
)) {
2225 return "\033[19;5~";
2228 if (keypress
.equals(kbCtrlF9
)) {
2230 return "\033[20;5~";
2233 if (keypress
.equals(kbCtrlF10
)) {
2235 return "\033[21;5~";
2238 if (keypress
.equals(kbCtrlF11
)) {
2240 return "\033[23;5~";
2243 if (keypress
.equals(kbCtrlF12
)) {
2245 return "\033[24;5~";
2248 if (keypress
.equalsWithoutModifiers(kbPgUp
)) {
2251 return xtermBuildKeySequence("\033[", '5', '~',
2252 keypress
.isCtrl(), keypress
.isAlt(),
2253 keypress
.isShift());
2259 if (keypress
.equalsWithoutModifiers(kbPgDn
)) {
2262 return xtermBuildKeySequence("\033[", '6', '~',
2263 keypress
.isCtrl(), keypress
.isAlt(),
2264 keypress
.isShift());
2270 if (keypress
.equalsWithoutModifiers(kbIns
)) {
2273 return xtermBuildKeySequence("\033[", '2', '~',
2274 keypress
.isCtrl(), keypress
.isAlt(),
2275 keypress
.isShift());
2281 if (keypress
.equalsWithoutModifiers(kbDel
)) {
2284 return xtermBuildKeySequence("\033[", '3', '~',
2285 keypress
.isCtrl(), keypress
.isAlt(),
2286 keypress
.isShift());
2288 // Delete sends real delete for VTxxx
2293 if (keypress
.equals(kbEnter
)) {
2297 if (keypress
.equals(kbEsc
)) {
2301 if (keypress
.equals(kbAltEsc
)) {
2305 if (keypress
.equals(kbTab
)) {
2309 if ((keypress
.equalsWithoutModifiers(kbBackTab
)) ||
2310 (keypress
.equals(kbShiftTab
))
2320 // Non-alt, non-ctrl characters
2321 if (!keypress
.isFnKey()) {
2322 StringBuilder sb
= new StringBuilder();
2323 sb
.append(Character
.toChars(keypress
.getChar()));
2324 return sb
.toString();
2330 * Map a symbol in any one of the VT100/VT220 character sets to a Unicode
2333 * @param ch 8-bit character from the remote side
2334 * @param charsetGl character set defined for GL
2335 * @param charsetGr character set defined for GR
2336 * @return character to display on the screen
2338 private char mapCharacterCharset(final int ch
,
2339 final CharacterSet charsetGl
,
2340 final CharacterSet charsetGr
) {
2342 int lookupChar
= ch
;
2343 CharacterSet lookupCharset
= charsetGl
;
2346 assert ((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
));
2347 lookupCharset
= charsetGr
;
2351 switch (lookupCharset
) {
2354 return DECCharacterSets
.SPECIAL_GRAPHICS
[lookupChar
];
2357 return DECCharacterSets
.UK
[lookupChar
];
2360 return DECCharacterSets
.US_ASCII
[lookupChar
];
2363 return DECCharacterSets
.NL
[lookupChar
];
2366 return DECCharacterSets
.FI
[lookupChar
];
2369 return DECCharacterSets
.FR
[lookupChar
];
2372 return DECCharacterSets
.FR_CA
[lookupChar
];
2375 return DECCharacterSets
.DE
[lookupChar
];
2378 return DECCharacterSets
.IT
[lookupChar
];
2381 return DECCharacterSets
.NO
[lookupChar
];
2384 return DECCharacterSets
.ES
[lookupChar
];
2387 return DECCharacterSets
.SV
[lookupChar
];
2390 return DECCharacterSets
.SWISS
[lookupChar
];
2392 case DEC_SUPPLEMENTAL
:
2393 return DECCharacterSets
.DEC_SUPPLEMENTAL
[lookupChar
];
2396 return DECCharacterSets
.VT52_SPECIAL_GRAPHICS
[lookupChar
];
2399 return DECCharacterSets
.US_ASCII
[lookupChar
];
2402 return DECCharacterSets
.US_ASCII
[lookupChar
];
2405 throw new IllegalArgumentException("Invalid character set value: "
2411 * Map an 8-bit byte into a printable character.
2413 * @param ch either 8-bit or Unicode character from the remote side
2414 * @return character to display on the screen
2416 private int mapCharacter(final int ch
) {
2418 // Unicode character, just return it
2422 CharacterSet charsetGl
= currentState
.g0Charset
;
2423 CharacterSet charsetGr
= currentState
.grCharset
;
2425 if (vt52Mode
== true) {
2426 if (shiftOut
== true) {
2427 // Shifted out character, pull from VT52 graphics
2428 charsetGl
= currentState
.g1Charset
;
2429 charsetGr
= CharacterSet
.US
;
2432 charsetGl
= currentState
.g0Charset
;
2433 charsetGr
= CharacterSet
.US
;
2436 // Pull the character
2437 return mapCharacterCharset(ch
, charsetGl
, charsetGr
);
2441 if (shiftOut
== true) {
2442 // Shifted out character, pull from G1
2443 charsetGl
= currentState
.g1Charset
;
2444 charsetGr
= currentState
.grCharset
;
2446 // Pull the character
2447 return mapCharacterCharset(ch
, charsetGl
, charsetGr
);
2451 if (singleshift
== Singleshift
.SS2
) {
2453 singleshift
= Singleshift
.NONE
;
2455 // Shifted out character, pull from G2
2456 charsetGl
= currentState
.g2Charset
;
2457 charsetGr
= currentState
.grCharset
;
2461 if (singleshift
== Singleshift
.SS3
) {
2463 singleshift
= Singleshift
.NONE
;
2465 // Shifted out character, pull from G3
2466 charsetGl
= currentState
.g3Charset
;
2467 charsetGr
= currentState
.grCharset
;
2470 if ((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
)) {
2471 // Check for locking shift
2473 switch (currentState
.glLockshift
) {
2476 throw new IllegalArgumentException("programming bug");
2479 throw new IllegalArgumentException("programming bug");
2482 throw new IllegalArgumentException("programming bug");
2486 charsetGl
= currentState
.g2Charset
;
2491 charsetGl
= currentState
.g3Charset
;
2496 charsetGl
= currentState
.g0Charset
;
2500 switch (currentState
.grLockshift
) {
2503 throw new IllegalArgumentException("programming bug");
2506 throw new IllegalArgumentException("programming bug");
2510 charsetGr
= currentState
.g1Charset
;
2515 charsetGr
= currentState
.g2Charset
;
2520 charsetGr
= currentState
.g3Charset
;
2525 charsetGr
= CharacterSet
.DEC_SUPPLEMENTAL
;
2532 // Pull the character
2533 return mapCharacterCharset(ch
, charsetGl
, charsetGr
);
2537 * Scroll the text within a scrolling region up n lines.
2539 * @param regionTop top row of the scrolling region
2540 * @param regionBottom bottom row of the scrolling region
2541 * @param n number of lines to scroll
2543 private void scrollingRegionScrollUp(final int regionTop
,
2544 final int regionBottom
, final int n
) {
2546 if (regionTop
>= regionBottom
) {
2550 // Sanity check: see if there will be any characters left after the
2552 if (regionBottom
+ 1 - regionTop
<= n
) {
2553 // There won't be anything left in the region, so just call
2554 // eraseScreen() and return.
2555 eraseScreen(regionTop
, 0, regionBottom
, width
- 1, false);
2559 int remaining
= regionBottom
+ 1 - regionTop
- n
;
2560 List
<DisplayLine
> displayTop
= display
.subList(0, regionTop
);
2561 List
<DisplayLine
> displayBottom
= display
.subList(regionBottom
+ 1,
2563 List
<DisplayLine
> displayMiddle
= display
.subList(regionBottom
+ 1
2564 - remaining
, regionBottom
+ 1);
2565 display
= new ArrayList
<DisplayLine
>(displayTop
);
2566 display
.addAll(displayMiddle
);
2567 for (int i
= 0; i
< n
; i
++) {
2568 DisplayLine line
= new DisplayLine(currentState
.attr
);
2569 line
.setReverseColor(reverseVideo
);
2572 display
.addAll(displayBottom
);
2574 assert (display
.size() == height
);
2578 * Scroll the text within a scrolling region down n lines.
2580 * @param regionTop top row of the scrolling region
2581 * @param regionBottom bottom row of the scrolling region
2582 * @param n number of lines to scroll
2584 private void scrollingRegionScrollDown(final int regionTop
,
2585 final int regionBottom
, final int n
) {
2587 if (regionTop
>= regionBottom
) {
2591 // Sanity check: see if there will be any characters left after the
2593 if (regionBottom
+ 1 - regionTop
<= n
) {
2594 // There won't be anything left in the region, so just call
2595 // eraseScreen() and return.
2596 eraseScreen(regionTop
, 0, regionBottom
, width
- 1, false);
2600 int remaining
= regionBottom
+ 1 - regionTop
- n
;
2601 List
<DisplayLine
> displayTop
= display
.subList(0, regionTop
);
2602 List
<DisplayLine
> displayBottom
= display
.subList(regionBottom
+ 1,
2604 List
<DisplayLine
> displayMiddle
= display
.subList(regionTop
,
2605 regionTop
+ remaining
);
2606 display
= new ArrayList
<DisplayLine
>(displayTop
);
2607 for (int i
= 0; i
< n
; i
++) {
2608 DisplayLine line
= new DisplayLine(currentState
.attr
);
2609 line
.setReverseColor(reverseVideo
);
2612 display
.addAll(displayMiddle
);
2613 display
.addAll(displayBottom
);
2615 assert (display
.size() == height
);
2619 * Process a control character.
2621 * @param ch 8-bit character from the remote side
2623 private void handleControlChar(final char ch
) {
2624 assert ((ch
<= 0x1F) || ((ch
>= 0x7F) && (ch
<= 0x9F)));
2635 // Transmit the answerback message.
2646 cursorLeft(1, false);
2651 advanceToNextTabStop();
2677 currentState
.glLockshift
= LockshiftMode
.NONE
;
2683 currentState
.glLockshift
= LockshiftMode
.NONE
;
2708 singleshift
= Singleshift
.SS2
;
2713 singleshift
= Singleshift
.SS3
;
2723 * Advance the cursor to the next tab stop.
2725 private void advanceToNextTabStop() {
2726 if (tabStops
.size() == 0) {
2727 // Go to the rightmost column
2728 cursorRight(rightMargin
- currentState
.cursorX
, false);
2731 for (Integer stop
: tabStops
) {
2732 if (stop
> currentState
.cursorX
) {
2733 cursorRight(stop
- currentState
.cursorX
, false);
2738 * We got here, meaning there isn't a tab stop beyond the current
2739 * cursor position. Place the cursor of the right-most edge of the
2742 cursorRight(rightMargin
- currentState
.cursorX
, false);
2746 * Save a character into the collect buffer.
2748 * @param ch character to save
2750 private void collect(final char ch
) {
2751 collectBuffer
.append(ch
);
2755 * Save a byte into the CSI parameters buffer.
2757 * @param ch byte to save
2759 private void param(final byte ch
) {
2760 if (csiParams
.size() == 0) {
2761 csiParams
.add(Integer
.valueOf(0));
2763 Integer x
= csiParams
.get(csiParams
.size() - 1);
2764 if ((ch
>= '0') && (ch
<= '9')) {
2767 csiParams
.set(csiParams
.size() - 1, x
);
2770 if ((ch
== ';') && (csiParams
.size() < 16)) {
2771 csiParams
.add(Integer
.valueOf(0));
2776 * Get a CSI parameter value, with a default.
2778 * @param position parameter index. 0 is the first parameter.
2779 * @param defaultValue value to use if csiParams[position] doesn't exist
2780 * @return parameter value
2782 private int getCsiParam(final int position
, final int defaultValue
) {
2783 if (csiParams
.size() < position
+ 1) {
2784 return defaultValue
;
2786 return csiParams
.get(position
).intValue();
2790 * Get a CSI parameter value, clamped to within min/max.
2792 * @param position parameter index. 0 is the first parameter.
2793 * @param defaultValue value to use if csiParams[position] doesn't exist
2794 * @param minValue minimum value inclusive
2795 * @param maxValue maximum value inclusive
2796 * @return parameter value
2798 private int getCsiParam(final int position
, final int defaultValue
,
2799 final int minValue
, final int maxValue
) {
2801 assert (minValue
<= maxValue
);
2802 int value
= getCsiParam(position
, defaultValue
);
2803 if (value
< minValue
) {
2806 if (value
> maxValue
) {
2813 * Set or unset a toggle.
2815 * @param value true for set ('h'), false for reset ('l')
2817 private void setToggle(final boolean value
) {
2818 boolean decPrivateModeFlag
= false;
2819 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
2820 if (collectBuffer
.charAt(i
) == '?') {
2821 decPrivateModeFlag
= true;
2826 for (Integer i
: csiParams
) {
2831 if (decPrivateModeFlag
== true) {
2833 if (value
== true) {
2834 // Use application arrow keys
2835 arrowKeyMode
= ArrowKeyMode
.VT100
;
2837 // Use ANSI arrow keys
2838 arrowKeyMode
= ArrowKeyMode
.ANSI
;
2843 if (decPrivateModeFlag
== true) {
2844 if (value
== false) {
2848 arrowKeyMode
= ArrowKeyMode
.VT52
;
2851 * From the VT102 docs: "You use ANSI mode to select
2852 * most terminal features; the terminal uses the same
2853 * features when it switches to VT52 mode. You
2854 * cannot, however, change most of these features in
2857 * In other words, do not reset any other attributes
2858 * when switching between VT52 submode and ANSI.
2860 * HOWEVER, the real vt100 does switch the character
2861 * set according to Usenet.
2863 currentState
.g0Charset
= CharacterSet
.US
;
2864 currentState
.g1Charset
= CharacterSet
.DRAWING
;
2867 if ((type
== DeviceType
.VT220
)
2868 || (type
== DeviceType
.XTERM
)) {
2870 // VT52 mode is explicitly 7-bit
2872 singleshift
= Singleshift
.NONE
;
2877 if (value
== true) {
2878 // Turn off keyboard
2887 if (decPrivateModeFlag
== true) {
2889 if (value
== true) {
2896 if ((displayListener
!= null)
2897 && (type
== DeviceType
.XTERM
)
2899 // For xterms, reset to the actual width, not 80
2901 width
= displayListener
.getDisplayWidth();
2902 rightMargin
= width
- 1;
2905 width
= rightMargin
+ 1;
2908 // Entire screen is cleared, and scrolling region is
2910 eraseScreen(0, 0, height
- 1, width
- 1, false);
2911 scrollRegionTop
= 0;
2912 scrollRegionBottom
= height
- 1;
2913 // Also home the cursor
2914 cursorPosition(0, 0);
2918 if (decPrivateModeFlag
== true) {
2920 if (value
== true) {
2929 if (value
== true) {
2937 if (decPrivateModeFlag
== true) {
2939 if (value
== true) {
2941 * Set selects reverse screen, a white screen
2942 * background with black characters.
2944 if (reverseVideo
!= true) {
2946 * If in normal video, switch it back
2948 invertDisplayColors();
2950 reverseVideo
= true;
2953 * Reset selects normal screen, a black screen
2954 * background with white characters.
2956 if (reverseVideo
== true) {
2958 * If in reverse video already, switch it back
2960 invertDisplayColors();
2962 reverseVideo
= false;
2967 if (decPrivateModeFlag
== true) {
2969 if (value
== true) {
2970 // Origin is relative to scroll region cursor.
2971 // Cursor can NEVER leave scrolling region.
2972 currentState
.originMode
= true;
2973 cursorPosition(0, 0);
2975 // Origin is absolute to entire screen. Cursor can
2976 // leave the scrolling region via cup() and hvp().
2977 currentState
.originMode
= false;
2978 cursorPosition(0, 0);
2983 if (decPrivateModeFlag
== true) {
2985 if (value
== true) {
2987 currentState
.lineWrap
= true;
2989 // Turn linewrap off
2990 currentState
.lineWrap
= false;
2995 if (decPrivateModeFlag
== true) {
2997 if (value
== true) {
2998 // Keyboard auto-repeat on
3001 // Keyboard auto-repeat off
3007 if (decPrivateModeFlag
== false) {
3009 if (value
== true) {
3019 if (decPrivateModeFlag
== true) {
3025 if (decPrivateModeFlag
== true) {
3031 if (decPrivateModeFlag
== false) {
3033 if (value
== true) {
3035 * Set causes a received linefeed, form feed, or
3036 * vertical tab to move cursor to first column of
3037 * next line. RETURN transmits both a carriage return
3038 * and linefeed. This selection is also called new
3044 * Reset causes a received linefeed, form feed, or
3045 * vertical tab to move cursor to next line in
3046 * current column. RETURN transmits a carriage
3049 newLineMode
= false;
3055 if ((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
)) {
3056 if (decPrivateModeFlag
== true) {
3058 if (value
== true) {
3060 cursorVisible
= true;
3063 cursorVisible
= false;
3070 if ((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
)) {
3071 if (decPrivateModeFlag
== true) {
3073 if (value
== true) {
3074 // Select national mode NRC
3077 // Select multi-national mode
3086 if ((type
== DeviceType
.XTERM
)
3087 && (decPrivateModeFlag
== true)
3089 // Mouse: normal tracking mode
3090 if (value
== true) {
3091 mouseProtocol
= MouseProtocol
.NORMAL
;
3093 mouseProtocol
= MouseProtocol
.OFF
;
3099 if ((type
== DeviceType
.XTERM
)
3100 && (decPrivateModeFlag
== true)
3102 // Mouse: normal tracking mode
3103 if (value
== true) {
3104 mouseProtocol
= MouseProtocol
.BUTTONEVENT
;
3106 mouseProtocol
= MouseProtocol
.OFF
;
3112 if ((type
== DeviceType
.XTERM
)
3113 && (decPrivateModeFlag
== true)
3115 // Mouse: Any-event tracking mode
3116 if (value
== true) {
3117 mouseProtocol
= MouseProtocol
.ANYEVENT
;
3119 mouseProtocol
= MouseProtocol
.OFF
;
3125 if ((type
== DeviceType
.XTERM
)
3126 && (decPrivateModeFlag
== true)
3128 // Mouse: UTF-8 coordinates
3129 if (value
== true) {
3130 mouseEncoding
= MouseEncoding
.UTF8
;
3132 mouseEncoding
= MouseEncoding
.X10
;
3138 if ((type
== DeviceType
.XTERM
)
3139 && (decPrivateModeFlag
== true)
3141 // Mouse: SGR coordinates
3142 if (value
== true) {
3143 mouseEncoding
= MouseEncoding
.SGR
;
3145 mouseEncoding
= MouseEncoding
.X10
;
3158 * DECSC - Save cursor.
3160 private void decsc() {
3161 savedState
.setTo(currentState
);
3165 * DECRC - Restore cursor.
3167 private void decrc() {
3168 currentState
.setTo(savedState
);
3174 private void ind() {
3175 // Move the cursor and scroll if necessary. If at the bottom line
3176 // already, a scroll up is supposed to be performed.
3177 if (currentState
.cursorY
== scrollRegionBottom
) {
3178 scrollingRegionScrollUp(scrollRegionTop
, scrollRegionBottom
, 1);
3180 cursorDown(1, true);
3184 * RI - Reverse index.
3187 // Move the cursor and scroll if necessary. If at the top line
3188 // already, a scroll down is supposed to be performed.
3189 if (currentState
.cursorY
== scrollRegionTop
) {
3190 scrollingRegionScrollDown(scrollRegionTop
, scrollRegionBottom
, 1);
3198 private void nel() {
3199 // Move the cursor and scroll if necessary. If at the bottom line
3200 // already, a scroll up is supposed to be performed.
3201 if (currentState
.cursorY
== scrollRegionBottom
) {
3202 scrollingRegionScrollUp(scrollRegionTop
, scrollRegionBottom
, 1);
3204 cursorDown(1, true);
3206 // Reset to the beginning of the next line
3207 currentState
.cursorX
= 0;
3211 * DECKPAM - Keypad application mode.
3213 private void deckpam() {
3214 keypadMode
= KeypadMode
.Application
;
3218 * DECKPNM - Keypad numeric mode.
3220 private void deckpnm() {
3221 keypadMode
= KeypadMode
.Numeric
;
3227 * @param n number of spaces to move
3228 * @param honorScrollRegion if true, then do nothing if the cursor is
3229 * outside the scrolling region
3231 private void cursorUp(final int n
, final boolean honorScrollRegion
) {
3235 * Special case: if a user moves the cursor from the right margin, we
3236 * have to reset the VT100 right margin flag.
3239 wrapLineFlag
= false;
3242 for (int i
= 0; i
< n
; i
++) {
3243 if (honorScrollRegion
== true) {
3244 // Honor the scrolling region
3245 if ((currentState
.cursorY
< scrollRegionTop
)
3246 || (currentState
.cursorY
> scrollRegionBottom
)
3248 // Outside region, do nothing
3251 // Inside region, go up
3252 top
= scrollRegionTop
;
3254 // Non-scrolling case
3258 if (currentState
.cursorY
> top
) {
3259 currentState
.cursorY
--;
3265 * Move down n spaces.
3267 * @param n number of spaces to move
3268 * @param honorScrollRegion if true, then do nothing if the cursor is
3269 * outside the scrolling region
3271 private void cursorDown(final int n
, final boolean honorScrollRegion
) {
3275 * Special case: if a user moves the cursor from the right margin, we
3276 * have to reset the VT100 right margin flag.
3279 wrapLineFlag
= false;
3282 for (int i
= 0; i
< n
; i
++) {
3284 if (honorScrollRegion
== true) {
3285 // Honor the scrolling region
3286 if (currentState
.cursorY
> scrollRegionBottom
) {
3287 // Outside region, do nothing
3290 // Inside region, go down
3291 bottom
= scrollRegionBottom
;
3293 // Non-scrolling case
3294 bottom
= height
- 1;
3297 if (currentState
.cursorY
< bottom
) {
3298 currentState
.cursorY
++;
3304 * Move left n spaces.
3306 * @param n number of spaces to move
3307 * @param honorScrollRegion if true, then do nothing if the cursor is
3308 * outside the scrolling region
3310 private void cursorLeft(final int n
, final boolean honorScrollRegion
) {
3312 * Special case: if a user moves the cursor from the right margin, we
3313 * have to reset the VT100 right margin flag.
3316 wrapLineFlag
= false;
3319 for (int i
= 0; i
< n
; i
++) {
3320 if (honorScrollRegion
== true) {
3321 // Honor the scrolling region
3322 if ((currentState
.cursorY
< scrollRegionTop
)
3323 || (currentState
.cursorY
> scrollRegionBottom
)
3325 // Outside region, do nothing
3330 if (currentState
.cursorX
> 0) {
3331 currentState
.cursorX
--;
3337 * Move right n spaces.
3339 * @param n number of spaces to move
3340 * @param honorScrollRegion if true, then do nothing if the cursor is
3341 * outside the scrolling region
3343 private void cursorRight(final int n
, final boolean honorScrollRegion
) {
3344 int rightMargin
= this.rightMargin
;
3347 * Special case: if a user moves the cursor from the right margin, we
3348 * have to reset the VT100 right margin flag.
3351 wrapLineFlag
= false;
3354 if (display
.get(currentState
.cursorY
).isDoubleWidth()) {
3355 rightMargin
= ((rightMargin
+ 1) / 2) - 1;
3358 for (int i
= 0; i
< n
; i
++) {
3359 if (honorScrollRegion
== true) {
3360 // Honor the scrolling region
3361 if ((currentState
.cursorY
< scrollRegionTop
)
3362 || (currentState
.cursorY
> scrollRegionBottom
)
3364 // Outside region, do nothing
3369 if (currentState
.cursorX
< rightMargin
) {
3370 currentState
.cursorX
++;
3376 * Move cursor to (col, row) where (0, 0) is the top-left corner.
3378 * @param row row to move to
3379 * @param col column to move to
3381 private void cursorPosition(int row
, final int col
) {
3382 int rightMargin
= this.rightMargin
;
3387 if (display
.get(currentState
.cursorY
).isDoubleWidth()) {
3388 rightMargin
= ((rightMargin
+ 1) / 2) - 1;
3391 // Set column number
3392 currentState
.cursorX
= col
;
3394 // Sanity check, bring column back to margin.
3395 if (currentState
.cursorX
> rightMargin
) {
3396 currentState
.cursorX
= rightMargin
;
3400 if (currentState
.originMode
== true) {
3401 row
+= scrollRegionTop
;
3403 if (currentState
.cursorY
< row
) {
3404 cursorDown(row
- currentState
.cursorY
, false);
3405 } else if (currentState
.cursorY
> row
) {
3406 cursorUp(currentState
.cursorY
- row
, false);
3409 wrapLineFlag
= false;
3413 * HTS - Horizontal tabulation set.
3415 private void hts() {
3416 for (Integer stop
: tabStops
) {
3417 if (stop
== currentState
.cursorX
) {
3418 // Already have a tab stop here
3423 // Append a tab stop to the end of the array and resort them
3424 tabStops
.add(currentState
.cursorX
);
3425 Collections
.sort(tabStops
);
3429 * DECSWL - Single-width line.
3431 private void decswl() {
3432 display
.get(currentState
.cursorY
).setDoubleWidth(false);
3433 display
.get(currentState
.cursorY
).setDoubleHeight(0);
3437 * DECDWL - Double-width line.
3439 private void decdwl() {
3440 display
.get(currentState
.cursorY
).setDoubleWidth(true);
3441 display
.get(currentState
.cursorY
).setDoubleHeight(0);
3445 * DECHDL - Double-height + double-width line.
3447 * @param topHalf if true, this sets the row to be the top half row of a
3450 private void dechdl(final boolean topHalf
) {
3451 display
.get(currentState
.cursorY
).setDoubleWidth(true);
3452 if (topHalf
== true) {
3453 display
.get(currentState
.cursorY
).setDoubleHeight(1);
3455 display
.get(currentState
.cursorY
).setDoubleHeight(2);
3460 * DECALN - Screen alignment display.
3462 private void decaln() {
3463 Cell newCell
= new Cell('E');
3464 for (DisplayLine line
: display
) {
3465 for (int i
= 0; i
< line
.length(); i
++) {
3466 line
.replace(i
, newCell
);
3472 * DECSCL - Compatibility level.
3474 private void decscl() {
3475 int i
= getCsiParam(0, 0);
3476 int j
= getCsiParam(1, 0);
3480 currentState
.g0Charset
= CharacterSet
.US
;
3481 currentState
.g1Charset
= CharacterSet
.DRAWING
;
3483 } else if (i
== 62) {
3485 if ((j
== 0) || (j
== 2)) {
3487 } else if (j
== 1) {
3494 * CUD - Cursor down.
3496 private void cud() {
3497 cursorDown(getCsiParam(0, 1, 1, height
), true);
3501 * CUF - Cursor forward.
3503 private void cuf() {
3504 cursorRight(getCsiParam(0, 1, 1, rightMargin
+ 1), true);
3508 * CUB - Cursor backward.
3510 private void cub() {
3511 cursorLeft(getCsiParam(0, 1, 1, currentState
.cursorX
+ 1), true);
3517 private void cuu() {
3518 cursorUp(getCsiParam(0, 1, 1, currentState
.cursorY
+ 1), true);
3522 * CUP - Cursor position.
3524 private void cup() {
3525 cursorPosition(getCsiParam(0, 1, 1, height
) - 1,
3526 getCsiParam(1, 1, 1, rightMargin
+ 1) - 1);
3530 * CNL - Cursor down and to column 1.
3532 private void cnl() {
3533 cursorDown(getCsiParam(0, 1, 1, height
), true);
3535 cursorLeft(currentState
.cursorX
, true);
3539 * CPL - Cursor up and to column 1.
3541 private void cpl() {
3542 cursorUp(getCsiParam(0, 1, 1, currentState
.cursorY
+ 1), true);
3544 cursorLeft(currentState
.cursorX
, true);
3548 * CHA - Cursor to column # in current row.
3550 private void cha() {
3551 cursorPosition(currentState
.cursorY
,
3552 getCsiParam(0, 1, 1, rightMargin
+ 1) - 1);
3556 * VPA - Cursor to row #, same column.
3558 private void vpa() {
3559 cursorPosition(getCsiParam(0, 1, 1, height
) - 1,
3560 currentState
.cursorX
);
3564 * ED - Erase in display.
3567 boolean honorProtected
= false;
3568 boolean decPrivateModeFlag
= false;
3570 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
3571 if (collectBuffer
.charAt(i
) == '?') {
3572 decPrivateModeFlag
= true;
3577 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
3578 && (decPrivateModeFlag
== true)
3580 honorProtected
= true;
3583 int i
= getCsiParam(0, 0);
3586 // Erase from here to end of screen
3587 if (currentState
.cursorY
< height
- 1) {
3588 eraseScreen(currentState
.cursorY
+ 1, 0, height
- 1, width
- 1,
3591 eraseLine(currentState
.cursorX
, width
- 1, honorProtected
);
3592 } else if (i
== 1) {
3593 // Erase from beginning of screen to here
3594 eraseScreen(0, 0, currentState
.cursorY
- 1, width
- 1,
3596 eraseLine(0, currentState
.cursorX
, honorProtected
);
3597 } else if (i
== 2) {
3598 // Erase entire screen
3599 eraseScreen(0, 0, height
- 1, width
- 1, honorProtected
);
3604 * EL - Erase in line.
3607 boolean honorProtected
= false;
3608 boolean decPrivateModeFlag
= false;
3610 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
3611 if (collectBuffer
.charAt(i
) == '?') {
3612 decPrivateModeFlag
= true;
3617 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
3618 && (decPrivateModeFlag
== true)
3620 honorProtected
= true;
3623 int i
= getCsiParam(0, 0);
3626 // Erase from here to end of line
3627 eraseLine(currentState
.cursorX
, width
- 1, honorProtected
);
3628 } else if (i
== 1) {
3629 // Erase from beginning of line to here
3630 eraseLine(0, currentState
.cursorX
, honorProtected
);
3631 } else if (i
== 2) {
3632 // Erase entire line
3633 eraseLine(0, width
- 1, honorProtected
);
3638 * ECH - Erase # of characters in current row.
3640 private void ech() {
3641 int i
= getCsiParam(0, 1, 1, width
);
3643 // Erase from here to i characters
3644 eraseLine(currentState
.cursorX
, currentState
.cursorX
+ i
- 1, false);
3651 int i
= getCsiParam(0, 1);
3653 if ((currentState
.cursorY
>= scrollRegionTop
)
3654 && (currentState
.cursorY
<= scrollRegionBottom
)
3657 // I can get the same effect with a scroll-down
3658 scrollingRegionScrollDown(currentState
.cursorY
,
3659 scrollRegionBottom
, i
);
3664 * DCH - Delete char.
3666 private void dch() {
3667 int n
= getCsiParam(0, 1);
3668 DisplayLine line
= display
.get(currentState
.cursorY
);
3669 Cell blank
= new Cell();
3670 for (int i
= 0; i
< n
; i
++) {
3671 line
.delete(currentState
.cursorX
, blank
);
3676 * ICH - Insert blank char at cursor.
3678 private void ich() {
3679 int n
= getCsiParam(0, 1);
3680 DisplayLine line
= display
.get(currentState
.cursorY
);
3681 Cell blank
= new Cell();
3682 for (int i
= 0; i
< n
; i
++) {
3683 line
.insert(currentState
.cursorX
, blank
);
3691 int i
= getCsiParam(0, 1);
3693 if ((currentState
.cursorY
>= scrollRegionTop
)
3694 && (currentState
.cursorY
<= scrollRegionBottom
)) {
3696 // I can get the same effect with a scroll-down
3697 scrollingRegionScrollUp(currentState
.cursorY
,
3698 scrollRegionBottom
, i
);
3703 * HVP - Horizontal and vertical position.
3705 private void hvp() {
3710 * REP - Repeat character.
3712 private void rep() {
3713 int n
= getCsiParam(0, 1);
3714 for (int i
= 0; i
< n
; i
++) {
3715 printCharacter(repCh
);
3723 scrollingRegionScrollUp(scrollRegionTop
, scrollRegionBottom
,
3724 getCsiParam(0, 1, 1, height
));
3731 scrollingRegionScrollDown(scrollRegionTop
, scrollRegionBottom
,
3732 getCsiParam(0, 1, 1, height
));
3736 * CBT - Go back X tab stops.
3738 private void cbt() {
3739 int tabsToMove
= getCsiParam(0, 1);
3742 for (int i
= 0; i
< tabsToMove
; i
++) {
3743 int j
= currentState
.cursorX
;
3744 for (tabI
= 0; tabI
< tabStops
.size(); tabI
++) {
3745 if (tabStops
.get(tabI
) >= currentState
.cursorX
) {
3753 j
= tabStops
.get(tabI
);
3755 cursorPosition(currentState
.cursorY
, j
);
3760 * CHT - Advance X tab stops.
3762 private void cht() {
3763 int n
= getCsiParam(0, 1);
3764 for (int i
= 0; i
< n
; i
++) {
3765 advanceToNextTabStop();
3770 * SGR - Select graphics rendition.
3772 private void sgr() {
3774 if (csiParams
.size() == 0) {
3775 currentState
.attr
.reset();
3779 int sgrColorMode
= -1;
3780 boolean idx88Color
= false;
3781 boolean rgbColor
= false;
3785 for (Integer i
: csiParams
) {
3787 if ((sgrColorMode
== 38) || (sgrColorMode
== 48)) {
3789 assert (type
== DeviceType
.XTERM
);
3793 * Indexed color mode, we now have the index number.
3795 if (sgrColorMode
== 38) {
3796 currentState
.attr
.setForeColorRGB(get88Color(i
));
3798 assert (sgrColorMode
== 48);
3799 currentState
.attr
.setBackColorRGB(get88Color(i
));
3808 * RGB color mode, we are collecting tokens.
3812 } else if (rgbGreen
== -1) {
3813 rgbGreen
= i
& 0xFF;
3815 int rgb
= rgbRed
<< 16;
3816 rgb
|= rgbGreen
<< 8;
3819 // System.err.printf("RGB: %08x\n", rgb);
3821 if (sgrColorMode
== 38) {
3822 currentState
.attr
.setForeColorRGB(rgb
);
3824 assert (sgrColorMode
== 48);
3825 currentState
.attr
.setBackColorRGB(rgb
);
3846 * Indexed color mode.
3853 * This is neither indexed nor RGB color. Bail out.
3858 } // if ((sgrColorMode == 38) || (sgrColorMode == 48))
3864 currentState
.attr
.reset();
3869 currentState
.attr
.setBold(true);
3874 currentState
.attr
.setUnderline(true);
3879 currentState
.attr
.setBlink(true);
3884 currentState
.attr
.setReverse(true);
3891 if (type
== DeviceType
.XTERM
) {
3901 // Set black foreground
3902 currentState
.attr
.setForeColorRGB(get88Color(8));
3905 // Set red foreground
3906 currentState
.attr
.setForeColorRGB(get88Color(9));
3909 // Set green foreground
3910 currentState
.attr
.setForeColorRGB(get88Color(10));
3913 // Set yellow foreground
3914 currentState
.attr
.setForeColorRGB(get88Color(11));
3917 // Set blue foreground
3918 currentState
.attr
.setForeColorRGB(get88Color(12));
3921 // Set magenta foreground
3922 currentState
.attr
.setForeColorRGB(get88Color(13));
3925 // Set cyan foreground
3926 currentState
.attr
.setForeColorRGB(get88Color(14));
3929 // Set white foreground
3930 currentState
.attr
.setForeColorRGB(get88Color(15));
3934 // Set black background
3935 currentState
.attr
.setBackColorRGB(get88Color(8));
3938 // Set red background
3939 currentState
.attr
.setBackColorRGB(get88Color(9));
3942 // Set green background
3943 currentState
.attr
.setBackColorRGB(get88Color(10));
3946 // Set yellow background
3947 currentState
.attr
.setBackColorRGB(get88Color(11));
3950 // Set blue background
3951 currentState
.attr
.setBackColorRGB(get88Color(12));
3954 // Set magenta background
3955 currentState
.attr
.setBackColorRGB(get88Color(13));
3958 // Set cyan background
3959 currentState
.attr
.setBackColorRGB(get88Color(14));
3962 // Set white background
3963 currentState
.attr
.setBackColorRGB(get88Color(15));
3971 if ((type
== DeviceType
.VT220
)
3972 || (type
== DeviceType
.XTERM
)) {
3978 currentState
.attr
.setBold(false);
3983 currentState
.attr
.setUnderline(false);
3988 currentState
.attr
.setBlink(false);
3993 currentState
.attr
.setReverse(false);
4001 // A true VT100/102/220 does not support color, however everyone
4002 // is used to their terminal emulator supporting color so we will
4003 // unconditionally support color for all DeviceType's.
4008 // Set black foreground
4009 currentState
.attr
.setForeColor(Color
.BLACK
);
4010 currentState
.attr
.setForeColorRGB(-1);
4013 // Set red foreground
4014 currentState
.attr
.setForeColor(Color
.RED
);
4015 currentState
.attr
.setForeColorRGB(-1);
4018 // Set green foreground
4019 currentState
.attr
.setForeColor(Color
.GREEN
);
4020 currentState
.attr
.setForeColorRGB(-1);
4023 // Set yellow foreground
4024 currentState
.attr
.setForeColor(Color
.YELLOW
);
4025 currentState
.attr
.setForeColorRGB(-1);
4028 // Set blue foreground
4029 currentState
.attr
.setForeColor(Color
.BLUE
);
4030 currentState
.attr
.setForeColorRGB(-1);
4033 // Set magenta foreground
4034 currentState
.attr
.setForeColor(Color
.MAGENTA
);
4035 currentState
.attr
.setForeColorRGB(-1);
4038 // Set cyan foreground
4039 currentState
.attr
.setForeColor(Color
.CYAN
);
4040 currentState
.attr
.setForeColorRGB(-1);
4043 // Set white foreground
4044 currentState
.attr
.setForeColor(Color
.WHITE
);
4045 currentState
.attr
.setForeColorRGB(-1);
4048 if (type
== DeviceType
.XTERM
) {
4050 * Xterm supports T.416 / ISO-8613-3 codes to select
4051 * either an indexed color or an RGB value. (It also
4052 * permits these ISO-8613-3 SGR sequences to be separated
4053 * by colons rather than semicolons.)
4055 * We will support only the following:
4057 * 1. Indexed color mode (88- or 256-color modes).
4061 * These cover most of the use cases in the real world.
4063 * HOWEVER, note that this is an awful broken "standard",
4064 * with no way to do it "right". See
4065 * http://invisible-island.net/ncurses/ncurses.faq.html#xterm_16MegaColors
4066 * for a detailed discussion of the current state of RGB
4067 * in various terminals, the point of which is that none
4068 * of them really do the same thing despite all appearing
4072 * https://bugs.kde.org/show_bug.cgi?id=107487#c3 .
4073 * where it is assumed that supporting just the "indexed
4074 * mode" of these sequences (which could align easily
4075 * with existing SGR colors) is assumed to mean full
4076 * support of 24-bit RGB. So it is all or nothing.
4078 * Finally, these sequences break the assumptions of
4079 * standard ECMA-48 style parsers as pointed out at
4080 * https://bugs.kde.org/show_bug.cgi?id=107487#c11 .
4081 * Therefore in order to keep a clean display, we cannot
4082 * parse anything else in this sequence.
4087 // Underscore on, default foreground color
4088 currentState
.attr
.setUnderline(true);
4089 currentState
.attr
.setForeColor(Color
.WHITE
);
4093 // Underscore off, default foreground color
4094 currentState
.attr
.setUnderline(false);
4095 currentState
.attr
.setForeColor(Color
.WHITE
);
4096 currentState
.attr
.setForeColorRGB(-1);
4099 // Set black background
4100 currentState
.attr
.setBackColor(Color
.BLACK
);
4101 currentState
.attr
.setBackColorRGB(-1);
4104 // Set red background
4105 currentState
.attr
.setBackColor(Color
.RED
);
4106 currentState
.attr
.setBackColorRGB(-1);
4109 // Set green background
4110 currentState
.attr
.setBackColor(Color
.GREEN
);
4111 currentState
.attr
.setBackColorRGB(-1);
4114 // Set yellow background
4115 currentState
.attr
.setBackColor(Color
.YELLOW
);
4116 currentState
.attr
.setBackColorRGB(-1);
4119 // Set blue background
4120 currentState
.attr
.setBackColor(Color
.BLUE
);
4121 currentState
.attr
.setBackColorRGB(-1);
4124 // Set magenta background
4125 currentState
.attr
.setBackColor(Color
.MAGENTA
);
4126 currentState
.attr
.setBackColorRGB(-1);
4129 // Set cyan background
4130 currentState
.attr
.setBackColor(Color
.CYAN
);
4131 currentState
.attr
.setBackColorRGB(-1);
4134 // Set white background
4135 currentState
.attr
.setBackColor(Color
.WHITE
);
4136 currentState
.attr
.setBackColorRGB(-1);
4139 if (type
== DeviceType
.XTERM
) {
4141 * Xterm supports T.416 / ISO-8613-3 codes to select
4142 * either an indexed color or an RGB value. (It also
4143 * permits these ISO-8613-3 SGR sequences to be separated
4144 * by colons rather than semicolons.)
4146 * We will support only the following:
4148 * 1. Indexed color mode (88- or 256-color modes).
4152 * These cover most of the use cases in the real world.
4154 * HOWEVER, note that this is an awful broken "standard",
4155 * with no way to do it "right". See
4156 * http://invisible-island.net/ncurses/ncurses.faq.html#xterm_16MegaColors
4157 * for a detailed discussion of the current state of RGB
4158 * in various terminals, the point of which is that none
4159 * of them really do the same thing despite all appearing
4163 * https://bugs.kde.org/show_bug.cgi?id=107487#c3 .
4164 * where it is assumed that supporting just the "indexed
4165 * mode" of these sequences (which could align easily
4166 * with existing SGR colors) is assumed to mean full
4167 * support of 24-bit RGB. So it is all or nothing.
4169 * Finally, these sequences break the assumptions of
4170 * standard ECMA-48 style parsers as pointed out at
4171 * https://bugs.kde.org/show_bug.cgi?id=107487#c11 .
4172 * Therefore in order to keep a clean display, we cannot
4173 * parse anything else in this sequence.
4180 // Default background
4181 currentState
.attr
.setBackColor(Color
.BLACK
);
4182 currentState
.attr
.setBackColorRGB(-1);
4192 * DA - Device attributes.
4195 int extendedFlag
= 0;
4197 if (collectBuffer
.length() > 0) {
4198 String args
= collectBuffer
.substring(1);
4199 if (collectBuffer
.charAt(0) == '>') {
4201 if (collectBuffer
.length() >= 2) {
4202 i
= Integer
.parseInt(args
);
4204 } else if (collectBuffer
.charAt(0) == '=') {
4206 if (collectBuffer
.length() >= 2) {
4207 i
= Integer
.parseInt(args
);
4210 // Unknown code, bail out
4215 if ((i
!= 0) && (i
!= 1)) {
4219 if ((extendedFlag
== 0) && (i
== 0)) {
4220 // Send string directly to remote side
4221 writeRemote(deviceTypeResponse());
4225 if ((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
)) {
4227 if ((extendedFlag
== 1) && (i
== 0)) {
4229 * Request "What type of terminal are you, what is your
4230 * firmware version, and what hardware options do you have
4233 * Respond: "I am a VT220 (identification code of 1), my
4234 * firmware version is _____ (Pv), and I have _____ Po
4235 * options installed."
4241 if (s8c1t
== true) {
4242 writeRemote("\u009b>1;10;0c");
4244 writeRemote("\033[>1;10;0c");
4250 if ((extendedFlag
== 2) && (i
== 0)) {
4253 * Request "What is your unit ID?"
4255 * Respond: "I was manufactured at site 00 and have a unique ID
4259 writeRemote("\033P!|00010203\033\\");
4264 * DECSTBM - Set top and bottom margins.
4266 private void decstbm() {
4267 boolean decPrivateModeFlag
= false;
4269 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4270 if (collectBuffer
.charAt(i
) == '?') {
4271 decPrivateModeFlag
= true;
4275 if (decPrivateModeFlag
) {
4276 // This could be restore DEC private mode values.
4280 int top
= getCsiParam(0, 1, 1, height
) - 1;
4281 int bottom
= getCsiParam(1, height
, 1, height
) - 1;
4286 scrollRegionTop
= top
;
4287 scrollRegionBottom
= bottom
;
4290 cursorPosition(0, 0);
4295 * DECREQTPARM - Request terminal parameters.
4297 private void decreqtparm() {
4298 int i
= getCsiParam(0, 0);
4300 if ((i
!= 0) && (i
!= 1)) {
4307 * Request terminal parameters.
4311 * Parity NONE, 8 bits, xmitspeed 38400, recvspeed 38400.
4312 * (CLoCk MULtiplier = 1, STP option flags = 0)
4316 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4319 str
= String
.format("\u009b%d;1;1;128;128;1;0x", i
+ 2);
4321 str
= String
.format("\033[%d;1;1;128;128;1;0x", i
+ 2);
4327 * DECSCA - Select Character Attributes.
4329 private void decsca() {
4330 int i
= getCsiParam(0, 0);
4332 if ((i
== 0) || (i
== 2)) {
4334 currentState
.attr
.setProtect(false);
4338 currentState
.attr
.setProtect(true);
4343 * DECSTR - Soft Terminal Reset.
4345 private void decstr() {
4346 // Do exactly like RIS - Reset to initial state
4348 // Do I clear screen too? I think so...
4349 eraseScreen(0, 0, height
- 1, width
- 1, false);
4350 cursorPosition(0, 0);
4354 * DSR - Device status report.
4356 private void dsr() {
4357 boolean decPrivateModeFlag
= false;
4358 int row
= currentState
.cursorY
;
4360 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4361 if (collectBuffer
.charAt(i
) == '?') {
4362 decPrivateModeFlag
= true;
4367 int i
= getCsiParam(0, 0);
4372 // Request status report. Respond with "OK, no malfunction."
4374 // Send string directly to remote side
4375 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4378 writeRemote("\u009b0n");
4380 writeRemote("\033[0n");
4385 // Request cursor position. Respond with current position.
4386 if (currentState
.originMode
== true) {
4387 row
-= scrollRegionTop
;
4390 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4393 str
= String
.format("\u009b%d;%dR", row
+ 1,
4394 currentState
.cursorX
+ 1);
4396 str
= String
.format("\033[%d;%dR", row
+ 1,
4397 currentState
.cursorX
+ 1);
4400 // Send string directly to remote side
4405 if (decPrivateModeFlag
== true) {
4407 // Request printer status report. Respond with "Printer not
4410 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4411 && (s8c1t
== true)) {
4412 writeRemote("\u009b?13n");
4414 writeRemote("\033[?13n");
4420 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4421 && (decPrivateModeFlag
== true)
4424 // Request user-defined keys are locked or unlocked. Respond
4425 // with "User-defined keys are locked."
4427 if (s8c1t
== true) {
4428 writeRemote("\u009b?21n");
4430 writeRemote("\033[?21n");
4436 if (((type
== DeviceType
.VT220
) || (type
== DeviceType
.XTERM
))
4437 && (decPrivateModeFlag
== true)
4440 // Request keyboard language. Respond with "Keyboard
4441 // language is North American."
4443 if (s8c1t
== true) {
4444 writeRemote("\u009b?27;1n");
4446 writeRemote("\033[?27;1n");
4453 // Some other option, ignore
4459 * TBC - Tabulation clear.
4461 private void tbc() {
4462 int i
= getCsiParam(0, 0);
4464 List
<Integer
> newStops
= new ArrayList
<Integer
>();
4465 for (Integer stop
: tabStops
) {
4466 if (stop
== currentState
.cursorX
) {
4471 tabStops
= newStops
;
4479 * Erase the characters in the current line from the start column to the
4480 * end column, inclusive.
4482 * @param start starting column to erase (between 0 and width - 1)
4483 * @param end ending column to erase (between 0 and width - 1)
4484 * @param honorProtected if true, do not erase characters with the
4485 * protected attribute set
4487 private void eraseLine(int start
, int end
, final boolean honorProtected
) {
4492 if (end
> width
- 1) {
4499 for (int i
= start
; i
<= end
; i
++) {
4500 DisplayLine line
= display
.get(currentState
.cursorY
);
4501 if ((!honorProtected
)
4502 || ((honorProtected
) && (!line
.charAt(i
).isProtect()))) {
4509 * From the VT102 manual:
4511 * Erasing a character also erases any character
4512 * attribute of the character.
4518 * Erase with the current color a.k.a. back-color erase
4521 line
.setChar(i
, ' ');
4522 line
.setAttr(i
, currentState
.attr
);
4530 * Erase a rectangular section of the screen, inclusive. end column,
4533 * @param startRow starting row to erase (between 0 and height - 1)
4534 * @param startCol starting column to erase (between 0 and width - 1)
4535 * @param endRow ending row to erase (between 0 and height - 1)
4536 * @param endCol ending column to erase (between 0 and width - 1)
4537 * @param honorProtected if true, do not erase characters with the
4538 * protected attribute set
4540 private void eraseScreen(final int startRow
, final int startCol
,
4541 final int endRow
, final int endCol
, final boolean honorProtected
) {
4549 || (endRow
< startRow
)
4550 || (endCol
< startCol
)
4555 oldCursorY
= currentState
.cursorY
;
4556 for (int i
= startRow
; i
<= endRow
; i
++) {
4557 currentState
.cursorY
= i
;
4558 eraseLine(startCol
, endCol
, honorProtected
);
4560 // Erase display clears the double attributes
4561 display
.get(i
).setDoubleWidth(false);
4562 display
.get(i
).setDoubleHeight(0);
4564 currentState
.cursorY
= oldCursorY
;
4568 * VT220 printer functions. All of these are parsed, but won't do
4571 private void printerFunctions() {
4572 boolean decPrivateModeFlag
= false;
4573 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4574 if (collectBuffer
.charAt(i
) == '?') {
4575 decPrivateModeFlag
= true;
4580 int i
= getCsiParam(0, 0);
4585 if (decPrivateModeFlag
== false) {
4591 if (decPrivateModeFlag
== true) {
4592 // Print cursor line
4597 if (decPrivateModeFlag
== true) {
4598 // Auto print mode OFF
4600 // Printer controller OFF
4602 // Characters re-appear on the screen
4603 printerControllerMode
= false;
4608 if (decPrivateModeFlag
== true) {
4612 // Printer controller
4614 // Characters get sucked into oblivion
4615 printerControllerMode
= true;
4626 * Handle the SCAN_OSC_STRING state. Handle this in VT100 because lots
4627 * of remote systems will send an XTerm title sequence even if TERM isn't
4630 * @param xtermChar the character received from the remote side
4632 private void oscPut(final char xtermChar
) {
4633 // System.err.println("oscPut: " + xtermChar);
4636 collectBuffer
.append(xtermChar
);
4639 if ((xtermChar
== 0x07)
4640 || (collectBuffer
.toString().endsWith("\033\\"))
4643 if (xtermChar
== 0x07) {
4644 args
= collectBuffer
.substring(0, collectBuffer
.length() - 1);
4646 args
= collectBuffer
.substring(0, collectBuffer
.length() - 2);
4649 String
[] p
= args
.split(";");
4651 if ((p
[0].equals("0")) || (p
[0].equals("2"))) {
4658 if (p
[0].equals("4")) {
4659 for (int i
= 1; i
+ 1 < p
.length
; i
+= 2) {
4660 // Set a color index value
4662 set88Color(Integer
.parseInt(p
[i
]), p
[i
+ 1]);
4663 } catch (NumberFormatException e
) {
4670 // Go to SCAN_GROUND state
4677 * Handle the SCAN_SOSPMAPC_STRING state. This is currently only used by
4678 * Jexer ECMA48Terminal to talk to ECMA48.
4680 * @param pmChar the character received from the remote side
4682 private void pmPut(final char pmChar
) {
4683 // System.err.println("pmPut: " + pmChar);
4686 collectBuffer
.append(pmChar
);
4689 if (collectBuffer
.toString().endsWith("\033\\")) {
4691 arg
= collectBuffer
.substring(0, collectBuffer
.length() - 2);
4693 // System.err.println("arg: '" + arg + "'");
4695 if (arg
.equals("hideMousePointer")) {
4696 hideMousePointer
= true;
4698 if (arg
.equals("showMousePointer")) {
4699 hideMousePointer
= false;
4702 // Go to SCAN_GROUND state
4709 * Perform xterm window operations.
4711 private void xtermWindowOps() {
4712 boolean xtermPrivateModeFlag
= false;
4714 for (int i
= 0; i
< collectBuffer
.length(); i
++) {
4715 if (collectBuffer
.charAt(i
) == '?') {
4716 xtermPrivateModeFlag
= true;
4721 int i
= getCsiParam(0, 0);
4723 if (!xtermPrivateModeFlag
) {
4725 // Report xterm window in pixels as CSI 4 ; height ; width t
4726 writeRemote(String
.format("\033[4;%d;%dt", textHeight
* height
,
4727 textWidth
* width
));
4733 * Run this input character through the ECMA48 state machine.
4735 * @param ch character from the remote side
4737 private void consume(int ch
) {
4740 // System.err.printf("%c STATE = %s\n", ch, scanState);
4742 // Special case for VT10x: 7-bit characters only
4743 if ((type
== DeviceType
.VT100
) || (type
== DeviceType
.VT102
)) {
4747 // Special "anywhere" states
4749 // 18, 1A --> execute, then switch to SCAN_GROUND
4750 if ((ch
== 0x18) || (ch
== 0x1A)) {
4751 // CAN and SUB abort escape sequences
4756 // 80-8F, 91-97, 99, 9A, 9C --> execute, then switch to SCAN_GROUND
4760 if ((type
== DeviceType
.XTERM
)
4761 && ((scanState
== ScanState
.OSC_STRING
)
4762 || (scanState
== ScanState
.DCS_SIXEL
)
4763 || (scanState
== ScanState
.SOSPMAPC_STRING
))
4765 // Xterm can pass ESCAPE to its OSC sequence.
4766 // Xterm can pass ESCAPE to its DCS sequence.
4767 // Jexer can pass ESCAPE to its PM sequence.
4768 } else if ((scanState
!= ScanState
.DCS_ENTRY
)
4769 && (scanState
!= ScanState
.DCS_INTERMEDIATE
)
4770 && (scanState
!= ScanState
.DCS_IGNORE
)
4771 && (scanState
!= ScanState
.DCS_PARAM
)
4772 && (scanState
!= ScanState
.DCS_PASSTHROUGH
)
4774 scanState
= ScanState
.ESCAPE
;
4779 // 0x9B == CSI 8-bit sequence
4781 scanState
= ScanState
.CSI_ENTRY
;
4785 // 0x9D goes to ScanState.OSC_STRING
4787 scanState
= ScanState
.OSC_STRING
;
4791 // 0x90 goes to DCS_ENTRY
4793 scanState
= ScanState
.DCS_ENTRY
;
4797 // 0x98, 0x9E, and 0x9F go to SOSPMAPC_STRING
4798 if ((ch
== 0x98) || (ch
== 0x9E) || (ch
== 0x9F)) {
4799 scanState
= ScanState
.SOSPMAPC_STRING
;
4803 // 0x7F (DEL) is always discarded
4808 switch (scanState
) {
4811 // 00-17, 19, 1C-1F --> execute
4812 // 80-8F, 91-9A, 9C --> execute
4813 if ((ch
<= 0x1F) || ((ch
>= 0x80) && (ch
<= 0x9F))) {
4814 handleControlChar((char) ch
);
4818 if (((ch
>= 0x20) && (ch
<= 0x7F))
4822 // VT220 printer --> trash bin
4823 if (((type
== DeviceType
.VT220
)
4824 || (type
== DeviceType
.XTERM
))
4825 && (printerControllerMode
== true)
4830 // Hang onto this character
4831 repCh
= mapCharacter(ch
);
4833 // Print this character
4834 printCharacter(repCh
);
4839 // 00-17, 19, 1C-1F --> execute
4841 handleControlChar((char) ch
);
4845 // 20-2F --> collect, then switch to ESCAPE_INTERMEDIATE
4846 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
4848 scanState
= ScanState
.ESCAPE_INTERMEDIATE
;
4852 // 30-4F, 51-57, 59, 5A, 5C, 60-7E --> dispatch, then switch to GROUND
4853 if ((ch
>= 0x30) && (ch
<= 0x4F)) {
4864 // DECSC - Save cursor
4865 // Note this code overlaps both ANSI and VT52 mode
4870 // DECRC - Restore cursor
4871 // Note this code overlaps both ANSI and VT52 mode
4880 if (vt52Mode
== true) {
4881 // DECANM - Enter ANSI mode
4883 arrowKeyMode
= ArrowKeyMode
.VT100
;
4886 * From the VT102 docs: "You use ANSI mode to select
4887 * most terminal features; the terminal uses the same
4888 * features when it switches to VT52 mode. You
4889 * cannot, however, change most of these features in
4892 * In other words, do not reset any other attributes
4893 * when switching between VT52 submode and ANSI.
4897 currentState
.g0Charset
= CharacterSet
.US
;
4898 currentState
.g1Charset
= CharacterSet
.DRAWING
;
4900 singleshift
= Singleshift
.NONE
;
4901 currentState
.glLockshift
= LockshiftMode
.NONE
;
4902 currentState
.grLockshift
= LockshiftMode
.NONE
;
4906 // DECKPAM - Keypad application mode
4907 // Note this code overlaps both ANSI and VT52 mode
4911 // DECKPNM - Keypad numeric mode
4912 // Note this code overlaps both ANSI and VT52 mode
4919 if (vt52Mode
== true) {
4920 // Cursor up, and stop at the top without scrolling
4925 if (vt52Mode
== true) {
4926 // Cursor down, and stop at the bottom without scrolling
4927 cursorDown(1, false);
4931 if (vt52Mode
== true) {
4932 // Cursor right, and stop at the right without scrolling
4933 cursorRight(1, false);
4937 if (vt52Mode
== true) {
4938 // Cursor left, and stop at the left without scrolling
4939 cursorLeft(1, false);
4946 if (vt52Mode
== true) {
4954 if (vt52Mode
== true) {
4955 // G0 --> Special graphics
4956 currentState
.g0Charset
= CharacterSet
.VT52_GRAPHICS
;
4960 if (vt52Mode
== true) {
4962 currentState
.g0Charset
= CharacterSet
.US
;
4966 if (vt52Mode
== true) {
4968 cursorPosition(0, 0);
4970 // HTS - Horizontal tabulation set
4975 if (vt52Mode
== true) {
4976 // Reverse line feed. Same as RI.
4981 if (vt52Mode
== true) {
4982 // Erase to end of screen
4983 eraseLine(currentState
.cursorX
, width
- 1, false);
4984 eraseScreen(currentState
.cursorY
+ 1, 0, height
- 1,
4989 if (vt52Mode
== true) {
4990 // Erase to end of line
4991 eraseLine(currentState
.cursorX
, width
- 1, false);
4997 if (vt52Mode
== true) {
5000 // RI - Reverse index
5005 if (vt52Mode
== false) {
5007 singleshift
= Singleshift
.SS2
;
5011 if (vt52Mode
== false) {
5013 singleshift
= Singleshift
.SS3
;
5020 if ((ch
>= 0x51) && (ch
<= 0x57)) {
5036 if (vt52Mode
== true) {
5037 scanState
= ScanState
.VT52_DIRECT_CURSOR_ADDRESS
;
5045 if (vt52Mode
== true) {
5047 // Send string directly to remote side
5048 writeRemote("\033/Z");
5051 // Send string directly to remote side
5052 writeRemote(deviceTypeResponse());
5063 // VT52 cannot get to any of these other states
5064 if (vt52Mode
== true) {
5069 if ((ch
>= 0x60) && (ch
<= 0x7E)) {
5076 // RIS - Reset to initial state
5078 // Do I clear screen too? I think so...
5079 eraseScreen(0, 0, height
- 1, width
- 1, false);
5080 cursorPosition(0, 0);
5094 if ((type
== DeviceType
.VT220
)
5095 || (type
== DeviceType
.XTERM
)) {
5097 // VT220 lockshift G2 into GL
5098 currentState
.glLockshift
= LockshiftMode
.G2_GL
;
5103 if ((type
== DeviceType
.VT220
)
5104 || (type
== DeviceType
.XTERM
)) {
5106 // VT220 lockshift G3 into GL
5107 currentState
.glLockshift
= LockshiftMode
.G3_GL
;
5125 if ((type
== DeviceType
.VT220
)
5126 || (type
== DeviceType
.XTERM
)) {
5128 // VT220 lockshift G3 into GR
5129 currentState
.grLockshift
= LockshiftMode
.G3_GR
;
5134 if ((type
== DeviceType
.VT220
)
5135 || (type
== DeviceType
.XTERM
)) {
5137 // VT220 lockshift G2 into GR
5138 currentState
.grLockshift
= LockshiftMode
.G2_GR
;
5144 if ((type
== DeviceType
.VT220
)
5145 || (type
== DeviceType
.XTERM
)) {
5147 // VT220 lockshift G1 into GR
5148 currentState
.grLockshift
= LockshiftMode
.G1_GR
;
5158 // 0x5B goes to CSI_ENTRY
5160 scanState
= ScanState
.CSI_ENTRY
;
5163 // 0x5D goes to OSC_STRING
5165 scanState
= ScanState
.OSC_STRING
;
5168 // 0x50 goes to DCS_ENTRY
5170 scanState
= ScanState
.DCS_ENTRY
;
5173 // 0x58, 0x5E, and 0x5F go to SOSPMAPC_STRING
5174 if ((ch
== 0x58) || (ch
== 0x5E) || (ch
== 0x5F)) {
5175 scanState
= ScanState
.SOSPMAPC_STRING
;
5180 case ESCAPE_INTERMEDIATE
:
5181 // 00-17, 19, 1C-1F --> execute
5183 handleControlChar((char) ch
);
5186 // 20-2F --> collect
5187 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
5191 // 30-7E --> dispatch, then switch to GROUND
5192 if ((ch
>= 0x30) && (ch
<= 0x7E)) {
5195 if ((collectBuffer
.length() == 1)
5196 && (collectBuffer
.charAt(0) == '(')) {
5197 // G0 --> Special graphics
5198 currentState
.g0Charset
= CharacterSet
.DRAWING
;
5200 if ((collectBuffer
.length() == 1)
5201 && (collectBuffer
.charAt(0) == ')')) {
5202 // G1 --> Special graphics
5203 currentState
.g1Charset
= CharacterSet
.DRAWING
;
5205 if ((type
== DeviceType
.VT220
)
5206 || (type
== DeviceType
.XTERM
)) {
5208 if ((collectBuffer
.length() == 1)
5209 && (collectBuffer
.charAt(0) == '*')) {
5210 // G2 --> Special graphics
5211 currentState
.g2Charset
= CharacterSet
.DRAWING
;
5213 if ((collectBuffer
.length() == 1)
5214 && (collectBuffer
.charAt(0) == '+')) {
5215 // G3 --> Special graphics
5216 currentState
.g3Charset
= CharacterSet
.DRAWING
;
5221 if ((collectBuffer
.length() == 1)
5222 && (collectBuffer
.charAt(0) == '(')) {
5223 // G0 --> Alternate character ROM standard character set
5224 currentState
.g0Charset
= CharacterSet
.ROM
;
5226 if ((collectBuffer
.length() == 1)
5227 && (collectBuffer
.charAt(0) == ')')) {
5228 // G1 --> Alternate character ROM standard character set
5229 currentState
.g1Charset
= CharacterSet
.ROM
;
5233 if ((collectBuffer
.length() == 1)
5234 && (collectBuffer
.charAt(0) == '(')) {
5235 // G0 --> Alternate character ROM special graphics
5236 currentState
.g0Charset
= CharacterSet
.ROM_SPECIAL
;
5238 if ((collectBuffer
.length() == 1)
5239 && (collectBuffer
.charAt(0) == ')')) {
5240 // G1 --> Alternate character ROM special graphics
5241 currentState
.g1Charset
= CharacterSet
.ROM_SPECIAL
;
5245 if ((collectBuffer
.length() == 1)
5246 && (collectBuffer
.charAt(0) == '#')) {
5247 // DECDHL - Double-height line (top half)
5252 if ((collectBuffer
.length() == 1)
5253 && (collectBuffer
.charAt(0) == '#')) {
5254 // DECDHL - Double-height line (bottom half)
5257 if ((type
== DeviceType
.VT220
)
5258 || (type
== DeviceType
.XTERM
)) {
5260 if ((collectBuffer
.length() == 1)
5261 && (collectBuffer
.charAt(0) == '(')) {
5263 currentState
.g0Charset
= CharacterSet
.NRC_DUTCH
;
5265 if ((collectBuffer
.length() == 1)
5266 && (collectBuffer
.charAt(0) == ')')) {
5268 currentState
.g1Charset
= CharacterSet
.NRC_DUTCH
;
5270 if ((collectBuffer
.length() == 1)
5271 && (collectBuffer
.charAt(0) == '*')) {
5273 currentState
.g2Charset
= CharacterSet
.NRC_DUTCH
;
5275 if ((collectBuffer
.length() == 1)
5276 && (collectBuffer
.charAt(0) == '+')) {
5278 currentState
.g3Charset
= CharacterSet
.NRC_DUTCH
;
5283 if ((collectBuffer
.length() == 1)
5284 && (collectBuffer
.charAt(0) == '#')) {
5285 // DECSWL - Single-width line
5288 if ((type
== DeviceType
.VT220
)
5289 || (type
== DeviceType
.XTERM
)) {
5291 if ((collectBuffer
.length() == 1)
5292 && (collectBuffer
.charAt(0) == '(')) {
5294 currentState
.g0Charset
= CharacterSet
.NRC_FINNISH
;
5296 if ((collectBuffer
.length() == 1)
5297 && (collectBuffer
.charAt(0) == ')')) {
5299 currentState
.g1Charset
= CharacterSet
.NRC_FINNISH
;
5301 if ((collectBuffer
.length() == 1)
5302 && (collectBuffer
.charAt(0) == '*')) {
5304 currentState
.g2Charset
= CharacterSet
.NRC_FINNISH
;
5306 if ((collectBuffer
.length() == 1)
5307 && (collectBuffer
.charAt(0) == '+')) {
5309 currentState
.g3Charset
= CharacterSet
.NRC_FINNISH
;
5314 if ((collectBuffer
.length() == 1)
5315 && (collectBuffer
.charAt(0) == '#')) {
5316 // DECDWL - Double-width line
5319 if ((type
== DeviceType
.VT220
)
5320 || (type
== DeviceType
.XTERM
)) {
5322 if ((collectBuffer
.length() == 1)
5323 && (collectBuffer
.charAt(0) == '(')) {
5325 currentState
.g0Charset
= CharacterSet
.NRC_NORWEGIAN
;
5327 if ((collectBuffer
.length() == 1)
5328 && (collectBuffer
.charAt(0) == ')')) {
5330 currentState
.g1Charset
= CharacterSet
.NRC_NORWEGIAN
;
5332 if ((collectBuffer
.length() == 1)
5333 && (collectBuffer
.charAt(0) == '*')) {
5335 currentState
.g2Charset
= CharacterSet
.NRC_NORWEGIAN
;
5337 if ((collectBuffer
.length() == 1)
5338 && (collectBuffer
.charAt(0) == '+')) {
5340 currentState
.g3Charset
= CharacterSet
.NRC_NORWEGIAN
;
5345 if ((type
== DeviceType
.VT220
)
5346 || (type
== DeviceType
.XTERM
)) {
5348 if ((collectBuffer
.length() == 1)
5349 && (collectBuffer
.charAt(0) == '(')) {
5351 currentState
.g0Charset
= CharacterSet
.NRC_SWEDISH
;
5353 if ((collectBuffer
.length() == 1)
5354 && (collectBuffer
.charAt(0) == ')')) {
5356 currentState
.g1Charset
= CharacterSet
.NRC_SWEDISH
;
5358 if ((collectBuffer
.length() == 1)
5359 && (collectBuffer
.charAt(0) == '*')) {
5361 currentState
.g2Charset
= CharacterSet
.NRC_SWEDISH
;
5363 if ((collectBuffer
.length() == 1)
5364 && (collectBuffer
.charAt(0) == '+')) {
5366 currentState
.g3Charset
= CharacterSet
.NRC_SWEDISH
;
5371 if ((collectBuffer
.length() == 1)
5372 && (collectBuffer
.charAt(0) == '#')) {
5373 // DECALN - Screen alignment display
5382 if ((type
== DeviceType
.VT220
)
5383 || (type
== DeviceType
.XTERM
)) {
5385 if ((collectBuffer
.length() == 1)
5386 && (collectBuffer
.charAt(0) == '(')) {
5387 // G0 --> DEC_SUPPLEMENTAL
5388 currentState
.g0Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5390 if ((collectBuffer
.length() == 1)
5391 && (collectBuffer
.charAt(0) == ')')) {
5392 // G1 --> DEC_SUPPLEMENTAL
5393 currentState
.g1Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5395 if ((collectBuffer
.length() == 1)
5396 && (collectBuffer
.charAt(0) == '*')) {
5397 // G2 --> DEC_SUPPLEMENTAL
5398 currentState
.g2Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5400 if ((collectBuffer
.length() == 1)
5401 && (collectBuffer
.charAt(0) == '+')) {
5402 // G3 --> DEC_SUPPLEMENTAL
5403 currentState
.g3Charset
= CharacterSet
.DEC_SUPPLEMENTAL
;
5408 if ((type
== DeviceType
.VT220
)
5409 || (type
== DeviceType
.XTERM
)) {
5411 if ((collectBuffer
.length() == 1)
5412 && (collectBuffer
.charAt(0) == '(')) {
5414 currentState
.g0Charset
= CharacterSet
.NRC_SWISS
;
5416 if ((collectBuffer
.length() == 1)
5417 && (collectBuffer
.charAt(0) == ')')) {
5419 currentState
.g1Charset
= CharacterSet
.NRC_SWISS
;
5421 if ((collectBuffer
.length() == 1)
5422 && (collectBuffer
.charAt(0) == '*')) {
5424 currentState
.g2Charset
= CharacterSet
.NRC_SWISS
;
5426 if ((collectBuffer
.length() == 1)
5427 && (collectBuffer
.charAt(0) == '+')) {
5429 currentState
.g3Charset
= CharacterSet
.NRC_SWISS
;
5438 if ((collectBuffer
.length() == 1)
5439 && (collectBuffer
.charAt(0) == '(')) {
5440 // G0 --> United Kingdom set
5441 currentState
.g0Charset
= CharacterSet
.UK
;
5443 if ((collectBuffer
.length() == 1)
5444 && (collectBuffer
.charAt(0) == ')')) {
5445 // G1 --> United Kingdom set
5446 currentState
.g1Charset
= CharacterSet
.UK
;
5448 if ((type
== DeviceType
.VT220
)
5449 || (type
== DeviceType
.XTERM
)) {
5451 if ((collectBuffer
.length() == 1)
5452 && (collectBuffer
.charAt(0) == '*')) {
5453 // G2 --> United Kingdom set
5454 currentState
.g2Charset
= CharacterSet
.UK
;
5456 if ((collectBuffer
.length() == 1)
5457 && (collectBuffer
.charAt(0) == '+')) {
5458 // G3 --> United Kingdom set
5459 currentState
.g3Charset
= CharacterSet
.UK
;
5464 if ((collectBuffer
.length() == 1)
5465 && (collectBuffer
.charAt(0) == '(')) {
5467 currentState
.g0Charset
= CharacterSet
.US
;
5469 if ((collectBuffer
.length() == 1)
5470 && (collectBuffer
.charAt(0) == ')')) {
5472 currentState
.g1Charset
= CharacterSet
.US
;
5474 if ((type
== DeviceType
.VT220
)
5475 || (type
== DeviceType
.XTERM
)) {
5477 if ((collectBuffer
.length() == 1)
5478 && (collectBuffer
.charAt(0) == '*')) {
5480 currentState
.g2Charset
= CharacterSet
.US
;
5482 if ((collectBuffer
.length() == 1)
5483 && (collectBuffer
.charAt(0) == '+')) {
5485 currentState
.g3Charset
= CharacterSet
.US
;
5490 if ((type
== DeviceType
.VT220
)
5491 || (type
== DeviceType
.XTERM
)) {
5493 if ((collectBuffer
.length() == 1)
5494 && (collectBuffer
.charAt(0) == '(')) {
5496 currentState
.g0Charset
= CharacterSet
.NRC_FINNISH
;
5498 if ((collectBuffer
.length() == 1)
5499 && (collectBuffer
.charAt(0) == ')')) {
5501 currentState
.g1Charset
= CharacterSet
.NRC_FINNISH
;
5503 if ((collectBuffer
.length() == 1)
5504 && (collectBuffer
.charAt(0) == '*')) {
5506 currentState
.g2Charset
= CharacterSet
.NRC_FINNISH
;
5508 if ((collectBuffer
.length() == 1)
5509 && (collectBuffer
.charAt(0) == '+')) {
5511 currentState
.g3Charset
= CharacterSet
.NRC_FINNISH
;
5518 if ((type
== DeviceType
.VT220
)
5519 || (type
== DeviceType
.XTERM
)) {
5521 if ((collectBuffer
.length() == 1)
5522 && (collectBuffer
.charAt(0) == '(')) {
5524 currentState
.g0Charset
= CharacterSet
.NRC_NORWEGIAN
;
5526 if ((collectBuffer
.length() == 1)
5527 && (collectBuffer
.charAt(0) == ')')) {
5529 currentState
.g1Charset
= CharacterSet
.NRC_NORWEGIAN
;
5531 if ((collectBuffer
.length() == 1)
5532 && (collectBuffer
.charAt(0) == '*')) {
5534 currentState
.g2Charset
= CharacterSet
.NRC_NORWEGIAN
;
5536 if ((collectBuffer
.length() == 1)
5537 && (collectBuffer
.charAt(0) == '+')) {
5539 currentState
.g3Charset
= CharacterSet
.NRC_NORWEGIAN
;
5544 if ((type
== DeviceType
.VT220
)
5545 || (type
== DeviceType
.XTERM
)) {
5547 if ((collectBuffer
.length() == 1)
5548 && (collectBuffer
.charAt(0) == ' ')) {
5555 if ((type
== DeviceType
.VT220
)
5556 || (type
== DeviceType
.XTERM
)) {
5558 if ((collectBuffer
.length() == 1)
5559 && (collectBuffer
.charAt(0) == ' ')) {
5566 if ((type
== DeviceType
.VT220
)
5567 || (type
== DeviceType
.XTERM
)) {
5569 if ((collectBuffer
.length() == 1)
5570 && (collectBuffer
.charAt(0) == '(')) {
5572 currentState
.g0Charset
= CharacterSet
.NRC_SWEDISH
;
5574 if ((collectBuffer
.length() == 1)
5575 && (collectBuffer
.charAt(0) == ')')) {
5577 currentState
.g1Charset
= CharacterSet
.NRC_SWEDISH
;
5579 if ((collectBuffer
.length() == 1)
5580 && (collectBuffer
.charAt(0) == '*')) {
5582 currentState
.g2Charset
= CharacterSet
.NRC_SWEDISH
;
5584 if ((collectBuffer
.length() == 1)
5585 && (collectBuffer
.charAt(0) == '+')) {
5587 currentState
.g3Charset
= CharacterSet
.NRC_SWEDISH
;
5595 if ((type
== DeviceType
.VT220
)
5596 || (type
== DeviceType
.XTERM
)) {
5598 if ((collectBuffer
.length() == 1)
5599 && (collectBuffer
.charAt(0) == '(')) {
5601 currentState
.g0Charset
= CharacterSet
.NRC_GERMAN
;
5603 if ((collectBuffer
.length() == 1)
5604 && (collectBuffer
.charAt(0) == ')')) {
5606 currentState
.g1Charset
= CharacterSet
.NRC_GERMAN
;
5608 if ((collectBuffer
.length() == 1)
5609 && (collectBuffer
.charAt(0) == '*')) {
5611 currentState
.g2Charset
= CharacterSet
.NRC_GERMAN
;
5613 if ((collectBuffer
.length() == 1)
5614 && (collectBuffer
.charAt(0) == '+')) {
5616 currentState
.g3Charset
= CharacterSet
.NRC_GERMAN
;
5627 if ((type
== DeviceType
.VT220
)
5628 || (type
== DeviceType
.XTERM
)) {
5630 if ((collectBuffer
.length() == 1)
5631 && (collectBuffer
.charAt(0) == '(')) {
5633 currentState
.g0Charset
= CharacterSet
.NRC_FRENCH_CA
;
5635 if ((collectBuffer
.length() == 1)
5636 && (collectBuffer
.charAt(0) == ')')) {
5638 currentState
.g1Charset
= CharacterSet
.NRC_FRENCH_CA
;
5640 if ((collectBuffer
.length() == 1)
5641 && (collectBuffer
.charAt(0) == '*')) {
5643 currentState
.g2Charset
= CharacterSet
.NRC_FRENCH_CA
;
5645 if ((collectBuffer
.length() == 1)
5646 && (collectBuffer
.charAt(0) == '+')) {
5648 currentState
.g3Charset
= CharacterSet
.NRC_FRENCH_CA
;
5653 if ((type
== DeviceType
.VT220
)
5654 || (type
== DeviceType
.XTERM
)) {
5656 if ((collectBuffer
.length() == 1)
5657 && (collectBuffer
.charAt(0) == '(')) {
5659 currentState
.g0Charset
= CharacterSet
.NRC_FRENCH
;
5661 if ((collectBuffer
.length() == 1)
5662 && (collectBuffer
.charAt(0) == ')')) {
5664 currentState
.g1Charset
= CharacterSet
.NRC_FRENCH
;
5666 if ((collectBuffer
.length() == 1)
5667 && (collectBuffer
.charAt(0) == '*')) {
5669 currentState
.g2Charset
= CharacterSet
.NRC_FRENCH
;
5671 if ((collectBuffer
.length() == 1)
5672 && (collectBuffer
.charAt(0) == '+')) {
5674 currentState
.g3Charset
= CharacterSet
.NRC_FRENCH
;
5686 if ((type
== DeviceType
.VT220
)
5687 || (type
== DeviceType
.XTERM
)) {
5689 if ((collectBuffer
.length() == 1)
5690 && (collectBuffer
.charAt(0) == '(')) {
5692 currentState
.g0Charset
= CharacterSet
.NRC_ITALIAN
;
5694 if ((collectBuffer
.length() == 1)
5695 && (collectBuffer
.charAt(0) == ')')) {
5697 currentState
.g1Charset
= CharacterSet
.NRC_ITALIAN
;
5699 if ((collectBuffer
.length() == 1)
5700 && (collectBuffer
.charAt(0) == '*')) {
5702 currentState
.g2Charset
= CharacterSet
.NRC_ITALIAN
;
5704 if ((collectBuffer
.length() == 1)
5705 && (collectBuffer
.charAt(0) == '+')) {
5707 currentState
.g3Charset
= CharacterSet
.NRC_ITALIAN
;
5712 if ((type
== DeviceType
.VT220
)
5713 || (type
== DeviceType
.XTERM
)) {
5715 if ((collectBuffer
.length() == 1)
5716 && (collectBuffer
.charAt(0) == '(')) {
5718 currentState
.g0Charset
= CharacterSet
.NRC_SPANISH
;
5720 if ((collectBuffer
.length() == 1)
5721 && (collectBuffer
.charAt(0) == ')')) {
5723 currentState
.g1Charset
= CharacterSet
.NRC_SPANISH
;
5725 if ((collectBuffer
.length() == 1)
5726 && (collectBuffer
.charAt(0) == '*')) {
5728 currentState
.g2Charset
= CharacterSet
.NRC_SPANISH
;
5730 if ((collectBuffer
.length() == 1)
5731 && (collectBuffer
.charAt(0) == '+')) {
5733 currentState
.g3Charset
= CharacterSet
.NRC_SPANISH
;
5780 // 0x9C goes to GROUND
5788 // 00-17, 19, 1C-1F --> execute
5790 handleControlChar((char) ch
);
5793 // 20-2F --> collect, then switch to CSI_INTERMEDIATE
5794 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
5796 scanState
= ScanState
.CSI_INTERMEDIATE
;
5799 // 30-39, 3B --> param, then switch to CSI_PARAM
5800 if ((ch
>= '0') && (ch
<= '9')) {
5802 scanState
= ScanState
.CSI_PARAM
;
5806 scanState
= ScanState
.CSI_PARAM
;
5809 // 3C-3F --> collect, then switch to CSI_PARAM
5810 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
5812 scanState
= ScanState
.CSI_PARAM
;
5815 // 40-7E --> dispatch, then switch to GROUND
5816 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
5819 // ICH - Insert character
5827 // CUD - Cursor down
5831 // CUF - Cursor forward
5835 // CUB - Cursor backward
5839 // CNL - Cursor down and to column 1
5840 if (type
== DeviceType
.XTERM
) {
5845 // CPL - Cursor up and to column 1
5846 if (type
== DeviceType
.XTERM
) {
5851 // CHA - Cursor to column # in current row
5852 if (type
== DeviceType
.XTERM
) {
5857 // CUP - Cursor position
5861 // CHT - Cursor forward X tab stops (default 1)
5862 if (type
== DeviceType
.XTERM
) {
5867 // ED - Erase in display
5871 // EL - Erase in line
5886 // DCH - Delete character
5893 // Scroll up X lines (default 1)
5894 if (type
== DeviceType
.XTERM
) {
5899 // Scroll down X lines (default 1)
5900 if (type
== DeviceType
.XTERM
) {
5909 if ((type
== DeviceType
.VT220
)
5910 || (type
== DeviceType
.XTERM
)) {
5912 // ECH - Erase character
5919 // CBT - Cursor backward X tab stops (default 1)
5920 if (type
== DeviceType
.XTERM
) {
5931 // HPA - Cursor to column # in current row. Same as CHA
5932 if (type
== DeviceType
.XTERM
) {
5937 // HPR - Cursor right. Same as CUF
5938 if (type
== DeviceType
.XTERM
) {
5943 // REP - Repeat last char X times
5944 if (type
== DeviceType
.XTERM
) {
5949 // DA - Device attributes
5953 // VPA - Cursor to row, current column.
5954 if (type
== DeviceType
.XTERM
) {
5959 // VPR - Cursor down. Same as CUD
5960 if (type
== DeviceType
.XTERM
) {
5965 // HVP - Horizontal and vertical position
5969 // TBC - Tabulation clear
5973 // Sets an ANSI or DEC private toggle
5977 if ((type
== DeviceType
.VT220
)
5978 || (type
== DeviceType
.XTERM
)) {
5980 // Printer functions
5988 // Sets an ANSI or DEC private toggle
5992 // SGR - Select graphics rendition
5996 // DSR - Device status report
6003 // DECLL - Load leds
6007 // DECSTBM - Set top and bottom margins
6011 // Save cursor (ANSI.SYS)
6012 if (type
== DeviceType
.XTERM
) {
6013 savedState
.cursorX
= currentState
.cursorX
;
6014 savedState
.cursorY
= currentState
.cursorY
;
6018 if (type
== DeviceType
.XTERM
) {
6019 // Window operations
6024 // Restore cursor (ANSI.SYS)
6025 if (type
== DeviceType
.XTERM
) {
6026 cursorPosition(savedState
.cursorY
, savedState
.cursorX
);
6033 // DECREQTPARM - Request terminal parameters
6049 // 0x9C goes to GROUND
6054 // 0x3A goes to CSI_IGNORE
6056 scanState
= ScanState
.CSI_IGNORE
;
6061 // 00-17, 19, 1C-1F --> execute
6063 handleControlChar((char) ch
);
6066 // 20-2F --> collect, then switch to CSI_INTERMEDIATE
6067 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6069 scanState
= ScanState
.CSI_INTERMEDIATE
;
6072 // 30-39, 3B --> param
6073 if ((ch
>= '0') && (ch
<= '9')) {
6080 // 0x3A goes to CSI_IGNORE
6082 scanState
= ScanState
.CSI_IGNORE
;
6084 // 0x3C-3F goes to CSI_IGNORE
6085 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
6086 scanState
= ScanState
.CSI_IGNORE
;
6089 // 40-7E --> dispatch, then switch to GROUND
6090 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6093 // ICH - Insert character
6101 // CUD - Cursor down
6105 // CUF - Cursor forward
6109 // CUB - Cursor backward
6113 // CNL - Cursor down and to column 1
6114 if (type
== DeviceType
.XTERM
) {
6119 // CPL - Cursor up and to column 1
6120 if (type
== DeviceType
.XTERM
) {
6125 // CHA - Cursor to column # in current row
6126 if (type
== DeviceType
.XTERM
) {
6131 // CUP - Cursor position
6135 // CHT - Cursor forward X tab stops (default 1)
6136 if (type
== DeviceType
.XTERM
) {
6141 // ED - Erase in display
6145 // EL - Erase in line
6160 // DCH - Delete character
6167 // Scroll up X lines (default 1)
6168 if (type
== DeviceType
.XTERM
) {
6173 // Scroll down X lines (default 1)
6174 if (type
== DeviceType
.XTERM
) {
6183 if ((type
== DeviceType
.VT220
)
6184 || (type
== DeviceType
.XTERM
)) {
6186 // ECH - Erase character
6193 // CBT - Cursor backward X tab stops (default 1)
6194 if (type
== DeviceType
.XTERM
) {
6205 // HPA - Cursor to column # in current row. Same as CHA
6206 if (type
== DeviceType
.XTERM
) {
6211 // HPR - Cursor right. Same as CUF
6212 if (type
== DeviceType
.XTERM
) {
6217 // REP - Repeat last char X times
6218 if (type
== DeviceType
.XTERM
) {
6223 // DA - Device attributes
6227 // VPA - Cursor to row, current column.
6228 if (type
== DeviceType
.XTERM
) {
6233 // VPR - Cursor down. Same as CUD
6234 if (type
== DeviceType
.XTERM
) {
6239 // HVP - Horizontal and vertical position
6243 // TBC - Tabulation clear
6247 // Sets an ANSI or DEC private toggle
6251 if ((type
== DeviceType
.VT220
)
6252 || (type
== DeviceType
.XTERM
)) {
6254 // Printer functions
6262 // Sets an ANSI or DEC private toggle
6266 // SGR - Select graphics rendition
6270 // DSR - Device status report
6277 // DECLL - Load leds
6281 // DECSTBM - Set top and bottom margins
6287 if (type
== DeviceType
.XTERM
) {
6288 // Window operations
6297 // DECREQTPARM - Request terminal parameters
6314 case CSI_INTERMEDIATE
:
6315 // 00-17, 19, 1C-1F --> execute
6317 handleControlChar((char) ch
);
6320 // 20-2F --> collect
6321 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6325 // 0x30-3F goes to CSI_IGNORE
6326 if ((ch
>= 0x30) && (ch
<= 0x3F)) {
6327 scanState
= ScanState
.CSI_IGNORE
;
6330 // 40-7E --> dispatch, then switch to GROUND
6331 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6383 if (((type
== DeviceType
.VT220
)
6384 || (type
== DeviceType
.XTERM
))
6385 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == '\"')
6387 // DECSCL - compatibility level
6390 if ((type
== DeviceType
.XTERM
)
6391 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == '!')
6393 // DECSTR - Soft terminal reset
6398 if (((type
== DeviceType
.VT220
)
6399 || (type
== DeviceType
.XTERM
))
6400 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == '\"')
6428 // 00-17, 19, 1C-1F --> execute
6430 handleControlChar((char) ch
);
6433 // 20-2F --> collect
6434 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6438 // 40-7E --> ignore, then switch to GROUND
6439 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6443 // 20-3F, 7F --> ignore
6449 // 0x9C goes to GROUND
6454 // 0x1B 0x5C goes to GROUND
6459 if ((collectBuffer
.length() > 0)
6460 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6466 // 20-2F --> collect, then switch to DCS_INTERMEDIATE
6467 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6469 scanState
= ScanState
.DCS_INTERMEDIATE
;
6472 // 30-39, 3B --> param, then switch to DCS_PARAM
6473 if ((ch
>= '0') && (ch
<= '9')) {
6475 scanState
= ScanState
.DCS_PARAM
;
6479 scanState
= ScanState
.DCS_PARAM
;
6482 // 3C-3F --> collect, then switch to DCS_PARAM
6483 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
6485 scanState
= ScanState
.DCS_PARAM
;
6488 // 00-17, 19, 1C-1F, 7F --> ignore
6490 // 0x3A goes to DCS_IGNORE
6492 scanState
= ScanState
.DCS_IGNORE
;
6495 // 0x71 goes to DCS_SIXEL
6497 sixelParseBuffer
= new StringBuilder();
6498 scanState
= ScanState
.DCS_SIXEL
;
6499 } else if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6500 // 0x40-7E goes to DCS_PASSTHROUGH
6501 scanState
= ScanState
.DCS_PASSTHROUGH
;
6505 case DCS_INTERMEDIATE
:
6507 // 0x9C goes to GROUND
6512 // 0x1B 0x5C goes to GROUND
6517 if ((collectBuffer
.length() > 0)
6518 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6524 // 0x30-3F goes to DCS_IGNORE
6525 if ((ch
>= 0x30) && (ch
<= 0x3F)) {
6526 scanState
= ScanState
.DCS_IGNORE
;
6529 // 0x40-7E goes to DCS_PASSTHROUGH
6530 if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6531 scanState
= ScanState
.DCS_PASSTHROUGH
;
6534 // 00-17, 19, 1C-1F, 7F --> ignore
6539 // 0x9C goes to GROUND
6544 // 0x1B 0x5C goes to GROUND
6549 if ((collectBuffer
.length() > 0)
6550 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6556 // 20-2F --> collect, then switch to DCS_INTERMEDIATE
6557 if ((ch
>= 0x20) && (ch
<= 0x2F)) {
6559 scanState
= ScanState
.DCS_INTERMEDIATE
;
6562 // 30-39, 3B --> param
6563 if ((ch
>= '0') && (ch
<= '9')) {
6570 // 00-17, 19, 1C-1F, 7F --> ignore
6572 // 0x3A, 3C-3F goes to DCS_IGNORE
6574 scanState
= ScanState
.DCS_IGNORE
;
6576 if ((ch
>= 0x3C) && (ch
<= 0x3F)) {
6577 scanState
= ScanState
.DCS_IGNORE
;
6580 // 0x71 goes to DCS_SIXEL
6582 sixelParseBuffer
= new StringBuilder();
6583 scanState
= ScanState
.DCS_SIXEL
;
6584 } else if ((ch
>= 0x40) && (ch
<= 0x7E)) {
6585 // 0x40-7E goes to DCS_PASSTHROUGH
6586 scanState
= ScanState
.DCS_PASSTHROUGH
;
6590 case DCS_PASSTHROUGH
:
6591 // 0x9C goes to GROUND
6596 // 0x1B 0x5C goes to GROUND
6601 if ((collectBuffer
.length() > 0)
6602 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6608 // 00-17, 19, 1C-1F, 20-7E --> put
6616 if ((ch
>= 0x1C) && (ch
<= 0x1F)) {
6619 if ((ch
>= 0x20) && (ch
<= 0x7E)) {
6628 // 00-17, 19, 1C-1F, 20-7F --> ignore
6630 // 0x9C goes to GROUND
6638 // 0x9C goes to GROUND
6644 // 0x1B 0x5C goes to GROUND
6649 if ((collectBuffer
.length() > 0)
6650 && (collectBuffer
.charAt(collectBuffer
.length() - 1) == 0x1B)
6657 // 00-17, 19, 1C-1F, 20-7E --> put
6659 sixelParseBuffer
.append(ch
);
6663 sixelParseBuffer
.append(ch
);
6666 if ((ch
>= 0x1C) && (ch
<= 0x1F)) {
6667 sixelParseBuffer
.append(ch
);
6670 if ((ch
>= 0x20) && (ch
<= 0x7E)) {
6671 sixelParseBuffer
.append(ch
);
6679 case SOSPMAPC_STRING
:
6680 // 00-17, 19, 1C-1F, 20-7F --> ignore
6682 // Special case for Jexer: PM can pass one control character
6687 if ((ch
>= 0x20) && (ch
<= 0x7F)) {
6691 // 0x9C goes to GROUND
6699 // Special case for Xterm: OSC can pass control characters
6700 if ((ch
== 0x9C) || (ch
== 0x07) || (ch
== 0x1B)) {
6704 // 00-17, 19, 1C-1F --> ignore
6706 // 20-7F --> osc_put
6707 if ((ch
>= 0x20) && (ch
<= 0x7F)) {
6711 // 0x9C goes to GROUND
6718 case VT52_DIRECT_CURSOR_ADDRESS
:
6719 // This is a special case for the VT52 sequence "ESC Y l c"
6720 if (collectBuffer
.length() == 0) {
6722 } else if (collectBuffer
.length() == 1) {
6723 // We've got the two characters, one in the buffer and the
6725 cursorPosition(collectBuffer
.charAt(0) - '\040', ch
- '\040');
6734 * Expose current cursor X to outside world.
6736 * @return current cursor X
6738 public final int getCursorX() {
6739 if (display
.get(currentState
.cursorY
).isDoubleWidth()) {
6740 return currentState
.cursorX
* 2;
6742 return currentState
.cursorX
;
6746 * Expose current cursor Y to outside world.
6748 * @return current cursor Y
6750 public final int getCursorY() {
6751 return currentState
.cursorY
;
6755 * Returns true if this terminal has requested the mouse pointer be
6758 * @return true if this terminal has requested the mouse pointer be
6761 public final boolean hasHiddenMousePointer() {
6762 return hideMousePointer
;
6766 * Get the mouse protocol.
6768 * @return MouseProtocol.OFF, MouseProtocol.X10, etc.
6770 public MouseProtocol
getMouseProtocol() {
6771 return mouseProtocol
;
6774 // ------------------------------------------------------------------------
6775 // Sixel support ----------------------------------------------------------
6776 // ------------------------------------------------------------------------
6779 * Set the width of a character cell in pixels.
6781 * @param textWidth the width in pixels of a character cell
6783 public void setTextWidth(final int textWidth
) {
6784 this.textWidth
= textWidth
;
6788 * Set the height of a character cell in pixels.
6790 * @param textHeight the height in pixels of a character cell
6792 public void setTextHeight(final int textHeight
) {
6793 this.textHeight
= textHeight
;
6797 * Parse a sixel string into a bitmap image, and overlay that image onto
6800 private void parseSixel() {
6803 System.err.println("parseSixel(): '" + sixelParseBuffer.toString()
6807 Sixel sixel
= new Sixel(sixelParseBuffer
.toString());
6808 BufferedImage image
= sixel
.getImage();
6810 // System.err.println("parseSixel(): image " + image);
6812 if (image
== null) {
6813 // Sixel data was malformed in some way, bail out.
6820 * Break up the image into text cell sized pieces as a new array of
6823 * Note original column position x0.
6827 * 1. Advance (printCharacter(' ')) for horizontal increment, or
6828 * index (linefeed() + cursorPosition(y, x0)) for vertical
6831 * 2. Set (x, y) cell image data.
6833 * 3. For the right and bottom edges:
6835 * a. Render the text to pixels using Terminus font.
6837 * b. Blit the image on top of the text, using alpha channel.
6839 int cellColumns
= image
.getWidth() / textWidth
;
6840 if (cellColumns
* textWidth
< image
.getWidth()) {
6843 int cellRows
= image
.getHeight() / textHeight
;
6844 if (cellRows
* textHeight
< image
.getHeight()) {
6848 // Break the image up into an array of cells.
6849 Cell
[][] cells
= new Cell
[cellColumns
][cellRows
];
6851 for (int x
= 0; x
< cellColumns
; x
++) {
6852 for (int y
= 0; y
< cellRows
; y
++) {
6854 int width
= textWidth
;
6855 if ((x
+ 1) * textWidth
> image
.getWidth()) {
6856 width
= image
.getWidth() - (x
* textWidth
);
6858 int height
= textHeight
;
6859 if ((y
+ 1) * textHeight
> image
.getHeight()) {
6860 height
= image
.getHeight() - (y
* textHeight
);
6863 Cell cell
= new Cell();
6864 cell
.setImage(image
.getSubimage(x
* textWidth
,
6865 y
* textHeight
, width
, height
));
6871 int x0
= currentState
.cursorX
;
6872 for (int y
= 0; y
< cellRows
; y
++) {
6873 for (int x
= 0; x
< cellColumns
; x
++) {
6874 printCharacter(' ');
6875 cursorLeft(1, false);
6876 if ((x
== cellColumns
- 1) || (y
== cellRows
- 1)) {
6877 // TODO: render text of current cell first, then image
6878 // over it. For now, just copy the cell.
6879 DisplayLine line
= display
.get(currentState
.cursorY
);
6880 line
.replace(currentState
.cursorX
, cells
[x
][y
]);
6882 // Copy the image cell into the display.
6883 DisplayLine line
= display
.get(currentState
.cursorY
);
6884 line
.replace(currentState
.cursorX
, cells
[x
][y
]);
6886 cursorRight(1, false);
6889 cursorPosition(currentState
.cursorY
, x0
);
6895 * Draw the left and right cells of a two-cell-wide (full-width) glyph.
6897 * @param leftX the x position to draw the left half to
6898 * @param leftY the y position to draw the left half to
6899 * @param rightX the x position to draw the right half to
6900 * @param rightY the y position to draw the right half to
6901 * @param ch the character to draw
6903 private void drawHalves(final int leftX
, final int leftY
,
6904 final int rightX
, final int rightY
, final int ch
) {
6906 // System.err.println("drawHalves(): " + Integer.toHexString(ch));
6908 if (lastTextHeight
!= textHeight
) {
6909 glyphMaker
= GlyphMaker
.getInstance(textHeight
);
6910 lastTextHeight
= textHeight
;
6913 Cell cell
= new Cell(ch
, 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(cell
);
6922 left
.setImage(leftImage
);
6923 left
.setWidth(Cell
.Width
.LEFT
);
6924 display
.get(leftY
).replace(leftX
, left
);
6926 Cell right
= new Cell(cell
);
6927 right
.setImage(rightImage
);
6928 right
.setWidth(Cell
.Width
.RIGHT
);
6929 display
.get(rightY
).replace(rightX
, right
);