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