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