Mercurial > 510Connectbot
annotate src/de/mud/terminal/vt320.java @ 102:6802f1cd1add
fix code typo
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 17 Jun 2014 16:23:25 -0700 |
parents | 8181cb01c64d |
children | 171e0a977544 |
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 /** | |
947 * main keytyping event handler... | |
948 */ | |
949 public void keyPressed(int keyCode, char keyChar, int modifiers) { | |
950 boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0; | |
951 boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0; | |
952 boolean alt = (modifiers & VDUInput.KEY_ALT) != 0; | |
953 | |
954 if (debug > 1) { | |
955 debugStr.append("keyPressed(") | |
956 .append(keyCode) | |
957 .append(", ") | |
958 .append((int)keyChar) | |
959 .append(", ") | |
960 .append(modifiers) | |
961 .append(')'); | |
962 debug(debugStr.toString()); | |
963 debugStr.setLength(0); | |
964 } | |
965 | |
966 int xind; | |
967 String fmap[]; | |
968 xind = 0; | |
969 fmap = FunctionKey; | |
970 | |
971 if (shift) { | |
972 fmap = FunctionKeyShift; | |
973 xind = 1; | |
974 } | |
975 | |
976 if (control) { | |
977 fmap = FunctionKeyCtrl; | |
978 xind = 2; | |
979 } | |
980 | |
981 if (alt) { | |
982 fmap = FunctionKeyAlt; | |
983 xind = 3; | |
984 } | |
985 | |
986 switch (keyCode) { | |
987 case KEY_PAUSE: | |
988 if (shift || control) | |
989 sendTelnetCommand((byte) 243); // BREAK | |
990 | |
991 break; | |
992 | |
993 case KEY_F1: | |
994 writeSpecial(fmap[1]); | |
995 break; | |
996 | |
997 case KEY_F2: | |
998 writeSpecial(fmap[2]); | |
999 break; | |
1000 | |
1001 case KEY_F3: | |
1002 writeSpecial(fmap[3]); | |
1003 break; | |
1004 | |
1005 case KEY_F4: | |
1006 writeSpecial(fmap[4]); | |
1007 break; | |
1008 | |
1009 case KEY_F5: | |
1010 writeSpecial(fmap[5]); | |
1011 break; | |
1012 | |
1013 case KEY_F6: | |
1014 writeSpecial(fmap[6]); | |
1015 break; | |
1016 | |
1017 case KEY_F7: | |
1018 writeSpecial(fmap[7]); | |
1019 break; | |
1020 | |
1021 case KEY_F8: | |
1022 writeSpecial(fmap[8]); | |
1023 break; | |
1024 | |
1025 case KEY_F9: | |
1026 writeSpecial(fmap[9]); | |
1027 break; | |
1028 | |
1029 case KEY_F10: | |
1030 writeSpecial(fmap[10]); | |
1031 break; | |
1032 | |
1033 case KEY_F11: | |
1034 writeSpecial(fmap[11]); | |
1035 break; | |
1036 | |
1037 case KEY_F12: | |
1038 writeSpecial(fmap[12]); | |
1039 break; | |
1040 | |
1041 case KEY_UP: | |
1042 writeSpecial(KeyUp[xind]); | |
1043 break; | |
1044 | |
1045 case KEY_DOWN: | |
1046 writeSpecial(KeyDown[xind]); | |
1047 break; | |
1048 | |
1049 case KEY_LEFT: | |
1050 writeSpecial(KeyLeft[xind]); | |
1051 break; | |
1052 | |
1053 case KEY_RIGHT: | |
1054 writeSpecial(KeyRight[xind]); | |
1055 break; | |
1056 | |
1057 case KEY_PAGE_DOWN: | |
1058 writeSpecial(NextScn[xind]); | |
1059 break; | |
1060 | |
1061 case KEY_PAGE_UP: | |
1062 writeSpecial(PrevScn[xind]); | |
1063 break; | |
1064 | |
1065 case KEY_INSERT: | |
1066 writeSpecial(Insert[xind]); | |
1067 break; | |
1068 | |
1069 case KEY_DELETE: | |
1070 writeSpecial(Remove[xind]); | |
1071 break; | |
1072 | |
1073 case KEY_BACK_SPACE: | |
1074 writeSpecial(BackSpace[xind]); | |
1075 | |
1076 if (localecho) { | |
1077 if (BackSpace[xind] == "\b") { | |
1078 putString("\b \b"); // make the last char 'deleted' | |
1079 } | |
1080 else { | |
1081 putString(BackSpace[xind]); // echo it | |
1082 } | |
1083 } | |
1084 | |
1085 break; | |
1086 | |
1087 case KEY_HOME: | |
1088 writeSpecial(KeyHome[xind]); | |
1089 break; | |
1090 | |
1091 case KEY_END: | |
1092 writeSpecial(KeyEnd[xind]); | |
1093 break; | |
1094 | |
1095 case KEY_NUM_LOCK: | |
1096 if (vms && control) { | |
1097 writeSpecial(PF1); | |
1098 } | |
1099 | |
1100 if (!control) | |
1101 numlock = !numlock; | |
1102 | |
1103 break; | |
1104 | |
1105 case KEY_CAPS_LOCK: | |
1106 capslock = !capslock; | |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
1107 break; |
0 | 1108 |
1109 case KEY_SHIFT: | |
1110 case KEY_CONTROL: | |
1111 case KEY_ALT: | |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
1112 break; |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
1113 |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
1114 case KEY_ESCAPE: |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
1115 write(0x1b); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
1116 break; |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
1117 |
56
556c387889b9
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
53
diff
changeset
|
1118 case KEY_ENTER: |
556c387889b9
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
53
diff
changeset
|
1119 write(0x0d); |
556c387889b9
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
53
diff
changeset
|
1120 break; |
556c387889b9
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
53
diff
changeset
|
1121 |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
1122 case KEY_TAB: |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
1123 write(0x09); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
45
diff
changeset
|
1124 break; |
0 | 1125 |
1126 default: | |
1127 break; | |
1128 } | |
1129 } | |
1130 /* | |
1131 public void keyReleased(KeyEvent evt) { | |
1132 if (debug > 1) debug("keyReleased("+evt+")"); | |
1133 // ignore | |
1134 } | |
1135 */ | |
1136 /** | |
1137 * Handle key Typed events for the terminal, this will get | |
1138 * all normal key types, but no shift/alt/control/numlock. | |
1139 */ | |
1140 public void keyTyped(int keyCode, char keyChar, int modifiers) { | |
1141 boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0; | |
1142 boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0; | |
1143 boolean alt = (modifiers & VDUInput.KEY_ALT) != 0; | |
1144 | |
1145 if (debug > 1) debug("keyTyped(" + keyCode + ", " + (int)keyChar + ", " + modifiers + ")"); | |
1146 | |
1147 if (keyChar == '\t') { | |
1148 if (shift) { | |
1149 write(TabKey[1], false); | |
1150 } | |
1151 else { | |
1152 if (control) { | |
1153 write(TabKey[2], false); | |
1154 } | |
1155 else { | |
1156 if (alt) { | |
1157 write(TabKey[3], false); | |
1158 } | |
1159 else { | |
1160 write(TabKey[0], false); | |
1161 } | |
1162 } | |
1163 } | |
1164 | |
1165 return; | |
1166 } | |
1167 | |
1168 if (alt) { | |
1169 write(((char)(keyChar | 0x80))); | |
1170 return; | |
1171 } | |
1172 | |
1173 if (((keyCode == KEY_ENTER) || (keyChar == 10)) | |
1174 && !control) { | |
1175 write('\r'); | |
1176 | |
1177 if (localecho) putString("\r\n"); // bad hack | |
1178 | |
1179 return; | |
1180 } | |
1181 | |
1182 if ((keyCode == 10) && !control) { | |
1183 debug("Sending \\r"); | |
1184 write('\r'); | |
1185 return; | |
1186 } | |
1187 | |
1188 // FIXME: on german PC keyboards you have to use Alt-Ctrl-q to get an @, | |
1189 // so we can't just use it here... will probably break some other VMS | |
1190 // codes. -Marcus | |
1191 // if(((!vms && keyChar == '2') || keyChar == '@' || keyChar == ' ') | |
1192 // && control) | |
1193 if (((!vms && keyChar == '2') || keyChar == ' ') && control) | |
1194 write(0); | |
1195 | |
1196 if (vms) { | |
1197 if (keyChar == 127 && !control) { | |
1198 if (shift) | |
1199 writeSpecial(Insert[0]); // VMS shift delete = insert | |
1200 else | |
1201 writeSpecial(Remove[0]); // VMS delete = remove | |
1202 | |
1203 return; | |
1204 } | |
1205 else if (control) | |
1206 switch (keyChar) { | |
1207 case '0': | |
1208 writeSpecial(Numpad[0]); | |
1209 return; | |
1210 | |
1211 case '1': | |
1212 writeSpecial(Numpad[1]); | |
1213 return; | |
1214 | |
1215 case '2': | |
1216 writeSpecial(Numpad[2]); | |
1217 return; | |
1218 | |
1219 case '3': | |
1220 writeSpecial(Numpad[3]); | |
1221 return; | |
1222 | |
1223 case '4': | |
1224 writeSpecial(Numpad[4]); | |
1225 return; | |
1226 | |
1227 case '5': | |
1228 writeSpecial(Numpad[5]); | |
1229 return; | |
1230 | |
1231 case '6': | |
1232 writeSpecial(Numpad[6]); | |
1233 return; | |
1234 | |
1235 case '7': | |
1236 writeSpecial(Numpad[7]); | |
1237 return; | |
1238 | |
1239 case '8': | |
1240 writeSpecial(Numpad[8]); | |
1241 return; | |
1242 | |
1243 case '9': | |
1244 writeSpecial(Numpad[9]); | |
1245 return; | |
1246 | |
1247 case '.': | |
1248 writeSpecial(KPPeriod); | |
1249 return; | |
1250 | |
1251 case '-': | |
1252 case 31: | |
1253 writeSpecial(KPMinus); | |
1254 return; | |
1255 | |
1256 case '+': | |
1257 writeSpecial(KPComma); | |
1258 return; | |
1259 | |
1260 case 10: | |
1261 writeSpecial(KPEnter); | |
1262 return; | |
1263 | |
1264 case '/': | |
1265 writeSpecial(PF2); | |
1266 return; | |
1267 | |
1268 case '*': | |
1269 writeSpecial(PF3); | |
1270 return; | |
1271 | |
1272 /* NUMLOCK handled in keyPressed */ | |
1273 default: | |
1274 break; | |
1275 } | |
1276 | |
1277 /* Now what does this do and how did it get here. -Marcus | |
1278 if (shift && keyChar < 32) { | |
1279 write(PF1+(char)(keyChar + 64)); | |
1280 return; | |
1281 } | |
1282 */ | |
1283 } | |
1284 | |
1285 // FIXME: not used? | |
1286 //String fmap[]; | |
1287 int xind; | |
1288 xind = 0; | |
1289 | |
1290 //fmap = FunctionKey; | |
1291 if (shift) { | |
1292 //fmap = FunctionKeyShift; | |
1293 xind = 1; | |
1294 } | |
1295 | |
1296 if (control) { | |
1297 //fmap = FunctionKeyCtrl; | |
1298 xind = 2; | |
1299 } | |
1300 | |
1301 if (alt) { | |
1302 //fmap = FunctionKeyAlt; | |
1303 xind = 3; | |
1304 } | |
1305 | |
1306 if (keyCode == KEY_ESCAPE) { | |
1307 writeSpecial(Escape[xind]); | |
1308 return; | |
1309 } | |
1310 | |
1311 if ((modifiers & VDUInput.KEY_ACTION) != 0) | |
1312 switch (keyCode) { | |
1313 case KEY_NUMPAD0: | |
1314 writeSpecial(Numpad[0]); | |
1315 return; | |
1316 | |
1317 case KEY_NUMPAD1: | |
1318 writeSpecial(Numpad[1]); | |
1319 return; | |
1320 | |
1321 case KEY_NUMPAD2: | |
1322 writeSpecial(Numpad[2]); | |
1323 return; | |
1324 | |
1325 case KEY_NUMPAD3: | |
1326 writeSpecial(Numpad[3]); | |
1327 return; | |
1328 | |
1329 case KEY_NUMPAD4: | |
1330 writeSpecial(Numpad[4]); | |
1331 return; | |
1332 | |
1333 case KEY_NUMPAD5: | |
1334 writeSpecial(Numpad[5]); | |
1335 return; | |
1336 | |
1337 case KEY_NUMPAD6: | |
1338 writeSpecial(Numpad[6]); | |
1339 return; | |
1340 | |
1341 case KEY_NUMPAD7: | |
1342 writeSpecial(Numpad[7]); | |
1343 return; | |
1344 | |
1345 case KEY_NUMPAD8: | |
1346 writeSpecial(Numpad[8]); | |
1347 return; | |
1348 | |
1349 case KEY_NUMPAD9: | |
1350 writeSpecial(Numpad[9]); | |
1351 return; | |
1352 | |
1353 case KEY_DECIMAL: | |
1354 writeSpecial(NUMDot[xind]); | |
1355 return; | |
1356 | |
1357 case KEY_ADD: | |
1358 writeSpecial(NUMPlus[xind]); | |
1359 return; | |
1360 } | |
1361 | |
1362 if (!((keyChar == 8) || (keyChar == 127) || (keyChar == '\r') || (keyChar == '\n'))) { | |
1363 write(keyChar); | |
1364 return; | |
1365 } | |
1366 } | |
1367 | |
1368 private void handle_dcs(String dcs) { | |
1369 debugStr.append("DCS: ") | |
1370 .append(dcs); | |
1371 debug(debugStr.toString()); | |
1372 debugStr.setLength(0); | |
1373 } | |
1374 | |
1375 private void handle_osc(String osc) { | |
1376 if (osc.length() > 2 && osc.substring(0, 2).equals("4;")) { | |
1377 // Define color palette | |
1378 String[] colorData = osc.split(";"); | |
1379 | |
1380 try { | |
1381 int colorIndex = Integer.parseInt(colorData[1]); | |
1382 | |
1383 if ("rgb:".equals(colorData[2].substring(0, 4))) { | |
1384 String[] rgb = colorData[2].substring(4).split("/"); | |
1385 int red = Integer.parseInt(rgb[0].substring(0, 2), 16) & 0xFF; | |
1386 int green = Integer.parseInt(rgb[1].substring(0, 2), 16) & 0xFF; | |
1387 int blue = Integer.parseInt(rgb[2].substring(0, 2), 16) & 0xFF; | |
1388 display.setColor(colorIndex, red, green, blue); | |
1389 } | |
1390 } | |
1391 catch (Exception e) { | |
1392 debugStr.append("OSC: invalid color sequence encountered: ") | |
1393 .append(osc); | |
1394 debug(debugStr.toString()); | |
1395 debugStr.setLength(0); | |
1396 } | |
1397 } | |
1398 else | |
1399 debug("OSC: " + osc); | |
1400 } | |
1401 | |
1402 private final static char unimap[] = { | |
1403 //# | |
1404 //# Name: cp437_DOSLatinUS to Unicode table | |
1405 //# Unicode version: 1.1 | |
1406 //# Table version: 1.1 | |
1407 //# Table format: Format A | |
1408 //# Date: 03/31/95 | |
1409 //# Authors: Michel Suignard <michelsu@microsoft.com> | |
1410 //# Lori Hoerth <lorih@microsoft.com> | |
1411 //# General notes: none | |
1412 //# | |
1413 //# Format: Three tab-separated columns | |
1414 //# Column #1 is the cp1255_WinHebrew code (in hex) | |
1415 //# Column #2 is the Unicode (in hex as 0xXXXX) | |
1416 //# Column #3 is the Unicode name (follows a comment sign, '#') | |
1417 //# | |
1418 //# The entries are in cp437_DOSLatinUS order | |
1419 //# | |
1420 | |
1421 0x0000, // #NULL | |
1422 0x0001, // #START OF HEADING | |
1423 0x0002, // #START OF TEXT | |
1424 0x0003, // #END OF TEXT | |
1425 0x0004, // #END OF TRANSMISSION | |
1426 0x0005, // #ENQUIRY | |
1427 0x0006, // #ACKNOWLEDGE | |
1428 0x0007, // #BELL | |
1429 0x0008, // #BACKSPACE | |
1430 0x0009, // #HORIZONTAL TABULATION | |
1431 0x000a, // #LINE FEED | |
1432 0x000b, // #VERTICAL TABULATION | |
1433 0x000c, // #FORM FEED | |
1434 0x000d, // #CARRIAGE RETURN | |
1435 0x000e, // #SHIFT OUT | |
1436 0x000f, // #SHIFT IN | |
1437 0x0010, // #DATA LINK ESCAPE | |
1438 0x0011, // #DEVICE CONTROL ONE | |
1439 0x0012, // #DEVICE CONTROL TWO | |
1440 0x0013, // #DEVICE CONTROL THREE | |
1441 0x0014, // #DEVICE CONTROL FOUR | |
1442 0x0015, // #NEGATIVE ACKNOWLEDGE | |
1443 0x0016, // #SYNCHRONOUS IDLE | |
1444 0x0017, // #END OF TRANSMISSION BLOCK | |
1445 0x0018, // #CANCEL | |
1446 0x0019, // #END OF MEDIUM | |
1447 0x001a, // #SUBSTITUTE | |
1448 0x001b, // #ESCAPE | |
1449 0x001c, // #FILE SEPARATOR | |
1450 0x001d, // #GROUP SEPARATOR | |
1451 0x001e, // #RECORD SEPARATOR | |
1452 0x001f, // #UNIT SEPARATOR | |
1453 0x0020, // #SPACE | |
1454 0x0021, // #EXCLAMATION MARK | |
1455 0x0022, // #QUOTATION MARK | |
1456 0x0023, // #NUMBER SIGN | |
1457 0x0024, // #DOLLAR SIGN | |
1458 0x0025, // #PERCENT SIGN | |
1459 0x0026, // #AMPERSAND | |
1460 0x0027, // #APOSTROPHE | |
1461 0x0028, // #LEFT PARENTHESIS | |
1462 0x0029, // #RIGHT PARENTHESIS | |
1463 0x002a, // #ASTERISK | |
1464 0x002b, // #PLUS SIGN | |
1465 0x002c, // #COMMA | |
1466 0x002d, // #HYPHEN-MINUS | |
1467 0x002e, // #FULL STOP | |
1468 0x002f, // #SOLIDUS | |
1469 0x0030, // #DIGIT ZERO | |
1470 0x0031, // #DIGIT ONE | |
1471 0x0032, // #DIGIT TWO | |
1472 0x0033, // #DIGIT THREE | |
1473 0x0034, // #DIGIT FOUR | |
1474 0x0035, // #DIGIT FIVE | |
1475 0x0036, // #DIGIT SIX | |
1476 0x0037, // #DIGIT SEVEN | |
1477 0x0038, // #DIGIT EIGHT | |
1478 0x0039, // #DIGIT NINE | |
1479 0x003a, // #COLON | |
1480 0x003b, // #SEMICOLON | |
1481 0x003c, // #LESS-THAN SIGN | |
1482 0x003d, // #EQUALS SIGN | |
1483 0x003e, // #GREATER-THAN SIGN | |
1484 0x003f, // #QUESTION MARK | |
1485 0x0040, // #COMMERCIAL AT | |
1486 0x0041, // #LATIN CAPITAL LETTER A | |
1487 0x0042, // #LATIN CAPITAL LETTER B | |
1488 0x0043, // #LATIN CAPITAL LETTER C | |
1489 0x0044, // #LATIN CAPITAL LETTER D | |
1490 0x0045, // #LATIN CAPITAL LETTER E | |
1491 0x0046, // #LATIN CAPITAL LETTER F | |
1492 0x0047, // #LATIN CAPITAL LETTER G | |
1493 0x0048, // #LATIN CAPITAL LETTER H | |
1494 0x0049, // #LATIN CAPITAL LETTER I | |
1495 0x004a, // #LATIN CAPITAL LETTER J | |
1496 0x004b, // #LATIN CAPITAL LETTER K | |
1497 0x004c, // #LATIN CAPITAL LETTER L | |
1498 0x004d, // #LATIN CAPITAL LETTER M | |
1499 0x004e, // #LATIN CAPITAL LETTER N | |
1500 0x004f, // #LATIN CAPITAL LETTER O | |
1501 0x0050, // #LATIN CAPITAL LETTER P | |
1502 0x0051, // #LATIN CAPITAL LETTER Q | |
1503 0x0052, // #LATIN CAPITAL LETTER R | |
1504 0x0053, // #LATIN CAPITAL LETTER S | |
1505 0x0054, // #LATIN CAPITAL LETTER T | |
1506 0x0055, // #LATIN CAPITAL LETTER U | |
1507 0x0056, // #LATIN CAPITAL LETTER V | |
1508 0x0057, // #LATIN CAPITAL LETTER W | |
1509 0x0058, // #LATIN CAPITAL LETTER X | |
1510 0x0059, // #LATIN CAPITAL LETTER Y | |
1511 0x005a, // #LATIN CAPITAL LETTER Z | |
1512 0x005b, // #LEFT SQUARE BRACKET | |
1513 0x005c, // #REVERSE SOLIDUS | |
1514 0x005d, // #RIGHT SQUARE BRACKET | |
1515 0x005e, // #CIRCUMFLEX ACCENT | |
1516 0x005f, // #LOW LINE | |
1517 0x0060, // #GRAVE ACCENT | |
1518 0x0061, // #LATIN SMALL LETTER A | |
1519 0x0062, // #LATIN SMALL LETTER B | |
1520 0x0063, // #LATIN SMALL LETTER C | |
1521 0x0064, // #LATIN SMALL LETTER D | |
1522 0x0065, // #LATIN SMALL LETTER E | |
1523 0x0066, // #LATIN SMALL LETTER F | |
1524 0x0067, // #LATIN SMALL LETTER G | |
1525 0x0068, // #LATIN SMALL LETTER H | |
1526 0x0069, // #LATIN SMALL LETTER I | |
1527 0x006a, // #LATIN SMALL LETTER J | |
1528 0x006b, // #LATIN SMALL LETTER K | |
1529 0x006c, // #LATIN SMALL LETTER L | |
1530 0x006d, // #LATIN SMALL LETTER M | |
1531 0x006e, // #LATIN SMALL LETTER N | |
1532 0x006f, // #LATIN SMALL LETTER O | |
1533 0x0070, // #LATIN SMALL LETTER P | |
1534 0x0071, // #LATIN SMALL LETTER Q | |
1535 0x0072, // #LATIN SMALL LETTER R | |
1536 0x0073, // #LATIN SMALL LETTER S | |
1537 0x0074, // #LATIN SMALL LETTER T | |
1538 0x0075, // #LATIN SMALL LETTER U | |
1539 0x0076, // #LATIN SMALL LETTER V | |
1540 0x0077, // #LATIN SMALL LETTER W | |
1541 0x0078, // #LATIN SMALL LETTER X | |
1542 0x0079, // #LATIN SMALL LETTER Y | |
1543 0x007a, // #LATIN SMALL LETTER Z | |
1544 0x007b, // #LEFT CURLY BRACKET | |
1545 0x007c, // #VERTICAL LINE | |
1546 0x007d, // #RIGHT CURLY BRACKET | |
1547 0x007e, // #TILDE | |
1548 0x007f, // #DELETE | |
1549 0x00c7, // #LATIN CAPITAL LETTER C WITH CEDILLA | |
1550 0x00fc, // #LATIN SMALL LETTER U WITH DIAERESIS | |
1551 0x00e9, // #LATIN SMALL LETTER E WITH ACUTE | |
1552 0x00e2, // #LATIN SMALL LETTER A WITH CIRCUMFLEX | |
1553 0x00e4, // #LATIN SMALL LETTER A WITH DIAERESIS | |
1554 0x00e0, // #LATIN SMALL LETTER A WITH GRAVE | |
1555 0x00e5, // #LATIN SMALL LETTER A WITH RING ABOVE | |
1556 0x00e7, // #LATIN SMALL LETTER C WITH CEDILLA | |
1557 0x00ea, // #LATIN SMALL LETTER E WITH CIRCUMFLEX | |
1558 0x00eb, // #LATIN SMALL LETTER E WITH DIAERESIS | |
1559 0x00e8, // #LATIN SMALL LETTER E WITH GRAVE | |
1560 0x00ef, // #LATIN SMALL LETTER I WITH DIAERESIS | |
1561 0x00ee, // #LATIN SMALL LETTER I WITH CIRCUMFLEX | |
1562 0x00ec, // #LATIN SMALL LETTER I WITH GRAVE | |
1563 0x00c4, // #LATIN CAPITAL LETTER A WITH DIAERESIS | |
1564 0x00c5, // #LATIN CAPITAL LETTER A WITH RING ABOVE | |
1565 0x00c9, // #LATIN CAPITAL LETTER E WITH ACUTE | |
1566 0x00e6, // #LATIN SMALL LIGATURE AE | |
1567 0x00c6, // #LATIN CAPITAL LIGATURE AE | |
1568 0x00f4, // #LATIN SMALL LETTER O WITH CIRCUMFLEX | |
1569 0x00f6, // #LATIN SMALL LETTER O WITH DIAERESIS | |
1570 0x00f2, // #LATIN SMALL LETTER O WITH GRAVE | |
1571 0x00fb, // #LATIN SMALL LETTER U WITH CIRCUMFLEX | |
1572 0x00f9, // #LATIN SMALL LETTER U WITH GRAVE | |
1573 0x00ff, // #LATIN SMALL LETTER Y WITH DIAERESIS | |
1574 0x00d6, // #LATIN CAPITAL LETTER O WITH DIAERESIS | |
1575 0x00dc, // #LATIN CAPITAL LETTER U WITH DIAERESIS | |
1576 0x00a2, // #CENT SIGN | |
1577 0x00a3, // #POUND SIGN | |
1578 0x00a5, // #YEN SIGN | |
1579 0x20a7, // #PESETA SIGN | |
1580 0x0192, // #LATIN SMALL LETTER F WITH HOOK | |
1581 0x00e1, // #LATIN SMALL LETTER A WITH ACUTE | |
1582 0x00ed, // #LATIN SMALL LETTER I WITH ACUTE | |
1583 0x00f3, // #LATIN SMALL LETTER O WITH ACUTE | |
1584 0x00fa, // #LATIN SMALL LETTER U WITH ACUTE | |
1585 0x00f1, // #LATIN SMALL LETTER N WITH TILDE | |
1586 0x00d1, // #LATIN CAPITAL LETTER N WITH TILDE | |
1587 0x00aa, // #FEMININE ORDINAL INDICATOR | |
1588 0x00ba, // #MASCULINE ORDINAL INDICATOR | |
1589 0x00bf, // #INVERTED QUESTION MARK | |
1590 0x2310, // #REVERSED NOT SIGN | |
1591 0x00ac, // #NOT SIGN | |
1592 0x00bd, // #VULGAR FRACTION ONE HALF | |
1593 0x00bc, // #VULGAR FRACTION ONE QUARTER | |
1594 0x00a1, // #INVERTED EXCLAMATION MARK | |
1595 0x00ab, // #LEFT-POINTING DOUBLE ANGLE QUOTATION MARK | |
1596 0x00bb, // #RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK | |
1597 0x2591, // #LIGHT SHADE | |
1598 0x2592, // #MEDIUM SHADE | |
1599 0x2593, // #DARK SHADE | |
1600 0x2502, // #BOX DRAWINGS LIGHT VERTICAL | |
1601 0x2524, // #BOX DRAWINGS LIGHT VERTICAL AND LEFT | |
1602 0x2561, // #BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE | |
1603 0x2562, // #BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE | |
1604 0x2556, // #BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE | |
1605 0x2555, // #BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE | |
1606 0x2563, // #BOX DRAWINGS DOUBLE VERTICAL AND LEFT | |
1607 0x2551, // #BOX DRAWINGS DOUBLE VERTICAL | |
1608 0x2557, // #BOX DRAWINGS DOUBLE DOWN AND LEFT | |
1609 0x255d, // #BOX DRAWINGS DOUBLE UP AND LEFT | |
1610 0x255c, // #BOX DRAWINGS UP DOUBLE AND LEFT SINGLE | |
1611 0x255b, // #BOX DRAWINGS UP SINGLE AND LEFT DOUBLE | |
1612 0x2510, // #BOX DRAWINGS LIGHT DOWN AND LEFT | |
1613 0x2514, // #BOX DRAWINGS LIGHT UP AND RIGHT | |
1614 0x2534, // #BOX DRAWINGS LIGHT UP AND HORIZONTAL | |
1615 0x252c, // #BOX DRAWINGS LIGHT DOWN AND HORIZONTAL | |
1616 0x251c, // #BOX DRAWINGS LIGHT VERTICAL AND RIGHT | |
1617 0x2500, // #BOX DRAWINGS LIGHT HORIZONTAL | |
1618 0x253c, // #BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL | |
1619 0x255e, // #BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE | |
1620 0x255f, // #BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE | |
1621 0x255a, // #BOX DRAWINGS DOUBLE UP AND RIGHT | |
1622 0x2554, // #BOX DRAWINGS DOUBLE DOWN AND RIGHT | |
1623 0x2569, // #BOX DRAWINGS DOUBLE UP AND HORIZONTAL | |
1624 0x2566, // #BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL | |
1625 0x2560, // #BOX DRAWINGS DOUBLE VERTICAL AND RIGHT | |
1626 0x2550, // #BOX DRAWINGS DOUBLE HORIZONTAL | |
1627 0x256c, // #BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL | |
1628 0x2567, // #BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE | |
1629 0x2568, // #BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE | |
1630 0x2564, // #BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE | |
1631 0x2565, // #BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE | |
1632 0x2559, // #BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE | |
1633 0x2558, // #BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE | |
1634 0x2552, // #BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE | |
1635 0x2553, // #BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE | |
1636 0x256b, // #BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE | |
1637 0x256a, // #BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE | |
1638 0x2518, // #BOX DRAWINGS LIGHT UP AND LEFT | |
1639 0x250c, // #BOX DRAWINGS LIGHT DOWN AND RIGHT | |
1640 0x2588, // #FULL BLOCK | |
1641 0x2584, // #LOWER HALF BLOCK | |
1642 0x258c, // #LEFT HALF BLOCK | |
1643 0x2590, // #RIGHT HALF BLOCK | |
1644 0x2580, // #UPPER HALF BLOCK | |
1645 0x03b1, // #GREEK SMALL LETTER ALPHA | |
1646 0x00df, // #LATIN SMALL LETTER SHARP S | |
1647 0x0393, // #GREEK CAPITAL LETTER GAMMA | |
1648 0x03c0, // #GREEK SMALL LETTER PI | |
1649 0x03a3, // #GREEK CAPITAL LETTER SIGMA | |
1650 0x03c3, // #GREEK SMALL LETTER SIGMA | |
1651 0x00b5, // #MICRO SIGN | |
1652 0x03c4, // #GREEK SMALL LETTER TAU | |
1653 0x03a6, // #GREEK CAPITAL LETTER PHI | |
1654 0x0398, // #GREEK CAPITAL LETTER THETA | |
1655 0x03a9, // #GREEK CAPITAL LETTER OMEGA | |
1656 0x03b4, // #GREEK SMALL LETTER DELTA | |
1657 0x221e, // #INFINITY | |
1658 0x03c6, // #GREEK SMALL LETTER PHI | |
1659 0x03b5, // #GREEK SMALL LETTER EPSILON | |
1660 0x2229, // #INTERSECTION | |
1661 0x2261, // #IDENTICAL TO | |
1662 0x00b1, // #PLUS-MINUS SIGN | |
1663 0x2265, // #GREATER-THAN OR EQUAL TO | |
1664 0x2264, // #LESS-THAN OR EQUAL TO | |
1665 0x2320, // #TOP HALF INTEGRAL | |
1666 0x2321, // #BOTTOM HALF INTEGRAL | |
1667 0x00f7, // #DIVISION SIGN | |
1668 0x2248, // #ALMOST EQUAL TO | |
1669 0x00b0, // #DEGREE SIGN | |
1670 0x2219, // #BULLET OPERATOR | |
1671 0x00b7, // #MIDDLE DOT | |
1672 0x221a, // #SQUARE ROOT | |
1673 0x207f, // #SUPERSCRIPT LATIN SMALL LETTER N | |
1674 0x00b2, // #SUPERSCRIPT TWO | |
1675 0x25a0, // #BLACK SQUARE | |
1676 0x00a0, // #NO-BREAK SPACE | |
1677 }; | |
1678 | |
1679 public char map_cp850_unicode(char x) { | |
1680 if (x >= 0x100) | |
1681 return x; | |
1682 | |
1683 return unimap[x]; | |
1684 } | |
1685 | |
1686 private void _SetCursor(int row, int col) { | |
1687 int maxr = height - 1; | |
1688 int tm = getTopMargin(); | |
1689 R = (row < 0) ? 0 : row; | |
1690 C = (col < 0) ? 0 : (col >= width) ? width - 1 : col; | |
1691 | |
1692 if (!moveoutsidemargins) { | |
1693 R += tm; | |
1694 maxr = getBottomMargin(); | |
1695 } | |
1696 | |
1697 if (R > maxr) R = maxr; | |
1698 } | |
1699 | |
1700 private void putChar(char c, boolean isWide, boolean doshowcursor) { | |
1701 int rows = this.height; //statusline | |
1702 int columns = this.width; | |
1703 | |
1704 // byte msg[]; | |
1705 // if (debug > 4) { | |
1706 // debugStr.append("putChar(") | |
1707 // .append(c) | |
1708 // .append(" [") | |
1709 // .append((int) c) | |
1710 // .append("]) at R=") | |
1711 // .append(R) | |
1712 // .append(" , C=") | |
1713 // .append(C) | |
1714 // .append(", columns=") | |
1715 // .append(columns) | |
1716 // .append(", rows=") | |
1717 // .append(rows); | |
1718 // debug(debugStr.toString()); | |
1719 // debugStr.setLength(0); | |
1720 // } | |
1721 // markLine(R, 1); | |
1722 // if (c > 255) { | |
1723 // if (debug > 0) | |
1724 // debug("char > 255:" + (int) c); | |
1725 // //return; | |
1726 // } | |
1727 switch (term_state) { | |
1728 case TSTATE_DATA: | |
1729 | |
1730 /* FIXME: we shouldn't use chars with bit 8 set if ibmcharset. | |
1731 * probably... but some BBS do anyway... | |
1732 */ | |
1733 if (!useibmcharset) { | |
1734 boolean doneflag = true; | |
1735 | |
1736 switch (c) { | |
1737 case OSC: | |
1738 osc = ""; | |
1739 term_state = TSTATE_OSC; | |
1740 break; | |
1741 | |
1742 case RI: | |
1743 if (R > getTopMargin()) | |
1744 R--; | |
1745 else | |
1746 insertLine(R, 1, SCROLL_DOWN); | |
1747 | |
1748 if (debug > 1) | |
1749 debug("RI"); | |
1750 | |
1751 break; | |
1752 | |
1753 case IND: | |
1754 if (debug > 2) { | |
1755 debugStr.append("IND at ") | |
1756 .append(R) | |
1757 .append(", tm is ") | |
1758 .append(getTopMargin()) | |
1759 .append(", bm is ") | |
1760 .append(getBottomMargin()); | |
1761 debug(debugStr.toString()); | |
1762 debugStr.setLength(0); | |
1763 } | |
1764 | |
1765 if (R == getBottomMargin() || R == rows - 1) | |
1766 insertLine(R, 1, SCROLL_UP); | |
1767 else | |
1768 R++; | |
1769 | |
1770 if (debug > 1) | |
1771 debug("IND (at " + R + " )"); | |
1772 | |
1773 break; | |
1774 | |
1775 case NEL: | |
1776 if (R == getBottomMargin() || R == rows - 1) | |
1777 insertLine(R, 1, SCROLL_UP); | |
1778 else | |
1779 R++; | |
1780 | |
1781 C = 0; | |
1782 | |
1783 if (debug > 1) | |
1784 debug("NEL (at " + R + " )"); | |
1785 | |
1786 break; | |
1787 | |
1788 case HTS: | |
1789 Tabs[C] = 1; | |
1790 | |
1791 if (debug > 1) | |
1792 debug("HTS"); | |
1793 | |
1794 break; | |
1795 | |
1796 case DCS: | |
1797 dcs = ""; | |
1798 term_state = TSTATE_DCS; | |
1799 break; | |
1800 | |
1801 default: | |
1802 doneflag = false; | |
1803 break; | |
1804 } | |
1805 | |
1806 if (doneflag) break; | |
1807 } | |
1808 | |
1809 switch (c) { | |
1810 case SS3: | |
1811 onegl = 3; | |
1812 break; | |
1813 | |
1814 case SS2: | |
1815 onegl = 2; | |
1816 break; | |
1817 | |
1818 case CSI: // should be in the 8bit section, but some BBS use this | |
1819 DCEvar = 0; | |
1820 DCEvars[0] = 0; | |
1821 DCEvars[1] = 0; | |
1822 DCEvars[2] = 0; | |
1823 DCEvars[3] = 0; | |
1824 term_state = TSTATE_CSI; | |
1825 break; | |
1826 | |
1827 case ESC: | |
1828 term_state = TSTATE_ESC; | |
1829 lastwaslf = 0; | |
1830 break; | |
1831 | |
1832 case 5: /* ENQ */ | |
1833 write(answerBack, false); | |
1834 break; | |
1835 | |
1836 case 12: | |
1837 /* FormFeed, Home for the BBS world */ | |
1838 deleteArea(0, 0, columns, rows, attributes); | |
1839 C = R = 0; | |
1840 break; | |
1841 | |
1842 case '\b': /* 8 */ | |
1843 C--; | |
1844 | |
1845 if (C < 0) | |
1846 C = 0; | |
1847 | |
1848 lastwaslf = 0; | |
1849 break; | |
1850 | |
1851 case '\t': | |
1852 do { | |
1853 // Don't overwrite or insert! TABS are not destructive, but movement! | |
1854 C++; | |
1855 } | |
1856 while (C < columns && (Tabs[C] == 0)); | |
1857 | |
1858 lastwaslf = 0; | |
1859 break; | |
1860 | |
1861 case '\r': // 13 CR | |
1862 C = 0; | |
1863 break; | |
1864 | |
1865 case '\n': // 10 LF | |
1866 if (debug > 3) | |
1867 debug("R= " + R + ", bm " + getBottomMargin() + ", tm=" + getTopMargin() + ", rows=" + rows); | |
1868 | |
1869 if (!vms) { | |
1870 if (lastwaslf != 0 && lastwaslf != c) // Ray: I do not understand this logic. | |
1871 break; | |
1872 | |
1873 lastwaslf = c; | |
1874 /*C = 0;*/ | |
1875 } | |
1876 | |
1877 if (R == getBottomMargin() || R >= rows - 1) | |
1878 insertLine(R, 1, SCROLL_UP); | |
1879 else | |
1880 R++; | |
1881 | |
1882 break; | |
1883 | |
1884 case 7: | |
1885 beep(); | |
1886 break; | |
1887 | |
1888 case '\016': /* SMACS , as */ | |
1889 /* ^N, Shift out - Put G1 into GL */ | |
1890 gl = 1; | |
1891 usedcharsets = true; | |
1892 break; | |
1893 | |
1894 case '\017': /* RMACS , ae */ | |
1895 /* ^O, Shift in - Put G0 into GL */ | |
1896 gl = 0; | |
1897 usedcharsets = true; | |
1898 break; | |
1899 | |
1900 default: { | |
1901 int thisgl = gl; | |
1902 | |
1903 if (onegl >= 0) { | |
1904 thisgl = onegl; | |
1905 onegl = -1; | |
1906 } | |
1907 | |
1908 lastwaslf = 0; | |
1909 | |
1910 if (c < 32) { | |
1911 if (c != 0) | |
1912 if (debug > 0) | |
1913 debug("TSTATE_DATA char: " + ((int) c)); | |
1914 | |
1915 /*break; some BBS really want those characters, like hearst etc. */ | |
1916 if (c == 0) /* print 0 ... you bet */ | |
1917 break; | |
1918 } | |
1919 | |
1920 if (C >= columns) { | |
1921 if (wraparound) { | |
1922 int bot = rows; | |
1923 | |
1924 // If we're in the scroll region, check against the bottom margin | |
1925 if (R <= getBottomMargin() && R >= getTopMargin()) | |
1926 bot = getBottomMargin() + 1; | |
1927 | |
1928 if (R < bot - 1) | |
1929 R++; | |
1930 else { | |
1931 if (debug > 3) debug("scrolling due to wrap at " + R); | |
1932 | |
1933 insertLine(R, 1, SCROLL_UP); | |
1934 } | |
1935 | |
1936 C = 0; | |
1937 } | |
1938 else { | |
1939 // cursor stays on last character. | |
1940 C = columns - 1; | |
1941 } | |
1942 } | |
1943 | |
1944 boolean mapped = false; | |
1945 | |
1946 // Mapping if DEC Special is chosen charset | |
1947 if (usedcharsets) { | |
1948 if (c >= '\u0020' && c <= '\u007f') { | |
1949 switch (gx[thisgl]) { | |
1950 case '0': | |
1951 | |
1952 // Remap SCOANSI line drawing to VT100 line drawing chars | |
1953 // for our SCO using customers. | |
1954 if (terminalID.equals("scoansi") || terminalID.equals("ansi")) { | |
1955 for (int i = 0; i < scoansi_acs.length(); i += 2) { | |
1956 if (c == scoansi_acs.charAt(i)) { | |
1957 c = scoansi_acs.charAt(i + 1); | |
1958 break; | |
1959 } | |
1960 } | |
1961 } | |
1962 | |
1963 if (c >= '\u005f' && c <= '\u007e') { | |
1964 c = DECSPECIAL[(short) c - 0x5f]; | |
1965 mapped = true; | |
1966 } | |
1967 | |
1968 break; | |
1969 | |
1970 case '<': // 'user preferred' is currently 'ISO Latin-1 suppl | |
1971 c = (char)((c & 0x7f) | 0x80); | |
1972 mapped = true; | |
1973 break; | |
1974 | |
1975 case 'A': | |
1976 case 'B': // Latin-1 , ASCII -> fall through | |
1977 mapped = true; | |
1978 break; | |
1979 | |
1980 default: | |
1981 debug("Unsupported GL mapping: " + gx[thisgl]); | |
1982 break; | |
1983 } | |
1984 } | |
1985 | |
1986 if (!mapped && (c >= '\u0080' && c <= '\u00ff')) { | |
1987 switch (gx[gr]) { | |
1988 case '0': | |
1989 if (c >= '\u00df' && c <= '\u00fe') { | |
1990 c = DECSPECIAL[c - '\u00df']; | |
1991 mapped = true; | |
1992 } | |
1993 | |
1994 break; | |
1995 | |
1996 case '<': | |
1997 case 'A': | |
1998 case 'B': | |
1999 mapped = true; | |
2000 break; | |
2001 | |
2002 default: | |
2003 debug("Unsupported GR mapping: " + gx[gr]); | |
2004 break; | |
2005 } | |
2006 } | |
2007 } | |
2008 | |
2009 if (!mapped && useibmcharset) | |
2010 c = map_cp850_unicode(c); | |
2011 | |
2012 /*if(true || (statusmode == 0)) { */ | |
2013 if (isWide) { | |
2014 if (C >= columns - 1) { | |
2015 if (wraparound) { | |
2016 int bot = rows; | |
2017 | |
2018 // If we're in the scroll region, check against the bottom margin | |
2019 if (R <= getBottomMargin() && R >= getTopMargin()) | |
2020 bot = getBottomMargin() + 1; | |
2021 | |
2022 if (R < bot - 1) | |
2023 R++; | |
2024 else { | |
2025 if (debug > 3) debug("scrolling due to wrap at " + R); | |
2026 | |
2027 insertLine(R, 1, SCROLL_UP); | |
2028 } | |
2029 | |
2030 C = 0; | |
2031 } | |
2032 else { | |
2033 // cursor stays on last wide character. | |
2034 C = columns - 2; | |
2035 } | |
2036 } | |
2037 } | |
2038 | |
2039 if (insertmode == 1) { | |
2040 if (isWide) { | |
2041 insertChar(C++, R, c, attributes | FULLWIDTH); | |
2042 insertChar(C, R, ' ', attributes | FULLWIDTH); | |
2043 } | |
2044 else | |
2045 insertChar(C, R, c, attributes); | |
2046 } | |
2047 else { | |
2048 if (isWide) { | |
2049 putChar(C++, R, c, attributes | FULLWIDTH); | |
2050 putChar(C, R, ' ', attributes | FULLWIDTH); | |
2051 } | |
2052 else | |
2053 putChar(C, R, c, attributes); | |
2054 } | |
2055 | |
2056 /* | |
2057 } else { | |
2058 if (insertmode==1) { | |
2059 insertChar(C, rows, c, attributes); | |
2060 } else { | |
2061 putChar(C, rows, c, attributes); | |
2062 } | |
2063 } | |
2064 */ | |
2065 C++; | |
2066 break; | |
2067 } | |
2068 } /* switch(c) */ | |
2069 | |
2070 break; | |
2071 | |
2072 case TSTATE_OSC: | |
2073 if ((c < 0x20) && (c != ESC)) {// NP - No printing character | |
2074 handle_osc(osc); | |
2075 term_state = TSTATE_DATA; | |
2076 break; | |
2077 } | |
2078 | |
2079 //but check for vt102 ESC \ | |
2080 if (c == '\\' && osc.charAt(osc.length() - 1) == ESC) { | |
2081 handle_osc(osc); | |
2082 term_state = TSTATE_DATA; | |
2083 break; | |
2084 } | |
2085 | |
2086 osc = osc + c; | |
2087 break; | |
2088 | |
2089 case TSTATE_ESCSPACE: | |
2090 term_state = TSTATE_DATA; | |
2091 | |
2092 switch (c) { | |
2093 case 'F': /* S7C1T, Disable output of 8-bit controls, use 7-bit */ | |
2094 output8bit = false; | |
2095 break; | |
2096 | |
2097 case 'G': /* S8C1T, Enable output of 8-bit control codes*/ | |
2098 output8bit = true; | |
2099 break; | |
2100 | |
2101 default: | |
2102 debug("ESC <space> " + c + " unhandled."); | |
2103 } | |
2104 | |
2105 break; | |
2106 | |
2107 case TSTATE_ESC: | |
2108 term_state = TSTATE_DATA; | |
2109 | |
2110 switch (c) { | |
2111 case ' ': | |
2112 term_state = TSTATE_ESCSPACE; | |
2113 break; | |
2114 | |
2115 case '#': | |
2116 term_state = TSTATE_ESCSQUARE; | |
2117 break; | |
2118 | |
2119 case 'c': | |
2120 /* Hard terminal reset */ | |
2121 reset(); | |
2122 break; | |
2123 | |
2124 case '[': | |
2125 DCEvar = 0; | |
2126 DCEvars[0] = 0; | |
2127 DCEvars[1] = 0; | |
2128 DCEvars[2] = 0; | |
2129 DCEvars[3] = 0; | |
2130 term_state = TSTATE_CSI; | |
2131 break; | |
2132 | |
2133 case ']': | |
2134 osc = ""; | |
2135 term_state = TSTATE_OSC; | |
2136 break; | |
2137 | |
2138 case 'P': | |
2139 dcs = ""; | |
2140 term_state = TSTATE_DCS; | |
2141 break; | |
2142 | |
2143 case 'A': /* CUU */ | |
2144 R--; | |
2145 | |
2146 if (R < 0) R = 0; | |
2147 | |
2148 break; | |
2149 | |
2150 case 'B': /* CUD */ | |
2151 R++; | |
2152 | |
2153 if (R >= rows) R = rows - 1; | |
2154 | |
2155 break; | |
2156 | |
2157 case 'C': | |
2158 C++; | |
2159 | |
2160 if (C >= columns) C = columns - 1; | |
2161 | |
2162 break; | |
2163 | |
2164 case 'I': // RI | |
2165 insertLine(R, 1, SCROLL_DOWN); | |
2166 break; | |
2167 | |
2168 case 'E': /* NEL */ | |
2169 if (R == getBottomMargin() || R == rows - 1) | |
2170 insertLine(R, 1, SCROLL_UP); | |
2171 else | |
2172 R++; | |
2173 | |
2174 C = 0; | |
2175 | |
2176 if (debug > 1) | |
2177 debug("ESC E (at " + R + ")"); | |
2178 | |
2179 break; | |
2180 | |
2181 case 'D': /* IND */ | |
2182 if (R == getBottomMargin() || R == rows - 1) | |
2183 insertLine(R, 1, SCROLL_UP); | |
2184 else | |
2185 R++; | |
2186 | |
2187 if (debug > 1) | |
2188 debug("ESC D (at " + R + " )"); | |
2189 | |
2190 break; | |
2191 | |
2192 case 'J': /* erase to end of screen */ | |
2193 if (R < rows - 1) | |
2194 deleteArea(0, R + 1, columns, rows - R - 1, attributes); | |
2195 | |
2196 if (C < columns - 1) | |
2197 deleteArea(C, R, columns - C, 1, attributes); | |
2198 | |
2199 break; | |
2200 | |
2201 case 'K': | |
2202 if (C < columns - 1) | |
2203 deleteArea(C, R, columns - C, 1, attributes); | |
2204 | |
2205 break; | |
2206 | |
2207 case 'M': // RI | |
2208 debug("ESC M : R is " + R + ", tm is " + getTopMargin() + ", bm is " + getBottomMargin()); | |
2209 | |
2210 if (R > getTopMargin()) { // just go up 1 line. | |
2211 R--; | |
2212 } | |
2213 else { // scroll down | |
2214 insertLine(R, 1, SCROLL_DOWN); | |
2215 } | |
2216 | |
2217 /* else do nothing ; */ | |
2218 if (debug > 2) | |
2219 debug("ESC M "); | |
2220 | |
2221 break; | |
2222 | |
2223 case 'H': | |
2224 if (debug > 1) | |
2225 debug("ESC H at " + C); | |
2226 | |
2227 /* right border probably ...*/ | |
2228 if (C >= columns) | |
2229 C = columns - 1; | |
2230 | |
2231 Tabs[C] = 1; | |
2232 break; | |
2233 | |
2234 case 'N': // SS2 | |
2235 onegl = 2; | |
2236 break; | |
2237 | |
2238 case 'O': // SS3 | |
2239 onegl = 3; | |
2240 break; | |
2241 | |
2242 case '=': | |
2243 | |
2244 /*application keypad*/ | |
2245 if (debug > 0) | |
2246 debug("ESC ="); | |
2247 | |
2248 keypadmode = true; | |
2249 break; | |
2250 | |
2251 case '<': /* vt52 mode off */ | |
2252 vt52mode = false; | |
2253 break; | |
2254 | |
2255 case '>': /*normal keypad*/ | |
2256 if (debug > 0) | |
2257 debug("ESC >"); | |
2258 | |
2259 keypadmode = false; | |
2260 break; | |
2261 | |
2262 case '7': /* DECSC: save cursor, attributes */ | |
2263 Sc = C; | |
2264 Sr = R; | |
2265 Sgl = gl; | |
2266 Sgr = gr; | |
2267 Sa = attributes; | |
2268 Sgx = new char[4]; | |
2269 | |
2270 for (int i = 0; i < 4; i++) Sgx[i] = gx[i]; | |
2271 | |
2272 if (debug > 1) | |
2273 debug("ESC 7"); | |
2274 | |
2275 break; | |
2276 | |
2277 case '8': /* DECRC: restore cursor, attributes */ | |
2278 C = Sc; | |
2279 R = Sr; | |
2280 gl = Sgl; | |
2281 gr = Sgr; | |
2282 | |
2283 if (Sgx != null) | |
2284 for (int i = 0; i < 4; i++) gx[i] = Sgx[i]; | |
2285 | |
2286 attributes = Sa; | |
2287 | |
2288 if (debug > 1) | |
2289 debug("ESC 8"); | |
2290 | |
2291 break; | |
2292 | |
2293 case '(': /* Designate G0 Character set (ISO 2022) */ | |
2294 term_state = TSTATE_SETG0; | |
2295 usedcharsets = true; | |
2296 break; | |
2297 | |
2298 case ')': /* Designate G1 character set (ISO 2022) */ | |
2299 term_state = TSTATE_SETG1; | |
2300 usedcharsets = true; | |
2301 break; | |
2302 | |
2303 case '*': /* Designate G2 Character set (ISO 2022) */ | |
2304 term_state = TSTATE_SETG2; | |
2305 usedcharsets = true; | |
2306 break; | |
2307 | |
2308 case '+': /* Designate G3 Character set (ISO 2022) */ | |
2309 term_state = TSTATE_SETG3; | |
2310 usedcharsets = true; | |
2311 break; | |
2312 | |
2313 case '~': /* Locking Shift 1, right */ | |
2314 gr = 1; | |
2315 usedcharsets = true; | |
2316 break; | |
2317 | |
2318 case 'n': /* Locking Shift 2 */ | |
2319 gl = 2; | |
2320 usedcharsets = true; | |
2321 break; | |
2322 | |
2323 case '}': /* Locking Shift 2, right */ | |
2324 gr = 2; | |
2325 usedcharsets = true; | |
2326 break; | |
2327 | |
2328 case 'o': /* Locking Shift 3 */ | |
2329 gl = 3; | |
2330 usedcharsets = true; | |
2331 break; | |
2332 | |
2333 case '|': /* Locking Shift 3, right */ | |
2334 gr = 3; | |
2335 usedcharsets = true; | |
2336 break; | |
2337 | |
2338 case 'Y': /* vt52 cursor address mode , next chars are x,y */ | |
2339 term_state = TSTATE_VT52Y; | |
2340 break; | |
2341 | |
2342 case '_': | |
2343 term_state = TSTATE_TITLE; | |
2344 break; | |
2345 | |
2346 case '\\': | |
2347 // TODO save title | |
2348 term_state = TSTATE_DATA; | |
2349 break; | |
2350 | |
2351 default: | |
2352 debug("ESC unknown letter: " + c + " (" + ((int) c) + ")"); | |
2353 break; | |
2354 } | |
2355 | |
2356 break; | |
2357 | |
2358 case TSTATE_VT52X: | |
2359 C = c - 37; | |
2360 | |
2361 if (C < 0) | |
2362 C = 0; | |
2363 else if (C >= width) | |
2364 C = width - 1; | |
2365 | |
2366 term_state = TSTATE_VT52Y; | |
2367 break; | |
2368 | |
2369 case TSTATE_VT52Y: | |
2370 R = c - 37; | |
2371 | |
2372 if (R < 0) | |
2373 R = 0; | |
2374 else if (R >= height) | |
2375 R = height - 1; | |
2376 | |
2377 term_state = TSTATE_DATA; | |
2378 break; | |
2379 | |
2380 case TSTATE_SETG0: | |
2381 if (c != '0' && c != 'A' && c != 'B' && c != '<') | |
2382 debug("ESC ( " + c + ": G0 char set? (" + ((int) c) + ")"); | |
2383 else { | |
2384 if (debug > 2) debug("ESC ( : G0 char set (" + c + " " + ((int) c) + ")"); | |
2385 | |
2386 gx[0] = c; | |
2387 } | |
2388 | |
2389 term_state = TSTATE_DATA; | |
2390 break; | |
2391 | |
2392 case TSTATE_SETG1: | |
2393 if (c != '0' && c != 'A' && c != 'B' && c != '<') { | |
2394 debug("ESC ) " + c + " (" + ((int) c) + ") :G1 char set?"); | |
2395 } | |
2396 else { | |
2397 if (debug > 2) debug("ESC ) :G1 char set (" + c + " " + ((int) c) + ")"); | |
2398 | |
2399 gx[1] = c; | |
2400 } | |
2401 | |
2402 term_state = TSTATE_DATA; | |
2403 break; | |
2404 | |
2405 case TSTATE_SETG2: | |
2406 if (c != '0' && c != 'A' && c != 'B' && c != '<') | |
2407 debug("ESC*:G2 char set? (" + ((int) c) + ")"); | |
2408 else { | |
2409 if (debug > 2) debug("ESC*:G2 char set (" + c + " " + ((int) c) + ")"); | |
2410 | |
2411 gx[2] = c; | |
2412 } | |
2413 | |
2414 term_state = TSTATE_DATA; | |
2415 break; | |
2416 | |
2417 case TSTATE_SETG3: | |
2418 if (c != '0' && c != 'A' && c != 'B' && c != '<') | |
2419 debug("ESC+:G3 char set? (" + ((int) c) + ")"); | |
2420 else { | |
2421 if (debug > 2) debug("ESC+:G3 char set (" + c + " " + ((int) c) + ")"); | |
2422 | |
2423 gx[3] = c; | |
2424 } | |
2425 | |
2426 term_state = TSTATE_DATA; | |
2427 break; | |
2428 | |
2429 case TSTATE_ESCSQUARE: | |
2430 switch (c) { | |
2431 case '8': | |
2432 for (int i = 0; i < columns; i++) | |
2433 for (int j = 0; j < rows; j++) | |
2434 putChar(i, j, 'E', 0); | |
2435 | |
2436 break; | |
2437 | |
2438 default: | |
2439 debug("ESC # " + c + " not supported."); | |
2440 break; | |
2441 } | |
2442 | |
2443 term_state = TSTATE_DATA; | |
2444 break; | |
2445 | |
2446 case TSTATE_DCS: | |
2447 if (c == '\\' && dcs.charAt(dcs.length() - 1) == ESC) { | |
2448 handle_dcs(dcs); | |
2449 term_state = TSTATE_DATA; | |
2450 break; | |
2451 } | |
2452 | |
2453 dcs = dcs + c; | |
2454 break; | |
2455 | |
2456 case TSTATE_DCEQ: | |
2457 term_state = TSTATE_DATA; | |
2458 | |
2459 switch (c) { | |
2460 case '0': | |
2461 case '1': | |
2462 case '2': | |
2463 case '3': | |
2464 case '4': | |
2465 case '5': | |
2466 case '6': | |
2467 case '7': | |
2468 case '8': | |
2469 case '9': | |
2470 DCEvars[DCEvar] = DCEvars[DCEvar] * 10 + (c) - 48; | |
2471 term_state = TSTATE_DCEQ; | |
2472 break; | |
2473 | |
2474 case ';': | |
2475 DCEvar++; | |
2476 DCEvars[DCEvar] = 0; | |
2477 term_state = TSTATE_DCEQ; | |
2478 break; | |
2479 | |
2480 case 's': // XTERM_SAVE missing! | |
2481 if (true || debug > 1) | |
2482 debug("ESC [ ? " + DCEvars[0] + " s unimplemented!"); | |
2483 | |
2484 break; | |
2485 | |
2486 case 'r': // XTERM_RESTORE | |
2487 if (true || debug > 1) | |
2488 debug("ESC [ ? " + DCEvars[0] + " r"); | |
2489 | |
2490 /* DEC Mode reset */ | |
2491 for (int i = 0; i <= DCEvar; i++) { | |
2492 switch (DCEvars[i]) { | |
2493 case 3: /* 80 columns*/ | |
2494 setScreenSize(80, height, true); | |
2495 break; | |
2496 | |
2497 case 4: /* scrolling mode, smooth */ | |
2498 break; | |
2499 | |
2500 case 5: /* light background */ | |
2501 break; | |
2502 | |
2503 case 6: /* DECOM (Origin Mode) move inside margins. */ | |
2504 moveoutsidemargins = true; | |
2505 break; | |
2506 | |
2507 case 7: /* DECAWM: Autowrap Mode */ | |
2508 wraparound = false; | |
2509 break; | |
2510 | |
2511 case 12:/* local echo off */ | |
2512 break; | |
2513 | |
2514 case 9: /* X10 mouse */ | |
2515 case 1000: /* xterm style mouse report on */ | |
2516 case 1001: | |
2517 case 1002: | |
2518 case 1003: | |
2519 mouserpt = DCEvars[i]; | |
2520 break; | |
2521 | |
2522 default: | |
2523 debug("ESC [ ? " + DCEvars[0] + " r, unimplemented!"); | |
2524 } | |
2525 } | |
2526 | |
2527 break; | |
2528 | |
2529 case 'h': // DECSET | |
2530 if (debug > 0) | |
2531 debug("ESC [ ? " + DCEvars[0] + " h"); | |
2532 | |
2533 /* DEC Mode set */ | |
2534 for (int i = 0; i <= DCEvar; i++) { | |
2535 switch (DCEvars[i]) { | |
2536 case 1: /* Application cursor keys */ | |
2537 KeyUp[0] = "\u001bOA"; | |
2538 KeyDown[0] = "\u001bOB"; | |
2539 KeyRight[0] = "\u001bOC"; | |
2540 KeyLeft[0] = "\u001bOD"; | |
2541 break; | |
2542 | |
2543 case 2: /* DECANM */ | |
2544 vt52mode = false; | |
2545 break; | |
2546 | |
2547 case 3: /* 132 columns*/ | |
2548 setScreenSize(132, height, true); | |
2549 break; | |
2550 | |
2551 case 6: /* DECOM: move inside margins. */ | |
2552 moveoutsidemargins = false; | |
2553 break; | |
2554 | |
2555 case 7: /* DECAWM: Autowrap Mode */ | |
2556 wraparound = true; | |
2557 break; | |
2558 | |
2559 case 25: /* turn cursor on */ | |
2560 showCursor(true); | |
2561 break; | |
2562 | |
2563 case 9: /* X10 mouse */ | |
2564 case 1000: /* xterm style mouse report on */ | |
2565 case 1001: | |
2566 case 1002: | |
2567 case 1003: | |
2568 mouserpt = DCEvars[i]; | |
2569 break; | |
2570 | |
2571 /* unimplemented stuff, fall through */ | |
2572 /* 4 - scrolling mode, smooth */ | |
2573 /* 5 - light background */ | |
2574 /* 12 - local echo off */ | |
2575 /* 18 - DECPFF - Printer Form Feed Mode -> On */ | |
2576 /* 19 - DECPEX - Printer Extent Mode -> Screen */ | |
2577 default: | |
2578 debug("ESC [ ? " + DCEvars[0] + " h, unsupported."); | |
2579 break; | |
2580 } | |
2581 } | |
2582 | |
2583 break; | |
2584 | |
2585 case 'i': // DEC Printer Control, autoprint, echo screenchars to printer | |
2586 | |
2587 // This is different to CSI i! | |
2588 // Also: "Autoprint prints a final display line only when the | |
2589 // cursor is moved off the line by an autowrap or LF, FF, or | |
2590 // VT (otherwise do not print the line)." | |
2591 switch (DCEvars[0]) { | |
2592 case 1: | |
2593 if (debug > 1) | |
2594 debug("CSI ? 1 i : Print line containing cursor"); | |
2595 | |
2596 break; | |
2597 | |
2598 case 4: | |
2599 if (debug > 1) | |
2600 debug("CSI ? 4 i : Start passthrough printing"); | |
2601 | |
2602 break; | |
2603 | |
2604 case 5: | |
2605 if (debug > 1) | |
2606 debug("CSI ? 4 i : Stop passthrough printing"); | |
2607 | |
2608 break; | |
2609 } | |
2610 | |
2611 break; | |
2612 | |
2613 case 'l': //DECRST | |
2614 | |
2615 /* DEC Mode reset */ | |
2616 if (debug > 0) | |
2617 debug("ESC [ ? " + DCEvars[0] + " l"); | |
2618 | |
2619 for (int i = 0; i <= DCEvar; i++) { | |
2620 switch (DCEvars[i]) { | |
2621 case 1: /* Application cursor keys */ | |
2622 KeyUp[0] = "\u001b[A"; | |
2623 KeyDown[0] = "\u001b[B"; | |
2624 KeyRight[0] = "\u001b[C"; | |
2625 KeyLeft[0] = "\u001b[D"; | |
2626 break; | |
2627 | |
2628 case 2: /* DECANM */ | |
2629 vt52mode = true; | |
2630 break; | |
2631 | |
2632 case 3: /* 80 columns*/ | |
2633 setScreenSize(80, height, true); | |
2634 break; | |
2635 | |
2636 case 6: /* DECOM: move outside margins. */ | |
2637 moveoutsidemargins = true; | |
2638 break; | |
2639 | |
2640 case 7: /* DECAWM: Autowrap Mode OFF */ | |
2641 wraparound = false; | |
2642 break; | |
2643 | |
2644 case 25: /* turn cursor off */ | |
2645 showCursor(false); | |
2646 break; | |
2647 | |
2648 /* Unimplemented stuff: */ | |
2649 /* 4 - scrolling mode, jump */ | |
2650 /* 5 - dark background */ | |
2651 /* 7 - DECAWM - no wrap around mode */ | |
2652 /* 12 - local echo on */ | |
2653 /* 18 - DECPFF - Printer Form Feed Mode -> Off*/ | |
2654 /* 19 - DECPEX - Printer Extent Mode -> Scrolling Region */ | |
2655 case 9: /* X10 mouse */ | |
2656 case 1000: /* xterm style mouse report OFF */ | |
2657 case 1001: | |
2658 case 1002: | |
2659 case 1003: | |
2660 mouserpt = 0; | |
2661 break; | |
2662 | |
2663 default: | |
2664 debug("ESC [ ? " + DCEvars[0] + " l, unsupported."); | |
2665 break; | |
2666 } | |
2667 } | |
2668 | |
2669 break; | |
2670 | |
2671 case 'n': | |
2672 if (debug > 0) | |
2673 debug("ESC [ ? " + DCEvars[0] + " n"); | |
2674 | |
2675 switch (DCEvars[0]) { | |
2676 case 15: | |
2677 /* printer? no printer. */ | |
2678 write((ESC) + "[?13n", false); | |
2679 debug("ESC[5n"); | |
2680 break; | |
2681 | |
2682 default: | |
2683 debug("ESC [ ? " + DCEvars[0] + " n, unsupported."); | |
2684 break; | |
2685 } | |
2686 | |
2687 break; | |
2688 | |
2689 default: | |
2690 debug("ESC [ ? " + DCEvars[0] + " " + c + ", unsupported."); | |
2691 break; | |
2692 } | |
2693 | |
2694 break; | |
2695 | |
2696 case TSTATE_CSI_EX: | |
2697 term_state = TSTATE_DATA; | |
2698 | |
2699 switch (c) { | |
2700 case ESC: | |
2701 term_state = TSTATE_ESC; | |
2702 break; | |
2703 | |
2704 default: | |
2705 debug("Unknown character ESC[! character is " + (int) c); | |
2706 break; | |
2707 } | |
2708 | |
2709 break; | |
2710 | |
2711 case TSTATE_CSI_TICKS: | |
2712 term_state = TSTATE_DATA; | |
2713 | |
2714 switch (c) { | |
2715 case 'p': | |
2716 debug("Conformance level: " + DCEvars[0] + " (unsupported)," + DCEvars[1]); | |
2717 | |
2718 if (DCEvars[0] == 61) { | |
2719 output8bit = false; | |
2720 break; | |
2721 } | |
2722 | |
2723 if (DCEvars[1] == 1) { | |
2724 output8bit = false; | |
2725 } | |
2726 else { | |
2727 output8bit = true; /* 0 or 2 */ | |
2728 } | |
2729 | |
2730 break; | |
2731 | |
2732 default: | |
2733 debug("Unknown ESC [... \"" + c); | |
2734 break; | |
2735 } | |
2736 | |
2737 break; | |
2738 | |
2739 case TSTATE_CSI_EQUAL: | |
2740 term_state = TSTATE_DATA; | |
2741 | |
2742 switch (c) { | |
2743 case '0': | |
2744 case '1': | |
2745 case '2': | |
2746 case '3': | |
2747 case '4': | |
2748 case '5': | |
2749 case '6': | |
2750 case '7': | |
2751 case '8': | |
2752 case '9': | |
2753 DCEvars[DCEvar] = DCEvars[DCEvar] * 10 + (c) - 48; | |
2754 term_state = TSTATE_CSI_EQUAL; | |
2755 break; | |
2756 | |
2757 case ';': | |
2758 DCEvar++; | |
2759 DCEvars[DCEvar] = 0; | |
2760 term_state = TSTATE_CSI_EQUAL; | |
2761 break; | |
2762 | |
2763 case 'F': { /* SCO ANSI foreground */ | |
2764 int newcolor; | |
2765 debug("ESC [ = " + DCEvars[0] + " F"); | |
2766 attributes &= ~COLOR_FG; | |
2767 newcolor = ((DCEvars[0] & 1) << 2) | | |
2768 (DCEvars[0] & 2) | | |
2769 ((DCEvars[0] & 4) >> 2) ; | |
2770 attributes |= (newcolor + 1) << COLOR_FG_SHIFT; | |
2771 break; | |
2772 } | |
2773 | |
2774 case 'G': { /* SCO ANSI background */ | |
2775 int newcolor; | |
2776 debug("ESC [ = " + DCEvars[0] + " G"); | |
2777 attributes &= ~COLOR_BG; | |
2778 newcolor = ((DCEvars[0] & 1) << 2) | | |
2779 (DCEvars[0] & 2) | | |
2780 ((DCEvars[0] & 4) >> 2) ; | |
2781 attributes |= (newcolor + 1) << COLOR_BG_SHIFT; | |
2782 break; | |
2783 } | |
2784 | |
2785 default: | |
2786 debugStr.append("Unknown ESC [ = "); | |
2787 | |
2788 for (int i = 0; i <= DCEvar; i++) { | |
2789 debugStr.append(DCEvars[i]) | |
2790 .append(','); | |
2791 } | |
2792 | |
2793 debugStr.append(c); | |
2794 debug(debugStr.toString()); | |
2795 debugStr.setLength(0); | |
2796 break; | |
2797 } | |
2798 | |
2799 break; | |
2800 | |
2801 case TSTATE_CSI_DOLLAR: | |
2802 term_state = TSTATE_DATA; | |
2803 | |
2804 switch (c) { | |
2805 case '}': | |
2806 debug("Active Status Display now " + DCEvars[0]); | |
2807 statusmode = DCEvars[0]; | |
2808 break; | |
2809 | |
2810 /* bad documentation? | |
2811 case '-': | |
2812 debug("Set Status Display now "+DCEvars[0]); | |
2813 break; | |
2814 */ | |
2815 case '~': | |
2816 debug("Status Line mode now " + DCEvars[0]); | |
2817 break; | |
2818 | |
2819 default: | |
2820 debug("UNKNOWN Status Display code " + c + ", with Pn=" + DCEvars[0]); | |
2821 break; | |
2822 } | |
2823 | |
2824 break; | |
2825 | |
2826 case TSTATE_CSI: | |
2827 term_state = TSTATE_DATA; | |
2828 | |
2829 switch (c) { | |
2830 case '"': | |
2831 term_state = TSTATE_CSI_TICKS; | |
2832 break; | |
2833 | |
2834 case '$': | |
2835 term_state = TSTATE_CSI_DOLLAR; | |
2836 break; | |
2837 | |
2838 case '=': | |
2839 term_state = TSTATE_CSI_EQUAL; | |
2840 break; | |
2841 | |
2842 case '!': | |
2843 term_state = TSTATE_CSI_EX; | |
2844 break; | |
2845 | |
2846 case '?': | |
2847 DCEvar = 0; | |
2848 DCEvars[0] = 0; | |
2849 term_state = TSTATE_DCEQ; | |
2850 break; | |
2851 | |
2852 case '0': | |
2853 case '1': | |
2854 case '2': | |
2855 case '3': | |
2856 case '4': | |
2857 case '5': | |
2858 case '6': | |
2859 case '7': | |
2860 case '8': | |
2861 case '9': | |
2862 DCEvars[DCEvar] = DCEvars[DCEvar] * 10 + (c) - 48; | |
2863 term_state = TSTATE_CSI; | |
2864 break; | |
2865 | |
2866 case ';': | |
2867 DCEvar++; | |
2868 DCEvars[DCEvar] = 0; | |
2869 term_state = TSTATE_CSI; | |
2870 break; | |
2871 | |
2872 case 'c':/* send primary device attributes */ | |
2873 /* send (ESC[?61c) */ | |
2874 String subcode = ""; | |
2875 | |
2876 if (terminalID.equals("vt320")) subcode = "63;"; | |
2877 | |
2878 if (terminalID.equals("vt220")) subcode = "62;"; | |
2879 | |
2880 if (terminalID.equals("vt100")) subcode = "61;"; | |
2881 | |
2882 write((ESC) + "[?" + subcode + "1;2c", false); | |
2883 | |
2884 if (debug > 1) | |
2885 debug("ESC [ " + DCEvars[0] + " c"); | |
2886 | |
2887 break; | |
2888 | |
2889 case 'q': | |
2890 if (debug > 1) | |
2891 debug("ESC [ " + DCEvars[0] + " q"); | |
2892 | |
2893 break; | |
2894 | |
2895 case 'g': | |
2896 | |
2897 /* used for tabsets */ | |
2898 switch (DCEvars[0]) { | |
2899 case 3:/* clear them */ | |
2900 Tabs = new byte[width]; | |
2901 break; | |
2902 | |
2903 case 0: | |
2904 Tabs[C] = 0; | |
2905 break; | |
2906 } | |
2907 | |
2908 if (debug > 1) | |
2909 debug("ESC [ " + DCEvars[0] + " g"); | |
2910 | |
2911 break; | |
2912 | |
2913 case 'h': | |
2914 switch (DCEvars[0]) { | |
2915 case 4: | |
2916 insertmode = 1; | |
2917 break; | |
2918 | |
2919 case 20: | |
2920 debug("Setting CRLF to TRUE"); | |
2921 sendcrlf = true; | |
2922 break; | |
2923 | |
2924 default: | |
2925 debug("unsupported: ESC [ " + DCEvars[0] + " h"); | |
2926 break; | |
2927 } | |
2928 | |
2929 if (debug > 1) | |
2930 debug("ESC [ " + DCEvars[0] + " h"); | |
2931 | |
2932 break; | |
2933 | |
2934 case 'i': // Printer Controller mode. | |
2935 | |
2936 // "Transparent printing sends all output, except the CSI 4 i | |
2937 // termination string, to the printer and not the screen, | |
2938 // uses an 8-bit channel if no parity so NUL and DEL will be | |
2939 // seen by the printer and by the termination recognizer code, | |
2940 // and all translation and character set selections are | |
2941 // bypassed." | |
2942 switch (DCEvars[0]) { | |
2943 case 0: | |
2944 if (debug > 1) | |
2945 debug("CSI 0 i: Print Screen, not implemented."); | |
2946 | |
2947 break; | |
2948 | |
2949 case 4: | |
2950 if (debug > 1) | |
2951 debug("CSI 4 i: Enable Transparent Printing, not implemented."); | |
2952 | |
2953 break; | |
2954 | |
2955 case 5: | |
2956 if (debug > 1) | |
2957 debug("CSI 4/5 i: Disable Transparent Printing, not implemented."); | |
2958 | |
2959 break; | |
2960 | |
2961 default: | |
2962 debug("ESC [ " + DCEvars[0] + " i, unimplemented!"); | |
2963 } | |
2964 | |
2965 break; | |
2966 | |
2967 case 'l': | |
2968 switch (DCEvars[0]) { | |
2969 case 4: | |
2970 insertmode = 0; | |
2971 break; | |
2972 | |
2973 case 20: | |
2974 debug("Setting CRLF to FALSE"); | |
2975 sendcrlf = false; | |
2976 break; | |
2977 | |
2978 default: | |
2979 debug("ESC [ " + DCEvars[0] + " l, unimplemented!"); | |
2980 break; | |
2981 } | |
2982 | |
2983 break; | |
2984 | |
2985 case 'A': { // CUU | |
2986 int limit; | |
2987 | |
2988 /* FIXME: xterm only cares about 0 and topmargin */ | |
2989 if (R >= getTopMargin()) { | |
2990 limit = getTopMargin(); | |
2991 } | |
2992 else | |
2993 limit = 0; | |
2994 | |
2995 if (DCEvars[0] == 0) | |
2996 R--; | |
2997 else | |
2998 R -= DCEvars[0]; | |
2999 | |
3000 if (R < limit) | |
3001 R = limit; | |
3002 | |
3003 if (debug > 1) | |
3004 debug("ESC [ " + DCEvars[0] + " A"); | |
3005 | |
3006 break; | |
3007 } | |
3008 | |
3009 case 'B': // CUD | |
3010 /* cursor down n (1) times */ | |
3011 { | |
3012 int limit; | |
3013 | |
3014 if (R <= getBottomMargin()) { | |
3015 limit = getBottomMargin(); | |
3016 } | |
3017 else | |
3018 limit = rows - 1; | |
3019 | |
3020 if (DCEvars[0] == 0) | |
3021 R++; | |
3022 else | |
3023 R += DCEvars[0]; | |
3024 | |
3025 if (R > limit) | |
3026 R = limit; | |
3027 else { | |
3028 if (debug > 2) debug("Not limited."); | |
3029 } | |
3030 | |
3031 if (debug > 2) debug("to: " + R); | |
3032 | |
3033 if (debug > 1) | |
3034 debug("ESC [ " + DCEvars[0] + " B (at C=" + C + ")"); | |
3035 | |
3036 break; | |
3037 } | |
3038 | |
3039 case 'C': | |
3040 if (DCEvars[0] == 0) | |
3041 DCEvars[0] = 1; | |
3042 | |
3043 while (DCEvars[0]-- > 0) { | |
3044 C++; | |
3045 } | |
3046 | |
3047 if (C >= columns) | |
3048 C = columns - 1; | |
3049 | |
3050 if (debug > 1) | |
3051 debug("ESC [ " + DCEvars[0] + " C"); | |
3052 | |
3053 break; | |
3054 | |
3055 case 'd': // CVA | |
3056 R = DCEvars[0] - 1; | |
3057 | |
3058 if (R < 0) | |
3059 R = 0; | |
3060 else if (R >= height) | |
3061 R = height - 1; | |
3062 | |
3063 if (debug > 1) | |
3064 debug("ESC [ " + DCEvars[0] + " d"); | |
3065 | |
3066 break; | |
3067 | |
3068 case 'D': | |
3069 if (DCEvars[0] == 0) | |
3070 DCEvars[0] = 1; | |
3071 | |
3072 while (DCEvars[0]-- > 0) { | |
3073 C--; | |
3074 } | |
3075 | |
3076 if (C < 0) C = 0; | |
3077 | |
3078 if (debug > 1) | |
3079 debug("ESC [ " + DCEvars[0] + " D"); | |
3080 | |
3081 break; | |
3082 | |
3083 case 'r': // DECSTBM | |
3084 if (DCEvar > 0) { // Ray: Any argument is optional | |
3085 R = DCEvars[1] - 1; | |
3086 | |
3087 if (R < 0) | |
3088 R = rows - 1; | |
3089 else if (R >= rows) { | |
3090 R = rows - 1; | |
3091 } | |
3092 } | |
3093 else | |
3094 R = rows - 1; | |
3095 | |
3096 int bot = R; | |
3097 | |
3098 if (R >= DCEvars[0]) { | |
3099 R = DCEvars[0] - 1; | |
3100 | |
3101 if (R < 0) | |
3102 R = 0; | |
3103 } | |
3104 | |
3105 setMargins(R, bot); | |
3106 _SetCursor(0, 0); | |
3107 | |
3108 if (debug > 1) | |
3109 debug("ESC [" + DCEvars[0] + " ; " + DCEvars[1] + " r"); | |
3110 | |
3111 break; | |
3112 | |
3113 case 'G': /* CUP / cursor absolute column */ | |
3114 C = DCEvars[0]; | |
3115 | |
3116 if (C < 0) | |
3117 C = 0; | |
3118 else if (C >= width) | |
3119 C = width - 1; | |
3120 | |
3121 if (debug > 1) debug("ESC [ " + DCEvars[0] + " G"); | |
3122 | |
3123 break; | |
3124 | |
3125 case 'H': /* CUP / cursor position */ | |
3126 /* gets 2 arguments */ | |
3127 _SetCursor(DCEvars[0] - 1, DCEvars[1] - 1); | |
3128 | |
3129 if (debug > 2) { | |
3130 debug("ESC [ " + DCEvars[0] + ";" + DCEvars[1] + " H, moveoutsidemargins " + moveoutsidemargins); | |
3131 debug(" -> R now " + R + ", C now " + C); | |
3132 } | |
3133 | |
3134 break; | |
3135 | |
3136 case 'f': /* move cursor 2 */ | |
3137 /* gets 2 arguments */ | |
3138 R = DCEvars[0] - 1; | |
3139 C = DCEvars[1] - 1; | |
3140 | |
3141 if (C < 0) | |
3142 C = 0; | |
3143 else if (C >= width) | |
3144 C = width - 1; | |
3145 | |
3146 if (R < 0) | |
3147 R = 0; | |
3148 else if (R >= height) | |
3149 R = height - 1; | |
3150 | |
3151 if (debug > 2) | |
3152 debug("ESC [ " + DCEvars[0] + ";" + DCEvars[1] + " f"); | |
3153 | |
3154 break; | |
3155 | |
3156 case 'S': /* ind aka 'scroll forward' */ | |
3157 if (DCEvars[0] == 0) | |
3158 insertLine(getBottomMargin(), SCROLL_UP); | |
3159 else | |
3160 insertLine(getBottomMargin(), DCEvars[0], SCROLL_UP); | |
3161 | |
3162 break; | |
3163 | |
3164 case 'L': | |
3165 | |
3166 /* insert n lines */ | |
3167 if (DCEvars[0] == 0) | |
3168 insertLine(R, SCROLL_DOWN); | |
3169 else | |
3170 insertLine(R, DCEvars[0], SCROLL_DOWN); | |
3171 | |
3172 if (debug > 1) | |
3173 debug("ESC [ " + DCEvars[0] + "" + (c) + " (at R " + R + ")"); | |
3174 | |
3175 break; | |
3176 | |
3177 case 'T': /* 'ri' aka scroll backward */ | |
3178 if (DCEvars[0] == 0) | |
3179 insertLine(getTopMargin(), SCROLL_DOWN); | |
3180 else | |
3181 insertLine(getTopMargin(), DCEvars[0], SCROLL_DOWN); | |
3182 | |
3183 break; | |
3184 | |
3185 case 'M': | |
3186 if (debug > 1) | |
3187 debug("ESC [ " + DCEvars[0] + "" + (c) + " at R=" + R); | |
3188 | |
3189 if (DCEvars[0] == 0) | |
3190 deleteLine(R); | |
3191 else | |
3192 for (int i = 0; i < DCEvars[0]; i++) | |
3193 deleteLine(R); | |
3194 | |
3195 break; | |
3196 | |
3197 case 'K': | |
3198 if (debug > 1) | |
3199 debug("ESC [ " + DCEvars[0] + " K"); | |
3200 | |
3201 /* clear in line */ | |
3202 switch (DCEvars[0]) { | |
3203 case 6: /* 97801 uses ESC[6K for delete to end of line */ | |
3204 case 0:/*clear to right*/ | |
3205 if (C < columns - 1) | |
3206 deleteArea(C, R, columns - C, 1, attributes); | |
3207 | |
3208 break; | |
3209 | |
3210 case 1:/*clear to the left, including this */ | |
3211 if (C > 0) | |
3212 deleteArea(0, R, C + 1, 1, attributes); | |
3213 | |
3214 break; | |
3215 | |
3216 case 2:/*clear whole line */ | |
3217 deleteArea(0, R, columns, 1, attributes); | |
3218 break; | |
3219 } | |
3220 | |
3221 break; | |
3222 | |
3223 case 'J': | |
3224 | |
3225 /* clear below current line */ | |
3226 switch (DCEvars[0]) { | |
3227 case 0: | |
3228 if (R < rows - 1) | |
3229 deleteArea(0, R + 1, columns, rows - R - 1, attributes); | |
3230 | |
3231 if (C < columns - 1) | |
3232 deleteArea(C, R, columns - C, 1, attributes); | |
3233 | |
3234 break; | |
3235 | |
3236 case 1: | |
3237 if (R > 0) | |
3238 deleteArea(0, 0, columns, R, attributes); | |
3239 | |
3240 if (C > 0) | |
3241 deleteArea(0, R, C + 1, 1, attributes); // include up to and including current | |
3242 | |
3243 break; | |
3244 | |
3245 case 2: | |
3246 deleteArea(0, 0, columns, rows, attributes); | |
3247 break; | |
3248 } | |
3249 | |
3250 if (debug > 1) | |
3251 debug("ESC [ " + DCEvars[0] + " J"); | |
3252 | |
3253 break; | |
3254 | |
3255 case '@': | |
3256 if (DCEvars[0] == 0) DCEvars[0] = 1; | |
3257 | |
3258 if (debug > 1) | |
3259 debug("ESC [ " + DCEvars[0] + " @"); | |
3260 | |
3261 for (int i = 0; i < DCEvars[0]; i++) | |
3262 insertChar(C, R, ' ', attributes); | |
3263 | |
3264 break; | |
3265 | |
3266 case 'X': { | |
3267 int toerase = DCEvars[0]; | |
3268 | |
3269 if (debug > 1) | |
3270 debug("ESC [ " + DCEvars[0] + " X, C=" + C + ",R=" + R); | |
3271 | |
3272 if (toerase == 0) | |
3273 toerase = 1; | |
3274 | |
3275 if (toerase + C > columns) | |
3276 toerase = columns - C; | |
3277 | |
3278 deleteArea(C, R, toerase, 1, attributes); | |
3279 // does not change cursor position | |
3280 break; | |
3281 } | |
3282 | |
3283 case 'P': | |
3284 if (debug > 1) | |
3285 debug("ESC [ " + DCEvars[0] + " P, C=" + C + ",R=" + R); | |
3286 | |
3287 if (DCEvars[0] == 0) DCEvars[0] = 1; | |
3288 | |
3289 for (int i = 0; i < DCEvars[0]; i++) | |
3290 deleteChar(C, R); | |
3291 | |
3292 break; | |
3293 | |
3294 case 'n': | |
3295 switch (DCEvars[0]) { | |
3296 case 5: /* malfunction? No malfunction. */ | |
3297 writeSpecial((ESC) + "[0n"); | |
3298 | |
3299 if (debug > 1) | |
3300 debug("ESC[5n"); | |
3301 | |
3302 break; | |
3303 | |
3304 case 6: | |
3305 // DO NOT offset R and C by 1! (checked against /usr/X11R6/bin/resize | |
3306 // FIXME check again. | |
3307 // FIXME: but vttest thinks different??? | |
3308 writeSpecial((ESC) + "[" + R + ";" + C + "R"); | |
3309 | |
3310 if (debug > 1) | |
3311 debug("ESC[6n"); | |
3312 | |
3313 break; | |
3314 | |
3315 default: | |
3316 if (debug > 0) | |
3317 debug("ESC [ " + DCEvars[0] + " n??"); | |
3318 | |
3319 break; | |
3320 } | |
3321 | |
3322 break; | |
3323 | |
3324 case 's': /* DECSC - save cursor */ | |
3325 Sc = C; | |
3326 Sr = R; | |
3327 Sa = attributes; | |
3328 | |
3329 if (debug > 3) | |
3330 debug("ESC[s"); | |
3331 | |
3332 break; | |
3333 | |
3334 case 'u': /* DECRC - restore cursor */ | |
3335 C = Sc; | |
3336 R = Sr; | |
3337 attributes = Sa; | |
3338 | |
3339 if (debug > 3) | |
3340 debug("ESC[u"); | |
3341 | |
3342 break; | |
3343 | |
3344 case 'm': /* attributes as color, bold , blink,*/ | |
3345 if (debug > 3) | |
3346 debug("ESC [ "); | |
3347 | |
3348 if (DCEvar == 0 && DCEvars[0] == 0) | |
3349 attributes = 0; | |
3350 | |
3351 for (int i = 0; i <= DCEvar; i++) { | |
3352 switch (DCEvars[i]) { | |
3353 case 0: | |
3354 if (DCEvar > 0) { | |
3355 if (terminalID.equals("scoansi")) { | |
3356 attributes &= COLOR; /* Keeps color. Strange but true. */ | |
3357 } | |
3358 else { | |
3359 attributes = 0; | |
3360 } | |
3361 } | |
3362 | |
3363 break; | |
3364 | |
3365 case 1: | |
3366 attributes |= BOLD; | |
3367 attributes &= ~LOW; | |
3368 break; | |
3369 | |
3370 case 2: | |
3371 | |
3372 /* SCO color hack mode */ | |
3373 if (terminalID.equals("scoansi") && ((DCEvar - i) >= 2)) { | |
3374 int ncolor; | |
3375 attributes &= ~(COLOR | BOLD); | |
3376 ncolor = DCEvars[i + 1]; | |
3377 | |
3378 if ((ncolor & 8) == 8) | |
3379 attributes |= BOLD; | |
3380 | |
3381 ncolor = ((ncolor & 1) << 2) | (ncolor & 2) | ((ncolor & 4) >> 2); | |
3382 attributes |= ((ncolor) + 1) << COLOR_FG_SHIFT; | |
3383 ncolor = DCEvars[i + 2]; | |
3384 ncolor = ((ncolor & 1) << 2) | (ncolor & 2) | ((ncolor & 4) >> 2); | |
3385 attributes |= ((ncolor) + 1) << COLOR_BG_SHIFT; | |
3386 i += 2; | |
3387 } | |
3388 else { | |
3389 attributes |= LOW; | |
3390 } | |
3391 | |
3392 break; | |
3393 | |
3394 case 3: /* italics */ | |
3395 attributes |= INVERT; | |
3396 break; | |
3397 | |
3398 case 4: | |
3399 attributes |= UNDERLINE; | |
3400 break; | |
3401 | |
3402 case 7: | |
3403 attributes |= INVERT; | |
3404 break; | |
3405 | |
3406 case 8: | |
3407 attributes |= INVISIBLE; | |
3408 break; | |
3409 | |
3410 case 5: /* blink on */ | |
3411 break; | |
3412 | |
3413 /* 10 - ANSI X3.64-1979, select primary font, don't display control | |
3414 * chars, don't set bit 8 on output */ | |
3415 case 10: | |
3416 gl = 0; | |
3417 usedcharsets = true; | |
3418 break; | |
3419 | |
3420 /* 11 - ANSI X3.64-1979, select second alt. font, display control | |
3421 * chars, set bit 8 on output */ | |
3422 case 11: /* SMACS , as */ | |
3423 case 12: | |
3424 gl = 1; | |
3425 usedcharsets = true; | |
3426 break; | |
3427 | |
3428 case 21: /* normal intensity */ | |
3429 attributes &= ~(LOW | BOLD); | |
3430 break; | |
3431 | |
3432 case 23: /* italics off */ | |
3433 attributes &= ~INVERT; | |
3434 break; | |
3435 | |
3436 case 25: /* blinking off */ | |
3437 break; | |
3438 | |
3439 case 27: | |
3440 attributes &= ~INVERT; | |
3441 break; | |
3442 | |
3443 case 28: | |
3444 attributes &= ~INVISIBLE; | |
3445 break; | |
3446 | |
3447 case 24: | |
3448 attributes &= ~UNDERLINE; | |
3449 break; | |
3450 | |
3451 case 22: | |
3452 attributes &= ~BOLD; | |
3453 break; | |
3454 | |
3455 case 30: | |
3456 case 31: | |
3457 case 32: | |
3458 case 33: | |
3459 case 34: | |
3460 case 35: | |
3461 case 36: | |
3462 case 37: | |
3463 attributes &= ~COLOR_FG; | |
3464 attributes |= ((DCEvars[i] - 30) + 1) << COLOR_FG_SHIFT; | |
3465 break; | |
3466 | |
3467 case 38: | |
3468 if (DCEvars[i + 1] == 5) { | |
3469 attributes &= ~COLOR_FG; | |
3470 attributes |= ((DCEvars[i + 2]) + 1) << COLOR_FG_SHIFT; | |
3471 i += 2; | |
3472 } | |
3473 | |
3474 break; | |
3475 | |
3476 case 39: | |
3477 attributes &= ~COLOR_FG; | |
3478 break; | |
3479 | |
3480 case 40: | |
3481 case 41: | |
3482 case 42: | |
3483 case 43: | |
3484 case 44: | |
3485 case 45: | |
3486 case 46: | |
3487 case 47: | |
3488 attributes &= ~COLOR_BG; | |
3489 attributes |= ((DCEvars[i] - 40) + 1) << COLOR_BG_SHIFT; | |
3490 break; | |
3491 | |
3492 case 48: | |
3493 if (DCEvars[i + 1] == 5) { | |
3494 attributes &= ~COLOR_BG; | |
3495 attributes |= (DCEvars[i + 2] + 1) << COLOR_BG_SHIFT; | |
3496 i += 2; | |
3497 } | |
3498 | |
3499 break; | |
3500 | |
3501 case 49: | |
3502 attributes &= ~COLOR_BG; | |
3503 break; | |
3504 | |
3505 case 90: | |
3506 case 91: | |
3507 case 92: | |
3508 case 93: | |
3509 case 94: | |
3510 case 95: | |
3511 case 96: | |
3512 case 97: | |
3513 attributes &= ~COLOR_FG; | |
3514 attributes |= ((DCEvars[i] - 82) + 1) << COLOR_FG_SHIFT; | |
3515 break; | |
3516 | |
3517 case 100: | |
3518 case 101: | |
3519 case 102: | |
3520 case 103: | |
3521 case 104: | |
3522 case 105: | |
3523 case 106: | |
3524 case 107: | |
3525 attributes &= ~COLOR_BG; | |
3526 attributes |= ((DCEvars[i] - 92) + 1) << COLOR_BG_SHIFT; | |
3527 break; | |
3528 | |
3529 default: | |
3530 debugStr.append("ESC [ ") | |
3531 .append(DCEvars[i]) | |
3532 .append(" m unknown..."); | |
3533 debug(debugStr.toString()); | |
3534 debugStr.setLength(0); | |
3535 break; | |
3536 } | |
3537 | |
3538 if (debug > 3) { | |
3539 debugStr.append(DCEvars[i]) | |
3540 .append(';'); | |
3541 debug(debugStr.toString()); | |
3542 debugStr.setLength(0); | |
3543 } | |
3544 } | |
3545 | |
3546 if (debug > 3) { | |
3547 debugStr.append(" (attributes = ") | |
3548 .append(attributes) | |
3549 .append(")m"); | |
3550 debug(debugStr.toString()); | |
3551 debugStr.setLength(0); | |
3552 } | |
3553 | |
3554 break; | |
3555 | |
3556 default: | |
3557 debugStr.append("ESC [ unknown letter: ") | |
3558 .append(c) | |
3559 .append(" (") | |
3560 .append((int)c) | |
3561 .append(')'); | |
3562 debug(debugStr.toString()); | |
3563 debugStr.setLength(0); | |
3564 break; | |
3565 } | |
3566 | |
3567 break; | |
3568 | |
3569 case TSTATE_TITLE: | |
3570 switch (c) { | |
3571 case ESC: | |
3572 term_state = TSTATE_ESC; | |
3573 break; | |
3574 | |
3575 default: | |
3576 // TODO save title | |
3577 break; | |
3578 } | |
3579 | |
3580 break; | |
3581 | |
3582 default: | |
3583 term_state = TSTATE_DATA; | |
3584 break; | |
3585 } | |
3586 | |
3587 setCursorPosition(C, R); | |
3588 } | |
3589 | |
3590 /* hard reset the terminal */ | |
3591 public void reset() { | |
3592 gx[0] = 'B'; | |
3593 gx[1] = 'B'; | |
3594 gx[2] = 'B'; | |
3595 gx[3] = 'B'; | |
3596 gl = 0; // default GL to G0 | |
3597 gr = 2; // default GR to G2 | |
3598 onegl = -1; // Single shift override | |
3599 /* reset tabs */ | |
3600 int nw = width; | |
3601 | |
3602 if (nw < 132) nw = 132; | |
3603 | |
3604 Tabs = new byte[nw]; | |
3605 | |
3606 for (int i = 0; i < nw; i += 8) { | |
3607 Tabs[i] = 1; | |
3608 } | |
3609 | |
3610 deleteArea(0, 0, width, height, attributes); | |
3611 setMargins(0, height); | |
3612 C = R = 0; | |
3613 _SetCursor(0, 0); | |
3614 | |
3615 if (display != null) | |
3616 display.resetColors(); | |
3617 | |
3618 showCursor(true); | |
3619 /*FIXME:*/ | |
3620 term_state = TSTATE_DATA; | |
3621 } | |
3622 } |