4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.6 2008/02/05 01:11:46 james
14 * *** empty log message ***
16 * Revision 1.5 2008/02/04 20:23:55 james
17 * *** empty log message ***
19 * Revision 1.4 2008/02/04 05:45:55 james
22 * Revision 1.3 2008/02/04 02:05:06 james
23 * *** empty log message ***
25 * Revision 1.2 2008/02/04 01:32:39 james
26 * *** empty log message ***
28 * Revision 1.1 2008/02/03 23:36:41 james
29 * *** empty log message ***
38 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
40 vt100|vt100-am|dec vt100 (w/advanced video):\
42 :co#80:it#8:li#24:vt#3:\
43 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
45 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
46 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
47 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
48 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
49 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
50 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
51 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
52 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
53 :us=\E[4m:tc=vt100+fnkeys:
55 vt100+fnkeys|dec vt100 numeric keypad:\
56 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
59 vt100+pfkeys|dec vt100 numeric keypad:\
60 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
62 vt100+keypad|dec vt100 numeric keypad no fkeys:\
63 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
68 so the parser needs to be able to at least do
125 if ((c >= 'a') && (c <= 'z'))
127 if ((c >= 'A') && (c <= 'Z'))
147 vt102_cursor_normalize (VT102 * v, int do_wrapscroll, int use_margins)
149 int wrap = do_wrapscroll ? 1 : 0;
150 int scroll = do_wrapscroll ? 1 : 0;
151 CRT_Pos *top, *bottom;
155 top = &v->top_margin;
156 bottom = &v->bottom_margin;
160 top = &v->screen_start;
161 bottom = &v->screen_end;
164 if (v->pos.x < top->x) /*don't wrap backwards */
167 if (v->pos.x > bottom->x)
176 v->pos.x = bottom->x;
180 if (v->pos.y < top->y)
183 if (v->pos.y > bottom->y)
186 crt_scroll_up (&v->crt, *top, *bottom, 1);
187 v->pos.y = bottom->y;
193 vt102_cursor_motion (VT102 * v, int x, int y, int wrapscroll)
199 vt102_cursor_normalize (v, wrapscroll, 1);
206 vt102_cursor_normalize (v, wrapscroll, 1);
213 vt102_cursor_normalize (v, wrapscroll, 1);
220 vt102_cursor_normalize (v, wrapscroll, 1);
225 vt102_delete_from_line (VT102 * v, CRT_Pos p)
227 int n = v->bottom_margin.x - p.x;
235 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
236 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
239 v->crt.screen[CRT_ADDR (v->bottom_margin.x, p.y)].chr = ' ';
240 /*But not attr due to vt102 bug*/
245 vt102_parse_esc (VT102 * v, int c)
247 fprintf (stderr, "ESC 0%o(%c)\n", c, c);
251 vt102_parse_csi (VT102 * v, char *buf, int len)
280 vt102_cursor_motion (v, 0, -narg, 0);
283 vt102_cursor_motion (v, 0, narg, 0);
286 vt102_cursor_motion (v, narg, 0, 0);
289 vt102_cursor_motion (v, -narg, 0, 0);
294 ptr = index (arg, ';');
296 v->pos.x = atoi (ptr + 1) - 1;
300 vt102_cursor_normalize (v, 0, 0);
303 fprintf(stderr,"OCTOPUS %d\n",narg);
307 crt_erase (&v->crt, v->pos, v->screen_end, 1);
310 crt_erase (&v->crt, v->screen_start, v->screen_end, 1);
316 CRT_Pos ls = { 0, v->pos.y };
317 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
319 narg = 0; /*Different default */
324 fprintf(stderr,"FISH %d %d -> %d %d\n",
327 crt_erase (&v->crt, v->pos, le, 1);
330 fprintf(stderr,"SOUP %d %d -> %d %d\n",
333 crt_erase (&v->crt, ls, v->pos, 1);
336 fprintf(stderr,"TREE %d %d -> %d %d\n",
339 crt_erase (&v->crt, ls, le, 1);
347 vt102_delete_from_line (v, v->pos);
350 if ((v->pos.y >= v->top_margin.y)
351 && (v->pos.y <= v->bottom_margin.y))
354 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1);
359 if ((v->pos.y >= v->top_margin.y)
360 && (v->pos.y <= v->bottom_margin.y))
363 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 0);
370 fprintf (stderr, "C: CSI %s buf[0]=%c\n", buf,buf[0]);
374 //horror of horrors parsing the ;
377 v->top_margin=v->screen_start;
378 v->bottom_margin=v->screen_end;
380 if ((len>2) && (ptr=index(arg,';'))) {
382 v->top_margin.y=narg-1;
383 v->bottom_margin.y=atoi(ptr)-1;
386 if (v->top_margin.y<v->screen_start.y) v->top_margin.y=v->screen_start.y;
387 if (v->top_margin.y>v->screen_end.y) v->top_margin.y=v->screen_end.y;
388 if (v->bottom_margin.y<v->screen_start.y) v->bottom_margin.y=v->screen_start.y;
389 if (v->bottom_margin.y>v->screen_end.y) v->bottom_margin.y=v->screen_end.y;
391 fprintf(stderr,"D: %d %d\n",v->top_margin.y,v->bottom_margin.y);
393 v->pos=v->top_margin;
397 fprintf (stderr, "A: CSI %s buf[0]=%c\n", buf,buf[0]);
401 fprintf (stderr, "B: CSI %s buf[0]=%c\n", buf,buf[0]);
409 vt102_status_line (VT102 * v, char *str)
412 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
416 ca->attr = CRT_ATTR_REVERSE;
427 vt102_parse_char (VT102 * v, int c)
429 VT102_parser *p = &v->parser;
432 fprintf (stderr, "%c pc %d %d %d %d %d\n", c, c, p->in_csi, p->in_escape,
437 p->csi_buf[p->csi_ptr++] = c;
438 if (csi_ender (c) || (p->csi_ptr == VT102_CSI_LEN))
440 vt102_parse_csi (v, p->csi_buf, p->csi_ptr);
444 else if (p->in_escape)
449 p->csi_buf[p->csi_ptr++] = c;
456 vt102_parse_esc (v, c);
473 vt102_cursor_motion (v, -1, 0, 1);
478 vt102_cursor_normalize(v,1,1);
483 vt102_cursor_motion (v, 0, 1, 1);
486 v->pos.x = v->top_margin.x;
511 /*regular character */ default:
512 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = c;
513 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
514 vt102_cursor_motion (v, 1, 0, 1);
520 vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
524 vt102_parser_reset (VT102_parser * p)
532 vt102_reset (VT102 * v)
534 VT102_parser *p = &v->parser;
536 vt102_parser_reset (p);
540 v->screen_start.x = 0;
541 v->screen_start.y = 0;
542 v->screen_end.x = VT102_COLS - 1;
543 v->screen_end.y = VT102_ROWS - 1;
545 v->top_margin = v->screen_start;
546 v->bottom_margin = v->screen_end;
548 v->pos = v->screen_start;