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