4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.5 2008/02/04 20:23:55 james
14 * *** empty log message ***
16 * Revision 1.4 2008/02/04 05:45:55 james
19 * Revision 1.3 2008/02/04 02:05:06 james
20 * *** empty log message ***
22 * Revision 1.2 2008/02/04 01:32:39 james
23 * *** empty log message ***
25 * Revision 1.1 2008/02/03 23:36:41 james
26 * *** empty log message ***
35 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
37 vt100|vt100-am|dec vt100 (w/advanced video):\
39 :co#80:it#8:li#24:vt#3:\
40 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
42 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
43 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
44 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
45 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
46 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
47 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
48 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
49 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
50 :us=\E[4m:tc=vt100+fnkeys:
52 vt100+fnkeys|dec vt100 numeric keypad:\
53 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
56 vt100+pfkeys|dec vt100 numeric keypad:\
57 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
59 vt100+keypad|dec vt100 numeric keypad no fkeys:\
60 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
65 so the parser needs to be able to at least do
122 if ((c >= 'a') && (c <= 'z'))
124 if ((c >= 'A') && (c <= 'Z'))
144 vt102_cursor_normalize (VT102 * v, int do_wrapscroll, int use_margins)
146 int wrap = do_wrapscroll ? 1 : 0;
147 int scroll = do_wrapscroll ? 1 : 0;
148 CRT_Pos *top, *bottom;
152 top = &v->top_margin;
153 bottom = &v->bottom_margin;
157 top = &v->screen_start;
158 bottom = &v->screen_end;
161 if (v->pos.x < top->x) /*don't wrap backwards */
164 if (v->pos.x > bottom->x)
173 v->pos.x = bottom->x;
177 if (v->pos.y < top->y)
180 if (v->pos.y > bottom->y)
183 crt_scroll_up (&v->crt, *top, *bottom, 1);
184 v->pos.y = bottom->y;
190 vt102_cursor_motion (VT102 * v, int x, int y, int wrapscroll)
196 vt102_cursor_normalize (v, wrapscroll, 1);
203 vt102_cursor_normalize (v, wrapscroll, 1);
210 vt102_cursor_normalize (v, wrapscroll, 1);
217 vt102_cursor_normalize (v, wrapscroll, 1);
222 vt102_delete_from_line (VT102 * v, CRT_Pos p)
224 int n = v->bottom_margin.x - p.x;
232 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
233 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
236 v->crt.screen[CRT_ADDR (v->bottom_margin.x, p.y)].chr = ' ';
237 /*But not attr due to vt102 bug*/
242 vt102_parse_esc (VT102 * v, int c)
244 fprintf (stderr, "ESC 0%o(%c)\n", c, c);
248 vt102_parse_csi (VT102 * v, char *buf, int len)
277 vt102_cursor_motion (v, 0, -narg, 0);
280 vt102_cursor_motion (v, 0, narg, 0);
283 vt102_cursor_motion (v, narg, 0, 0);
286 vt102_cursor_motion (v, -narg, 0, 0);
291 ptr = index (arg, ';');
293 v->pos.x = atoi (ptr + 1) - 1;
297 vt102_cursor_normalize (v, 0, 0);
300 fprintf(stderr,"OCTOPUS %d\n",narg);
304 crt_erase (&v->crt, v->pos, v->screen_end, 1);
307 crt_erase (&v->crt, v->screen_start, v->screen_end, 1);
313 CRT_Pos ls = { 0, v->pos.y };
314 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
316 narg = 0; /*Different default */
321 fprintf(stderr,"FISH %d %d -> %d %d\n",
324 crt_erase (&v->crt, v->pos, le, 1);
327 fprintf(stderr,"SOUP %d %d -> %d %d\n",
330 crt_erase (&v->crt, ls, v->pos, 1);
333 fprintf(stderr,"TREE %d %d -> %d %d\n",
336 crt_erase (&v->crt, ls, le, 1);
344 vt102_delete_from_line (v, v->pos);
347 if ((v->pos.y >= v->top_margin.y)
348 && (v->pos.y <= v->bottom_margin.y))
351 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1);
356 if ((v->pos.y >= v->top_margin.y)
357 && (v->pos.y <= v->bottom_margin.y))
360 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 0);
365 fprintf (stderr, "A: CSI %s buf[0]=%c\n", buf,buf[0]);
369 fprintf (stderr, "B: CSI %s buf[0]=%c\n", buf,buf[0]);
377 vt102_status_line (VT102 * v, char *str)
380 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
384 ca->attr = CRT_ATTR_REVERSE;
395 vt102_parse_char (VT102 * v, int c)
397 VT102_parser *p = &v->parser;
400 fprintf (stderr, "%c pc %d %d %d %d %d\n", c, c, p->in_csi, p->in_escape,
405 p->csi_buf[p->csi_ptr++] = c;
406 if (csi_ender (c) || (p->csi_ptr == VT102_CSI_LEN))
408 vt102_parse_csi (v, p->csi_buf, p->csi_ptr);
412 else if (p->in_escape)
417 p->csi_buf[p->csi_ptr++] = c;
424 vt102_parse_esc (v, c);
441 vt102_cursor_motion (v, -1, 0, 1);
448 vt102_cursor_motion (v, 0, 1, 1);
451 v->pos.x = v->top_margin.x;
476 /*regular character */ default:
477 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = c;
478 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
479 vt102_cursor_motion (v, 1, 0, 1);
485 vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
489 vt102_parser_reset (VT102_parser * p)
497 vt102_reset (VT102 * v)
499 VT102_parser *p = &v->parser;
501 vt102_parser_reset (p);
505 v->screen_start.x = 0;
506 v->screen_start.y = 0;
507 v->screen_end.x = VT102_COLS - 1;
508 v->screen_end.y = VT102_ROWS - 1;
510 v->top_margin = v->screen_start;
511 v->bottom_margin = v->screen_end;
513 v->pos = v->screen_start;