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