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