1 static void escseq(void);
2 static void escseq_cs(void);
3 static void escseq_g0(void);
4 static void escseq_g1(void);
5 static void escseq_g2(void);
6 static void escseq_g3(void);
7 static void csiseq(void);
8 static void csiseq_da(int c
);
9 static void csiseq_dsr(int c
);
10 static void modeseq(int c
, int set
);
12 /* comments taken from: http://www.ivarch.com/programs/termvt102.shtml */
14 static int readutf8(int c
)
22 while (++l
< 6 && c
& z
) {
28 result
= (result
<< 6) | (readpty() & 0x3f);
32 /* control sequences */
33 static void ctlseq(void)
37 case 0x09: /* HT horizontal tab to next tab stop */
38 advance(0, 8 - col
% 8, 0);
40 case 0x0a: /* LF line feed */
41 case 0x0b: /* VT line feed */
42 case 0x0c: /* FF line feed */
43 advance(1, (mode
& MODE_NOAUTOCR
) ? 0 : -col
, 1);
45 case 0x08: /* BS backspace one column */
48 case 0x1b: /* ESC start escape sequence */
51 case 0x0d: /* CR carriage return */
54 case 0x00: /* NUL ignored */
55 case 0x07: /* BEL beep */
56 case 0x7f: /* DEL ignored */
58 case 0x05: /* ENQ trigger answerback message */
59 case 0x0e: /* SO activate G1 character set & newline */
60 case 0x0f: /* SI activate G0 character set */
61 case 0x11: /* XON resume transmission */
62 case 0x13: /* XOFF stop transmission, ignore characters */
63 case 0x18: /* CAN interrupt escape sequence */
64 case 0x1a: /* SUB interrupt escape sequence */
65 case 0x9b: /* CSI equivalent to ESC [ */
66 printf("ctlseq: <%d:%c>\n", c
, c
);
69 term_put(readutf8(c
), row
, col
);
75 #define ESCM(c) (((c) & 0xf0) == 0x20)
76 #define ESCF(c) ((c) > 0x30 && (c) < 0x7f)
78 /* escape sequences */
79 static void escseq(void)
85 case '[': /* CSI control sequence introducer */
88 case '%': /* CS... escseq_cs table */
91 case '(': /* G0... escseq_g0 table */
94 case ')': /* G1... escseq_g1 table */
97 case '*': /* G2... escseq_g2 table */
100 case '+': /* G3... escseq_g3 table */
103 case '7': /* DECSC save state (position, charset, attributes) */
104 misc_save(&term
->sav
);
106 case '8': /* DECRC restore most recently saved state */
107 misc_load(&term
->sav
);
109 case 'M': /* RI reverse line feed */
112 case 'D': /* IND line feed */
115 case 'E': /* NEL newline */
118 case 'c': /* RIS reset */
119 case 'H': /* HTS set tab stop at current column */
120 case 'Z': /* DECID DEC private ID; return ESC [ ? 6 c (VT102) */
121 case '#': /* DECALN ("#8") DEC alignment test - fill screen with E's */
122 case '>': /* DECPNM set numeric keypad mode */
123 case '=': /* DECPAM set application keypad mode */
124 case 'N': /* SS2 select G2 charset for next char only */
125 case 'O': /* SS3 select G3 charset for next char only */
126 case 'P': /* DCS device control string (ended by ST) */
127 case 'X': /* SOS start of string */
128 case '^': /* PM privacy message (ended by ST) */
129 case '_': /* APC application program command (ended by ST) */
130 case '\\': /* ST string terminator */
131 case 'n': /* LS2 invoke G2 charset */
132 case 'o': /* LS3 invoke G3 charset */
133 case '|': /* LS3R invoke G3 charset as GR */
134 case '}': /* LS2R invoke G2 charset as GR */
135 case '~': /* LS1R invoke G1 charset as GR */
136 case ']': /* OSC operating system command */
137 case 'g': /* BEL alternate BEL */
139 printf("escseq: <%d:%c>\n", c
, c
);
144 static void escseq_cs(void)
148 case '@': /* CSDFL select default charset (ISO646/8859-1) */
149 case 'G': /* CSUTF8 select UTF-8 */
150 case '8': /* CSUTF8 select UTF-8 (obsolete) */
152 printf("escseq_cs: <%d:%c>\n", c
, c
);
157 static void escseq_g0(void)
161 case '8': /* G0DFL G0 charset = default mapping (ISO8859-1) */
162 case '0': /* G0GFX G0 charset = VT100 graphics mapping */
163 case 'U': /* G0ROM G0 charset = null mapping (straight to ROM) */
164 case 'K': /* G0USR G0 charset = user defined mapping */
165 case 'B': /* G0TXT G0 charset = ASCII mapping */
167 printf("escseq_g0: <%d:%c>\n", c
, c
);
172 static void escseq_g1(void)
176 case '8': /* G1DFL G1 charset = default mapping (ISO8859-1) */
177 case '0': /* G1GFX G1 charset = VT100 graphics mapping */
178 case 'U': /* G1ROM G1 charset = null mapping (straight to ROM) */
179 case 'K': /* G1USR G1 charset = user defined mapping */
180 case 'B': /* G1TXT G1 charset = ASCII mapping */
182 printf("escseq_g1: <%d:%c>\n", c
, c
);
187 static void escseq_g2(void)
191 case '8': /* G2DFL G2 charset = default mapping (ISO8859-1) */
192 case '0': /* G2GFX G2 charset = VT100 graphics mapping */
193 case 'U': /* G2ROM G2 charset = null mapping (straight to ROM) */
194 case 'K': /* G2USR G2 charset = user defined mapping */
196 printf("escseq_g2: <%d:%c>\n", c
, c
);
201 static void escseq_g3(void)
205 case '8': /* G3DFL G3 charset = default mapping (ISO8859-1) */
206 case '0': /* G3GFX G3 charset = VT100 graphics mapping */
207 case 'U': /* G3ROM G3 charset = null mapping (straight to ROM) */
208 case 'K': /* G3USR G3 charset = user defined mapping */
210 printf("escseq_g3: <%d:%c>\n", c
, c
);
215 static int absrow(int r
)
217 return origin() ? top
+ r
: r
;
220 #define CSIP(c) (((c) & 0xf0) == 0x30)
221 #define CSII(c) (((c) & 0xf0) == 0x20)
222 #define CSIF(c) ((c) >= 0x40 && (c) < 0x80)
224 #define MAXCSIARGS 32
225 /* ECMA-48 CSI sequences */
226 static void csiseq(void)
228 int args
[MAXCSIARGS
] = {0};
235 if (strchr("<=>?", c
)) {
242 arg
= arg
* 10 + (c
- '0');
248 n
= n
< ARRAY_SIZE(args
) ? n
+ 1 : 0;
255 case 'H': /* CUP move cursor to row, column */
256 case 'f': /* HVP move cursor to row, column */
257 move_cursor(absrow(MAX(0, args
[0] - 1)), MAX(0, args
[1] - 1));
259 case 'J': /* ED erase display */
262 kill_chars(col
, pad_cols());
263 blank_rows(row
+ 1, pad_rows());
266 kill_chars(0, col
+ 1);
267 blank_rows(0, row
- 1);
274 case 'A': /* CUU move cursor up */
275 advance(-MAX(1, args
[0]), 0, 0);
277 case 'e': /* VPR move cursor down */
278 case 'B': /* CUD move cursor down */
279 advance(MAX(1, args
[0]), 0, 0);
281 case 'a': /* HPR move cursor right */
282 case 'C': /* CUF move cursor right */
283 advance(0, MAX(1, args
[0]), 0);
285 case 'D': /* CUB move cursor left */
286 advance(0, -MAX(1, args
[0]), 0);
288 case 'K': /* EL erase line */
291 kill_chars(col
, pad_cols());
294 kill_chars(0, col
+ 1);
297 kill_chars(0, pad_cols());
301 case 'L': /* IL insert blank lines */
302 if (row
>= top
&& row
< bot
)
303 insert_lines(MAX(1, args
[0]));
305 case 'M': /* DL delete lines */
306 if (row
>= top
&& row
< bot
)
307 delete_lines(MAX(1, args
[0]));
309 case 'd': /* VPA move to row (current column) */
310 move_cursor(absrow(MAX(1, args
[0]) - 1), col
);
312 case 'm': /* SGR set graphic rendition */
314 for (i
= 0; i
< n
; i
++)
317 case 'r': /* DECSTBM set scrolling region to (top, bottom) rows
319 set_region(args
[0], args
[1]);
321 case 'c': /* DA return ESC [ ? 6 c (VT102) */
322 csiseq_da(priv
== '?' ? args
[0] | 0x80 : args
[0]);
324 case 'h': /* SM set mode */
325 for (i
= 0; i
< n
; i
++)
326 modeseq(priv
== '?' ? args
[i
] | 0x80 : args
[i
], 1);
328 case 'l': /* RM reset mode */
329 for (i
= 0; i
< n
; i
++)
330 modeseq(priv
== '?' ? args
[i
] | 0x80 : args
[i
], 0);
332 case 'P': /* DCH delete characters on current line */
333 delete_chars(MAX(1, args
[0]));
335 case '@': /* ICH insert blank characters */
336 insert_chars(MAX(1, args
[0]));
338 case 'n': /* DSR device status report */
341 case 'G': /* CHA move cursor to column in current row */
342 advance(0, MAX(0, args
[0] - 1) - col
, 0);
344 case 'X': /* ECH erase characters on current line */
345 kill_chars(col
, MAX(col
+ MAX(1, args
[0]), pad_cols()));
347 case '[': /* IGN ignored control sequence */
348 case 'E': /* CNL move cursor down and to column 1 */
349 case 'F': /* CPL move cursor up and to column 1 */
350 case 'g': /* TBC clear tab stop (CSI 3 g = clear all stops) */
351 case 'q': /* DECLL set keyboard LEDs */
352 case 's': /* CUPSV save cursor position */
353 case 'u': /* CUPRS restore cursor position */
354 case '`': /* HPA move cursor to column in current row */
356 printf("csiseq: <%d:%c>:", c
, c
);
357 for (i
= 0; i
< n
; i
++)
358 printf(" %d", args
[i
]);
364 static void csiseq_da(int c
)
368 term_sendstr("\x1b[?6c");
371 /* we don't care much about cursor shape */
372 /* printf("csiseq_da <0x%x>\n", c); */
377 static void csiseq_dsr(int c
)
382 term_sendstr("\x1b[0n");
385 snprintf(status
, sizeof(status
), "\x1b[%d;%dR",
386 (origin() ? row
- top
: row
) + 1, col
+ 1);
387 term_sendstr(status
);
390 printf("csiseq_dsr <0x%x>\n", c
);
395 /* ANSI/DEC specified modes for SM/RM ANSI Specified Modes */
396 static void modeseq(int c
, int set
)
399 case 0x87: /* DECAWM Auto Wrap */
400 mode
= BIT_SET(mode
, MODE_NOWRAP
, !set
);
402 case 0x99: /* DECTCEM Cursor on (set); Cursor off (reset) */
403 mode
= BIT_SET(mode
, MODE_NOCURSOR
, !set
);
405 case 0x86: /* DECOM Sets relative coordinates (set); Sets absolute coordinates (reset) */
406 mode
= BIT_SET(mode
, MODE_ORIGIN
, set
);
408 case 0x14: /* LNM Line Feed / New Line Mode */
409 mode
= BIT_SET(mode
, MODE_NOAUTOCR
, !set
);
411 case 0x04: /* IRM insertion/replacement mode (always reset) */
413 case 0x00: /* IGN Error (Ignored) */
414 case 0x01: /* GATM guarded-area transfer mode (ignored) */
415 case 0x02: /* KAM keyboard action mode (always reset) */
416 case 0x03: /* CRM control representation mode (always reset) */
417 case 0x05: /* SRTM status-reporting transfer mode */
418 case 0x06: /* ERM erasure mode (always set) */
419 case 0x07: /* VEM vertical editing mode (ignored) */
420 case 0x0a: /* HEM horizontal editing mode */
421 case 0x0b: /* PUM positioning unit mode */
422 case 0x0c: /* SRM send/receive mode (echo on/off) */
423 case 0x0d: /* FEAM format effector action mode */
424 case 0x0e: /* FETM format effector transfer mode */
425 case 0x0f: /* MATM multiple area transfer mode */
426 case 0x10: /* TTM transfer termination mode */
427 case 0x11: /* SATM selected area transfer mode */
428 case 0x12: /* TSM tabulation stop mode */
429 case 0x13: /* EBM editing boundary mode */
430 /* DEC Private Modes: "?NUM" -> (NUM | 0x80) */
431 case 0x80: /* IGN Error (Ignored) */
432 case 0x81: /* DECCKM Cursorkeys application (set); Cursorkeys normal (reset) */
433 case 0x82: /* DECANM ANSI (set); VT52 (reset) */
434 case 0x83: /* DECCOLM 132 columns (set); 80 columns (reset) */
435 case 0x84: /* DECSCLM Jump scroll (set); Smooth scroll (reset) */
436 case 0x85: /* DECSCNM Reverse screen (set); Normal screen (reset) */
437 case 0x88: /* DECARM Auto Repeat */
438 case 0x89: /* DECINLM Interlace */
439 case 0x92: /* DECPFF Send FF to printer after print screen (set); No char after PS (reset) */
440 case 0x93: /* DECPEX Print screen: prints full screen (set); prints scroll region (reset) */
442 printf("modeseq <0x%x>: %d\n", c
, set
);