Mercurial > 510Connectbot
annotate src/de/mud/terminal/vt320.java @ 48:1e931ef5f776 tn5250
start tn5250 integration
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 11 Jun 2014 10:11:29 -0700 |
parents | 80dcebe51af2 |
children | e872762ec105 |
rev | line source |
---|---|
0 | 1 /* |
2 * This file is part of "JTA - Telnet/SSH for the JAVA(tm) platform". | |
3 * | |
4 * (c) Matthias L. Jugel, Marcus Meiner 1996-2005. All Rights Reserved. | |
5 * | |
6 * Please visit http://javatelnet.org/ for updates and contact. | |
7 * | |
8 * --LICENSE NOTICE-- | |
9 * This program is free software; you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License | |
11 * as published by the Free Software Foundation; either version 2 | |
12 * of the License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 * --LICENSE NOTICE-- | |
23 * | |
24 */ | |
25 | |
26 package de.mud.terminal; | |
27 | |
28 import android.text.AndroidCharacter; | |
29 | |
30 import java.util.Properties; | |
31 | |
32 /** | |
33 * Implementation of a VT terminal emulation plus ANSI compatible. | |
34 * <P> | |
35 * <B>Maintainer:</B> Marcus Meißner | |
36 * | |
37 * @version $Id: vt320.java 507 2005-10-25 10:14:52Z marcus $ | |
38 * @author Matthias L. Jugel, Marcus Meißner | |
39 */ | |
40 public abstract class vt320 extends VDUBuffer implements VDUInput { | |
41 | |
42 /** the debug level */ | |
43 private final static int debug = 0; | |
44 private StringBuilder debugStr; | |
45 public abstract void debug(String notice); | |
46 | |
47 /** | |
48 * Write an answer back to the remote host. This is needed to be able to | |
49 * send terminal answers requests like status and type information. | |
50 * @param b the array of bytes to be sent | |
51 */ | |
52 public abstract void write(byte[] b); | |
53 | |
54 /** | |
55 * Write an answer back to the remote host. This is needed to be able to | |
56 * send terminal answers requests like status and type information. | |
57 * @param b the byte to be sent | |
58 */ | |
59 public abstract void write(int b); | |
60 | |
61 /** | |
62 * No more bytes to read from the transport, hook here to test screen changes | |
63 */ | |
64 public void testChanged() { | |
65 /* do nothing by default */ | |
66 } | |
67 | |
68 /** | |
69 * Play the beep sound ... | |
70 */ | |
71 public void beep() { | |
72 /* do nothing by default */ | |
73 } | |
74 | |
41
9621ac4dd5eb
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
75 public void redrawPassthru() { |
9621ac4dd5eb
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
76 redraw(); // VDUBuffer.redraw is protected |
9621ac4dd5eb
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
77 } |
9621ac4dd5eb
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
78 |
0 | 79 /** |
80 * Convenience function for putString(char[], int, int) | |
81 */ | |
82 public void putString(String s) { | |
83 int len = s.length(); | |
84 char[] tmp = new char[len]; | |
85 s.getChars(0, len, tmp, 0); | |
86 putString(tmp, null, 0, len); | |
87 } | |
88 | |
89 /** | |
90 * Put string at current cursor position. Moves cursor | |
91 * according to the String. Does NOT wrap. | |
92 * @param s character array | |
93 * @param start place to start in array | |
94 * @param len number of characters to process | |
95 */ | |
96 public void putString(char[] s, byte[] fullwidths, int start, int len) { | |
97 if (len > 0) { | |
98 //markLine(R, 1); | |
99 int lastChar = -1; | |
100 char c; | |
101 boolean isWide = false; | |
102 | |
103 for (int i = 0; i < len; i++) { | |
104 c = s[start + i]; | |
105 | |
106 // Shortcut for my favorite ASCII | |
107 if (c <= 0x7F) { | |
108 if (lastChar != -1) | |
109 putChar((char) lastChar, isWide, false); | |
110 | |
111 lastChar = c; | |
112 isWide = false; | |
113 } | |
114 else if (!Character.isLowSurrogate(c) && !Character.isHighSurrogate(c)) { | |
115 if (Character.getType(c) == Character.NON_SPACING_MARK) { | |
116 if (lastChar != -1) { | |
117 char nc = Precomposer.precompose((char) lastChar, c); | |
118 putChar(nc, isWide, false); | |
119 lastChar = -1; | |
120 } | |
121 } | |
122 else { | |
123 if (lastChar != -1) | |
124 putChar((char) lastChar, isWide, false); | |
125 | |
126 lastChar = c; | |
127 | |
128 if (fullwidths != null) { | |
129 final byte width = fullwidths[i]; | |
130 isWide = (width == AndroidCharacter.EAST_ASIAN_WIDTH_WIDE) | |
131 || (width == AndroidCharacter.EAST_ASIAN_WIDTH_FULL_WIDTH); | |
132 } | |
133 } | |
134 } | |
135 } | |
136 | |
137 if (lastChar != -1) | |
138 putChar((char) lastChar, isWide, false); | |
139 | |
140 setCursorPosition(C, R); | |
141 redraw(); | |
142 } | |
143 } | |
144 | |
145 protected void sendTelnetCommand(byte cmd) { | |
146 /* do nothing by default */ | |
147 } | |
148 | |
149 /** | |
150 * Sent the changed window size from the terminal to all listeners. | |
151 */ | |
152 protected void setWindowSize(int c, int r) { | |
153 /* To be overridden by Terminal.java */ | |
154 } | |
155 | |
156 @Override | |
157 public void setScreenSize(int c, int r, boolean broadcast) { | |
158 int oldrows = height; | |
159 | |
160 if (debug > 2) { | |
161 if (debugStr == null) | |
162 debugStr = new StringBuilder(); | |
163 | |
164 debugStr.append("setscreensize (") | |
165 .append(c) | |
166 .append(',') | |
167 .append(r) | |
168 .append(',') | |
169 .append(broadcast) | |
170 .append(')'); | |
171 debug(debugStr.toString()); | |
172 debugStr.setLength(0); | |
173 } | |
174 | |
175 super.setScreenSize(c, r, false); | |
176 boolean cursorChanged = false; | |
177 | |
178 // Don't let the cursor go off the screen. | |
179 if (C >= c) { | |
180 C = c - 1; | |
181 cursorChanged = true; | |
182 } | |
183 | |
184 if (R >= r) { | |
185 R = r - 1; | |
186 cursorChanged = true; | |
187 } | |
188 | |
189 if (cursorChanged) { | |
190 setCursorPosition(C, R); | |
191 redraw(); | |
192 } | |
193 | |
194 if (broadcast) { | |
195 setWindowSize(c, r); /* broadcast up */ | |
196 } | |
197 } | |
198 | |
199 | |
200 /** | |
201 * Create a new vt320 terminal and intialize it with useful settings. | |
202 */ | |
203 public vt320(int width, int height) { | |
204 super(width, height); | |
205 debugStr = new StringBuilder(); | |
206 setVMS(false); | |
207 setIBMCharset(false); | |
208 setTerminalID("vt320"); | |
209 setBufferSize(100); | |
210 //setBorder(2, false); | |
211 gx = new char[4]; | |
212 reset(); | |
213 /* top row of numpad */ | |
214 PF1 = "\u001bOP"; | |
215 PF2 = "\u001bOQ"; | |
216 PF3 = "\u001bOR"; | |
217 PF4 = "\u001bOS"; | |
218 /* the 3x2 keyblock on PC keyboards */ | |
219 Insert = new String[4]; | |
220 Remove = new String[4]; | |
221 KeyHome = new String[4]; | |
222 KeyEnd = new String[4]; | |
223 NextScn = new String[4]; | |
224 PrevScn = new String[4]; | |
225 Escape = new String[4]; | |
226 BackSpace = new String[4]; | |
227 TabKey = new String[4]; | |
228 Insert[0] = Insert[1] = Insert[2] = Insert[3] = "\u001b[2~"; | |
229 Remove[0] = Remove[1] = Remove[2] = Remove[3] = "\u001b[3~"; | |
230 PrevScn[0] = PrevScn[1] = PrevScn[2] = PrevScn[3] = "\u001b[5~"; | |
231 NextScn[0] = NextScn[1] = NextScn[2] = NextScn[3] = "\u001b[6~"; | |
232 KeyHome[0] = KeyHome[1] = KeyHome[2] = KeyHome[3] = "\u001b[H"; | |
233 KeyEnd[0] = KeyEnd[1] = KeyEnd[2] = KeyEnd[3] = "\u001b[F"; | |
234 Escape[0] = Escape[1] = Escape[2] = Escape[3] = "\u001b"; | |
235 | |
236 if (vms) { | |
237 BackSpace[1] = "" + (char) 10; // VMS shift deletes word back | |
238 BackSpace[2] = "\u0018"; // VMS control deletes line back | |
239 BackSpace[0] = BackSpace[3] = "\u007f"; // VMS other is delete | |
240 } | |
241 else { | |
242 //BackSpace[0] = BackSpace[1] = BackSpace[2] = BackSpace[3] = "\b"; | |
243 // ConnectBot modifications. | |
244 BackSpace[0] = "\b"; | |
245 BackSpace[1] = "\u007f"; | |
246 BackSpace[2] = "\u001b[3~"; | |
247 BackSpace[3] = "\u001b[2~"; | |
248 } | |
249 | |
250 /* some more VT100 keys */ | |
251 Find = "\u001b[1~"; | |
252 Select = "\u001b[4~"; | |
253 Help = "\u001b[28~"; | |
254 Do = "\u001b[29~"; | |
255 FunctionKey = new String[21]; | |
256 FunctionKey[0] = ""; | |
257 FunctionKey[1] = PF1; | |
258 FunctionKey[2] = PF2; | |
259 FunctionKey[3] = PF3; | |
260 FunctionKey[4] = PF4; | |
261 /* following are defined differently for vt220 / vt132 ... */ | |
262 FunctionKey[5] = "\u001b[15~"; | |
263 FunctionKey[6] = "\u001b[17~"; | |
264 FunctionKey[7] = "\u001b[18~"; | |
265 FunctionKey[8] = "\u001b[19~"; | |
266 FunctionKey[9] = "\u001b[20~"; | |
267 FunctionKey[10] = "\u001b[21~"; | |
268 FunctionKey[11] = "\u001b[23~"; | |
269 FunctionKey[12] = "\u001b[24~"; | |
270 FunctionKey[13] = "\u001b[25~"; | |
271 FunctionKey[14] = "\u001b[26~"; | |
272 FunctionKey[15] = Help; | |
273 FunctionKey[16] = Do; | |
274 FunctionKey[17] = "\u001b[31~"; | |
275 FunctionKey[18] = "\u001b[32~"; | |
276 FunctionKey[19] = "\u001b[33~"; | |
277 FunctionKey[20] = "\u001b[34~"; | |
278 FunctionKeyShift = new String[21]; | |
279 FunctionKeyAlt = new String[21]; | |
280 FunctionKeyCtrl = new String[21]; | |
281 | |
282 for (int i = 0; i < 20; i++) { | |
283 FunctionKeyShift[i] = ""; | |
284 FunctionKeyAlt[i] = ""; | |
285 FunctionKeyCtrl[i] = ""; | |
286 } | |
287 | |
288 FunctionKeyShift[15] = Find; | |
289 FunctionKeyShift[16] = Select; | |
290 TabKey[0] = "\u0009"; | |
291 TabKey[1] = "\u001bOP\u0009"; | |
292 TabKey[2] = TabKey[3] = ""; | |
293 KeyUp = new String[4]; | |
294 KeyUp[0] = "\u001b[A"; | |
295 KeyDown = new String[4]; | |
296 KeyDown[0] = "\u001b[B"; | |
297 KeyRight = new String[4]; | |
298 KeyRight[0] = "\u001b[C"; | |
299 KeyLeft = new String[4]; | |
300 KeyLeft[0] = "\u001b[D"; | |
301 Numpad = new String[10]; | |
302 Numpad[0] = "\u001bOp"; | |
303 Numpad[1] = "\u001bOq"; | |
304 Numpad[2] = "\u001bOr"; | |
305 Numpad[3] = "\u001bOs"; | |
306 Numpad[4] = "\u001bOt"; | |
307 Numpad[5] = "\u001bOu"; | |
308 Numpad[6] = "\u001bOv"; | |
309 Numpad[7] = "\u001bOw"; | |
310 Numpad[8] = "\u001bOx"; | |
311 Numpad[9] = "\u001bOy"; | |
312 KPMinus = PF4; | |
313 KPComma = "\u001bOl"; | |
314 KPPeriod = "\u001bOn"; | |
315 KPEnter = "\u001bOM"; | |
316 NUMPlus = new String[4]; | |
317 NUMPlus[0] = "+"; | |
318 NUMDot = new String[4]; | |
319 NUMDot[0] = "."; | |
320 } | |
321 | |
322 public void setBackspace(int type) { | |
323 switch (type) { | |
324 case DELETE_IS_DEL: | |
325 BackSpace[0] = "\u007f"; | |
326 BackSpace[1] = "\b"; | |
327 break; | |
328 | |
329 case DELETE_IS_BACKSPACE: | |
330 BackSpace[0] = "\b"; | |
331 BackSpace[1] = "\u007f"; | |
332 break; | |
333 } | |
334 } | |
335 | |
336 /** | |
337 * Create a default vt320 terminal with 80 columns and 24 lines. | |
338 */ | |
339 public vt320() { | |
340 this(80, 24); | |
341 } | |
342 | |
343 /** | |
344 * Terminal is mouse-aware and requires (x,y) coordinates of | |
345 * on the terminal (character coordinates) and the button clicked. | |
346 * @param x | |
347 * @param y | |
348 * @param modifiers | |
349 */ | |
350 public void mousePressed(int x, int y, int modifiers) { | |
351 if (mouserpt == 0) | |
352 return; | |
353 | |
354 int mods = modifiers; | |
355 mousebut = 3; | |
356 | |
357 if ((mods & 16) == 16) mousebut = 0; | |
358 | |
359 if ((mods & 8) == 8) mousebut = 1; | |
360 | |
361 if ((mods & 4) == 4) mousebut = 2; | |
362 | |
363 int mousecode; | |
364 | |
365 if (mouserpt == 9) /* X10 Mouse */ | |
366 mousecode = 0x20 | mousebut; | |
367 else /* normal xterm mouse reporting */ | |
368 mousecode = mousebut | 0x20 | ((mods & 7) << 2); | |
369 | |
370 byte b[] = new byte[6]; | |
371 b[0] = 27; | |
372 b[1] = (byte) '['; | |
373 b[2] = (byte) 'M'; | |
374 b[3] = (byte) mousecode; | |
375 b[4] = (byte)(0x20 + x + 1); | |
376 b[5] = (byte)(0x20 + y + 1); | |
377 write(b); // FIXME: writeSpecial here | |
378 } | |
379 | |
380 /** | |
381 * Terminal is mouse-aware and requires the coordinates and button | |
382 * of the release. | |
383 * @param x | |
384 * @param y | |
385 * @param modifiers | |
386 */ | |
387 public void mouseReleased(int x, int y, int modifiers) { | |
388 if (mouserpt == 0) | |
389 return; | |
390 | |
391 /* problem is tht modifiers still have the released button set in them. | |
392 int mods = modifiers; | |
393 mousebut = 3; | |
394 if ((mods & 16)==16) mousebut=0; | |
395 if ((mods & 8)==8 ) mousebut=1; | |
396 if ((mods & 4)==4 ) mousebut=2; | |
397 */ | |
398 int mousecode; | |
399 | |
400 if (mouserpt == 9) | |
401 mousecode = 0x20 + mousebut; /* same as press? appears so. */ | |
402 else | |
403 mousecode = '#'; | |
404 | |
405 byte b[] = new byte[6]; | |
406 b[0] = 27; | |
407 b[1] = (byte) '['; | |
408 b[2] = (byte) 'M'; | |
409 b[3] = (byte) mousecode; | |
410 b[4] = (byte)(0x20 + x + 1); | |
411 b[5] = (byte)(0x20 + y + 1); | |
412 write(b); // FIXME: writeSpecial here | |
413 mousebut = 0; | |
414 } | |
415 | |
416 | |
417 /** we should do localecho (passed from other modules). false is default */ | |
418 private boolean localecho = false; | |
419 | |
420 /** | |
421 * Enable or disable the local echo property of the terminal. | |
422 * @param echo true if the terminal should echo locally | |
423 */ | |
424 public void setLocalEcho(boolean echo) { | |
425 localecho = echo; | |
426 } | |
427 | |
428 /** | |
429 * Enable the VMS mode of the terminal to handle some things differently | |
430 * for VMS hosts. | |
431 * @param vms true for vms mode, false for normal mode | |
432 */ | |
433 public void setVMS(boolean vms) { | |
434 this.vms = vms; | |
435 } | |
436 | |
437 /** | |
438 * Enable the usage of the IBM character set used by some BBS's. Special | |
439 * graphical character are available in this mode. | |
440 * @param ibm true to use the ibm character set | |
441 */ | |
442 public void setIBMCharset(boolean ibm) { | |
443 useibmcharset = ibm; | |
444 } | |
445 | |
446 /** | |
447 * Override the standard key codes used by the terminal emulation. | |
448 * @param codes a properties object containing key code definitions | |
449 */ | |
450 public void setKeyCodes(Properties codes) { | |
451 String res, prefixes[] = {"", "S", "C", "A"}; | |
452 int i; | |
453 | |
454 for (i = 0; i < 10; i++) { | |
455 res = codes.getProperty("NUMPAD" + i); | |
456 | |
457 if (res != null) Numpad[i] = unEscape(res); | |
458 } | |
459 | |
460 for (i = 1; i < 20; i++) { | |
461 res = codes.getProperty("F" + i); | |
462 | |
463 if (res != null) FunctionKey[i] = unEscape(res); | |
464 | |
465 res = codes.getProperty("SF" + i); | |
466 | |
467 if (res != null) FunctionKeyShift[i] = unEscape(res); | |
468 | |
469 res = codes.getProperty("CF" + i); | |
470 | |
471 if (res != null) FunctionKeyCtrl[i] = unEscape(res); | |
472 | |
473 res = codes.getProperty("AF" + i); | |
474 | |
475 if (res != null) FunctionKeyAlt[i] = unEscape(res); | |
476 } | |
477 | |
478 for (i = 0; i < 4; i++) { | |
479 res = codes.getProperty(prefixes[i] + "PGUP"); | |
480 | |
481 if (res != null) PrevScn[i] = unEscape(res); | |
482 | |
483 res = codes.getProperty(prefixes[i] + "PGDOWN"); | |
484 | |
485 if (res != null) NextScn[i] = unEscape(res); | |
486 | |
487 res = codes.getProperty(prefixes[i] + "END"); | |
488 | |
489 if (res != null) KeyEnd[i] = unEscape(res); | |
490 | |
491 res = codes.getProperty(prefixes[i] + "HOME"); | |
492 | |
493 if (res != null) KeyHome[i] = unEscape(res); | |
494 | |
495 res = codes.getProperty(prefixes[i] + "INSERT"); | |
496 | |
497 if (res != null) Insert[i] = unEscape(res); | |
498 | |
499 res = codes.getProperty(prefixes[i] + "REMOVE"); | |
500 | |
501 if (res != null) Remove[i] = unEscape(res); | |
502 | |
503 res = codes.getProperty(prefixes[i] + "UP"); | |
504 | |
505 if (res != null) KeyUp[i] = unEscape(res); | |
506 | |
507 res = codes.getProperty(prefixes[i] + "DOWN"); | |
508 | |
509 if (res != null) KeyDown[i] = unEscape(res); | |
510 | |
511 res = codes.getProperty(prefixes[i] + "LEFT"); | |
512 | |
513 if (res != null) KeyLeft[i] = unEscape(res); | |
514 | |
515 res = codes.getProperty(prefixes[i] + "RIGHT"); | |
516 | |
517 if (res != null) KeyRight[i] = unEscape(res); | |
518 | |
519 res = codes.getProperty(prefixes[i] + "ESCAPE"); | |
520 | |
521 if (res != null) Escape[i] = unEscape(res); | |
522 | |
523 res = codes.getProperty(prefixes[i] + "BACKSPACE"); | |
524 | |
525 if (res != null) BackSpace[i] = unEscape(res); | |
526 | |
527 res = codes.getProperty(prefixes[i] + "TAB"); | |
528 | |
529 if (res != null) TabKey[i] = unEscape(res); | |
530 | |
531 res = codes.getProperty(prefixes[i] + "NUMPLUS"); | |
532 | |
533 if (res != null) NUMPlus[i] = unEscape(res); | |
534 | |
535 res = codes.getProperty(prefixes[i] + "NUMDECIMAL"); | |
536 | |
537 if (res != null) NUMDot[i] = unEscape(res); | |
538 } | |
539 } | |
540 | |
541 /** | |
542 * Set the terminal id used to identify this terminal. | |
543 * @param terminalID the id string | |
544 */ | |
545 public void setTerminalID(String terminalID) { | |
546 this.terminalID = terminalID; | |
547 | |
548 if (terminalID.equals("scoansi")) { | |
549 FunctionKey[1] = "\u001b[M"; FunctionKey[2] = "\u001b[N"; | |
550 FunctionKey[3] = "\u001b[O"; FunctionKey[4] = "\u001b[P"; | |
551 FunctionKey[5] = "\u001b[Q"; FunctionKey[6] = "\u001b[R"; | |
552 FunctionKey[7] = "\u001b[S"; FunctionKey[8] = "\u001b[T"; | |
553 FunctionKey[9] = "\u001b[U"; FunctionKey[10] = "\u001b[V"; | |
554 FunctionKey[11] = "\u001b[W"; FunctionKey[12] = "\u001b[X"; | |
555 FunctionKey[13] = "\u001b[Y"; FunctionKey[14] = "?"; | |
556 FunctionKey[15] = "\u001b[a"; FunctionKey[16] = "\u001b[b"; | |
557 FunctionKey[17] = "\u001b[c"; FunctionKey[18] = "\u001b[d"; | |
558 FunctionKey[19] = "\u001b[e"; FunctionKey[20] = "\u001b[f"; | |
559 PrevScn[0] = PrevScn[1] = PrevScn[2] = PrevScn[3] = "\u001b[I"; | |
560 NextScn[0] = NextScn[1] = NextScn[2] = NextScn[3] = "\u001b[G"; | |
561 // more theoretically. | |
562 } | |
563 } | |
564 | |
565 public void setAnswerBack(String ab) { | |
566 this.answerBack = unEscape(ab); | |
567 } | |
568 | |
569 /** | |
570 * Get the terminal id used to identify this terminal. | |
571 */ | |
572 public String getTerminalID() { | |
573 return terminalID; | |
574 } | |
575 | |
576 /** | |
577 * A small conveniance method thar converts the string to a byte array | |
578 * for sending. | |
579 * @param s the string to be sent | |
580 */ | |
581 private boolean write(String s, boolean doecho) { | |
582 if (debug > 2) { | |
583 debugStr.append("write(|") | |
584 .append(s) | |
585 .append("|,") | |
586 .append(doecho); | |
587 debug(debugStr.toString()); | |
588 debugStr.setLength(0); | |
589 } | |
590 | |
591 if (s == null) // aka the empty string. | |
592 return true; | |
593 | |
594 /* NOTE: getBytes() honours some locale, it *CONVERTS* the string. | |
595 * However, we output only 7bit stuff towards the target, and *some* | |
596 * 8 bit control codes. We must not mess up the latter, so we do hand | |
597 * by hand copy. | |
598 */ | |
599 byte arr[] = new byte[s.length()]; | |
600 | |
601 for (int i = 0; i < s.length(); i++) { | |
602 arr[i] = (byte) s.charAt(i); | |
603 } | |
604 | |
605 write(arr); | |
606 | |
607 if (doecho) | |
608 putString(s); | |
609 | |
610 return true; | |
611 } | |
612 | |
613 private boolean write(int s, boolean doecho) { | |
614 if (debug > 2) { | |
615 debugStr.append("write(|") | |
616 .append(s) | |
617 .append("|,") | |
618 .append(doecho); | |
619 debug(debugStr.toString()); | |
620 debugStr.setLength(0); | |
621 } | |
622 | |
623 write(s); | |
624 | |
625 // TODO check if character is wide | |
626 if (doecho) | |
627 putChar((char)s, false, false); | |
628 | |
629 return true; | |
630 } | |
631 | |
632 private boolean write(String s) { | |
633 return write(s, localecho); | |
634 } | |
635 | |
636 // =================================================================== | |
637 // the actual terminal emulation code comes here: | |
638 // =================================================================== | |
639 | |
640 private String terminalID = "vt320"; | |
641 private String answerBack = "Use Terminal.answerback to set ...\n"; | |
642 | |
643 // X - COLUMNS, Y - ROWS | |
644 int R, C; | |
645 int attributes = 0; | |
646 | |
647 int Sc, Sr, Sa, Stm, Sbm; | |
648 char Sgr, Sgl; | |
649 char Sgx[]; | |
650 | |
651 int insertmode = 0; | |
652 int statusmode = 0; | |
653 boolean vt52mode = false; | |
654 boolean keypadmode = false; /* false - numeric, true - application */ | |
655 boolean output8bit = false; | |
656 int normalcursor = 0; | |
657 boolean moveoutsidemargins = true; | |
658 boolean wraparound = true; | |
659 boolean sendcrlf = true; | |
660 boolean capslock = false; | |
661 boolean numlock = false; | |
662 int mouserpt = 0; | |
663 byte mousebut = 0; | |
664 | |
665 boolean useibmcharset = false; | |
666 | |
667 int lastwaslf = 0; | |
668 boolean usedcharsets = false; | |
669 | |
670 private final static char ESC = 27; | |
671 private final static char IND = 132; | |
672 private final static char NEL = 133; | |
673 private final static char RI = 141; | |
674 private final static char SS2 = 142; | |
675 private final static char SS3 = 143; | |
676 private final static char DCS = 144; | |
677 private final static char HTS = 136; | |
678 private final static char CSI = 155; | |
679 private final static char OSC = 157; | |
680 private final static int TSTATE_DATA = 0; | |
681 private final static int TSTATE_ESC = 1; /* ESC */ | |
682 private final static int TSTATE_CSI = 2; /* ESC [ */ | |
683 private final static int TSTATE_DCS = 3; /* ESC P */ | |
684 private final static int TSTATE_DCEQ = 4; /* ESC [? */ | |
685 private final static int TSTATE_ESCSQUARE = 5; /* ESC # */ | |
686 private final static int TSTATE_OSC = 6; /* ESC ] */ | |
687 private final static int TSTATE_SETG0 = 7; /* ESC (? */ | |
688 private final static int TSTATE_SETG1 = 8; /* ESC )? */ | |
689 private final static int TSTATE_SETG2 = 9; /* ESC *? */ | |
690 private final static int TSTATE_SETG3 = 10; /* ESC +? */ | |
691 private final static int TSTATE_CSI_DOLLAR = 11; /* ESC [ Pn $ */ | |
692 private final static int TSTATE_CSI_EX = 12; /* ESC [ ! */ | |
693 private final static int TSTATE_ESCSPACE = 13; /* ESC <space> */ | |
694 private final static int TSTATE_VT52X = 14; | |
695 private final static int TSTATE_VT52Y = 15; | |
696 private final static int TSTATE_CSI_TICKS = 16; | |
697 private final static int TSTATE_CSI_EQUAL = 17; /* ESC [ = */ | |
698 private final static int TSTATE_TITLE = 18; /* xterm title */ | |
699 | |
700 /* Keys we support */ | |
701 public final static int KEY_PAUSE = 1; | |
702 public final static int KEY_F1 = 2; | |
703 public final static int KEY_F2 = 3; | |
704 public final static int KEY_F3 = 4; | |
705 public final static int KEY_F4 = 5; | |
706 public final static int KEY_F5 = 6; | |
707 public final static int KEY_F6 = 7; | |
708 public final static int KEY_F7 = 8; | |
709 public final static int KEY_F8 = 9; | |
710 public final static int KEY_F9 = 10; | |
711 public final static int KEY_F10 = 11; | |
712 public final static int KEY_F11 = 12; | |
713 public final static int KEY_F12 = 13; | |
714 public final static int KEY_UP = 14; | |
715 public final static int KEY_DOWN = 15 ; | |
716 public final static int KEY_LEFT = 16; | |
717 public final static int KEY_RIGHT = 17; | |
718 public final static int KEY_PAGE_DOWN = 18; | |
719 public final static int KEY_PAGE_UP = 19; | |
720 public final static int KEY_INSERT = 20; | |
721 public final static int KEY_DELETE = 21; | |
722 public final static int KEY_BACK_SPACE = 22; | |
723 public final static int KEY_HOME = 23; | |
724 public final static int KEY_END = 24; | |
725 public final static int KEY_NUM_LOCK = 25; | |
726 public final static int KEY_CAPS_LOCK = 26; | |
727 public final static int KEY_SHIFT = 27; | |
728 public final static int KEY_CONTROL = 28; | |
729 public final static int KEY_ALT = 29; | |
730 public final static int KEY_ENTER = 30; | |
731 public final static int KEY_NUMPAD0 = 31; | |
732 public final static int KEY_NUMPAD1 = 32; | |
733 public final static int KEY_NUMPAD2 = 33; | |
734 public final static int KEY_NUMPAD3 = 34; | |
735 public final static int KEY_NUMPAD4 = 35; | |
736 public final static int KEY_NUMPAD5 = 36; | |
737 public final static int KEY_NUMPAD6 = 37; | |
738 public final static int KEY_NUMPAD7 = 38; | |
739 public final static int KEY_NUMPAD8 = 39; | |
740 public final static int KEY_NUMPAD9 = 40; | |
741 public final static int KEY_DECIMAL = 41; | |
742 public final static int KEY_ADD = 42; | |
743 public final static int KEY_ESCAPE = 43; | |
744 | |
745 public final static int DELETE_IS_DEL = 0; | |
746 public final static int DELETE_IS_BACKSPACE = 1; | |
747 | |
748 /* The graphics charsets | |
749 * B - default ASCII | |
750 * A - ISO Latin 1 | |
751 * 0 - DEC SPECIAL | |
752 * < - User defined | |
753 * .... | |
754 */ | |
755 char gx[]; | |
756 char gl; // GL (left charset) | |
757 char gr; // GR (right charset) | |
758 int onegl; // single shift override for GL. | |
759 | |
760 // Map from scoansi linedrawing to DEC _and_ unicode (for the stuff which | |
761 // is not in linedrawing). Got from experimenting with scoadmin. | |
762 private final static String scoansi_acs = "Tm7k3x4u?kZl@mYjEnB\u2566DqCtAvM\u2550:\u2551N\u2557I\u2554;\u2557H\u255a0a<\u255d"; | |
763 // array to store DEC Special -> Unicode mapping | |
764 // Unicode DEC Unicode name (DEC name) | |
765 private static char DECSPECIAL[] = { | |
766 '\u0040', //5f blank | |
767 '\u2666', //60 black diamond | |
768 '\u2592', //61 grey square | |
769 '\u2409', //62 Horizontal tab (ht) pict. for control | |
770 '\u240c', //63 Form Feed (ff) pict. for control | |
771 '\u240d', //64 Carriage Return (cr) pict. for control | |
772 '\u240a', //65 Line Feed (lf) pict. for control | |
773 '\u00ba', //66 Masculine ordinal indicator | |
774 '\u00b1', //67 Plus or minus sign | |
775 '\u2424', //68 New Line (nl) pict. for control | |
776 '\u240b', //69 Vertical Tab (vt) pict. for control | |
777 '\u2518', //6a Forms light up and left | |
778 '\u2510', //6b Forms light down and left | |
779 '\u250c', //6c Forms light down and right | |
780 '\u2514', //6d Forms light up and right | |
781 '\u253c', //6e Forms light vertical and horizontal | |
782 '\u2594', //6f Upper 1/8 block (Scan 1) | |
783 '\u2580', //70 Upper 1/2 block (Scan 3) | |
784 '\u2500', //71 Forms light horizontal or ?em dash? (Scan 5) | |
785 '\u25ac', //72 \u25ac black rect. or \u2582 lower 1/4 (Scan 7) | |
786 '\u005f', //73 \u005f underscore or \u2581 lower 1/8 (Scan 9) | |
787 '\u251c', //74 Forms light vertical and right | |
788 '\u2524', //75 Forms light vertical and left | |
789 '\u2534', //76 Forms light up and horizontal | |
790 '\u252c', //77 Forms light down and horizontal | |
791 '\u2502', //78 vertical bar | |
792 '\u2264', //79 less than or equal | |
793 '\u2265', //7a greater than or equal | |
794 '\u00b6', //7b paragraph | |
795 '\u2260', //7c not equal | |
796 '\u00a3', //7d Pound Sign (british) | |
797 '\u00b7' //7e Middle Dot | |
798 }; | |
799 | |
800 /** Strings to send on function key pressing */ | |
801 private String Numpad[]; | |
802 private String FunctionKey[]; | |
803 private String FunctionKeyShift[]; | |
804 private String FunctionKeyCtrl[]; | |
805 private String FunctionKeyAlt[]; | |
806 private String TabKey[]; | |
807 private String KeyUp[], KeyDown[], KeyLeft[], KeyRight[]; | |
808 private String KPMinus, KPComma, KPPeriod, KPEnter; | |
809 private String PF1, PF2, PF3, PF4; | |
810 private String Help, Do, Find, Select; | |
811 | |
812 private String KeyHome[], KeyEnd[], Insert[], Remove[], PrevScn[], NextScn[]; | |
813 private String Escape[], BackSpace[], NUMDot[], NUMPlus[]; | |
814 | |
815 private String osc, dcs; /* to memorize OSC & DCS control sequence */ | |
816 | |
817 /** vt320 state variable (internal) */ | |
818 private int term_state = TSTATE_DATA; | |
819 /** in vms mode, set by Terminal.VMS property */ | |
820 private boolean vms = false; | |
821 /** Tabulators */ | |
822 private byte[] Tabs; | |
823 /** The list of integers as used by CSI */ | |
824 private int[] DCEvars = new int[30]; | |
825 private int DCEvar; | |
826 | |
827 /** | |
828 * Replace escape code characters (backslash + identifier) with their | |
829 * respective codes. | |
830 * @param tmp the string to be parsed | |
831 * @return a unescaped string | |
832 */ | |
833 static String unEscape(String tmp) { | |
834 int idx = 0, oldidx = 0; | |
835 String cmd; | |
836 // f.println("unescape("+tmp+")"); | |
837 cmd = ""; | |
838 | |
839 while ((idx = tmp.indexOf('\\', oldidx)) >= 0 && | |
840 ++idx <= tmp.length()) { | |
841 cmd += tmp.substring(oldidx, idx - 1); | |
842 | |
843 if (idx == tmp.length()) return cmd; | |
844 | |
845 switch (tmp.charAt(idx)) { | |
846 case 'b': | |
847 cmd += "\b"; | |
848 break; | |
849 | |
850 case 'e': | |
851 cmd += "\u001b"; | |
852 break; | |
853 | |
854 case 'n': | |
855 cmd += "\n"; | |
856 break; | |
857 | |
858 case 'r': | |
859 cmd += "\r"; | |
860 break; | |
861 | |
862 case 't': | |
863 cmd += "\t"; | |
864 break; | |
865 | |
866 case 'v': | |
867 cmd += "\u000b"; | |
868 break; | |
869 | |
870 case 'a': | |
871 cmd += "\u0012"; | |
872 break; | |
873 | |
874 default : | |
875 if ((tmp.charAt(idx) >= '0') && (tmp.charAt(idx) <= '9')) { | |
876 int i; | |
877 | |
878 for (i = idx; i < tmp.length(); i++) | |
879 if ((tmp.charAt(i) < '0') || (tmp.charAt(i) > '9')) | |
880 break; | |
881 | |
882 cmd += (char) Integer.parseInt(tmp.substring(idx, i)); | |
883 idx = i - 1; | |
884 } | |
885 else | |
886 cmd += tmp.substring(idx, ++idx); | |
887 | |
888 break; | |
889 } | |
890 | |
891 oldidx = ++idx; | |
892 } | |
893 | |
894 if (oldidx <= tmp.length()) cmd += tmp.substring(oldidx); | |
895 | |
896 return cmd; | |
897 } | |
898 | |
899 /** | |
900 * A small conveniance method thar converts a 7bit string to the 8bit | |
901 * version depending on VT52/Output8Bit mode. | |
902 * | |
903 * @param s the string to be sent | |
904 */ | |
905 private boolean writeSpecial(String s) { | |
906 if (s == null) | |
907 return true; | |
908 | |
909 if (((s.length() >= 3) && (s.charAt(0) == 27) && (s.charAt(1) == 'O'))) { | |
910 if (vt52mode) { | |
911 if ((s.charAt(2) >= 'P') && (s.charAt(2) <= 'S')) { | |
912 s = "\u001b" + s.substring(2); /* ESC x */ | |
913 } | |
914 else { | |
915 s = "\u001b?" + s.substring(2); /* ESC ? x */ | |
916 } | |
917 } | |
918 else { | |
919 if (output8bit) { | |
920 s = "\u008f" + s.substring(2); /* SS3 x */ | |
921 } /* else keep string as it is */ | |
922 } | |
923 } | |
924 | |
925 if (((s.length() >= 3) && (s.charAt(0) == 27) && (s.charAt(1) == '['))) { | |
926 if (output8bit) { | |
927 s = "\u009b" + s.substring(2); /* CSI ... */ | |
928 } /* else keep */ | |
929 } | |
930 | |
931 return write(s, false); | |
932 } | |
933 | |
934 /** | |
935 * main keytyping event handler... | |
936 */ | |
937 public void keyPressed(int keyCode, char keyChar, int modifiers) { | |
938 boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0; | |
939 boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0; | |
940 boolean alt = (modifiers & VDUInput.KEY_ALT) != 0; | |
941 | |
942 if (debug > 1) { | |
943 debugStr.append("keyPressed(") | |
944 .append(keyCode) | |
945 .append(", ") | |
946 .append((int)keyChar) | |
947 .append(", ") | |
948 .append(modifiers) | |
949 .append(')'); | |
950 debug(debugStr.toString()); | |
951 debugStr.setLength(0); | |
952 } | |
953 | |
954 int xind; | |
955 String fmap[]; | |
956 xind = 0; | |
957 fmap = FunctionKey; | |
958 | |
959 if (shift) { | |
960 fmap = FunctionKeyShift; | |
961 xind = 1; | |
962 } | |
963 | |
964 if (control) { | |
965 fmap = FunctionKeyCtrl; | |
966 xind = 2; | |
967 } | |
968 | |
969 if (alt) { | |
970 fmap = FunctionKeyAlt; | |
971 xind = 3; | |
972 } | |
973 | |
974 switch (keyCode) { | |
975 case KEY_PAUSE: | |
976 if (shift || control) | |
977 sendTelnetCommand((byte) 243); // BREAK | |
978 | |
979 break; | |
980 | |
981 case KEY_F1: | |
982 writeSpecial(fmap[1]); | |
983 break; | |
984 | |
985 case KEY_F2: | |
986 writeSpecial(fmap[2]); | |
987 break; | |
988 | |
989 case KEY_F3: | |
990 writeSpecial(fmap[3]); | |
991 break; | |
992 | |
993 case KEY_F4: | |
994 writeSpecial(fmap[4]); | |
995 break; | |
996 | |
997 case KEY_F5: | |
998 writeSpecial(fmap[5]); | |
999 break; | |
1000 | |
1001 case KEY_F6: | |
1002 writeSpecial(fmap[6]); | |
1003 break; | |
1004 | |
1005 case KEY_F7: | |
1006 writeSpecial(fmap[7]); | |
1007 break; | |
1008 | |
1009 case KEY_F8: | |
1010 writeSpecial(fmap[8]); | |
1011 break; | |
1012 | |
1013 case KEY_F9: | |
1014 writeSpecial(fmap[9]); | |
1015 break; | |
1016 | |
1017 case KEY_F10: | |
1018 writeSpecial(fmap[10]); | |
1019 break; | |
1020 | |
1021 case KEY_F11: | |
1022 writeSpecial(fmap[11]); | |
1023 break; | |
1024 | |
1025 case KEY_F12: | |
1026 writeSpecial(fmap[12]); | |
1027 break; | |
1028 | |
1029 case KEY_UP: | |
1030 writeSpecial(KeyUp[xind]); | |
1031 break; | |
1032 | |
1033 case KEY_DOWN: | |
1034 writeSpecial(KeyDown[xind]); | |
1035 break; | |
1036 | |
1037 case KEY_LEFT: | |
1038 writeSpecial(KeyLeft[xind]); | |
1039 break; | |
1040 | |
1041 case KEY_RIGHT: | |
1042 writeSpecial(KeyRight[xind]); | |
1043 break; | |
1044 | |
1045 case KEY_PAGE_DOWN: | |
1046 writeSpecial(NextScn[xind]); | |
1047 break; | |
1048 | |
1049 case KEY_PAGE_UP: | |
1050 writeSpecial(PrevScn[xind]); | |
1051 break; | |
1052 | |
1053 case KEY_INSERT: | |
1054 writeSpecial(Insert[xind]); | |
1055 break; | |
1056 | |
1057 case KEY_DELETE: | |
1058 writeSpecial(Remove[xind]); | |
1059 break; | |
1060 | |
1061 case KEY_BACK_SPACE: | |
1062 writeSpecial(BackSpace[xind]); | |
1063 | |
1064 if (localecho) { | |
1065 if (BackSpace[xind] == "\b") { | |
1066 putString("\b \b"); // make the last char 'deleted' | |
1067 } | |
1068 else { | |
1069 putString(BackSpace[xind]); // echo it | |
1070 } | |
1071 } | |
1072 | |
1073 break; | |
1074 | |
1075 case KEY_HOME: | |
1076 writeSpecial(KeyHome[xind]); | |
1077 break; | |
1078 | |
1079 case KEY_END: | |
1080 writeSpecial(KeyEnd[xind]); | |
1081 break; | |
1082 | |
1083 case KEY_NUM_LOCK: | |
1084 if (vms && control) { | |
1085 writeSpecial(PF1); | |
1086 } | |
1087 | |
1088 if (!control) | |
1089 numlock = !numlock; | |
1090 | |
1091 break; | |
1092 | |
1093 case KEY_CAPS_LOCK: | |
1094 capslock = !capslock; | |
1095 return; | |
1096 | |
1097 case KEY_SHIFT: | |
1098 case KEY_CONTROL: | |
1099 case KEY_ALT: | |
1100 return; | |
1101 | |
1102 default: | |
1103 break; | |
1104 } | |
1105 } | |
1106 /* | |
1107 public void keyReleased(KeyEvent evt) { | |
1108 if (debug > 1) debug("keyReleased("+evt+")"); | |
1109 // ignore | |
1110 } | |
1111 */ | |
1112 /** | |
1113 * Handle key Typed events for the terminal, this will get | |
1114 * all normal key types, but no shift/alt/control/numlock. | |
1115 */ | |
1116 public void keyTyped(int keyCode, char keyChar, int modifiers) { | |
1117 boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0; | |
1118 boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0; | |
1119 boolean alt = (modifiers & VDUInput.KEY_ALT) != 0; | |
1120 | |
1121 if (debug > 1) debug("keyTyped(" + keyCode + ", " + (int)keyChar + ", " + modifiers + ")"); | |
1122 | |
1123 if (keyChar == '\t') { | |
1124 if (shift) { | |
1125 write(TabKey[1], false); | |
1126 } | |
1127 else { | |
1128 if (control) { | |
1129 write(TabKey[2], false); | |
1130 } | |
1131 else { | |
1132 if (alt) { | |
1133 write(TabKey[3], false); | |
1134 } | |
1135 else { | |
1136 write(TabKey[0], false); | |
1137 } | |
1138 } | |
1139 } | |
1140 | |
1141 return; | |
1142 } | |
1143 | |
1144 if (alt) { | |
1145 write(((char)(keyChar | 0x80))); | |
1146 return; | |
1147 } | |
1148 | |
1149 if (((keyCode == KEY_ENTER) || (keyChar == 10)) | |
1150 && !control) { | |
1151 write('\r'); | |
1152 | |
1153 if (localecho) putString("\r\n"); // bad hack | |
1154 | |
1155 return; | |
1156 } | |
1157 | |
1158 if ((keyCode == 10) && !control) { | |
1159 debug("Sending \\r"); | |
1160 write('\r'); | |
1161 return; | |
1162 } | |
1163 | |
1164 // FIXME: on german PC keyboards you have to use Alt-Ctrl-q to get an @, | |
1165 // so we can't just use it here... will probably break some other VMS | |
1166 // codes. -Marcus | |
1167 // if(((!vms && keyChar == '2') || keyChar == '@' || keyChar == ' ') | |
1168 // && control) | |
1169 if (((!vms && keyChar == '2') || keyChar == ' ') && control) | |
1170 write(0); | |
1171 | |
1172 if (vms) { | |
1173 if (keyChar == 127 && !control) { | |
1174 if (shift) | |
1175 writeSpecial(Insert[0]); // VMS shift delete = insert | |
1176 else | |
1177 writeSpecial(Remove[0]); // VMS delete = remove | |
1178 | |
1179 return; | |
1180 } | |
1181 else if (control) | |
1182 switch (keyChar) { | |
1183 case '0': | |
1184 writeSpecial(Numpad[0]); | |
1185 return; | |
1186 | |
1187 case '1': | |
1188 writeSpecial(Numpad[1]); | |
1189 return; | |
1190 | |
1191 case '2': | |
1192 writeSpecial(Numpad[2]); | |
1193 return; | |
1194 | |
1195 case '3': | |
1196 writeSpecial(Numpad[3]); | |
1197 return; | |
1198 | |
1199 case '4': | |
1200 writeSpecial(Numpad[4]); | |
1201 return; | |
1202 | |
1203 case '5': | |
1204 writeSpecial(Numpad[5]); | |
1205 return; | |
1206 | |
1207 case '6': | |
1208 writeSpecial(Numpad[6]); | |
1209 return; | |
1210 | |
1211 case '7': | |
1212 writeSpecial(Numpad[7]); | |
1213 return; | |
1214 | |
1215 case '8': | |
1216 writeSpecial(Numpad[8]); | |
1217 return; | |
1218 | |
1219 case '9': | |
1220 writeSpecial(Numpad[9]); | |
1221 return; | |
1222 | |
1223 case '.': | |
1224 writeSpecial(KPPeriod); | |
1225 return; | |
1226 | |
1227 case '-': | |
1228 case 31: | |
1229 writeSpecial(KPMinus); | |
1230 return; | |
1231 | |
1232 case '+': | |
1233 writeSpecial(KPComma); | |
1234 return; | |
1235 | |
1236 case 10: | |
1237 writeSpecial(KPEnter); | |
1238 return; | |
1239 | |
1240 case '/': | |
1241 writeSpecial(PF2); | |
1242 return; | |
1243 | |
1244 case '*': | |
1245 writeSpecial(PF3); | |
1246 return; | |
1247 | |
1248 /* NUMLOCK handled in keyPressed */ | |
1249 default: | |
1250 break; | |
1251 } | |
1252 | |
1253 /* Now what does this do and how did it get here. -Marcus | |
1254 if (shift && keyChar < 32) { | |
1255 write(PF1+(char)(keyChar + 64)); | |
1256 return; | |
1257 } | |
1258 */ | |
1259 } | |
1260 | |
1261 // FIXME: not used? | |
1262 //String fmap[]; | |
1263 int xind; | |
1264 xind = 0; | |
1265 | |
1266 //fmap = FunctionKey; | |
1267 if (shift) { | |
1268 //fmap = FunctionKeyShift; | |
1269 xind = 1; | |
1270 } | |
1271 | |
1272 if (control) { | |
1273 //fmap = FunctionKeyCtrl; | |
1274 xind = 2; | |
1275 } | |
1276 | |
1277 if (alt) { | |
1278 //fmap = FunctionKeyAlt; | |
1279 xind = 3; | |
1280 } | |
1281 | |
1282 if (keyCode == KEY_ESCAPE) { | |
1283 writeSpecial(Escape[xind]); | |
1284 return; | |
1285 } | |
1286 | |
1287 if ((modifiers & VDUInput.KEY_ACTION) != 0) | |
1288 switch (keyCode) { | |
1289 case KEY_NUMPAD0: | |
1290 writeSpecial(Numpad[0]); | |
1291 return; | |
1292 | |
1293 case KEY_NUMPAD1: | |
1294 writeSpecial(Numpad[1]); | |
1295 return; | |
1296 | |
1297 case KEY_NUMPAD2: | |
1298 writeSpecial(Numpad[2]); | |
1299 return; | |
1300 | |
1301 case KEY_NUMPAD3: | |
1302 writeSpecial(Numpad[3]); | |
1303 return; | |
1304 | |
1305 case KEY_NUMPAD4: | |
1306 writeSpecial(Numpad[4]); | |
1307 return; | |
1308 | |
1309 case KEY_NUMPAD5: | |
1310 writeSpecial(Numpad[5]); | |
1311 return; | |
1312 | |
1313 case KEY_NUMPAD6: | |
1314 writeSpecial(Numpad[6]); | |
1315 return; | |
1316 | |
1317 case KEY_NUMPAD7: | |
1318 writeSpecial(Numpad[7]); | |
1319 return; | |
1320 | |
1321 case KEY_NUMPAD8: | |
1322 writeSpecial(Numpad[8]); | |
1323 return; | |
1324 | |
1325 case KEY_NUMPAD9: | |
1326 writeSpecial(Numpad[9]); | |
1327 return; | |
1328 | |
1329 case KEY_DECIMAL: | |
1330 writeSpecial(NUMDot[xind]); | |
1331 return; | |
1332 | |
1333 case KEY_ADD: | |
1334 writeSpecial(NUMPlus[xind]); | |
1335 return; | |
1336 } | |
1337 | |
1338 if (!((keyChar == 8) || (keyChar == 127) || (keyChar == '\r') || (keyChar == '\n'))) { | |
1339 write(keyChar); | |
1340 return; | |
1341 } | |
1342 } | |
1343 | |
1344 private void handle_dcs(String dcs) { | |
1345 debugStr.append("DCS: ") | |
1346 .append(dcs); | |
1347 debug(debugStr.toString()); | |
1348 debugStr.setLength(0); | |
1349 } | |
1350 | |
1351 private void handle_osc(String osc) { | |
1352 if (osc.length() > 2 && osc.substring(0, 2).equals("4;")) { | |
1353 // Define color palette | |
1354 String[] colorData = osc.split(";"); | |
1355 | |
1356 try { | |
1357 int colorIndex = Integer.parseInt(colorData[1]); | |
1358 | |
1359 if ("rgb:".equals(colorData[2].substring(0, 4))) { | |
1360 String[] rgb = colorData[2].substring(4).split("/"); | |
1361 int red = Integer.parseInt(rgb[0].substring(0, 2), 16) & 0xFF; | |
1362 int green = Integer.parseInt(rgb[1].substring(0, 2), 16) & 0xFF; | |
1363 int blue = Integer.parseInt(rgb[2].substring(0, 2), 16) & 0xFF; | |
1364 display.setColor(colorIndex, red, green, blue); | |
1365 } | |
1366 } | |
1367 catch (Exception e) { | |
1368 debugStr.append("OSC: invalid color sequence encountered: ") | |
1369 .append(osc); | |
1370 debug(debugStr.toString()); | |
1371 debugStr.setLength(0); | |
1372 } | |
1373 } | |
1374 else | |
1375 debug("OSC: " + osc); | |
1376 } | |
1377 | |
1378 private final static char unimap[] = { | |
1379 //# | |
1380 //# Name: cp437_DOSLatinUS to Unicode table | |
1381 //# Unicode version: 1.1 | |
1382 //# Table version: 1.1 | |
1383 //# Table format: Format A | |
1384 //# Date: 03/31/95 | |
1385 //# Authors: Michel Suignard <michelsu@microsoft.com> | |
1386 //# Lori Hoerth <lorih@microsoft.com> | |
1387 //# General notes: none | |
1388 //# | |
1389 //# Format: Three tab-separated columns | |
1390 //# Column #1 is the cp1255_WinHebrew code (in hex) | |
1391 //# Column #2 is the Unicode (in hex as 0xXXXX) | |
1392 //# Column #3 is the Unicode name (follows a comment sign, '#') | |
1393 //# | |
1394 //# The entries are in cp437_DOSLatinUS order | |
1395 //# | |
1396 | |
1397 0x0000, // #NULL | |
1398 0x0001, // #START OF HEADING | |
1399 0x0002, // #START OF TEXT | |
1400 0x0003, // #END OF TEXT | |
1401 0x0004, // #END OF TRANSMISSION | |
1402 0x0005, // #ENQUIRY | |
1403 0x0006, // #ACKNOWLEDGE | |
1404 0x0007, // #BELL | |
1405 0x0008, // #BACKSPACE | |
1406 0x0009, // #HORIZONTAL TABULATION | |
1407 0x000a, // #LINE FEED | |
1408 0x000b, // #VERTICAL TABULATION | |
1409 0x000c, // #FORM FEED | |
1410 0x000d, // #CARRIAGE RETURN | |
1411 0x000e, // #SHIFT OUT | |
1412 0x000f, // #SHIFT IN | |
1413 0x0010, // #DATA LINK ESCAPE | |
1414 0x0011, // #DEVICE CONTROL ONE | |
1415 0x0012, // #DEVICE CONTROL TWO | |
1416 0x0013, // #DEVICE CONTROL THREE | |
1417 0x0014, // #DEVICE CONTROL FOUR | |
1418 0x0015, // #NEGATIVE ACKNOWLEDGE | |
1419 0x0016, // #SYNCHRONOUS IDLE | |
1420 0x0017, // #END OF TRANSMISSION BLOCK | |
1421 0x0018, // #CANCEL | |
1422 0x0019, // #END OF MEDIUM | |
1423 0x001a, // #SUBSTITUTE | |
1424 0x001b, // #ESCAPE | |
1425 0x001c, // #FILE SEPARATOR | |
1426 0x001d, // #GROUP SEPARATOR | |
1427 0x001e, // #RECORD SEPARATOR | |
1428 0x001f, // #UNIT SEPARATOR | |
1429 0x0020, // #SPACE | |
1430 0x0021, // #EXCLAMATION MARK | |
1431 0x0022, // #QUOTATION MARK | |
1432 0x0023, // #NUMBER SIGN | |
1433 0x0024, // #DOLLAR SIGN | |
1434 0x0025, // #PERCENT SIGN | |
1435 0x0026, // #AMPERSAND | |
1436 0x0027, // #APOSTROPHE | |
1437 0x0028, // #LEFT PARENTHESIS | |
1438 0x0029, // #RIGHT PARENTHESIS | |
1439 0x002a, // #ASTERISK | |
1440 0x002b, // #PLUS SIGN | |
1441 0x002c, // #COMMA | |
1442 0x002d, // #HYPHEN-MINUS | |
1443 0x002e, // #FULL STOP | |
1444 0x002f, // #SOLIDUS | |
1445 0x0030, // #DIGIT ZERO | |
1446 0x0031, // #DIGIT ONE | |
1447 0x0032, // #DIGIT TWO | |
1448 0x0033, // #DIGIT THREE | |
1449 0x0034, // #DIGIT FOUR | |
1450 0x0035, // #DIGIT FIVE | |
1451 0x0036, // #DIGIT SIX | |
1452 0x0037, // #DIGIT SEVEN | |
1453 0x0038, // #DIGIT EIGHT | |
1454 0x0039, // #DIGIT NINE | |
1455 0x003a, // #COLON | |
1456 0x003b, // #SEMICOLON | |
1457 0x003c, // #LESS-THAN SIGN | |
1458 0x003d, // #EQUALS SIGN | |
1459 0x003e, // #GREATER-THAN SIGN | |
1460 0x003f, // #QUESTION MARK | |
1461 0x0040, // #COMMERCIAL AT | |
1462 0x0041, // #LATIN CAPITAL LETTER A | |
1463 0x0042, // #LATIN CAPITAL LETTER B | |
1464 0x0043, // #LATIN CAPITAL LETTER C | |
1465 0x0044, // #LATIN CAPITAL LETTER D | |
1466 0x0045, // #LATIN CAPITAL LETTER E | |
1467 0x0046, // #LATIN CAPITAL LETTER F | |
1468 0x0047, // #LATIN CAPITAL LETTER G | |
1469 0x0048, // #LATIN CAPITAL LETTER H | |
1470 0x0049, // #LATIN CAPITAL LETTER I | |
1471 0x004a, // #LATIN CAPITAL LETTER J | |
1472 0x004b, // #LATIN CAPITAL LETTER K | |
1473 0x004c, // #LATIN CAPITAL LETTER L | |
1474 0x004d, // #LATIN CAPITAL LETTER M | |
1475 0x004e, // #LATIN CAPITAL LETTER N | |
1476 0x004f, // #LATIN CAPITAL LETTER O | |
1477 0x0050, // #LATIN CAPITAL LETTER P | |
1478 0x0051, // #LATIN CAPITAL LETTER Q | |
1479 0x0052, // #LATIN CAPITAL LETTER R | |
1480 0x0053, // #LATIN CAPITAL LETTER S | |
1481 0x0054, // #LATIN CAPITAL LETTER T | |
1482 0x0055, // #LATIN CAPITAL LETTER U | |
1483 0x0056, // #LATIN CAPITAL LETTER V | |
1484 0x0057, // #LATIN CAPITAL LETTER W | |
1485 0x0058, // #LATIN CAPITAL LETTER X | |
1486 0x0059, // #LATIN CAPITAL LETTER Y | |
1487 0x005a, // #LATIN CAPITAL LETTER Z | |
1488 0x005b, // #LEFT SQUARE BRACKET | |
1489 0x005c, // #REVERSE SOLIDUS | |
1490 0x005d, // #RIGHT SQUARE BRACKET | |
1491 0x005e, // #CIRCUMFLEX ACCENT | |
1492 0x005f, // #LOW LINE | |
1493 0x0060, // #GRAVE ACCENT | |
1494 0x0061, // #LATIN SMALL LETTER A | |
1495 0x0062, // #LATIN SMALL LETTER B | |
1496 0x0063, // #LATIN SMALL LETTER C | |
1497 0x0064, // #LATIN SMALL LETTER D | |
1498 0x0065, // #LATIN SMALL LETTER E | |
1499 0x0066, // #LATIN SMALL LETTER F | |
1500 0x0067, // #LATIN SMALL LETTER G | |
1501 0x0068, // #LATIN SMALL LETTER H | |
1502 0x0069, // #LATIN SMALL LETTER I | |
1503 0x006a, // #LATIN SMALL LETTER J | |
1504 0x006b, // #LATIN SMALL LETTER K | |
1505 0x006c, // #LATIN SMALL LETTER L | |
1506 0x006d, // #LATIN SMALL LETTER M | |
1507 0x006e, // #LATIN SMALL LETTER N | |
1508 0x006f, // #LATIN SMALL LETTER O | |
1509 0x0070, // #LATIN SMALL LETTER P | |
1510 0x0071, // #LATIN SMALL LETTER Q | |
1511 0x0072, // #LATIN SMALL LETTER R | |
1512 0x0073, // #LATIN SMALL LETTER S | |
1513 0x0074, // #LATIN SMALL LETTER T | |
1514 0x0075, // #LATIN SMALL LETTER U | |
1515 0x0076, // #LATIN SMALL LETTER V | |
1516 0x0077, // #LATIN SMALL LETTER W | |
1517 0x0078, // #LATIN SMALL LETTER X | |
1518 0x0079, // #LATIN SMALL LETTER Y | |
1519 0x007a, // #LATIN SMALL LETTER Z | |
1520 0x007b, // #LEFT CURLY BRACKET | |
1521 0x007c, // #VERTICAL LINE | |
1522 0x007d, // #RIGHT CURLY BRACKET | |
1523 0x007e, // #TILDE | |
1524 0x007f, // #DELETE | |
1525 0x00c7, // #LATIN CAPITAL LETTER C WITH CEDILLA | |
1526 0x00fc, // #LATIN SMALL LETTER U WITH DIAERESIS | |
1527 0x00e9, // #LATIN SMALL LETTER E WITH ACUTE | |
1528 0x00e2, // #LATIN SMALL LETTER A WITH CIRCUMFLEX | |
1529 0x00e4, // #LATIN SMALL LETTER A WITH DIAERESIS | |
1530 0x00e0, // #LATIN SMALL LETTER A WITH GRAVE | |
1531 0x00e5, // #LATIN SMALL LETTER A WITH RING ABOVE | |
1532 0x00e7, // #LATIN SMALL LETTER C WITH CEDILLA | |
1533 0x00ea, // #LATIN SMALL LETTER E WITH CIRCUMFLEX | |
1534 0x00eb, // #LATIN SMALL LETTER E WITH DIAERESIS | |
1535 0x00e8, // #LATIN SMALL LETTER E WITH GRAVE | |
1536 0x00ef, // #LATIN SMALL LETTER I WITH DIAERESIS | |
1537 0x00ee, // #LATIN SMALL LETTER I WITH CIRCUMFLEX | |
1538 0x00ec, // #LATIN SMALL LETTER I WITH GRAVE | |
1539 0x00c4, // #LATIN CAPITAL LETTER A WITH DIAERESIS | |
1540 0x00c5, // #LATIN CAPITAL LETTER A WITH RING ABOVE | |
1541 0x00c9, // #LATIN CAPITAL LETTER E WITH ACUTE | |
1542 0x00e6, // #LATIN SMALL LIGATURE AE | |
1543 0x00c6, // #LATIN CAPITAL LIGATURE AE | |
1544 0x00f4, // #LATIN SMALL LETTER O WITH CIRCUMFLEX | |
1545 0x00f6, // #LATIN SMALL LETTER O WITH DIAERESIS | |
1546 0x00f2, // #LATIN SMALL LETTER O WITH GRAVE | |
1547 0x00fb, // #LATIN SMALL LETTER U WITH CIRCUMFLEX | |
1548 0x00f9, // #LATIN SMALL LETTER U WITH GRAVE | |
1549 0x00ff, // #LATIN SMALL LETTER Y WITH DIAERESIS | |
1550 0x00d6, // #LATIN CAPITAL LETTER O WITH DIAERESIS | |
1551 0x00dc, // #LATIN CAPITAL LETTER U WITH DIAERESIS | |
1552 0x00a2, // #CENT SIGN | |
1553 0x00a3, // #POUND SIGN | |
1554 0x00a5, // #YEN SIGN | |
1555 0x20a7, // #PESETA SIGN | |
1556 0x0192, // #LATIN SMALL LETTER F WITH HOOK | |
1557 0x00e1, // #LATIN SMALL LETTER A WITH ACUTE | |
1558 0x00ed, // #LATIN SMALL LETTER I WITH ACUTE | |
1559 0x00f3, // #LATIN SMALL LETTER O WITH ACUTE | |
1560 0x00fa, // #LATIN SMALL LETTER U WITH ACUTE | |
1561 0x00f1, // #LATIN SMALL LETTER N WITH TILDE | |
1562 0x00d1, // #LATIN CAPITAL LETTER N WITH TILDE | |
1563 0x00aa, // #FEMININE ORDINAL INDICATOR | |
1564 0x00ba, // #MASCULINE ORDINAL INDICATOR | |
1565 0x00bf, // #INVERTED QUESTION MARK | |
1566 0x2310, // #REVERSED NOT SIGN | |
1567 0x00ac, // #NOT SIGN | |
1568 0x00bd, // #VULGAR FRACTION ONE HALF | |
1569 0x00bc, // #VULGAR FRACTION ONE QUARTER | |
1570 0x00a1, // #INVERTED EXCLAMATION MARK | |
1571 0x00ab, // #LEFT-POINTING DOUBLE ANGLE QUOTATION MARK | |
1572 0x00bb, // #RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK | |
1573 0x2591, // #LIGHT SHADE | |
1574 0x2592, // #MEDIUM SHADE | |
1575 0x2593, // #DARK SHADE | |
1576 0x2502, // #BOX DRAWINGS LIGHT VERTICAL | |
1577 0x2524, // #BOX DRAWINGS LIGHT VERTICAL AND LEFT | |
1578 0x2561, // #BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE | |
1579 0x2562, // #BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE | |
1580 0x2556, // #BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE | |
1581 0x2555, // #BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE | |
1582 0x2563, // #BOX DRAWINGS DOUBLE VERTICAL AND LEFT | |
1583 0x2551, // #BOX DRAWINGS DOUBLE VERTICAL | |
1584 0x2557, // #BOX DRAWINGS DOUBLE DOWN AND LEFT | |
1585 0x255d, // #BOX DRAWINGS DOUBLE UP AND LEFT | |
1586 0x255c, // #BOX DRAWINGS UP DOUBLE AND LEFT SINGLE | |
1587 0x255b, // #BOX DRAWINGS UP SINGLE AND LEFT DOUBLE | |
1588 0x2510, // #BOX DRAWINGS LIGHT DOWN AND LEFT | |
1589 0x2514, // #BOX DRAWINGS LIGHT UP AND RIGHT | |
1590 0x2534, // #BOX DRAWINGS LIGHT UP AND HORIZONTAL | |
1591 0x252c, // #BOX DRAWINGS LIGHT DOWN AND HORIZONTAL | |
1592 0x251c, // #BOX DRAWINGS LIGHT VERTICAL AND RIGHT | |
1593 0x2500, // #BOX DRAWINGS LIGHT HORIZONTAL | |
1594 0x253c, // #BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL | |
1595 0x255e, // #BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE | |
1596 0x255f, // #BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE | |
1597 0x255a, // #BOX DRAWINGS DOUBLE UP AND RIGHT | |
1598 0x2554, // #BOX DRAWINGS DOUBLE DOWN AND RIGHT | |
1599 0x2569, // #BOX DRAWINGS DOUBLE UP AND HORIZONTAL | |
1600 0x2566, // #BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL | |
1601 0x2560, // #BOX DRAWINGS DOUBLE VERTICAL AND RIGHT | |
1602 0x2550, // #BOX DRAWINGS DOUBLE HORIZONTAL | |
1603 0x256c, // #BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL | |
1604 0x2567, // #BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE | |
1605 0x2568, // #BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE | |
1606 0x2564, // #BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE | |
1607 0x2565, // #BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE | |
1608 0x2559, // #BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE | |
1609 0x2558, // #BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE | |
1610 0x2552, // #BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE | |
1611 0x2553, // #BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE | |
1612 0x256b, // #BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE | |
1613 0x256a, // #BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE | |
1614 0x2518, // #BOX DRAWINGS LIGHT UP AND LEFT | |
1615 0x250c, // #BOX DRAWINGS LIGHT DOWN AND RIGHT | |
1616 0x2588, // #FULL BLOCK | |
1617 0x2584, // #LOWER HALF BLOCK | |
1618 0x258c, // #LEFT HALF BLOCK | |
1619 0x2590, // #RIGHT HALF BLOCK | |
1620 0x2580, // #UPPER HALF BLOCK | |
1621 0x03b1, // #GREEK SMALL LETTER ALPHA | |
1622 0x00df, // #LATIN SMALL LETTER SHARP S | |
1623 0x0393, // #GREEK CAPITAL LETTER GAMMA | |
1624 0x03c0, // #GREEK SMALL LETTER PI | |
1625 0x03a3, // #GREEK CAPITAL LETTER SIGMA | |
1626 0x03c3, // #GREEK SMALL LETTER SIGMA | |
1627 0x00b5, // #MICRO SIGN | |
1628 0x03c4, // #GREEK SMALL LETTER TAU | |
1629 0x03a6, // #GREEK CAPITAL LETTER PHI | |
1630 0x0398, // #GREEK CAPITAL LETTER THETA | |
1631 0x03a9, // #GREEK CAPITAL LETTER OMEGA | |
1632 0x03b4, // #GREEK SMALL LETTER DELTA | |
1633 0x221e, // #INFINITY | |
1634 0x03c6, // #GREEK SMALL LETTER PHI | |
1635 0x03b5, // #GREEK SMALL LETTER EPSILON | |
1636 0x2229, // #INTERSECTION | |
1637 0x2261, // #IDENTICAL TO | |
1638 0x00b1, // #PLUS-MINUS SIGN | |
1639 0x2265, // #GREATER-THAN OR EQUAL TO | |
1640 0x2264, // #LESS-THAN OR EQUAL TO | |
1641 0x2320, // #TOP HALF INTEGRAL | |
1642 0x2321, // #BOTTOM HALF INTEGRAL | |
1643 0x00f7, // #DIVISION SIGN | |
1644 0x2248, // #ALMOST EQUAL TO | |
1645 0x00b0, // #DEGREE SIGN | |
1646 0x2219, // #BULLET OPERATOR | |
1647 0x00b7, // #MIDDLE DOT | |
1648 0x221a, // #SQUARE ROOT | |
1649 0x207f, // #SUPERSCRIPT LATIN SMALL LETTER N | |
1650 0x00b2, // #SUPERSCRIPT TWO | |
1651 0x25a0, // #BLACK SQUARE | |
1652 0x00a0, // #NO-BREAK SPACE | |
1653 }; | |
1654 | |
1655 public char map_cp850_unicode(char x) { | |
1656 if (x >= 0x100) | |
1657 return x; | |
1658 | |
1659 return unimap[x]; | |
1660 } | |
1661 | |
1662 private void _SetCursor(int row, int col) { | |
1663 int maxr = height - 1; | |
1664 int tm = getTopMargin(); | |
1665 R = (row < 0) ? 0 : row; | |
1666 C = (col < 0) ? 0 : (col >= width) ? width - 1 : col; | |
1667 | |
1668 if (!moveoutsidemargins) { | |
1669 R += tm; | |
1670 maxr = getBottomMargin(); | |
1671 } | |
1672 | |
1673 if (R > maxr) R = maxr; | |
1674 } | |
1675 | |
1676 private void putChar(char c, boolean isWide, boolean doshowcursor) { | |
1677 int rows = this.height; //statusline | |
1678 int columns = this.width; | |
1679 | |
1680 // byte msg[]; | |
1681 // if (debug > 4) { | |
1682 // debugStr.append("putChar(") | |
1683 // .append(c) | |
1684 // .append(" [") | |
1685 // .append((int) c) | |
1686 // .append("]) at R=") | |
1687 // .append(R) | |
1688 // .append(" , C=") | |
1689 // .append(C) | |
1690 // .append(", columns=") | |
1691 // .append(columns) | |
1692 // .append(", rows=") | |
1693 // .append(rows); | |
1694 // debug(debugStr.toString()); | |
1695 // debugStr.setLength(0); | |
1696 // } | |
1697 // markLine(R, 1); | |
1698 // if (c > 255) { | |
1699 // if (debug > 0) | |
1700 // debug("char > 255:" + (int) c); | |
1701 // //return; | |
1702 // } | |
1703 switch (term_state) { | |
1704 case TSTATE_DATA: | |
1705 | |
1706 /* FIXME: we shouldn't use chars with bit 8 set if ibmcharset. | |
1707 * probably... but some BBS do anyway... | |
1708 */ | |
1709 if (!useibmcharset) { | |
1710 boolean doneflag = true; | |
1711 | |
1712 switch (c) { | |
1713 case OSC: | |
1714 osc = ""; | |
1715 term_state = TSTATE_OSC; | |
1716 break; | |
1717 | |
1718 case RI: | |
1719 if (R > getTopMargin()) | |
1720 R--; | |
1721 else | |
1722 insertLine(R, 1, SCROLL_DOWN); | |
1723 | |
1724 if (debug > 1) | |
1725 debug("RI"); | |
1726 | |
1727 break; | |
1728 | |
1729 case IND: | |
1730 if (debug > 2) { | |
1731 debugStr.append("IND at ") | |
1732 .append(R) | |
1733 .append(", tm is ") | |
1734 .append(getTopMargin()) | |
1735 .append(", bm is ") | |
1736 .append(getBottomMargin()); | |
1737 debug(debugStr.toString()); | |
1738 debugStr.setLength(0); | |
1739 } | |
1740 | |
1741 if (R == getBottomMargin() || R == rows - 1) | |
1742 insertLine(R, 1, SCROLL_UP); | |
1743 else | |
1744 R++; | |
1745 | |
1746 if (debug > 1) | |
1747 debug("IND (at " + R + " )"); | |
1748 | |
1749 break; | |
1750 | |
1751 case NEL: | |
1752 if (R == getBottomMargin() || R == rows - 1) | |
1753 insertLine(R, 1, SCROLL_UP); | |
1754 else | |
1755 R++; | |
1756 | |
1757 C = 0; | |
1758 | |
1759 if (debug > 1) | |
1760 debug("NEL (at " + R + " )"); | |
1761 | |
1762 break; | |
1763 | |
1764 case HTS: | |
1765 Tabs[C] = 1; | |
1766 | |
1767 if (debug > 1) | |
1768 debug("HTS"); | |
1769 | |
1770 break; | |
1771 | |
1772 case DCS: | |
1773 dcs = ""; | |
1774 term_state = TSTATE_DCS; | |
1775 break; | |
1776 | |
1777 default: | |
1778 doneflag = false; | |
1779 break; | |
1780 } | |
1781 | |
1782 if (doneflag) break; | |
1783 } | |
1784 | |
1785 switch (c) { | |
1786 case SS3: | |
1787 onegl = 3; | |
1788 break; | |
1789 | |
1790 case SS2: | |
1791 onegl = 2; | |
1792 break; | |
1793 | |
1794 case CSI: // should be in the 8bit section, but some BBS use this | |
1795 DCEvar = 0; | |
1796 DCEvars[0] = 0; | |
1797 DCEvars[1] = 0; | |
1798 DCEvars[2] = 0; | |
1799 DCEvars[3] = 0; | |
1800 term_state = TSTATE_CSI; | |
1801 break; | |
1802 | |
1803 case ESC: | |
1804 term_state = TSTATE_ESC; | |
1805 lastwaslf = 0; | |
1806 break; | |
1807 | |
1808 case 5: /* ENQ */ | |
1809 write(answerBack, false); | |
1810 break; | |
1811 | |
1812 case 12: | |
1813 /* FormFeed, Home for the BBS world */ | |
1814 deleteArea(0, 0, columns, rows, attributes); | |
1815 C = R = 0; | |
1816 break; | |
1817 | |
1818 case '\b': /* 8 */ | |
1819 C--; | |
1820 | |
1821 if (C < 0) | |
1822 C = 0; | |
1823 | |
1824 lastwaslf = 0; | |
1825 break; | |
1826 | |
1827 case '\t': | |
1828 do { | |
1829 // Don't overwrite or insert! TABS are not destructive, but movement! | |
1830 C++; | |
1831 } | |
1832 while (C < columns && (Tabs[C] == 0)); | |
1833 | |
1834 lastwaslf = 0; | |
1835 break; | |
1836 | |
1837 case '\r': // 13 CR | |
1838 C = 0; | |
1839 break; | |
1840 | |
1841 case '\n': // 10 LF | |
1842 if (debug > 3) | |
1843 debug("R= " + R + ", bm " + getBottomMargin() + ", tm=" + getTopMargin() + ", rows=" + rows); | |
1844 | |
1845 if (!vms) { | |
1846 if (lastwaslf != 0 && lastwaslf != c) // Ray: I do not understand this logic. | |
1847 break; | |
1848 | |
1849 lastwaslf = c; | |
1850 /*C = 0;*/ | |
1851 } | |
1852 | |
1853 if (R == getBottomMargin() || R >= rows - 1) | |
1854 insertLine(R, 1, SCROLL_UP); | |
1855 else | |
1856 R++; | |
1857 | |
1858 break; | |
1859 | |
1860 case 7: | |
1861 beep(); | |
1862 break; | |
1863 | |
1864 case '\016': /* SMACS , as */ | |
1865 /* ^N, Shift out - Put G1 into GL */ | |
1866 gl = 1; | |
1867 usedcharsets = true; | |
1868 break; | |
1869 | |
1870 case '\017': /* RMACS , ae */ | |
1871 /* ^O, Shift in - Put G0 into GL */ | |
1872 gl = 0; | |
1873 usedcharsets = true; | |
1874 break; | |
1875 | |
1876 default: { | |
1877 int thisgl = gl; | |
1878 | |
1879 if (onegl >= 0) { | |
1880 thisgl = onegl; | |
1881 onegl = -1; | |
1882 } | |
1883 | |
1884 lastwaslf = 0; | |
1885 | |
1886 if (c < 32) { | |
1887 if (c != 0) | |
1888 if (debug > 0) | |
1889 debug("TSTATE_DATA char: " + ((int) c)); | |
1890 | |
1891 /*break; some BBS really want those characters, like hearst etc. */ | |
1892 if (c == 0) /* print 0 ... you bet */ | |
1893 break; | |
1894 } | |
1895 | |
1896 if (C >= columns) { | |
1897 if (wraparound) { | |
1898 int bot = rows; | |
1899 | |
1900 // If we're in the scroll region, check against the bottom margin | |
1901 if (R <= getBottomMargin() && R >= getTopMargin()) | |
1902 bot = getBottomMargin() + 1; | |
1903 | |
1904 if (R < bot - 1) | |
1905 R++; | |
1906 else { | |
1907 if (debug > 3) debug("scrolling due to wrap at " + R); | |
1908 | |
1909 insertLine(R, 1, SCROLL_UP); | |
1910 } | |
1911 | |
1912 C = 0; | |
1913 } | |
1914 else { | |
1915 // cursor stays on last character. | |
1916 C = columns - 1; | |
1917 } | |
1918 } | |
1919 | |
1920 boolean mapped = false; | |
1921 | |
1922 // Mapping if DEC Special is chosen charset | |
1923 if (usedcharsets) { | |
1924 if (c >= '\u0020' && c <= '\u007f') { | |
1925 switch (gx[thisgl]) { | |
1926 case '0': | |
1927 | |
1928 // Remap SCOANSI line drawing to VT100 line drawing chars | |
1929 // for our SCO using customers. | |
1930 if (terminalID.equals("scoansi") || terminalID.equals("ansi")) { | |
1931 for (int i = 0; i < scoansi_acs.length(); i += 2) { | |
1932 if (c == scoansi_acs.charAt(i)) { | |
1933 c = scoansi_acs.charAt(i + 1); | |
1934 break; | |
1935 } | |
1936 } | |
1937 } | |
1938 | |
1939 if (c >= '\u005f' && c <= '\u007e') { | |
1940 c = DECSPECIAL[(short) c - 0x5f]; | |
1941 mapped = true; | |
1942 } | |
1943 | |
1944 break; | |
1945 | |
1946 case '<': // 'user preferred' is currently 'ISO Latin-1 suppl | |
1947 c = (char)((c & 0x7f) | 0x80); | |
1948 mapped = true; | |
1949 break; | |
1950 | |
1951 case 'A': | |
1952 case 'B': // Latin-1 , ASCII -> fall through | |
1953 mapped = true; | |
1954 break; | |
1955 | |
1956 default: | |
1957 debug("Unsupported GL mapping: " + gx[thisgl]); | |
1958 break; | |
1959 } | |
1960 } | |
1961 | |
1962 if (!mapped && (c >= '\u0080' && c <= '\u00ff')) { | |
1963 switch (gx[gr]) { | |
1964 case '0': | |
1965 if (c >= '\u00df' && c <= '\u00fe') { | |
1966 c = DECSPECIAL[c - '\u00df']; | |
1967 mapped = true; | |
1968 } | |
1969 | |
1970 break; | |
1971 | |
1972 case '<': | |
1973 case 'A': | |
1974 case 'B': | |
1975 mapped = true; | |
1976 break; | |
1977 | |
1978 default: | |
1979 debug("Unsupported GR mapping: " + gx[gr]); | |
1980 break; | |
1981 } | |
1982 } | |
1983 } | |
1984 | |
1985 if (!mapped && useibmcharset) | |
1986 c = map_cp850_unicode(c); | |
1987 | |
1988 /*if(true || (statusmode == 0)) { */ | |
1989 if (isWide) { | |
1990 if (C >= columns - 1) { | |
1991 if (wraparound) { | |
1992 int bot = rows; | |
1993 | |
1994 // If we're in the scroll region, check against the bottom margin | |
1995 if (R <= getBottomMargin() && R >= getTopMargin()) | |
1996 bot = getBottomMargin() + 1; | |
1997 | |
1998 if (R < bot - 1) | |
1999 R++; | |
2000 else { | |
2001 if (debug > 3) debug("scrolling due to wrap at " + R); | |
2002 | |
2003 insertLine(R, 1, SCROLL_UP); | |
2004 } | |
2005 | |
2006 C = 0; | |
2007 } | |
2008 else { | |
2009 // cursor stays on last wide character. | |
2010 C = columns - 2; | |
2011 } | |
2012 } | |
2013 } | |
2014 | |
2015 if (insertmode == 1) { | |
2016 if (isWide) { | |
2017 insertChar(C++, R, c, attributes | FULLWIDTH); | |
2018 insertChar(C, R, ' ', attributes | FULLWIDTH); | |
2019 } | |
2020 else | |
2021 insertChar(C, R, c, attributes); | |
2022 } | |
2023 else { | |
2024 if (isWide) { | |
2025 putChar(C++, R, c, attributes | FULLWIDTH); | |
2026 putChar(C, R, ' ', attributes | FULLWIDTH); | |
2027 } | |
2028 else | |
2029 putChar(C, R, c, attributes); | |
2030 } | |
2031 | |
2032 /* | |
2033 } else { | |
2034 if (insertmode==1) { | |
2035 insertChar(C, rows, c, attributes); | |
2036 } else { | |
2037 putChar(C, rows, c, attributes); | |
2038 } | |
2039 } | |
2040 */ | |
2041 C++; | |
2042 break; | |
2043 } | |
2044 } /* switch(c) */ | |
2045 | |
2046 break; | |
2047 | |
2048 case TSTATE_OSC: | |
2049 if ((c < 0x20) && (c != ESC)) {// NP - No printing character | |
2050 handle_osc(osc); | |
2051 term_state = TSTATE_DATA; | |
2052 break; | |
2053 } | |
2054 | |
2055 //but check for vt102 ESC \ | |
2056 if (c == '\\' && osc.charAt(osc.length() - 1) == ESC) { | |
2057 handle_osc(osc); | |
2058 term_state = TSTATE_DATA; | |
2059 break; | |
2060 } | |
2061 | |
2062 osc = osc + c; | |
2063 break; | |
2064 | |
2065 case TSTATE_ESCSPACE: | |
2066 term_state = TSTATE_DATA; | |
2067 | |
2068 switch (c) { | |
2069 case 'F': /* S7C1T, Disable output of 8-bit controls, use 7-bit */ | |
2070 output8bit = false; | |
2071 break; | |
2072 | |
2073 case 'G': /* S8C1T, Enable output of 8-bit control codes*/ | |
2074 output8bit = true; | |
2075 break; | |
2076 | |
2077 default: | |
2078 debug("ESC <space> " + c + " unhandled."); | |
2079 } | |
2080 | |
2081 break; | |
2082 | |
2083 case TSTATE_ESC: | |
2084 term_state = TSTATE_DATA; | |
2085 | |
2086 switch (c) { | |
2087 case ' ': | |
2088 term_state = TSTATE_ESCSPACE; | |
2089 break; | |
2090 | |
2091 case '#': | |
2092 term_state = TSTATE_ESCSQUARE; | |
2093 break; | |
2094 | |
2095 case 'c': | |
2096 /* Hard terminal reset */ | |
2097 reset(); | |
2098 break; | |
2099 | |
2100 case '[': | |
2101 DCEvar = 0; | |
2102 DCEvars[0] = 0; | |
2103 DCEvars[1] = 0; | |
2104 DCEvars[2] = 0; | |
2105 DCEvars[3] = 0; | |
2106 term_state = TSTATE_CSI; | |
2107 break; | |
2108 | |
2109 case ']': | |
2110 osc = ""; | |
2111 term_state = TSTATE_OSC; | |
2112 break; | |
2113 | |
2114 case 'P': | |
2115 dcs = ""; | |
2116 term_state = TSTATE_DCS; | |
2117 break; | |
2118 | |
2119 case 'A': /* CUU */ | |
2120 R--; | |
2121 | |
2122 if (R < 0) R = 0; | |
2123 | |
2124 break; | |
2125 | |
2126 case 'B': /* CUD */ | |
2127 R++; | |
2128 | |
2129 if (R >= rows) R = rows - 1; | |
2130 | |
2131 break; | |
2132 | |
2133 case 'C': | |
2134 C++; | |
2135 | |
2136 if (C >= columns) C = columns - 1; | |
2137 | |
2138 break; | |
2139 | |
2140 case 'I': // RI | |
2141 insertLine(R, 1, SCROLL_DOWN); | |
2142 break; | |
2143 | |
2144 case 'E': /* NEL */ | |
2145 if (R == getBottomMargin() || R == rows - 1) | |
2146 insertLine(R, 1, SCROLL_UP); | |
2147 else | |
2148 R++; | |
2149 | |
2150 C = 0; | |
2151 | |
2152 if (debug > 1) | |
2153 debug("ESC E (at " + R + ")"); | |
2154 | |
2155 break; | |
2156 | |
2157 case 'D': /* IND */ | |
2158 if (R == getBottomMargin() || R == rows - 1) | |
2159 insertLine(R, 1, SCROLL_UP); | |
2160 else | |
2161 R++; | |
2162 | |
2163 if (debug > 1) | |
2164 debug("ESC D (at " + R + " )"); | |
2165 | |
2166 break; | |
2167 | |
2168 case 'J': /* erase to end of screen */ | |
2169 if (R < rows - 1) | |
2170 deleteArea(0, R + 1, columns, rows - R - 1, attributes); | |
2171 | |
2172 if (C < columns - 1) | |
2173 deleteArea(C, R, columns - C, 1, attributes); | |
2174 | |
2175 break; | |
2176 | |
2177 case 'K': | |
2178 if (C < columns - 1) | |
2179 deleteArea(C, R, columns - C, 1, attributes); | |
2180 | |
2181 break; | |
2182 | |
2183 case 'M': // RI | |
2184 debug("ESC M : R is " + R + ", tm is " + getTopMargin() + ", bm is " + getBottomMargin()); | |
2185 | |
2186 if (R > getTopMargin()) { // just go up 1 line. | |
2187 R--; | |
2188 } | |
2189 else { // scroll down | |
2190 insertLine(R, 1, SCROLL_DOWN); | |
2191 } | |
2192 | |
2193 /* else do nothing ; */ | |
2194 if (debug > 2) | |
2195 debug("ESC M "); | |
2196 | |
2197 break; | |
2198 | |
2199 case 'H': | |
2200 if (debug > 1) | |
2201 debug("ESC H at " + C); | |
2202 | |
2203 /* right border probably ...*/ | |
2204 if (C >= columns) | |
2205 C = columns - 1; | |
2206 | |
2207 Tabs[C] = 1; | |
2208 break; | |
2209 | |
2210 case 'N': // SS2 | |
2211 onegl = 2; | |
2212 break; | |
2213 | |
2214 case 'O': // SS3 | |
2215 onegl = 3; | |
2216 break; | |
2217 | |
2218 case '=': | |
2219 | |
2220 /*application keypad*/ | |
2221 if (debug > 0) | |
2222 debug("ESC ="); | |
2223 | |
2224 keypadmode = true; | |
2225 break; | |
2226 | |
2227 case '<': /* vt52 mode off */ | |
2228 vt52mode = false; | |
2229 break; | |
2230 | |
2231 case '>': /*normal keypad*/ | |
2232 if (debug > 0) | |
2233 debug("ESC >"); | |
2234 | |
2235 keypadmode = false; | |
2236 break; | |
2237 | |
2238 case '7': /* DECSC: save cursor, attributes */ | |
2239 Sc = C; | |
2240 Sr = R; | |
2241 Sgl = gl; | |
2242 Sgr = gr; | |
2243 Sa = attributes; | |
2244 Sgx = new char[4]; | |
2245 | |
2246 for (int i = 0; i < 4; i++) Sgx[i] = gx[i]; | |
2247 | |
2248 if (debug > 1) | |
2249 debug("ESC 7"); | |
2250 | |
2251 break; | |
2252 | |
2253 case '8': /* DECRC: restore cursor, attributes */ | |
2254 C = Sc; | |
2255 R = Sr; | |
2256 gl = Sgl; | |
2257 gr = Sgr; | |
2258 | |
2259 if (Sgx != null) | |
2260 for (int i = 0; i < 4; i++) gx[i] = Sgx[i]; | |
2261 | |
2262 attributes = Sa; | |
2263 | |
2264 if (debug > 1) | |
2265 debug("ESC 8"); | |
2266 | |
2267 break; | |
2268 | |
2269 case '(': /* Designate G0 Character set (ISO 2022) */ | |
2270 term_state = TSTATE_SETG0; | |
2271 usedcharsets = true; | |
2272 break; | |
2273 | |
2274 case ')': /* Designate G1 character set (ISO 2022) */ | |
2275 term_state = TSTATE_SETG1; | |
2276 usedcharsets = true; | |
2277 break; | |
2278 | |
2279 case '*': /* Designate G2 Character set (ISO 2022) */ | |
2280 term_state = TSTATE_SETG2; | |
2281 usedcharsets = true; | |
2282 break; | |
2283 | |
2284 case '+': /* Designate G3 Character set (ISO 2022) */ | |
2285 term_state = TSTATE_SETG3; | |
2286 usedcharsets = true; | |
2287 break; | |
2288 | |
2289 case '~': /* Locking Shift 1, right */ | |
2290 gr = 1; | |
2291 usedcharsets = true; | |
2292 break; | |
2293 | |
2294 case 'n': /* Locking Shift 2 */ | |
2295 gl = 2; | |
2296 usedcharsets = true; | |
2297 break; | |
2298 | |
2299 case '}': /* Locking Shift 2, right */ | |
2300 gr = 2; | |
2301 usedcharsets = true; | |
2302 break; | |
2303 | |
2304 case 'o': /* Locking Shift 3 */ | |
2305 gl = 3; | |
2306 usedcharsets = true; | |
2307 break; | |
2308 | |
2309 case '|': /* Locking Shift 3, right */ | |
2310 gr = 3; | |
2311 usedcharsets = true; | |
2312 break; | |
2313 | |
2314 case 'Y': /* vt52 cursor address mode , next chars are x,y */ | |
2315 term_state = TSTATE_VT52Y; | |
2316 break; | |
2317 | |
2318 case '_': | |
2319 term_state = TSTATE_TITLE; | |
2320 break; | |
2321 | |
2322 case '\\': | |
2323 // TODO save title | |
2324 term_state = TSTATE_DATA; | |
2325 break; | |
2326 | |
2327 default: | |
2328 debug("ESC unknown letter: " + c + " (" + ((int) c) + ")"); | |
2329 break; | |
2330 } | |
2331 | |
2332 break; | |
2333 | |
2334 case TSTATE_VT52X: | |
2335 C = c - 37; | |
2336 | |
2337 if (C < 0) | |
2338 C = 0; | |
2339 else if (C >= width) | |
2340 C = width - 1; | |
2341 | |
2342 term_state = TSTATE_VT52Y; | |
2343 break; | |
2344 | |
2345 case TSTATE_VT52Y: | |
2346 R = c - 37; | |
2347 | |
2348 if (R < 0) | |
2349 R = 0; | |
2350 else if (R >= height) | |
2351 R = height - 1; | |
2352 | |
2353 term_state = TSTATE_DATA; | |
2354 break; | |
2355 | |
2356 case TSTATE_SETG0: | |
2357 if (c != '0' && c != 'A' && c != 'B' && c != '<') | |
2358 debug("ESC ( " + c + ": G0 char set? (" + ((int) c) + ")"); | |
2359 else { | |
2360 if (debug > 2) debug("ESC ( : G0 char set (" + c + " " + ((int) c) + ")"); | |
2361 | |
2362 gx[0] = c; | |
2363 } | |
2364 | |
2365 term_state = TSTATE_DATA; | |
2366 break; | |
2367 | |
2368 case TSTATE_SETG1: | |
2369 if (c != '0' && c != 'A' && c != 'B' && c != '<') { | |
2370 debug("ESC ) " + c + " (" + ((int) c) + ") :G1 char set?"); | |
2371 } | |
2372 else { | |
2373 if (debug > 2) debug("ESC ) :G1 char set (" + c + " " + ((int) c) + ")"); | |
2374 | |
2375 gx[1] = c; | |
2376 } | |
2377 | |
2378 term_state = TSTATE_DATA; | |
2379 break; | |
2380 | |
2381 case TSTATE_SETG2: | |
2382 if (c != '0' && c != 'A' && c != 'B' && c != '<') | |
2383 debug("ESC*:G2 char set? (" + ((int) c) + ")"); | |
2384 else { | |
2385 if (debug > 2) debug("ESC*:G2 char set (" + c + " " + ((int) c) + ")"); | |
2386 | |
2387 gx[2] = c; | |
2388 } | |
2389 | |
2390 term_state = TSTATE_DATA; | |
2391 break; | |
2392 | |
2393 case TSTATE_SETG3: | |
2394 if (c != '0' && c != 'A' && c != 'B' && c != '<') | |
2395 debug("ESC+:G3 char set? (" + ((int) c) + ")"); | |
2396 else { | |
2397 if (debug > 2) debug("ESC+:G3 char set (" + c + " " + ((int) c) + ")"); | |
2398 | |
2399 gx[3] = c; | |
2400 } | |
2401 | |
2402 term_state = TSTATE_DATA; | |
2403 break; | |
2404 | |
2405 case TSTATE_ESCSQUARE: | |
2406 switch (c) { | |
2407 case '8': | |
2408 for (int i = 0; i < columns; i++) | |
2409 for (int j = 0; j < rows; j++) | |
2410 putChar(i, j, 'E', 0); | |
2411 | |
2412 break; | |
2413 | |
2414 default: | |
2415 debug("ESC # " + c + " not supported."); | |
2416 break; | |
2417 } | |
2418 | |
2419 term_state = TSTATE_DATA; | |
2420 break; | |
2421 | |
2422 case TSTATE_DCS: | |
2423 if (c == '\\' && dcs.charAt(dcs.length() - 1) == ESC) { | |
2424 handle_dcs(dcs); | |
2425 term_state = TSTATE_DATA; | |
2426 break; | |
2427 } | |
2428 | |
2429 dcs = dcs + c; | |
2430 break; | |
2431 | |
2432 case TSTATE_DCEQ: | |
2433 term_state = TSTATE_DATA; | |
2434 | |
2435 switch (c) { | |
2436 case '0': | |
2437 case '1': | |
2438 case '2': | |
2439 case '3': | |
2440 case '4': | |
2441 case '5': | |
2442 case '6': | |
2443 case '7': | |
2444 case '8': | |
2445 case '9': | |
2446 DCEvars[DCEvar] = DCEvars[DCEvar] * 10 + (c) - 48; | |
2447 term_state = TSTATE_DCEQ; | |
2448 break; | |
2449 | |
2450 case ';': | |
2451 DCEvar++; | |
2452 DCEvars[DCEvar] = 0; | |
2453 term_state = TSTATE_DCEQ; | |
2454 break; | |
2455 | |
2456 case 's': // XTERM_SAVE missing! | |
2457 if (true || debug > 1) | |
2458 debug("ESC [ ? " + DCEvars[0] + " s unimplemented!"); | |
2459 | |
2460 break; | |
2461 | |
2462 case 'r': // XTERM_RESTORE | |
2463 if (true || debug > 1) | |
2464 debug("ESC [ ? " + DCEvars[0] + " r"); | |
2465 | |
2466 /* DEC Mode reset */ | |
2467 for (int i = 0; i <= DCEvar; i++) { | |
2468 switch (DCEvars[i]) { | |
2469 case 3: /* 80 columns*/ | |
2470 setScreenSize(80, height, true); | |
2471 break; | |
2472 | |
2473 case 4: /* scrolling mode, smooth */ | |
2474 break; | |
2475 | |
2476 case 5: /* light background */ | |
2477 break; | |
2478 | |
2479 case 6: /* DECOM (Origin Mode) move inside margins. */ | |
2480 moveoutsidemargins = true; | |
2481 break; | |
2482 | |
2483 case 7: /* DECAWM: Autowrap Mode */ | |
2484 wraparound = false; | |
2485 break; | |
2486 | |
2487 case 12:/* local echo off */ | |
2488 break; | |
2489 | |
2490 case 9: /* X10 mouse */ | |
2491 case 1000: /* xterm style mouse report on */ | |
2492 case 1001: | |
2493 case 1002: | |
2494 case 1003: | |
2495 mouserpt = DCEvars[i]; | |
2496 break; | |
2497 | |
2498 default: | |
2499 debug("ESC [ ? " + DCEvars[0] + " r, unimplemented!"); | |
2500 } | |
2501 } | |
2502 | |
2503 break; | |
2504 | |
2505 case 'h': // DECSET | |
2506 if (debug > 0) | |
2507 debug("ESC [ ? " + DCEvars[0] + " h"); | |
2508 | |
2509 /* DEC Mode set */ | |
2510 for (int i = 0; i <= DCEvar; i++) { | |
2511 switch (DCEvars[i]) { | |
2512 case 1: /* Application cursor keys */ | |
2513 KeyUp[0] = "\u001bOA"; | |
2514 KeyDown[0] = "\u001bOB"; | |
2515 KeyRight[0] = "\u001bOC"; | |
2516 KeyLeft[0] = "\u001bOD"; | |
2517 break; | |
2518 | |
2519 case 2: /* DECANM */ | |
2520 vt52mode = false; | |
2521 break; | |
2522 | |
2523 case 3: /* 132 columns*/ | |
2524 setScreenSize(132, height, true); | |
2525 break; | |
2526 | |
2527 case 6: /* DECOM: move inside margins. */ | |
2528 moveoutsidemargins = false; | |
2529 break; | |
2530 | |
2531 case 7: /* DECAWM: Autowrap Mode */ | |
2532 wraparound = true; | |
2533 break; | |
2534 | |
2535 case 25: /* turn cursor on */ | |
2536 showCursor(true); | |
2537 break; | |
2538 | |
2539 case 9: /* X10 mouse */ | |
2540 case 1000: /* xterm style mouse report on */ | |
2541 case 1001: | |
2542 case 1002: | |
2543 case 1003: | |
2544 mouserpt = DCEvars[i]; | |
2545 break; | |
2546 | |
2547 /* unimplemented stuff, fall through */ | |
2548 /* 4 - scrolling mode, smooth */ | |
2549 /* 5 - light background */ | |
2550 /* 12 - local echo off */ | |
2551 /* 18 - DECPFF - Printer Form Feed Mode -> On */ | |
2552 /* 19 - DECPEX - Printer Extent Mode -> Screen */ | |
2553 default: | |
2554 debug("ESC [ ? " + DCEvars[0] + " h, unsupported."); | |
2555 break; | |
2556 } | |
2557 } | |
2558 | |
2559 break; | |
2560 | |
2561 case 'i': // DEC Printer Control, autoprint, echo screenchars to printer | |
2562 | |
2563 // This is different to CSI i! | |
2564 // Also: "Autoprint prints a final display line only when the | |
2565 // cursor is moved off the line by an autowrap or LF, FF, or | |
2566 // VT (otherwise do not print the line)." | |
2567 switch (DCEvars[0]) { | |
2568 case 1: | |
2569 if (debug > 1) | |
2570 debug("CSI ? 1 i : Print line containing cursor"); | |
2571 | |
2572 break; | |
2573 | |
2574 case 4: | |
2575 if (debug > 1) | |
2576 debug("CSI ? 4 i : Start passthrough printing"); | |
2577 | |
2578 break; | |
2579 | |
2580 case 5: | |
2581 if (debug > 1) | |
2582 debug("CSI ? 4 i : Stop passthrough printing"); | |
2583 | |
2584 break; | |
2585 } | |
2586 | |
2587 break; | |
2588 | |
2589 case 'l': //DECRST | |
2590 | |
2591 /* DEC Mode reset */ | |
2592 if (debug > 0) | |
2593 debug("ESC [ ? " + DCEvars[0] + " l"); | |
2594 | |
2595 for (int i = 0; i <= DCEvar; i++) { | |
2596 switch (DCEvars[i]) { | |
2597 case 1: /* Application cursor keys */ | |
2598 KeyUp[0] = "\u001b[A"; | |
2599 KeyDown[0] = "\u001b[B"; | |
2600 KeyRight[0] = "\u001b[C"; | |
2601 KeyLeft[0] = "\u001b[D"; | |
2602 break; | |
2603 | |
2604 case 2: /* DECANM */ | |
2605 vt52mode = true; | |
2606 break; | |
2607 | |
2608 case 3: /* 80 columns*/ | |
2609 setScreenSize(80, height, true); | |
2610 break; | |
2611 | |
2612 case 6: /* DECOM: move outside margins. */ | |
2613 moveoutsidemargins = true; | |
2614 break; | |
2615 | |
2616 case 7: /* DECAWM: Autowrap Mode OFF */ | |
2617 wraparound = false; | |
2618 break; | |
2619 | |
2620 case 25: /* turn cursor off */ | |
2621 showCursor(false); | |
2622 break; | |
2623 | |
2624 /* Unimplemented stuff: */ | |
2625 /* 4 - scrolling mode, jump */ | |
2626 /* 5 - dark background */ | |
2627 /* 7 - DECAWM - no wrap around mode */ | |
2628 /* 12 - local echo on */ | |
2629 /* 18 - DECPFF - Printer Form Feed Mode -> Off*/ | |
2630 /* 19 - DECPEX - Printer Extent Mode -> Scrolling Region */ | |
2631 case 9: /* X10 mouse */ | |
2632 case 1000: /* xterm style mouse report OFF */ | |
2633 case 1001: | |
2634 case 1002: | |
2635 case 1003: | |
2636 mouserpt = 0; | |
2637 break; | |
2638 | |
2639 default: | |
2640 debug("ESC [ ? " + DCEvars[0] + " l, unsupported."); | |
2641 break; | |
2642 } | |
2643 } | |
2644 | |
2645 break; | |
2646 | |
2647 case 'n': | |
2648 if (debug > 0) | |
2649 debug("ESC [ ? " + DCEvars[0] + " n"); | |
2650 | |
2651 switch (DCEvars[0]) { | |
2652 case 15: | |
2653 /* printer? no printer. */ | |
2654 write((ESC) + "[?13n", false); | |
2655 debug("ESC[5n"); | |
2656 break; | |
2657 | |
2658 default: | |
2659 debug("ESC [ ? " + DCEvars[0] + " n, unsupported."); | |
2660 break; | |
2661 } | |
2662 | |
2663 break; | |
2664 | |
2665 default: | |
2666 debug("ESC [ ? " + DCEvars[0] + " " + c + ", unsupported."); | |
2667 break; | |
2668 } | |
2669 | |
2670 break; | |
2671 | |
2672 case TSTATE_CSI_EX: | |
2673 term_state = TSTATE_DATA; | |
2674 | |
2675 switch (c) { | |
2676 case ESC: | |
2677 term_state = TSTATE_ESC; | |
2678 break; | |
2679 | |
2680 default: | |
2681 debug("Unknown character ESC[! character is " + (int) c); | |
2682 break; | |
2683 } | |
2684 | |
2685 break; | |
2686 | |
2687 case TSTATE_CSI_TICKS: | |
2688 term_state = TSTATE_DATA; | |
2689 | |
2690 switch (c) { | |
2691 case 'p': | |
2692 debug("Conformance level: " + DCEvars[0] + " (unsupported)," + DCEvars[1]); | |
2693 | |
2694 if (DCEvars[0] == 61) { | |
2695 output8bit = false; | |
2696 break; | |
2697 } | |
2698 | |
2699 if (DCEvars[1] == 1) { | |
2700 output8bit = false; | |
2701 } | |
2702 else { | |
2703 output8bit = true; /* 0 or 2 */ | |
2704 } | |
2705 | |
2706 break; | |
2707 | |
2708 default: | |
2709 debug("Unknown ESC [... \"" + c); | |
2710 break; | |
2711 } | |
2712 | |
2713 break; | |
2714 | |
2715 case TSTATE_CSI_EQUAL: | |
2716 term_state = TSTATE_DATA; | |
2717 | |
2718 switch (c) { | |
2719 case '0': | |
2720 case '1': | |
2721 case '2': | |
2722 case '3': | |
2723 case '4': | |
2724 case '5': | |
2725 case '6': | |
2726 case '7': | |
2727 case '8': | |
2728 case '9': | |
2729 DCEvars[DCEvar] = DCEvars[DCEvar] * 10 + (c) - 48; | |
2730 term_state = TSTATE_CSI_EQUAL; | |
2731 break; | |
2732 | |
2733 case ';': | |
2734 DCEvar++; | |
2735 DCEvars[DCEvar] = 0; | |
2736 term_state = TSTATE_CSI_EQUAL; | |
2737 break; | |
2738 | |
2739 case 'F': { /* SCO ANSI foreground */ | |
2740 int newcolor; | |
2741 debug("ESC [ = " + DCEvars[0] + " F"); | |
2742 attributes &= ~COLOR_FG; | |
2743 newcolor = ((DCEvars[0] & 1) << 2) | | |
2744 (DCEvars[0] & 2) | | |
2745 ((DCEvars[0] & 4) >> 2) ; | |
2746 attributes |= (newcolor + 1) << COLOR_FG_SHIFT; | |
2747 break; | |
2748 } | |
2749 | |
2750 case 'G': { /* SCO ANSI background */ | |
2751 int newcolor; | |
2752 debug("ESC [ = " + DCEvars[0] + " G"); | |
2753 attributes &= ~COLOR_BG; | |
2754 newcolor = ((DCEvars[0] & 1) << 2) | | |
2755 (DCEvars[0] & 2) | | |
2756 ((DCEvars[0] & 4) >> 2) ; | |
2757 attributes |= (newcolor + 1) << COLOR_BG_SHIFT; | |
2758 break; | |
2759 } | |
2760 | |
2761 default: | |
2762 debugStr.append("Unknown ESC [ = "); | |
2763 | |
2764 for (int i = 0; i <= DCEvar; i++) { | |
2765 debugStr.append(DCEvars[i]) | |
2766 .append(','); | |
2767 } | |
2768 | |
2769 debugStr.append(c); | |
2770 debug(debugStr.toString()); | |
2771 debugStr.setLength(0); | |
2772 break; | |
2773 } | |
2774 | |
2775 break; | |
2776 | |
2777 case TSTATE_CSI_DOLLAR: | |
2778 term_state = TSTATE_DATA; | |
2779 | |
2780 switch (c) { | |
2781 case '}': | |
2782 debug("Active Status Display now " + DCEvars[0]); | |
2783 statusmode = DCEvars[0]; | |
2784 break; | |
2785 | |
2786 /* bad documentation? | |
2787 case '-': | |
2788 debug("Set Status Display now "+DCEvars[0]); | |
2789 break; | |
2790 */ | |
2791 case '~': | |
2792 debug("Status Line mode now " + DCEvars[0]); | |
2793 break; | |
2794 | |
2795 default: | |
2796 debug("UNKNOWN Status Display code " + c + ", with Pn=" + DCEvars[0]); | |
2797 break; | |
2798 } | |
2799 | |
2800 break; | |
2801 | |
2802 case TSTATE_CSI: | |
2803 term_state = TSTATE_DATA; | |
2804 | |
2805 switch (c) { | |
2806 case '"': | |
2807 term_state = TSTATE_CSI_TICKS; | |
2808 break; | |
2809 | |
2810 case '$': | |
2811 term_state = TSTATE_CSI_DOLLAR; | |
2812 break; | |
2813 | |
2814 case '=': | |
2815 term_state = TSTATE_CSI_EQUAL; | |
2816 break; | |
2817 | |
2818 case '!': | |
2819 term_state = TSTATE_CSI_EX; | |
2820 break; | |
2821 | |
2822 case '?': | |
2823 DCEvar = 0; | |
2824 DCEvars[0] = 0; | |
2825 term_state = TSTATE_DCEQ; | |
2826 break; | |
2827 | |
2828 case '0': | |
2829 case '1': | |
2830 case '2': | |
2831 case '3': | |
2832 case '4': | |
2833 case '5': | |
2834 case '6': | |
2835 case '7': | |
2836 case '8': | |
2837 case '9': | |
2838 DCEvars[DCEvar] = DCEvars[DCEvar] * 10 + (c) - 48; | |
2839 term_state = TSTATE_CSI; | |
2840 break; | |
2841 | |
2842 case ';': | |
2843 DCEvar++; | |
2844 DCEvars[DCEvar] = 0; | |
2845 term_state = TSTATE_CSI; | |
2846 break; | |
2847 | |
2848 case 'c':/* send primary device attributes */ | |
2849 /* send (ESC[?61c) */ | |
2850 String subcode = ""; | |
2851 | |
2852 if (terminalID.equals("vt320")) subcode = "63;"; | |
2853 | |
2854 if (terminalID.equals("vt220")) subcode = "62;"; | |
2855 | |
2856 if (terminalID.equals("vt100")) subcode = "61;"; | |
2857 | |
2858 write((ESC) + "[?" + subcode + "1;2c", false); | |
2859 | |
2860 if (debug > 1) | |
2861 debug("ESC [ " + DCEvars[0] + " c"); | |
2862 | |
2863 break; | |
2864 | |
2865 case 'q': | |
2866 if (debug > 1) | |
2867 debug("ESC [ " + DCEvars[0] + " q"); | |
2868 | |
2869 break; | |
2870 | |
2871 case 'g': | |
2872 | |
2873 /* used for tabsets */ | |
2874 switch (DCEvars[0]) { | |
2875 case 3:/* clear them */ | |
2876 Tabs = new byte[width]; | |
2877 break; | |
2878 | |
2879 case 0: | |
2880 Tabs[C] = 0; | |
2881 break; | |
2882 } | |
2883 | |
2884 if (debug > 1) | |
2885 debug("ESC [ " + DCEvars[0] + " g"); | |
2886 | |
2887 break; | |
2888 | |
2889 case 'h': | |
2890 switch (DCEvars[0]) { | |
2891 case 4: | |
2892 insertmode = 1; | |
2893 break; | |
2894 | |
2895 case 20: | |
2896 debug("Setting CRLF to TRUE"); | |
2897 sendcrlf = true; | |
2898 break; | |
2899 | |
2900 default: | |
2901 debug("unsupported: ESC [ " + DCEvars[0] + " h"); | |
2902 break; | |
2903 } | |
2904 | |
2905 if (debug > 1) | |
2906 debug("ESC [ " + DCEvars[0] + " h"); | |
2907 | |
2908 break; | |
2909 | |
2910 case 'i': // Printer Controller mode. | |
2911 | |
2912 // "Transparent printing sends all output, except the CSI 4 i | |
2913 // termination string, to the printer and not the screen, | |
2914 // uses an 8-bit channel if no parity so NUL and DEL will be | |
2915 // seen by the printer and by the termination recognizer code, | |
2916 // and all translation and character set selections are | |
2917 // bypassed." | |
2918 switch (DCEvars[0]) { | |
2919 case 0: | |
2920 if (debug > 1) | |
2921 debug("CSI 0 i: Print Screen, not implemented."); | |
2922 | |
2923 break; | |
2924 | |
2925 case 4: | |
2926 if (debug > 1) | |
2927 debug("CSI 4 i: Enable Transparent Printing, not implemented."); | |
2928 | |
2929 break; | |
2930 | |
2931 case 5: | |
2932 if (debug > 1) | |
2933 debug("CSI 4/5 i: Disable Transparent Printing, not implemented."); | |
2934 | |
2935 break; | |
2936 | |
2937 default: | |
2938 debug("ESC [ " + DCEvars[0] + " i, unimplemented!"); | |
2939 } | |
2940 | |
2941 break; | |
2942 | |
2943 case 'l': | |
2944 switch (DCEvars[0]) { | |
2945 case 4: | |
2946 insertmode = 0; | |
2947 break; | |
2948 | |
2949 case 20: | |
2950 debug("Setting CRLF to FALSE"); | |
2951 sendcrlf = false; | |
2952 break; | |
2953 | |
2954 default: | |
2955 debug("ESC [ " + DCEvars[0] + " l, unimplemented!"); | |
2956 break; | |
2957 } | |
2958 | |
2959 break; | |
2960 | |
2961 case 'A': { // CUU | |
2962 int limit; | |
2963 | |
2964 /* FIXME: xterm only cares about 0 and topmargin */ | |
2965 if (R >= getTopMargin()) { | |
2966 limit = getTopMargin(); | |
2967 } | |
2968 else | |
2969 limit = 0; | |
2970 | |
2971 if (DCEvars[0] == 0) | |
2972 R--; | |
2973 else | |
2974 R -= DCEvars[0]; | |
2975 | |
2976 if (R < limit) | |
2977 R = limit; | |
2978 | |
2979 if (debug > 1) | |
2980 debug("ESC [ " + DCEvars[0] + " A"); | |
2981 | |
2982 break; | |
2983 } | |
2984 | |
2985 case 'B': // CUD | |
2986 /* cursor down n (1) times */ | |
2987 { | |
2988 int limit; | |
2989 | |
2990 if (R <= getBottomMargin()) { | |
2991 limit = getBottomMargin(); | |
2992 } | |
2993 else | |
2994 limit = rows - 1; | |
2995 | |
2996 if (DCEvars[0] == 0) | |
2997 R++; | |
2998 else | |
2999 R += DCEvars[0]; | |
3000 | |
3001 if (R > limit) | |
3002 R = limit; | |
3003 else { | |
3004 if (debug > 2) debug("Not limited."); | |
3005 } | |
3006 | |
3007 if (debug > 2) debug("to: " + R); | |
3008 | |
3009 if (debug > 1) | |
3010 debug("ESC [ " + DCEvars[0] + " B (at C=" + C + ")"); | |
3011 | |
3012 break; | |
3013 } | |
3014 | |
3015 case 'C': | |
3016 if (DCEvars[0] == 0) | |
3017 DCEvars[0] = 1; | |
3018 | |
3019 while (DCEvars[0]-- > 0) { | |
3020 C++; | |
3021 } | |
3022 | |
3023 if (C >= columns) | |
3024 C = columns - 1; | |
3025 | |
3026 if (debug > 1) | |
3027 debug("ESC [ " + DCEvars[0] + " C"); | |
3028 | |
3029 break; | |
3030 | |
3031 case 'd': // CVA | |
3032 R = DCEvars[0] - 1; | |
3033 | |
3034 if (R < 0) | |
3035 R = 0; | |
3036 else if (R >= height) | |
3037 R = height - 1; | |
3038 | |
3039 if (debug > 1) | |
3040 debug("ESC [ " + DCEvars[0] + " d"); | |
3041 | |
3042 break; | |
3043 | |
3044 case 'D': | |
3045 if (DCEvars[0] == 0) | |
3046 DCEvars[0] = 1; | |
3047 | |
3048 while (DCEvars[0]-- > 0) { | |
3049 C--; | |
3050 } | |
3051 | |
3052 if (C < 0) C = 0; | |
3053 | |
3054 if (debug > 1) | |
3055 debug("ESC [ " + DCEvars[0] + " D"); | |
3056 | |
3057 break; | |
3058 | |
3059 case 'r': // DECSTBM | |
3060 if (DCEvar > 0) { // Ray: Any argument is optional | |
3061 R = DCEvars[1] - 1; | |
3062 | |
3063 if (R < 0) | |
3064 R = rows - 1; | |
3065 else if (R >= rows) { | |
3066 R = rows - 1; | |
3067 } | |
3068 } | |
3069 else | |
3070 R = rows - 1; | |
3071 | |
3072 int bot = R; | |
3073 | |
3074 if (R >= DCEvars[0]) { | |
3075 R = DCEvars[0] - 1; | |
3076 | |
3077 if (R < 0) | |
3078 R = 0; | |
3079 } | |
3080 | |
3081 setMargins(R, bot); | |
3082 _SetCursor(0, 0); | |
3083 | |
3084 if (debug > 1) | |
3085 debug("ESC [" + DCEvars[0] + " ; " + DCEvars[1] + " r"); | |
3086 | |
3087 break; | |
3088 | |
3089 case 'G': /* CUP / cursor absolute column */ | |
3090 C = DCEvars[0]; | |
3091 | |
3092 if (C < 0) | |
3093 C = 0; | |
3094 else if (C >= width) | |
3095 C = width - 1; | |
3096 | |
3097 if (debug > 1) debug("ESC [ " + DCEvars[0] + " G"); | |
3098 | |
3099 break; | |
3100 | |
3101 case 'H': /* CUP / cursor position */ | |
3102 /* gets 2 arguments */ | |
3103 _SetCursor(DCEvars[0] - 1, DCEvars[1] - 1); | |
3104 | |
3105 if (debug > 2) { | |
3106 debug("ESC [ " + DCEvars[0] + ";" + DCEvars[1] + " H, moveoutsidemargins " + moveoutsidemargins); | |
3107 debug(" -> R now " + R + ", C now " + C); | |
3108 } | |
3109 | |
3110 break; | |
3111 | |
3112 case 'f': /* move cursor 2 */ | |
3113 /* gets 2 arguments */ | |
3114 R = DCEvars[0] - 1; | |
3115 C = DCEvars[1] - 1; | |
3116 | |
3117 if (C < 0) | |
3118 C = 0; | |
3119 else if (C >= width) | |
3120 C = width - 1; | |
3121 | |
3122 if (R < 0) | |
3123 R = 0; | |
3124 else if (R >= height) | |
3125 R = height - 1; | |
3126 | |
3127 if (debug > 2) | |
3128 debug("ESC [ " + DCEvars[0] + ";" + DCEvars[1] + " f"); | |
3129 | |
3130 break; | |
3131 | |
3132 case 'S': /* ind aka 'scroll forward' */ | |
3133 if (DCEvars[0] == 0) | |
3134 insertLine(getBottomMargin(), SCROLL_UP); | |
3135 else | |
3136 insertLine(getBottomMargin(), DCEvars[0], SCROLL_UP); | |
3137 | |
3138 break; | |
3139 | |
3140 case 'L': | |
3141 | |
3142 /* insert n lines */ | |
3143 if (DCEvars[0] == 0) | |
3144 insertLine(R, SCROLL_DOWN); | |
3145 else | |
3146 insertLine(R, DCEvars[0], SCROLL_DOWN); | |
3147 | |
3148 if (debug > 1) | |
3149 debug("ESC [ " + DCEvars[0] + "" + (c) + " (at R " + R + ")"); | |
3150 | |
3151 break; | |
3152 | |
3153 case 'T': /* 'ri' aka scroll backward */ | |
3154 if (DCEvars[0] == 0) | |
3155 insertLine(getTopMargin(), SCROLL_DOWN); | |
3156 else | |
3157 insertLine(getTopMargin(), DCEvars[0], SCROLL_DOWN); | |
3158 | |
3159 break; | |
3160 | |
3161 case 'M': | |
3162 if (debug > 1) | |
3163 debug("ESC [ " + DCEvars[0] + "" + (c) + " at R=" + R); | |
3164 | |
3165 if (DCEvars[0] == 0) | |
3166 deleteLine(R); | |
3167 else | |
3168 for (int i = 0; i < DCEvars[0]; i++) | |
3169 deleteLine(R); | |
3170 | |
3171 break; | |
3172 | |
3173 case 'K': | |
3174 if (debug > 1) | |
3175 debug("ESC [ " + DCEvars[0] + " K"); | |
3176 | |
3177 /* clear in line */ | |
3178 switch (DCEvars[0]) { | |
3179 case 6: /* 97801 uses ESC[6K for delete to end of line */ | |
3180 case 0:/*clear to right*/ | |
3181 if (C < columns - 1) | |
3182 deleteArea(C, R, columns - C, 1, attributes); | |
3183 | |
3184 break; | |
3185 | |
3186 case 1:/*clear to the left, including this */ | |
3187 if (C > 0) | |
3188 deleteArea(0, R, C + 1, 1, attributes); | |
3189 | |
3190 break; | |
3191 | |
3192 case 2:/*clear whole line */ | |
3193 deleteArea(0, R, columns, 1, attributes); | |
3194 break; | |
3195 } | |
3196 | |
3197 break; | |
3198 | |
3199 case 'J': | |
3200 | |
3201 /* clear below current line */ | |
3202 switch (DCEvars[0]) { | |
3203 case 0: | |
3204 if (R < rows - 1) | |
3205 deleteArea(0, R + 1, columns, rows - R - 1, attributes); | |
3206 | |
3207 if (C < columns - 1) | |
3208 deleteArea(C, R, columns - C, 1, attributes); | |
3209 | |
3210 break; | |
3211 | |
3212 case 1: | |
3213 if (R > 0) | |
3214 deleteArea(0, 0, columns, R, attributes); | |
3215 | |
3216 if (C > 0) | |
3217 deleteArea(0, R, C + 1, 1, attributes); // include up to and including current | |
3218 | |
3219 break; | |
3220 | |
3221 case 2: | |
3222 deleteArea(0, 0, columns, rows, attributes); | |
3223 break; | |
3224 } | |
3225 | |
3226 if (debug > 1) | |
3227 debug("ESC [ " + DCEvars[0] + " J"); | |
3228 | |
3229 break; | |
3230 | |
3231 case '@': | |
3232 if (DCEvars[0] == 0) DCEvars[0] = 1; | |
3233 | |
3234 if (debug > 1) | |
3235 debug("ESC [ " + DCEvars[0] + " @"); | |
3236 | |
3237 for (int i = 0; i < DCEvars[0]; i++) | |
3238 insertChar(C, R, ' ', attributes); | |
3239 | |
3240 break; | |
3241 | |
3242 case 'X': { | |
3243 int toerase = DCEvars[0]; | |
3244 | |
3245 if (debug > 1) | |
3246 debug("ESC [ " + DCEvars[0] + " X, C=" + C + ",R=" + R); | |
3247 | |
3248 if (toerase == 0) | |
3249 toerase = 1; | |
3250 | |
3251 if (toerase + C > columns) | |
3252 toerase = columns - C; | |
3253 | |
3254 deleteArea(C, R, toerase, 1, attributes); | |
3255 // does not change cursor position | |
3256 break; | |
3257 } | |
3258 | |
3259 case 'P': | |
3260 if (debug > 1) | |
3261 debug("ESC [ " + DCEvars[0] + " P, C=" + C + ",R=" + R); | |
3262 | |
3263 if (DCEvars[0] == 0) DCEvars[0] = 1; | |
3264 | |
3265 for (int i = 0; i < DCEvars[0]; i++) | |
3266 deleteChar(C, R); | |
3267 | |
3268 break; | |
3269 | |
3270 case 'n': | |
3271 switch (DCEvars[0]) { | |
3272 case 5: /* malfunction? No malfunction. */ | |
3273 writeSpecial((ESC) + "[0n"); | |
3274 | |
3275 if (debug > 1) | |
3276 debug("ESC[5n"); | |
3277 | |
3278 break; | |
3279 | |
3280 case 6: | |
3281 // DO NOT offset R and C by 1! (checked against /usr/X11R6/bin/resize | |
3282 // FIXME check again. | |
3283 // FIXME: but vttest thinks different??? | |
3284 writeSpecial((ESC) + "[" + R + ";" + C + "R"); | |
3285 | |
3286 if (debug > 1) | |
3287 debug("ESC[6n"); | |
3288 | |
3289 break; | |
3290 | |
3291 default: | |
3292 if (debug > 0) | |
3293 debug("ESC [ " + DCEvars[0] + " n??"); | |
3294 | |
3295 break; | |
3296 } | |
3297 | |
3298 break; | |
3299 | |
3300 case 's': /* DECSC - save cursor */ | |
3301 Sc = C; | |
3302 Sr = R; | |
3303 Sa = attributes; | |
3304 | |
3305 if (debug > 3) | |
3306 debug("ESC[s"); | |
3307 | |
3308 break; | |
3309 | |
3310 case 'u': /* DECRC - restore cursor */ | |
3311 C = Sc; | |
3312 R = Sr; | |
3313 attributes = Sa; | |
3314 | |
3315 if (debug > 3) | |
3316 debug("ESC[u"); | |
3317 | |
3318 break; | |
3319 | |
3320 case 'm': /* attributes as color, bold , blink,*/ | |
3321 if (debug > 3) | |
3322 debug("ESC [ "); | |
3323 | |
3324 if (DCEvar == 0 && DCEvars[0] == 0) | |
3325 attributes = 0; | |
3326 | |
3327 for (int i = 0; i <= DCEvar; i++) { | |
3328 switch (DCEvars[i]) { | |
3329 case 0: | |
3330 if (DCEvar > 0) { | |
3331 if (terminalID.equals("scoansi")) { | |
3332 attributes &= COLOR; /* Keeps color. Strange but true. */ | |
3333 } | |
3334 else { | |
3335 attributes = 0; | |
3336 } | |
3337 } | |
3338 | |
3339 break; | |
3340 | |
3341 case 1: | |
3342 attributes |= BOLD; | |
3343 attributes &= ~LOW; | |
3344 break; | |
3345 | |
3346 case 2: | |
3347 | |
3348 /* SCO color hack mode */ | |
3349 if (terminalID.equals("scoansi") && ((DCEvar - i) >= 2)) { | |
3350 int ncolor; | |
3351 attributes &= ~(COLOR | BOLD); | |
3352 ncolor = DCEvars[i + 1]; | |
3353 | |
3354 if ((ncolor & 8) == 8) | |
3355 attributes |= BOLD; | |
3356 | |
3357 ncolor = ((ncolor & 1) << 2) | (ncolor & 2) | ((ncolor & 4) >> 2); | |
3358 attributes |= ((ncolor) + 1) << COLOR_FG_SHIFT; | |
3359 ncolor = DCEvars[i + 2]; | |
3360 ncolor = ((ncolor & 1) << 2) | (ncolor & 2) | ((ncolor & 4) >> 2); | |
3361 attributes |= ((ncolor) + 1) << COLOR_BG_SHIFT; | |
3362 i += 2; | |
3363 } | |
3364 else { | |
3365 attributes |= LOW; | |
3366 } | |
3367 | |
3368 break; | |
3369 | |
3370 case 3: /* italics */ | |
3371 attributes |= INVERT; | |
3372 break; | |
3373 | |
3374 case 4: | |
3375 attributes |= UNDERLINE; | |
3376 break; | |
3377 | |
3378 case 7: | |
3379 attributes |= INVERT; | |
3380 break; | |
3381 | |
3382 case 8: | |
3383 attributes |= INVISIBLE; | |
3384 break; | |
3385 | |
3386 case 5: /* blink on */ | |
3387 break; | |
3388 | |
3389 /* 10 - ANSI X3.64-1979, select primary font, don't display control | |
3390 * chars, don't set bit 8 on output */ | |
3391 case 10: | |
3392 gl = 0; | |
3393 usedcharsets = true; | |
3394 break; | |
3395 | |
3396 /* 11 - ANSI X3.64-1979, select second alt. font, display control | |
3397 * chars, set bit 8 on output */ | |
3398 case 11: /* SMACS , as */ | |
3399 case 12: | |
3400 gl = 1; | |
3401 usedcharsets = true; | |
3402 break; | |
3403 | |
3404 case 21: /* normal intensity */ | |
3405 attributes &= ~(LOW | BOLD); | |
3406 break; | |
3407 | |
3408 case 23: /* italics off */ | |
3409 attributes &= ~INVERT; | |
3410 break; | |
3411 | |
3412 case 25: /* blinking off */ | |
3413 break; | |
3414 | |
3415 case 27: | |
3416 attributes &= ~INVERT; | |
3417 break; | |
3418 | |
3419 case 28: | |
3420 attributes &= ~INVISIBLE; | |
3421 break; | |
3422 | |
3423 case 24: | |
3424 attributes &= ~UNDERLINE; | |
3425 break; | |
3426 | |
3427 case 22: | |
3428 attributes &= ~BOLD; | |
3429 break; | |
3430 | |
3431 case 30: | |
3432 case 31: | |
3433 case 32: | |
3434 case 33: | |
3435 case 34: | |
3436 case 35: | |
3437 case 36: | |
3438 case 37: | |
3439 attributes &= ~COLOR_FG; | |
3440 attributes |= ((DCEvars[i] - 30) + 1) << COLOR_FG_SHIFT; | |
3441 break; | |
3442 | |
3443 case 38: | |
3444 if (DCEvars[i + 1] == 5) { | |
3445 attributes &= ~COLOR_FG; | |
3446 attributes |= ((DCEvars[i + 2]) + 1) << COLOR_FG_SHIFT; | |
3447 i += 2; | |
3448 } | |
3449 | |
3450 break; | |
3451 | |
3452 case 39: | |
3453 attributes &= ~COLOR_FG; | |
3454 break; | |
3455 | |
3456 case 40: | |
3457 case 41: | |
3458 case 42: | |
3459 case 43: | |
3460 case 44: | |
3461 case 45: | |
3462 case 46: | |
3463 case 47: | |
3464 attributes &= ~COLOR_BG; | |
3465 attributes |= ((DCEvars[i] - 40) + 1) << COLOR_BG_SHIFT; | |
3466 break; | |
3467 | |
3468 case 48: | |
3469 if (DCEvars[i + 1] == 5) { | |
3470 attributes &= ~COLOR_BG; | |
3471 attributes |= (DCEvars[i + 2] + 1) << COLOR_BG_SHIFT; | |
3472 i += 2; | |
3473 } | |
3474 | |
3475 break; | |
3476 | |
3477 case 49: | |
3478 attributes &= ~COLOR_BG; | |
3479 break; | |
3480 | |
3481 case 90: | |
3482 case 91: | |
3483 case 92: | |
3484 case 93: | |
3485 case 94: | |
3486 case 95: | |
3487 case 96: | |
3488 case 97: | |
3489 attributes &= ~COLOR_FG; | |
3490 attributes |= ((DCEvars[i] - 82) + 1) << COLOR_FG_SHIFT; | |
3491 break; | |
3492 | |
3493 case 100: | |
3494 case 101: | |
3495 case 102: | |
3496 case 103: | |
3497 case 104: | |
3498 case 105: | |
3499 case 106: | |
3500 case 107: | |
3501 attributes &= ~COLOR_BG; | |
3502 attributes |= ((DCEvars[i] - 92) + 1) << COLOR_BG_SHIFT; | |
3503 break; | |
3504 | |
3505 default: | |
3506 debugStr.append("ESC [ ") | |
3507 .append(DCEvars[i]) | |
3508 .append(" m unknown..."); | |
3509 debug(debugStr.toString()); | |
3510 debugStr.setLength(0); | |
3511 break; | |
3512 } | |
3513 | |
3514 if (debug > 3) { | |
3515 debugStr.append(DCEvars[i]) | |
3516 .append(';'); | |
3517 debug(debugStr.toString()); | |
3518 debugStr.setLength(0); | |
3519 } | |
3520 } | |
3521 | |
3522 if (debug > 3) { | |
3523 debugStr.append(" (attributes = ") | |
3524 .append(attributes) | |
3525 .append(")m"); | |
3526 debug(debugStr.toString()); | |
3527 debugStr.setLength(0); | |
3528 } | |
3529 | |
3530 break; | |
3531 | |
3532 default: | |
3533 debugStr.append("ESC [ unknown letter: ") | |
3534 .append(c) | |
3535 .append(" (") | |
3536 .append((int)c) | |
3537 .append(')'); | |
3538 debug(debugStr.toString()); | |
3539 debugStr.setLength(0); | |
3540 break; | |
3541 } | |
3542 | |
3543 break; | |
3544 | |
3545 case TSTATE_TITLE: | |
3546 switch (c) { | |
3547 case ESC: | |
3548 term_state = TSTATE_ESC; | |
3549 break; | |
3550 | |
3551 default: | |
3552 // TODO save title | |
3553 break; | |
3554 } | |
3555 | |
3556 break; | |
3557 | |
3558 default: | |
3559 term_state = TSTATE_DATA; | |
3560 break; | |
3561 } | |
3562 | |
3563 setCursorPosition(C, R); | |
3564 } | |
3565 | |
3566 /* hard reset the terminal */ | |
3567 public void reset() { | |
3568 gx[0] = 'B'; | |
3569 gx[1] = 'B'; | |
3570 gx[2] = 'B'; | |
3571 gx[3] = 'B'; | |
3572 gl = 0; // default GL to G0 | |
3573 gr = 2; // default GR to G2 | |
3574 onegl = -1; // Single shift override | |
3575 /* reset tabs */ | |
3576 int nw = width; | |
3577 | |
3578 if (nw < 132) nw = 132; | |
3579 | |
3580 Tabs = new byte[nw]; | |
3581 | |
3582 for (int i = 0; i < nw; i += 8) { | |
3583 Tabs[i] = 1; | |
3584 } | |
3585 | |
3586 deleteArea(0, 0, width, height, attributes); | |
3587 setMargins(0, height); | |
3588 C = R = 0; | |
3589 _SetCursor(0, 0); | |
3590 | |
3591 if (display != null) | |
3592 display.resetColors(); | |
3593 | |
3594 showCursor(true); | |
3595 /*FIXME:*/ | |
3596 term_state = TSTATE_DATA; | |
3597 } | |
3598 } |