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