1 | /* |
---|
2 | * neercs console-based window manager |
---|
3 | * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
---|
4 | * 2008 Jean-Yves Lamoureux <jylam@lnxscene.org> |
---|
5 | * 2008 Pascal Terjan <pterjan@linuxfr.org> |
---|
6 | * All Rights Reserved |
---|
7 | * |
---|
8 | * $Id: ansi.c 4071 2009-11-30 10:03:47Z jylam $ |
---|
9 | * |
---|
10 | * This program is free software. It comes without any warranty, to |
---|
11 | * the extent permitted by applicable law. You can redistribute it |
---|
12 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
13 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
14 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
15 | */ |
---|
16 | #include "config.h" |
---|
17 | #include <caca.h> |
---|
18 | #include <string.h> |
---|
19 | #include "neercs.h" |
---|
20 | |
---|
21 | /* DEC ACS with common extensions */ |
---|
22 | static uint32_t dec_acs(uint32_t uc) |
---|
23 | { |
---|
24 | switch (uc) |
---|
25 | { |
---|
26 | case '+': |
---|
27 | return 0x2192; /* RIGHTWARDS ARROW */ |
---|
28 | case ',': |
---|
29 | return 0x2190; /* LEFTWARDS ARROW */ |
---|
30 | case '-': |
---|
31 | return 0x2191; /* UPWARDS ARROW */ |
---|
32 | case '.': |
---|
33 | return 0x2193; /* DOWNWARDS ARROW */ |
---|
34 | case '0': |
---|
35 | return 0x25AE; /* BLACK VERTICAL RECTANGLE */ |
---|
36 | case '_': |
---|
37 | return 0x25AE; /* BLACK VERTICAL RECTANGLE */ |
---|
38 | case '`': |
---|
39 | return 0x25C6; /* BLACK DIAMOND */ |
---|
40 | case 'a': |
---|
41 | return 0x2592; /* MEDIUM SHADE */ |
---|
42 | case 'b': |
---|
43 | return 0x2409; /* SYMBOL FOR HORIZONTAL TABULATION */ |
---|
44 | case 'c': |
---|
45 | return 0x240C; /* SYMBOL FOR FORM FEED */ |
---|
46 | case 'd': |
---|
47 | return 0x240D; /* SYMBOL FOR CARRIAGE RETURN */ |
---|
48 | case 'e': |
---|
49 | return 0x240A; /* SYMBOL FOR LINE FEED */ |
---|
50 | case 'f': |
---|
51 | return 0x00B0; /* DEGREE SIGN */ |
---|
52 | case 'g': |
---|
53 | return 0x00B1; /* PLUS-MINUS SIGN */ |
---|
54 | case 'h': |
---|
55 | return 0x2424; /* SYMBOL FOR NEWLINE */ |
---|
56 | case 'i': |
---|
57 | return 0x240B; /* SYMBOL FOR VERTICAL TABULATION */ |
---|
58 | case 'j': |
---|
59 | return 0x2518; /* BOX DRAWINGS LIGHT UP AND LEFT */ |
---|
60 | case 'k': |
---|
61 | return 0x2510; /* BOX DRAWINGS LIGHT DOWN AND LEFT */ |
---|
62 | case 'l': |
---|
63 | return 0x250C; /* BOX DRAWINGS LIGHT DOWN AND RIGHT */ |
---|
64 | case 'm': |
---|
65 | return 0x2514; /* BOX DRAWINGS LIGHT UP AND RIGHT */ |
---|
66 | case 'n': |
---|
67 | return 0x253C; /* BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL */ |
---|
68 | case 'o': |
---|
69 | return 0x23BA; /* HORIZONTAL SCAN LINE-1 */ |
---|
70 | case 'p': |
---|
71 | return 0x23BB; /* HORIZONTAL SCAN LINE-3 */ |
---|
72 | case 'q': |
---|
73 | return 0x2500; /* BOX DRAWINGS LIGHT HORIZONTAL */ |
---|
74 | case 'r': |
---|
75 | return 0x23BC; /* HORIZONTAL SCAN LINE-7 */ |
---|
76 | case 's': |
---|
77 | return 0x23BD; /* HORIZONTAL SCAN LINE-9 */ |
---|
78 | case 't': |
---|
79 | return 0x251C; /* BOX DRAWINGS LIGHT VERTICAL AND RIGHT */ |
---|
80 | case 'u': |
---|
81 | return 0x2524; /* BOX DRAWINGS LIGHT VERTICAL AND LEFT */ |
---|
82 | case 'v': |
---|
83 | return 0x2534; /* BOX DRAWINGS LIGHT UP AND HORIZONTAL */ |
---|
84 | case 'w': |
---|
85 | return 0x252C; /* BOX DRAWINGS LIGHT DOWN AND HORIZONTAL */ |
---|
86 | case 'x': |
---|
87 | return 0x2502; /* BOX DRAWINGS LIGHT VERTICAL */ |
---|
88 | case 'y': |
---|
89 | return 0x2264; /* LESS-THAN OR EQUAL TO */ |
---|
90 | case 'z': |
---|
91 | return 0x2265; /* GREATER-THAN OR EQUAL TO */ |
---|
92 | case '{': |
---|
93 | return 0x03C0; /* GREEK SMALL LETTER PI */ |
---|
94 | case '|': |
---|
95 | return 0x2260; /* NOT EQUAL TO */ |
---|
96 | case '}': |
---|
97 | return 0x00A3; /* POUND SIGN */ |
---|
98 | case '~': |
---|
99 | return 0x00B7; /* MIDDLE DOT */ |
---|
100 | default: |
---|
101 | return uc; |
---|
102 | } |
---|
103 | }; |
---|
104 | |
---|
105 | static void reset_conv_state(struct screen *); |
---|
106 | |
---|
107 | #define LITERAL2CHAR(i0,i1) (((i0) << 8) | (i1)) |
---|
108 | |
---|
109 | #define LITERAL3CHAR(i0,i1,i2) LITERAL2CHAR(LITERAL2CHAR(i0, i1), i2) |
---|
110 | |
---|
111 | static void ansi_parse_grcm(struct screen *, |
---|
112 | unsigned int, unsigned int const *); |
---|
113 | |
---|
114 | static int handle_single_char(unsigned char c, int *x, int *y, |
---|
115 | struct screen_list *screen_list, |
---|
116 | struct screen *sc); |
---|
117 | |
---|
118 | static int handle_single_char(unsigned char c, int *x, int *y, |
---|
119 | struct screen_list *screen_list, |
---|
120 | struct screen *sc) |
---|
121 | { |
---|
122 | if (c == '\r') |
---|
123 | { |
---|
124 | *x = 0; |
---|
125 | } |
---|
126 | |
---|
127 | else if (c == '\n') |
---|
128 | { |
---|
129 | *x = 0; |
---|
130 | *y = *y + 1; |
---|
131 | } |
---|
132 | else if (c == '\a') |
---|
133 | { |
---|
134 | if (!sc->bell) |
---|
135 | screen_list->in_bell = 10; |
---|
136 | sc->bell = 1; |
---|
137 | } |
---|
138 | |
---|
139 | else if (c == '\t') |
---|
140 | { |
---|
141 | *x = (*x + 7) & ~7; |
---|
142 | } |
---|
143 | |
---|
144 | else if (c == '\x08') |
---|
145 | { |
---|
146 | if (*x > 0) |
---|
147 | *x = *x - 1; |
---|
148 | } |
---|
149 | else if (c == '\x0b') |
---|
150 | { |
---|
151 | /* Vertical tab */ |
---|
152 | /* Not sure about the real meaning of it, just y++ for now */ |
---|
153 | if (*y < caca_get_canvas_height(sc->cv)) |
---|
154 | *y = *y + 1; |
---|
155 | } |
---|
156 | else if (c == '\x0e') |
---|
157 | { |
---|
158 | /* Shift Out (Ctrl-N) -> Switch to Alternate Character Set: invokes |
---|
159 | the G1 character set. */ |
---|
160 | sc->conv_state.glr[0] = 1; |
---|
161 | } |
---|
162 | |
---|
163 | else if (c == '\x0f') |
---|
164 | { |
---|
165 | /* Shift In (Ctrl-O) -> Switch to Standard Character Set: invokes the |
---|
166 | G0 character set. */ |
---|
167 | sc->conv_state.glr[0] = 0; |
---|
168 | } |
---|
169 | else |
---|
170 | { |
---|
171 | return 1; |
---|
172 | } |
---|
173 | return 0; |
---|
174 | |
---|
175 | } |
---|
176 | |
---|
177 | long int import_term(struct screen_list *screen_list, struct screen *sc, |
---|
178 | void const *data, unsigned int size) |
---|
179 | { |
---|
180 | unsigned char const *buffer = (unsigned char const *)data; |
---|
181 | unsigned int i, j, k, skip, dummy = 0; |
---|
182 | unsigned int width, height, top, bottom; |
---|
183 | uint32_t savedattr; |
---|
184 | int x = 0, y = 0, save_x = 0, save_y = 0; |
---|
185 | char b[100]; |
---|
186 | |
---|
187 | debug("ansi : import_term\n"); |
---|
188 | |
---|
189 | width = caca_get_canvas_width(sc->cv); |
---|
190 | height = caca_get_canvas_height(sc->cv); |
---|
191 | x = caca_get_cursor_x(sc->cv); |
---|
192 | y = caca_get_cursor_y(sc->cv); |
---|
193 | top = 1; |
---|
194 | bottom = height; |
---|
195 | |
---|
196 | if (!sc->init) |
---|
197 | { |
---|
198 | sc->dfg = CACA_LIGHTGRAY; |
---|
199 | sc->dbg = CACA_BLACK; |
---|
200 | |
---|
201 | caca_set_color_ansi(sc->cv, sc->dfg, sc->dbg); |
---|
202 | sc->clearattr = caca_get_attr(sc->cv, -1, -1); |
---|
203 | |
---|
204 | ansi_parse_grcm(sc, 1, &dummy); |
---|
205 | |
---|
206 | reset_conv_state(sc); |
---|
207 | |
---|
208 | sc->init = 1; |
---|
209 | } |
---|
210 | |
---|
211 | for (i = 0; i < size; i += skip) |
---|
212 | { |
---|
213 | uint32_t ch = 0; |
---|
214 | int wch = 0; |
---|
215 | |
---|
216 | skip = 1; |
---|
217 | |
---|
218 | /* Control codes (ASCII < \x20) */ |
---|
219 | if (!handle_single_char(buffer[i], &x, &y, screen_list, sc)) |
---|
220 | { |
---|
221 | } |
---|
222 | |
---|
223 | /* If there are not enough characters to parse the escape sequence, |
---|
224 | wait until the next try. We require 3. */ |
---|
225 | |
---|
226 | else if (buffer[i] == '\033' && i + 2 >= size) |
---|
227 | break; |
---|
228 | |
---|
229 | /* Single Shift Select of G2 Character Set (SS2: 0x8e): affects next |
---|
230 | character only */ |
---|
231 | else if (buffer[i] == '\033' && buffer[i + 1] == 'N') |
---|
232 | { |
---|
233 | sc->conv_state.ss = 2; |
---|
234 | skip += 1; |
---|
235 | } |
---|
236 | /* Reverse Index (RI) go up one line, reverse scroll if necessary */ |
---|
237 | else if (buffer[i] == '\033' && buffer[i + 1] == 'M') |
---|
238 | { |
---|
239 | /* FIXME : not sure about the meaning of 'go up one line' and 'if |
---|
240 | necessary' words. Implemented as a scroller only. */ |
---|
241 | for (j = bottom - 1; j > top; j--) |
---|
242 | { |
---|
243 | for (k = 0; k < width; k++) |
---|
244 | { |
---|
245 | caca_put_char(sc->cv, k, j, |
---|
246 | caca_get_char(sc->cv, k, j - 1)); |
---|
247 | caca_put_attr(sc->cv, k, j, |
---|
248 | caca_get_attr(sc->cv, k, j - 1)); |
---|
249 | } |
---|
250 | } |
---|
251 | caca_draw_line(sc->cv, 0, top - 1, width - 1, top - 1, ' '); |
---|
252 | skip += 1; |
---|
253 | } |
---|
254 | |
---|
255 | /* Single Shift Select of G3 Character Set (SS2: 0x8f): affects next |
---|
256 | character only */ |
---|
257 | else if (buffer[i] == '\033' && buffer[i + 1] == 'O') |
---|
258 | { |
---|
259 | sc->conv_state.ss = 3; |
---|
260 | skip += 1; |
---|
261 | } |
---|
262 | |
---|
263 | /* LOCKING-SHIFT TWO (LS2), ISO 2022, ECMA-48 (1986), ISO 6429 : 1988 */ |
---|
264 | else if (buffer[i] == '\033' && buffer[i + 1] == 'n') |
---|
265 | { |
---|
266 | sc->conv_state.glr[0] = 2; |
---|
267 | skip += 1; |
---|
268 | } |
---|
269 | |
---|
270 | /* LOCKING-SHIFT THREE (LS3) ISO 2022, ECMA-48 (1986), ISO 6429 : 1988 |
---|
271 | */ |
---|
272 | else if (buffer[i] == '\033' && buffer[i + 1] == 'o') |
---|
273 | { |
---|
274 | sc->conv_state.glr[0] = 3; |
---|
275 | skip += 1; |
---|
276 | } |
---|
277 | |
---|
278 | /* RESET TO INITIAL STATE (RIS), ECMA-48 (1986), ISO 6429 : 1988 */ |
---|
279 | else if (buffer[i] == '\033' && buffer[i + 1] == 'c') |
---|
280 | { |
---|
281 | sc->dfg = CACA_DEFAULT; |
---|
282 | sc->dbg = CACA_DEFAULT; |
---|
283 | |
---|
284 | caca_set_color_ansi(sc->cv, sc->dfg, sc->dbg); |
---|
285 | sc->clearattr = caca_get_attr(sc->cv, -1, -1); |
---|
286 | ansi_parse_grcm(sc, 1, &dummy); |
---|
287 | |
---|
288 | reset_conv_state(sc); |
---|
289 | skip += 1; |
---|
290 | } |
---|
291 | |
---|
292 | /* Coding Method Delimiter (CMD), ECMA-48 (1991), ISO/IEC 6429:1992 |
---|
293 | (ISO IR 189) */ |
---|
294 | else if (buffer[i] == '\033' && buffer[i + 1] == 'd') |
---|
295 | { |
---|
296 | reset_conv_state(sc); |
---|
297 | skip += 1; |
---|
298 | } |
---|
299 | |
---|
300 | /* GZDM4, G0-Designators, multi, 94^n chars [grandfathered short form |
---|
301 | from ISO 2022:1986] */ |
---|
302 | else if (buffer[i] == '\033' && buffer[i + 1] == '$' |
---|
303 | && (buffer[i + 2] >= '@') && (buffer[i + 2] <= 'C')) |
---|
304 | { |
---|
305 | sc->conv_state.gn[0] = LITERAL2CHAR('$', buffer[i + 2]); |
---|
306 | skip += 2; |
---|
307 | } |
---|
308 | |
---|
309 | /* GnDMx Gn-Designators, 9x^n chars; need one more char to distinguish |
---|
310 | these */ |
---|
311 | else if (buffer[i] == '\033' && buffer[i + 1] == '$' |
---|
312 | && (i + 3 >= size)) |
---|
313 | break; |
---|
314 | |
---|
315 | /* GZD4 G0-Designator, 94 chars */ |
---|
316 | else if (buffer[i] == '\033' && buffer[i + 1] == '(') |
---|
317 | { |
---|
318 | sc->conv_state.gn[0] = buffer[i + 2]; |
---|
319 | skip += 2; |
---|
320 | } |
---|
321 | |
---|
322 | /* G1D4 G1-Designator, 94 chars */ |
---|
323 | else if (buffer[i] == '\033' && buffer[i + 1] == ')') |
---|
324 | { |
---|
325 | sc->conv_state.gn[1] = buffer[i + 2]; |
---|
326 | skip += 2; |
---|
327 | } |
---|
328 | |
---|
329 | /* G2D4 G2-Designator, 94 chars */ |
---|
330 | else if (buffer[i] == '\033' && buffer[i + 1] == '*') |
---|
331 | { |
---|
332 | sc->conv_state.gn[2] = buffer[i + 2]; |
---|
333 | skip += 2; |
---|
334 | } |
---|
335 | |
---|
336 | /* G3D4 G3-Designator, 94 chars */ |
---|
337 | else if (buffer[i] == '\033' && buffer[i + 1] == '+') |
---|
338 | { |
---|
339 | sc->conv_state.gn[3] = buffer[i + 2]; |
---|
340 | skip += 2; |
---|
341 | } |
---|
342 | |
---|
343 | /* G2D6 G2-Designator, 96 chars */ |
---|
344 | else if (buffer[i] == '\033' && buffer[i + 1] == '.') |
---|
345 | { |
---|
346 | sc->conv_state.gn[2] = LITERAL2CHAR('.', buffer[i + 2]); |
---|
347 | skip += 2; |
---|
348 | } |
---|
349 | |
---|
350 | /* G3D6 G3-Designator, 96 chars */ |
---|
351 | else if (buffer[i] == '\033' && buffer[i + 1] == '/') |
---|
352 | { |
---|
353 | sc->conv_state.gn[3] = LITERAL2CHAR('.', buffer[i + 2]); |
---|
354 | skip += 2; |
---|
355 | } |
---|
356 | |
---|
357 | /* GZDM4 G0-Designator, 94^n chars */ |
---|
358 | else if (buffer[i] == '\033' && buffer[i + 1] == '$' |
---|
359 | && buffer[i + 2] == '(') |
---|
360 | { |
---|
361 | sc->conv_state.gn[0] = LITERAL2CHAR('$', buffer[i + 3]); |
---|
362 | skip += 3; |
---|
363 | } |
---|
364 | |
---|
365 | /* G1DM4 G1-Designator, 94^n chars */ |
---|
366 | else if (buffer[i] == '\033' && buffer[i + 1] == '$' |
---|
367 | && buffer[i + 2] == ')') |
---|
368 | { |
---|
369 | sc->conv_state.gn[1] = LITERAL2CHAR('$', buffer[i + 3]); |
---|
370 | skip += 3; |
---|
371 | } |
---|
372 | |
---|
373 | /* G2DM4 G2-Designator, 94^n chars */ |
---|
374 | else if (buffer[i] == '\033' && buffer[i + 1] == '$' |
---|
375 | && buffer[i + 2] == '*') |
---|
376 | { |
---|
377 | sc->conv_state.gn[2] = LITERAL2CHAR('$', buffer[i + 3]); |
---|
378 | skip += 3; |
---|
379 | } |
---|
380 | |
---|
381 | /* G3DM4 G3-Designator, 94^n chars */ |
---|
382 | else if (buffer[i] == '\033' && buffer[i + 1] == '$' |
---|
383 | && buffer[i + 2] == '+') |
---|
384 | { |
---|
385 | sc->conv_state.gn[3] = LITERAL2CHAR('$', buffer[i + 3]); |
---|
386 | skip += 3; |
---|
387 | } |
---|
388 | |
---|
389 | /* G2DM6 G2-Designator, 96^n chars */ |
---|
390 | else if (buffer[i] == '\033' && buffer[i + 1] == '$' |
---|
391 | && buffer[i + 2] == '.') |
---|
392 | { |
---|
393 | sc->conv_state.gn[2] = LITERAL3CHAR('$', '.', buffer[i + 3]); |
---|
394 | skip += 3; |
---|
395 | } |
---|
396 | |
---|
397 | /* G3DM6 G3-Designator, 96^n chars */ |
---|
398 | else if (buffer[i] == '\033' && buffer[i + 1] == '$' |
---|
399 | && buffer[i + 2] == '/') |
---|
400 | { |
---|
401 | sc->conv_state.gn[3] = LITERAL3CHAR('$', '.', buffer[i + 3]); |
---|
402 | skip += 3; |
---|
403 | } |
---|
404 | else if (buffer[i] == '\033' && buffer[i + 1] == '#') |
---|
405 | { |
---|
406 | debug("ansi private '#' sequence\n"); |
---|
407 | |
---|
408 | switch (buffer[i + 2]) |
---|
409 | { |
---|
410 | case '8': /* DECALN Fills the entire screen area with |
---|
411 | uppercase Es for screen focus and |
---|
412 | alignment. */ |
---|
413 | for (j = 0; j < height; j++) |
---|
414 | { |
---|
415 | for (k = 0; k < width; k++) |
---|
416 | { |
---|
417 | caca_put_char(sc->cv, k, j, 'E'); |
---|
418 | } |
---|
419 | } |
---|
420 | x = 0; |
---|
421 | y = 0; |
---|
422 | skip += 2; |
---|
423 | break; |
---|
424 | |
---|
425 | default: |
---|
426 | debug("Unknow private sequence 'ESC#%c'\n", buffer[i + 2]); |
---|
427 | continue; |
---|
428 | } |
---|
429 | |
---|
430 | } |
---|
431 | /* Interpret escape commands, as per Standard ECMA-48 "Control |
---|
432 | Functions for Coded Character Sets", 5.4. Control sequences. */ |
---|
433 | else if (buffer[i] == '\033' && buffer[i + 1] == '[') |
---|
434 | { |
---|
435 | unsigned int argc = 0, argv[101]; |
---|
436 | unsigned int param, inter, junk, final; |
---|
437 | |
---|
438 | if (buffer[i + 2] == '?') |
---|
439 | { |
---|
440 | debug("CSI? %c%c%c%c%c\n", |
---|
441 | buffer[i + 3], buffer[i + 4], buffer[i + 5], |
---|
442 | buffer[i + 6], buffer[i + 7]); |
---|
443 | } |
---|
444 | |
---|
445 | /* Compute offsets to parameter bytes, intermediate bytes and to |
---|
446 | the final byte. Only the final byte is mandatory, there can be |
---|
447 | zero of the others. 0 param=2 inter final final+1 |
---|
448 | +-----+------------------+---------------------+-----------------+ |
---|
449 | | CSI | parameter bytes | intermediate bytes | final byte | | | |
---|
450 | 0x30 - 0x3f | 0x20 - 0x2f | 0x40 - 0x7e | | ^[[ | 0123456789:;<=>? |
---|
451 | | SPC !"#$%&'()*+,-./ | azAZ@[\]^_`{|}~ | |
---|
452 | +-----+------------------+---------------------+-----------------+ */ |
---|
453 | param = 2; |
---|
454 | |
---|
455 | /* vttest use to interleave control characters (\014 CR or \010 |
---|
456 | BS) into CSI sequences, either directly after ESC[ or after |
---|
457 | param. Can't find anything related to this in any documentation |
---|
458 | nor XTerm sources, thought. */ |
---|
459 | |
---|
460 | for (junk = param; i + junk < size; junk++) |
---|
461 | if (buffer[i + junk] < 0x20) |
---|
462 | { |
---|
463 | handle_single_char(buffer[i + junk], &x, &y, screen_list, |
---|
464 | sc); |
---|
465 | } |
---|
466 | else |
---|
467 | { |
---|
468 | break; |
---|
469 | } |
---|
470 | |
---|
471 | /* Intermediate offset */ |
---|
472 | for (inter = junk; i + inter < size; inter++) |
---|
473 | if (buffer[i + inter] < 0x30 || buffer[i + inter] > 0x3f) |
---|
474 | { |
---|
475 | break; |
---|
476 | } |
---|
477 | /* Interleaved character */ |
---|
478 | for (junk = inter; i + junk < size; junk++) |
---|
479 | if (buffer[i + junk] < 0x20) |
---|
480 | { |
---|
481 | handle_single_char(buffer[i + junk], &x, &y, screen_list, |
---|
482 | sc); |
---|
483 | } |
---|
484 | else |
---|
485 | { |
---|
486 | break; |
---|
487 | } |
---|
488 | |
---|
489 | /* Final Byte offset */ |
---|
490 | for (final = junk; i + final < size; final++) |
---|
491 | if (buffer[i + final] < 0x20 || buffer[i + final] > 0x2f) |
---|
492 | { |
---|
493 | break; |
---|
494 | } |
---|
495 | if (i + final >= size |
---|
496 | || buffer[i + final] < 0x40 || buffer[i + final] > 0x7e) |
---|
497 | { |
---|
498 | debug("ansi Invalid Final Byte (%d %c)\n", buffer[i + final], |
---|
499 | buffer[i + final]); |
---|
500 | break; /* Invalid Final Byte */ |
---|
501 | } |
---|
502 | |
---|
503 | skip += final; |
---|
504 | |
---|
505 | /* Sanity checks */ |
---|
506 | if (param < inter && buffer[i + param] >= 0x3c) |
---|
507 | { |
---|
508 | /* Private sequence, only parse what we know */ |
---|
509 | debug("ansi import: private sequence \"^[[%.*s\"", |
---|
510 | final - param + 1, buffer + i + param); |
---|
511 | /* FIXME better parsing */ |
---|
512 | if (buffer[i + 2] == '?') |
---|
513 | { |
---|
514 | char arg[5]; |
---|
515 | int a = 0; |
---|
516 | int c, p; |
---|
517 | for (p = 0; p < 4; p++) |
---|
518 | { |
---|
519 | if (buffer[i + 3 + p] >= '0' |
---|
520 | && buffer[i + 3 + p] <= '9') |
---|
521 | { |
---|
522 | arg[a] = buffer[i + 3 + p]; |
---|
523 | arg[a + 1] = 0; |
---|
524 | a++; |
---|
525 | debug("private a now '%s'\n", arg); |
---|
526 | } |
---|
527 | else |
---|
528 | { |
---|
529 | break; |
---|
530 | } |
---|
531 | } |
---|
532 | c = buffer[i + 3 + 4]; |
---|
533 | int Pm = atoi(arg); |
---|
534 | debug("private mouse : command %c, arg %d", c, Pm); |
---|
535 | if (c == 'h') /* DECSET DEC Private Mode Set */ |
---|
536 | { |
---|
537 | |
---|
538 | switch (Pm) |
---|
539 | { |
---|
540 | /* FIXME Handle different modes */ |
---|
541 | case 1000: /* Send Mouse X & Y on button press |
---|
542 | and release. */ |
---|
543 | case 1001: /* Use Hilite Mouse Tracking. */ |
---|
544 | case 1002: /* Use Cell Motion Mouse Tracking. */ |
---|
545 | case 1003: /* Use All Motion Mouse Tracking. */ |
---|
546 | sc->report_mouse = 1; |
---|
547 | break; |
---|
548 | default: |
---|
549 | break; |
---|
550 | } |
---|
551 | } |
---|
552 | else if (c == 'l') /* DECRST DEC Private Mode Reset */ |
---|
553 | { |
---|
554 | Pm = atoi(arg); |
---|
555 | switch (Pm) |
---|
556 | { |
---|
557 | /* FIXME Handle different modes */ |
---|
558 | case 1000: /* Send Mouse X & Y on button press |
---|
559 | and release. */ |
---|
560 | case 1001: /* Use Hilite Mouse Tracking. */ |
---|
561 | case 1002: /* Use Cell Motion Mouse Tracking. */ |
---|
562 | case 1003: /* Use All Motion Mouse Tracking. */ |
---|
563 | sc->report_mouse = 0; |
---|
564 | break; |
---|
565 | default: |
---|
566 | break; |
---|
567 | } |
---|
568 | } |
---|
569 | } |
---|
570 | continue; /* Private sequence, skip it entirely */ |
---|
571 | } |
---|
572 | |
---|
573 | if (final - param > 100) |
---|
574 | continue; /* Suspiciously long sequence, skip it */ |
---|
575 | |
---|
576 | /* Parse parameter bytes as per ECMA-48 5.4.2: Parameter string |
---|
577 | format */ |
---|
578 | if (param < inter) |
---|
579 | { |
---|
580 | argv[0] = 0; |
---|
581 | for (j = param; j < inter; j++) |
---|
582 | { |
---|
583 | if (buffer[i + j] == ';') |
---|
584 | argv[++argc] = 0; |
---|
585 | else if (buffer[i + j] >= '0' && buffer[i + j] <= '9') |
---|
586 | argv[argc] = 10 * argv[argc] + (buffer[i + j] - '0'); |
---|
587 | } |
---|
588 | argc++; |
---|
589 | } |
---|
590 | |
---|
591 | /* Interpret final byte. The code representations are given in |
---|
592 | ECMA-48 5.4: Control sequences, and the code definitions are |
---|
593 | given in ECMA-48 8.3: Definition of control functions. */ |
---|
594 | debug("ansi import: command '%c'", buffer[i + final]); |
---|
595 | switch (buffer[i + final]) |
---|
596 | { |
---|
597 | case 'A': /* CUU (0x41) - Cursor Up */ |
---|
598 | y -= argc ? argv[0] : 1; |
---|
599 | if (y < 0) |
---|
600 | y = 0; |
---|
601 | break; |
---|
602 | case 'B': /* CUD (0x42) - Cursor Down */ |
---|
603 | y += argc ? argv[0] : 1; |
---|
604 | break; |
---|
605 | case 'C': /* CUF (0x43) - Cursor Right */ |
---|
606 | x += argc ? argv[0] : 1; |
---|
607 | break; |
---|
608 | case 'D': /* CUB (0x44) - Cursor Left */ |
---|
609 | x -= argc ? argv[0] : 1; |
---|
610 | if (x < 0) |
---|
611 | x = 0; |
---|
612 | break; |
---|
613 | case 'G': /* CHA (0x47) - Cursor Character Absolute */ |
---|
614 | x = (argc && argv[0] > 0) ? argv[0] - 1 : 0; |
---|
615 | break; |
---|
616 | case 'H': /* CUP (0x48) - Cursor Position */ |
---|
617 | x = (argc > 1 && argv[1] > 0) ? argv[1] - 1 : 0; |
---|
618 | y = (argc > 0 && argv[0] > 0) ? argv[0] - 1 : 0; |
---|
619 | debug("ansi CUP : Cursor at %dx%d\n", x, y); |
---|
620 | break; |
---|
621 | case 'J': /* ED (0x4a) - Erase In Page */ |
---|
622 | savedattr = caca_get_attr(sc->cv, -1, -1); |
---|
623 | caca_set_attr(sc->cv, sc->clearattr); |
---|
624 | if (!argc || argv[0] == 0) |
---|
625 | { |
---|
626 | caca_draw_line(sc->cv, x, y, width, y, ' '); |
---|
627 | caca_fill_box(sc->cv, 0, y + 1, width, height - 1, ' '); |
---|
628 | } |
---|
629 | else if (argv[0] == 1) |
---|
630 | { |
---|
631 | caca_fill_box(sc->cv, 0, 0, width, y, ' '); |
---|
632 | caca_draw_line(sc->cv, 0, y, x, y, ' '); |
---|
633 | } |
---|
634 | else if (argv[0] == 2) |
---|
635 | { |
---|
636 | // x = y = 0; |
---|
637 | caca_fill_box(sc->cv, 0, 0, width, height, ' '); |
---|
638 | } |
---|
639 | caca_set_attr(sc->cv, savedattr); |
---|
640 | break; |
---|
641 | case 'K': /* EL (0x4b) - Erase In Line */ |
---|
642 | debug("ansi EL : cursor at %dx%d\n", x, y); |
---|
643 | if (!argc || argv[0] == 0) |
---|
644 | { |
---|
645 | caca_draw_line(sc->cv, x, y, width, y, ' '); |
---|
646 | } |
---|
647 | else if (argv[0] == 1) |
---|
648 | { |
---|
649 | caca_draw_line(sc->cv, 0, y, x, y, ' '); |
---|
650 | } |
---|
651 | else if (argv[0] == 2) |
---|
652 | { |
---|
653 | caca_draw_line(sc->cv, 0, y, width, y, ' '); |
---|
654 | } |
---|
655 | break; |
---|
656 | case 'L': /* IL - Insert line */ |
---|
657 | { |
---|
658 | unsigned int nb_lines = argc ? argv[0] : 1; |
---|
659 | for (j = bottom - 1; j >= (unsigned int)y + nb_lines; j--) |
---|
660 | { |
---|
661 | for (k = 0; k < width; k++) |
---|
662 | { |
---|
663 | caca_put_char(sc->cv, k, j, |
---|
664 | caca_get_char(sc->cv, k, |
---|
665 | j - nb_lines)); |
---|
666 | caca_put_attr(sc->cv, k, j, |
---|
667 | caca_get_attr(sc->cv, k, |
---|
668 | j - nb_lines)); |
---|
669 | } |
---|
670 | caca_draw_line(sc->cv, 0, j - nb_lines, width, |
---|
671 | j - nb_lines, ' '); |
---|
672 | } |
---|
673 | } |
---|
674 | break; |
---|
675 | case 'P': /* DCH (0x50) - Delete Character */ |
---|
676 | if (!argc || argv[0] == 0) |
---|
677 | argv[0] = 1; /* echo -ne 'foobar\r\e[0P\n' */ |
---|
678 | |
---|
679 | for (j = x; (unsigned int)(j + argv[0]) < width; j++) |
---|
680 | { |
---|
681 | caca_put_char(sc->cv, j, y, |
---|
682 | caca_get_char(sc->cv, j + argv[0], y)); |
---|
683 | caca_put_attr(sc->cv, j, y, |
---|
684 | caca_get_attr(sc->cv, j + argv[0], y)); |
---|
685 | } |
---|
686 | break; |
---|
687 | #if 0 |
---|
688 | savedattr = caca_get_attr(sc->cv, -1, -1); |
---|
689 | caca_set_attr(sc->cv, sc->clearattr); |
---|
690 | for (; (unsigned int)j < width; j++) |
---|
691 | caca_put_char(sc->cv, j, y, ' '); |
---|
692 | caca_set_attr(sc->cv, savedattr); |
---|
693 | #endif |
---|
694 | case 'X': /* ECH (0x58) - Erase Character */ |
---|
695 | if (argc && argv[0]) |
---|
696 | { |
---|
697 | savedattr = caca_get_attr(sc->cv, -1, -1); |
---|
698 | caca_set_attr(sc->cv, sc->clearattr); |
---|
699 | caca_draw_line(sc->cv, x, y, x + argv[0] - 1, y, ' '); |
---|
700 | caca_set_attr(sc->cv, savedattr); |
---|
701 | } |
---|
702 | case 'c': /* DA -- Device Attributes */ |
---|
703 | /* |
---|
704 | 0 Base VT100, no options 1 Processor options (STP) 2 |
---|
705 | Advanced video option (AVO) 3 AVO and STP 4 Graphics |
---|
706 | processor option (GPO) 5 GPO and STP 6 GPO and AVO 7 GPO, |
---|
707 | STP, and AVO */ |
---|
708 | /* Warning, argument is Pn */ |
---|
709 | debug("ansi Got command c, argc %d, argv[0] (%d)\n", argc, |
---|
710 | argv[0], argv[0]); |
---|
711 | if (!argc || argv[0] == 0) |
---|
712 | { |
---|
713 | send_ansi_sequence(screen_list, "\x1b[?1;0c"); |
---|
714 | } |
---|
715 | else |
---|
716 | { |
---|
717 | switch (argv[0]) |
---|
718 | { |
---|
719 | case 1: |
---|
720 | send_ansi_sequence(screen_list, "\x1b[?\x1;\x1c"); |
---|
721 | break; |
---|
722 | case 2: |
---|
723 | send_ansi_sequence(screen_list, "\x1b[?\x1;\x2c"); |
---|
724 | break; |
---|
725 | case 3: |
---|
726 | send_ansi_sequence(screen_list, "\x1b[?\x1;\x3c"); |
---|
727 | break; |
---|
728 | case 4: |
---|
729 | send_ansi_sequence(screen_list, "\x1b[?\x1;\x4c"); |
---|
730 | break; |
---|
731 | case 5: |
---|
732 | send_ansi_sequence(screen_list, "\x1b[?\x1;\x5c"); |
---|
733 | break; |
---|
734 | case 6: |
---|
735 | send_ansi_sequence(screen_list, "\x1b[?\x1;\x6c"); |
---|
736 | break; |
---|
737 | case 7: |
---|
738 | send_ansi_sequence(screen_list, "\x1b[?\x1;\x7c"); |
---|
739 | break; |
---|
740 | default: |
---|
741 | debug("Unsupported DA option '%d'\n", argv[0]); |
---|
742 | break; |
---|
743 | } |
---|
744 | } |
---|
745 | break; |
---|
746 | case 'd': /* VPA (0x64) - Line Position Absolute */ |
---|
747 | y = (argc && argv[0] > 0) ? argv[0] - 1 : 0; |
---|
748 | break; |
---|
749 | case 'f': /* HVP (0x66) - Character And Line Position */ |
---|
750 | x = (argc > 1 && argv[1] > 0) ? argv[1] - 1 : 0; |
---|
751 | y = (argc > 0 && argv[0] > 0) ? argv[0] - 1 : 0; |
---|
752 | break; |
---|
753 | case 'g': /* TBC -- Tabulation Clear */ |
---|
754 | break; |
---|
755 | case 'r': /* FIXME */ |
---|
756 | if (argc == 2) /* DCSTBM - Set top and bottom margin */ |
---|
757 | { |
---|
758 | debug("DCSTBM %d %d", argv[0], argv[1]); |
---|
759 | top = argv[0]; |
---|
760 | bottom = argv[1]; |
---|
761 | } |
---|
762 | else |
---|
763 | debug("ansi import: command r with %d params", argc); |
---|
764 | break; |
---|
765 | case 'h': /* SM (0x68) - FIXME */ |
---|
766 | debug("ansi import: set mode %i", argc ? (int)argv[0] : -1); |
---|
767 | break; |
---|
768 | case 'l': /* RM (0x6c) - FIXME */ |
---|
769 | debug("ansi import: reset mode %i", argc ? (int)argv[0] : -1); |
---|
770 | break; |
---|
771 | case 'm': /* SGR (0x6d) - Select Graphic Rendition */ |
---|
772 | if (argc) |
---|
773 | ansi_parse_grcm(sc, argc, argv); |
---|
774 | else |
---|
775 | ansi_parse_grcm(sc, 1, &dummy); |
---|
776 | break; |
---|
777 | case 'n': |
---|
778 | debug("ansi command n, argc %d, argv[0] %d\n", argc, argv[0]); |
---|
779 | if (!argc) |
---|
780 | break; |
---|
781 | |
---|
782 | switch (argv[0]) |
---|
783 | { |
---|
784 | case 5: |
---|
785 | /* Term ok */ |
---|
786 | send_ansi_sequence(screen_list, "\x1b[0n"); |
---|
787 | break; |
---|
788 | case 6: |
---|
789 | /* Cursor Position */ |
---|
790 | sprintf(b, "\x1b[%d;%dR", y + 1, x + 1); |
---|
791 | send_ansi_sequence(screen_list, b); |
---|
792 | break; |
---|
793 | } |
---|
794 | |
---|
795 | break; |
---|
796 | case 's': /* Private (save cursor position) */ |
---|
797 | save_x = x; |
---|
798 | save_y = y; |
---|
799 | break; |
---|
800 | case 'u': /* Private (reload cursor position) */ |
---|
801 | x = save_x; |
---|
802 | y = save_y; |
---|
803 | break; |
---|
804 | default: |
---|
805 | debug("ansi import: unknown command \"^[%.*s\"", |
---|
806 | final - param + 1, buffer + i + param); |
---|
807 | break; |
---|
808 | } |
---|
809 | } |
---|
810 | |
---|
811 | /* Parse OSC stuff. */ |
---|
812 | else if (buffer[i] == '\033' && buffer[i + 1] == ']') |
---|
813 | { |
---|
814 | char *string; |
---|
815 | unsigned int command = 0; |
---|
816 | unsigned int mode = 2, semicolon, final; |
---|
817 | |
---|
818 | for (semicolon = mode; i + semicolon < size; semicolon++) |
---|
819 | { |
---|
820 | if (buffer[i + semicolon] < '0' || buffer[i + semicolon] > '9') |
---|
821 | break; |
---|
822 | command = 10 * command + (buffer[i + semicolon] - '0'); |
---|
823 | } |
---|
824 | |
---|
825 | if (i + semicolon >= size || buffer[i + semicolon] != ';') |
---|
826 | break; /* Invalid Mode */ |
---|
827 | |
---|
828 | for (final = semicolon + 1; i + final < size; final++) |
---|
829 | if (buffer[i + final] < 0x20) |
---|
830 | break; |
---|
831 | |
---|
832 | if (i + final >= size || buffer[i + final] != '\a') |
---|
833 | break; /* Not enough data or no bell found */ |
---|
834 | /* FIXME: XTerm also reacts to <ESC><backslash> and <ST> */ |
---|
835 | /* FIXME: differenciate between not enough data (try again) and |
---|
836 | invalid data (print shit) */ |
---|
837 | |
---|
838 | skip += final; |
---|
839 | |
---|
840 | string = malloc(final - (semicolon + 1) + 1); |
---|
841 | memcpy(string, buffer + i + (semicolon + 1), |
---|
842 | final - (semicolon + 1)); |
---|
843 | string[final - (semicolon + 1)] = '\0'; |
---|
844 | debug("ansi import: got OSC command %i string '%s'", command, |
---|
845 | string); |
---|
846 | if (command == 0 || command == 2) |
---|
847 | { |
---|
848 | if (sc->title) |
---|
849 | free(sc->title); |
---|
850 | sc->title = string; |
---|
851 | } |
---|
852 | else |
---|
853 | free(string); |
---|
854 | } |
---|
855 | |
---|
856 | /* Get the character we’re going to paste */ |
---|
857 | else |
---|
858 | { |
---|
859 | size_t bytes; |
---|
860 | |
---|
861 | if (i + 6 < size) |
---|
862 | { |
---|
863 | ch = caca_utf8_to_utf32((char const *)(buffer + i), &bytes); |
---|
864 | } |
---|
865 | else |
---|
866 | { |
---|
867 | /* Add a trailing zero to what we're going to read */ |
---|
868 | char tmp[7]; |
---|
869 | memcpy(tmp, buffer + i, size - i); |
---|
870 | tmp[size - i] = '\0'; |
---|
871 | ch = caca_utf8_to_utf32(tmp, &bytes); |
---|
872 | } |
---|
873 | |
---|
874 | if (!bytes) |
---|
875 | { |
---|
876 | /* If the Unicode is invalid, assume it was latin1. */ |
---|
877 | ch = buffer[i]; |
---|
878 | bytes = 1; |
---|
879 | } |
---|
880 | |
---|
881 | /* very incomplete ISO-2022 implementation tailored to DEC ACS */ |
---|
882 | if (sc->conv_state.cs == '@') |
---|
883 | { |
---|
884 | if (((ch > ' ') && (ch <= '~')) |
---|
885 | && |
---|
886 | (sc-> |
---|
887 | conv_state.gn[sc->conv_state.ss ? sc-> |
---|
888 | conv_state.gn[sc->conv_state.ss] : sc-> |
---|
889 | conv_state.glr[0]] == '0')) |
---|
890 | { |
---|
891 | ch = dec_acs(ch); |
---|
892 | } |
---|
893 | else if (((ch > 0x80) && (ch < 0xff)) |
---|
894 | && (sc->conv_state.gn[sc->conv_state.glr[1]] == '0')) |
---|
895 | { |
---|
896 | ch = dec_acs(ch + ' ' - 0x80); |
---|
897 | } |
---|
898 | } |
---|
899 | sc->conv_state.ss = 0; /* no single-shift (GL) */ |
---|
900 | |
---|
901 | wch = caca_utf32_is_fullwidth(ch) ? 2 : 1; |
---|
902 | |
---|
903 | skip += bytes - 1; |
---|
904 | } |
---|
905 | |
---|
906 | /* Wrap long lines or grow horizontally */ |
---|
907 | while ((unsigned int)x + wch > width) |
---|
908 | { |
---|
909 | x -= width; |
---|
910 | y++; |
---|
911 | } |
---|
912 | |
---|
913 | /* Scroll or grow vertically */ |
---|
914 | if ((unsigned int)y >= bottom) |
---|
915 | { |
---|
916 | int lines = (y - bottom) + 1; |
---|
917 | |
---|
918 | savedattr = caca_get_attr(sc->cv, -1, -1); |
---|
919 | |
---|
920 | for (j = top - 1; j + lines < bottom; j++) |
---|
921 | { |
---|
922 | for (k = 0; k < width; k++) |
---|
923 | { |
---|
924 | caca_put_char(sc->cv, k, j, |
---|
925 | caca_get_char(sc->cv, k, j + lines)); |
---|
926 | caca_put_attr(sc->cv, k, j, |
---|
927 | caca_get_attr(sc->cv, k, j + lines)); |
---|
928 | } |
---|
929 | } |
---|
930 | caca_set_attr(sc->cv, sc->clearattr); |
---|
931 | caca_fill_box(sc->cv, 0, bottom - lines, width, bottom - 1, ' '); |
---|
932 | y -= lines; |
---|
933 | caca_set_attr(sc->cv, savedattr); |
---|
934 | } |
---|
935 | |
---|
936 | /* Now paste our character, if any */ |
---|
937 | if (wch) |
---|
938 | { |
---|
939 | caca_put_char(sc->cv, x, y, ch); |
---|
940 | x += wch; |
---|
941 | } |
---|
942 | } |
---|
943 | |
---|
944 | caca_gotoxy(sc->cv, x, y); |
---|
945 | |
---|
946 | if (i) |
---|
947 | sc->changed = 1; |
---|
948 | return i; |
---|
949 | } |
---|
950 | |
---|
951 | /* Coding Method Delimiter (CMD), ECMA-48 (1991), ISO/IEC 6429:1992 (ISO IR |
---|
952 | 189) */ |
---|
953 | |
---|
954 | static void reset_conv_state(struct screen *sc) |
---|
955 | { |
---|
956 | sc->conv_state.cs = '@'; /* ISO-2022 coding system */ |
---|
957 | sc->conv_state.cn[0] = '@'; /* ISO 646 C0 control charset */ |
---|
958 | sc->conv_state.cn[1] = 'C'; /* ISO 6429-1983 C1 control charset */ |
---|
959 | sc->conv_state.glr[0] = 0; /* G0 in GL */ |
---|
960 | sc->conv_state.glr[1] = 2; /* G2 in GR */ |
---|
961 | sc->conv_state.gn[0] = 'B'; /* US-ASCII G0 charset */ |
---|
962 | sc->conv_state.gn[1] = '0'; /* DEC ACS G1 charset */ |
---|
963 | sc->conv_state.gn[2] = LITERAL2CHAR('.', 'A'); /* ISO 8859-1 G2 |
---|
964 | charset */ |
---|
965 | sc->conv_state.gn[3] = LITERAL2CHAR('.', 'A'); /* ISO 8859-1 G3 |
---|
966 | charset */ |
---|
967 | sc->conv_state.ss = 0; /* no single-shift (GL) */ |
---|
968 | sc->conv_state.ctrl8bit = 1; |
---|
969 | } |
---|
970 | |
---|
971 | /* XXX : ANSI loader helper */ |
---|
972 | |
---|
973 | static void ansi_parse_grcm(struct screen *sc, |
---|
974 | unsigned int argc, unsigned int const *argv) |
---|
975 | { |
---|
976 | static uint8_t const ansi2caca[] = { |
---|
977 | CACA_BLACK, CACA_RED, CACA_GREEN, CACA_BROWN, |
---|
978 | CACA_BLUE, CACA_MAGENTA, CACA_CYAN, CACA_LIGHTGRAY |
---|
979 | }; |
---|
980 | |
---|
981 | unsigned int j; |
---|
982 | uint8_t efg, ebg; /* Effective (libcaca) fg/bg */ |
---|
983 | |
---|
984 | for (j = 0; j < argc; j++) |
---|
985 | { |
---|
986 | /* Defined in ECMA-48 8.3.117: SGR - SELECT GRAPHIC RENDITION */ |
---|
987 | if (argv[j] >= 30 && argv[j] <= 37) |
---|
988 | sc->fg = ansi2caca[argv[j] - 30]; |
---|
989 | else if (argv[j] >= 40 && argv[j] <= 47) |
---|
990 | sc->bg = ansi2caca[argv[j] - 40]; |
---|
991 | else if (argv[j] >= 90 && argv[j] <= 97) |
---|
992 | sc->fg = ansi2caca[argv[j] - 90] + 8; |
---|
993 | else if (argv[j] >= 100 && argv[j] <= 107) |
---|
994 | sc->bg = ansi2caca[argv[j] - 100] + 8; |
---|
995 | else |
---|
996 | switch (argv[j]) |
---|
997 | { |
---|
998 | case 0: /* default rendition */ |
---|
999 | sc->fg = sc->dfg; |
---|
1000 | sc->bg = sc->dbg; |
---|
1001 | sc->bold = sc->blink = sc->italics = sc->negative |
---|
1002 | = sc->concealed = sc->underline = sc->faint = sc->strike |
---|
1003 | = sc->proportional = 0; |
---|
1004 | break; |
---|
1005 | case 1: /* bold or increased intensity */ |
---|
1006 | sc->bold = 1; |
---|
1007 | break; |
---|
1008 | case 2: /* faint, decreased intensity or second colour |
---|
1009 | */ |
---|
1010 | sc->faint = 1; |
---|
1011 | break; |
---|
1012 | case 3: /* italicized */ |
---|
1013 | sc->italics = 1; |
---|
1014 | break; |
---|
1015 | case 4: /* singly underlined */ |
---|
1016 | sc->underline = 1; |
---|
1017 | break; |
---|
1018 | case 5: /* slowly blinking (less then 150 per minute) */ |
---|
1019 | case 6: /* rapidly blinking (150 per minute or more) */ |
---|
1020 | sc->blink = 1; |
---|
1021 | break; |
---|
1022 | case 7: /* negative image */ |
---|
1023 | sc->negative = 1; |
---|
1024 | break; |
---|
1025 | case 8: /* concealed characters */ |
---|
1026 | sc->concealed = 1; |
---|
1027 | break; |
---|
1028 | case 9: /* crossed-out (characters still legible but |
---|
1029 | marked as to be deleted */ |
---|
1030 | sc->strike = 1; |
---|
1031 | break; |
---|
1032 | case 21: /* doubly underlined */ |
---|
1033 | sc->underline = 1; |
---|
1034 | break; |
---|
1035 | case 22: /* normal colour or normal intensity (neither |
---|
1036 | bold nor faint) */ |
---|
1037 | sc->bold = sc->faint = 0; |
---|
1038 | break; |
---|
1039 | case 23: /* not italicized, not fraktur */ |
---|
1040 | sc->italics = 0; |
---|
1041 | break; |
---|
1042 | case 24: /* not underlined (neither singly nor doubly) */ |
---|
1043 | sc->underline = 0; |
---|
1044 | break; |
---|
1045 | case 25: /* steady (not blinking) */ |
---|
1046 | sc->blink = 0; |
---|
1047 | break; |
---|
1048 | case 26: /* (reserved for proportional spacing as |
---|
1049 | specified in CCITT Recommendation T.61) */ |
---|
1050 | sc->proportional = 1; |
---|
1051 | break; |
---|
1052 | case 27: /* positive image */ |
---|
1053 | sc->negative = 0; |
---|
1054 | break; |
---|
1055 | case 28: /* revealed characters */ |
---|
1056 | sc->concealed = 0; |
---|
1057 | break; |
---|
1058 | case 29: /* not crossed out */ |
---|
1059 | sc->strike = 0; |
---|
1060 | break; |
---|
1061 | case 38: /* (reserved for future standardization, |
---|
1062 | intended for setting character foreground |
---|
1063 | colour as specified in ISO 8613-6 [CCITT |
---|
1064 | Recommendation T.416]) */ |
---|
1065 | break; |
---|
1066 | case 39: /* default display colour |
---|
1067 | (implementation-defined) */ |
---|
1068 | sc->fg = sc->dfg; |
---|
1069 | break; |
---|
1070 | case 48: /* (reserved for future standardization, |
---|
1071 | intended for setting character background |
---|
1072 | colour as specified in ISO 8613-6 [CCITT |
---|
1073 | Recommendation T.416]) */ |
---|
1074 | break; |
---|
1075 | case 49: /* default background colour |
---|
1076 | (implementation-defined) */ |
---|
1077 | sc->bg = sc->dbg; |
---|
1078 | break; |
---|
1079 | case 50: /* (reserved for cancelling the effect of the |
---|
1080 | rendering aspect established by parameter |
---|
1081 | value 26) */ |
---|
1082 | sc->proportional = 0; |
---|
1083 | break; |
---|
1084 | default: |
---|
1085 | debug("ansi import: unknown sgr %i", argv[j]); |
---|
1086 | break; |
---|
1087 | } |
---|
1088 | } |
---|
1089 | |
---|
1090 | if (sc->concealed) |
---|
1091 | { |
---|
1092 | efg = ebg = CACA_TRANSPARENT; |
---|
1093 | } |
---|
1094 | else |
---|
1095 | { |
---|
1096 | efg = sc->negative ? sc->bg : sc->fg; |
---|
1097 | ebg = sc->negative ? sc->fg : sc->bg; |
---|
1098 | |
---|
1099 | if (sc->bold) |
---|
1100 | { |
---|
1101 | if (efg < 8) |
---|
1102 | efg += 8; |
---|
1103 | else if (efg == CACA_DEFAULT) |
---|
1104 | efg = CACA_WHITE; |
---|
1105 | } |
---|
1106 | } |
---|
1107 | |
---|
1108 | caca_set_color_ansi(sc->cv, efg, ebg); |
---|
1109 | } |
---|