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