4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.30 2008/02/22 14:51:54 james
14 * *** empty log message ***
16 * Revision 1.29 2008/02/15 03:32:07 james
17 * *** empty log message ***
19 * Revision 1.28 2008/02/14 10:34:30 james
20 * *** empty log message ***
22 * Revision 1.27 2008/02/14 02:46:45 james
23 * *** empty log message ***
25 * Revision 1.26 2008/02/14 01:55:57 james
26 * *** empty log message ***
28 * Revision 1.25 2008/02/13 16:57:29 james
29 * *** empty log message ***
31 * Revision 1.24 2008/02/13 09:12:21 james
32 * *** empty log message ***
34 * Revision 1.23 2008/02/07 13:26:35 james
35 * *** empty log message ***
37 * Revision 1.22 2008/02/07 13:22:51 james
38 * *** empty log message ***
40 * Revision 1.21 2008/02/07 12:21:16 james
41 * *** empty log message ***
43 * Revision 1.20 2008/02/07 12:16:04 james
44 * *** empty log message ***
46 * Revision 1.19 2008/02/07 11:27:02 james
47 * *** empty log message ***
49 * Revision 1.18 2008/02/07 01:59:25 james
50 * *** empty log message ***
52 * Revision 1.17 2008/02/07 01:58:28 james
53 * *** empty log message ***
55 * Revision 1.16 2008/02/07 01:57:46 james
56 * *** empty log message ***
58 * Revision 1.15 2008/02/07 00:43:27 james
59 * *** empty log message ***
61 * Revision 1.14 2008/02/07 00:40:23 james
62 * *** empty log message ***
64 * Revision 1.13 2008/02/07 00:39:59 james
65 * *** empty log message ***
67 * Revision 1.12 2008/02/07 00:39:13 james
68 * *** empty log message ***
70 * Revision 1.11 2008/02/06 20:26:58 james
71 * *** empty log message ***
73 * Revision 1.10 2008/02/06 17:53:28 james
74 * *** empty log message ***
76 * Revision 1.9 2008/02/06 15:53:22 james
77 * *** empty log message ***
79 * Revision 1.8 2008/02/06 11:49:47 james
80 * *** empty log message ***
82 * Revision 1.7 2008/02/06 11:30:37 james
83 * *** empty log message ***
85 * Revision 1.6 2008/02/05 01:11:46 james
86 * *** empty log message ***
88 * Revision 1.5 2008/02/04 20:23:55 james
89 * *** empty log message ***
91 * Revision 1.4 2008/02/04 05:45:55 james
94 * Revision 1.3 2008/02/04 02:05:06 james
95 * *** empty log message ***
97 * Revision 1.2 2008/02/04 01:32:39 james
98 * *** empty log message ***
100 * Revision 1.1 2008/02/03 23:36:41 james
101 * *** empty log message ***
112 :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100:
114 vt100|vt100-am|dec vt100 (w/advanced video):\
116 :co#80:it#8:li#24:vt#3:\
117 :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\
119 :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\
120 :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
121 :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\
122 :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\
123 :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\
124 :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\
125 :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\
126 :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\
127 :us=\E[4m:tc=vt100+fnkeys:
129 vt100+fnkeys|dec vt100 numeric keypad:\
130 :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\
133 vt100+pfkeys|dec vt100 numeric keypad:\
134 :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad:
136 vt100+keypad|dec vt100 numeric keypad no fkeys:\
137 :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:
142 so the parser needs to be able to at least do
204 ansi|ansi/pc-term compatible with color:\
205 :u6=\E[%i%d;%dR:u7=\E[6n:u9=\E[c:tc=ecma+color:\
206 :tc=klone+sgr:tc=ansi-m:
207 ansi-m|ansi-mono|ANSI X3.64-1979 terminal with ANSI.SYS compatible attributes:\
209 :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\
210 :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\
211 :cb=\E[1K:ch=\E[%i%dG:ct=\E[2g:cv=\E[%i%dd:ec=\E[%dX:ei=:\
212 :im=:kB=\E[Z:kI=\E[L:kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:\
213 :nw=\r\E[S:pf=\E[4i:po=\E[5i:s0=\E(B:s1=\E)B:s2=\E*B:\
214 :s3=\E+B:ta=\E[I:tc=pcansi-m:
215 pcansi-m|pcansi-mono|ibm-pc terminal programs claiming to be ansi (mono mode):\
218 :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\
219 :cm=\E[%i%d;%dH:cr=^M:ct=\E[2g:dc=\E[P:dl=\E[M:do=\E[B:\
220 :ho=\E[H:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\
221 :le=\E[D:nd=\E[C:sf=^J:st=\EH:ta=^I:up=\E[A:\
223 klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 m):\
224 :as=\E[12m:mb=\E[5m:md=\E[1m:me=\E[0;10m:mk=\E[8m:\
225 :mr=\E[7m:se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:tc=klone+acs:
226 klone+acs|alternate character set for ansi.sys displays:\
227 :ac=+\020,\021-\030.^Y0\333`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376:\
228 :ae=\E[10m:as=\E[11m:
229 ecma+color|color control for ECMA-48-compatible terminals:\
231 :AB=\E[4%dm:AF=\E[3%dm:op=\E[39;49m:
234 Ignoreing ones in the VT102 spec
267 if (c<32) return ' ';
268 if (c>126) return ' ';
275 if ((c >= 'a') && (c <= 'z'))
277 if ((c >= 'A') && (c <= 'Z'))
308 in_margins (VT102 * v, CRT_Pos p)
310 if (v->pos.x < v->top_margin.x)
312 if (v->pos.y < v->top_margin.y)
315 if (v->pos.x > v->bottom_margin.x)
317 if (v->pos.y > v->bottom_margin.y)
324 vt102_log_line (Context * c, int line)
326 CRT_Pos e = { VT102_COLS - 1, line };
327 CRT_Pos p = { 0, line };
328 char logbuf[VT102_COLS + 1];
334 for (; e.x > 0; --e.x)
336 if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
340 for (; p.x <= e.x; ++p.x)
342 int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr;
351 c->l->log (c->l, logbuf);
354 /*Called for every upward scroll with same args*/
356 vt102_history (Context * c, CRT_Pos t, CRT_Pos b)
358 /*Only log if it scrolls off the top*/
363 history_add (c->h, &(c->v->crt.screen[CRT_ADDR_POS (&t)]));
367 vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br)
382 vt102_cursor_normalize (VT102 * v)
384 CRT_Pos *top, *bottom;
386 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
388 vt102_clip_cursor (v, v->top_margin, v->bottom_margin);
392 vt102_clip_cursor (v, v->screen_start, v->screen_end);
398 vt102_cursor_carriage_return (VT102 * v)
400 /*FISH*/ v->pos.x = v->top_margin.x;
405 vt102_cursor_advance_line (Context * c)
408 int couldscroll = in_margins (v, v->pos);
410 /*have wraped off end of last line in scrolling region */
411 /* (|| not necessary, but shuts compiler up */
412 if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) &&
415 vt102_log_line (c, v->pos.y);
417 vt102_history (c, v->top_margin, v->bottom_margin);
419 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
423 if (v->pos.y!=v->screen_end.y) v->pos.y++;
429 vt102_do_pending_wrap (Context * c)
432 int couldscroll = in_margins (v, v->pos);
433 int autowrap = v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP];
435 if (!v->pending_wrap)
439 fprintf (stderr, "ca: (%d,%d) autowrap %d couldscroll %d\n", v->pos.x,
440 v->pos.y, autowrap, couldscroll);
443 /*End of line but no autowrap, nothing to do*/
447 /*End of screen and not allowed to scroll, nothing to do*/
448 if ((v->pos.y == v->screen_end.y) && (!couldscroll))
453 v->pos.x = v->top_margin.x;
460 vt102_cursor_advance_line (c);
464 vt102_cursor_advance (Context * c)
468 if (v->pos.x < v->bottom_margin.x)
477 vt102_do_pending_wrap(c);
483 vt102_cursor_retard (VT102 * v)
485 if (v->pos.x != v->top_margin.x)
492 vt102_reset_tabs (VT102 * v)
496 memset (v->tabs, 0, sizeof (v->tabs));
498 for (i = 0; i < VT102_COLS; i += 8)
504 vt102_cursor_advance_tab (VT102 * v)
506 if (v->pos.x == v->bottom_margin.x)
508 while (v->pos.x < v->bottom_margin.x)
511 if (v->tabs[v->pos.x])
518 vt102_cursor_retard_tab (VT102 * v)
520 if (v->pos.x == v->top_margin.x)
522 while (v->pos.x > v->top_margin.x)
525 if (v->tabs[v->pos.x])
531 vt102_cursor_home (VT102 * v)
533 v->pos = v->top_margin;
534 vt102_cursor_normalize (v);
539 vt102_cursor_absolute (VT102 * v, int x, int y)
541 if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
543 v->pos.x = x + v->top_margin.x;
544 v->pos.y = y + v->top_margin.x;
551 vt102_cursor_normalize (v);
555 vt102_cursor_relative (VT102 * v, int x, int y)
559 vt102_cursor_normalize (v);
566 vt102_delete_from_line (VT102 * v, CRT_Pos p)
568 int n = v->bottom_margin.x - p.x;
576 memmove (&v->crt.screen[CRT_ADDR_POS (&p)],
577 &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
580 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
581 /*But not attr due to vt102 bug*/
585 vt102_insert_into_line (VT102 * v, CRT_Pos p)
587 int n = v->bottom_margin.x - p.x;
595 memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1],
596 &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n);
599 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
600 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].attr = CRT_ATTR_NORMAL;
601 v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].color = CRT_COLOR_NORMAL;
607 vt102_change_mode (VT102 * v, int private, char *ns, int set)
623 if (m >= VT102_NMODES)
628 v->private_modes[m] = set;
631 case VT102_PRIVATE_MODE_CURSOR_MODE:
632 if (v->application_keypad_mode)
633 v->private_modes[m] = 0;
635 fprintf (stderr, "APPLICATION CURSOR MODE %d wanted %d\n",
636 v->private_modes[m], set);
639 case VT102_PRIVATE_MODE_ORIGIN_MODE:
640 vt102_cursor_home (v);
649 fprintf (stderr, "mode set=%d private=%d num=%d\n", set, private, m);
654 vt102_parse_mode_string (VT102 * v, char *buf, int len)
657 char last = buf[len - 1];
661 memset (num, 0, sizeof (num));
662 o = sizeof (num) - 1;
680 vt102_change_mode (v, private, &num[o], last == 'h');
681 memset (num, 0, sizeof (num));
682 o = sizeof (num) - 1;
697 vt102_change_mode (v, private, &num[o], last == 'h');
703 vt102_change_attr (VT102 * v, char *na)
720 v->attr = CRT_ATTR_NORMAL;
721 v->color = CRT_COLOR_NORMAL;
724 v->attr |= CRT_ATTR_BOLD;
728 v->attr &= ~CRT_ATTR_BOLD;
731 v->attr |= CRT_ATTR_UNDERLINE;
734 v->attr &= ~CRT_ATTR_UNDERLINE;
737 v->attr |= CRT_ATTR_BLINK;
740 v->attr &= ~CRT_ATTR_BLINK;
743 v->attr |= CRT_ATTR_REVERSE;
746 v->attr &= ~CRT_ATTR_REVERSE;
756 v->color &= ~CRT_COLOR_FG_MASK;
757 v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
767 v->color &= ~CRT_COLOR_FG_MASK;
770 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) &
775 v->color &= ~CRT_COLOR_FG_MASK;
777 (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK;
787 v->color &= ~CRT_COLOR_BG_MASK;
788 v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
798 v->color &= ~CRT_COLOR_BG_MASK;
801 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) &
806 v->color &= ~CRT_COLOR_BG_MASK;
808 (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK;
814 fprintf (stderr, "unhandled SGR %d\n", a);
822 vt102_parse_attr_string (VT102 * v, char *buf, int len)
825 char last = buf[len - 1];
829 memset (num, 0, sizeof (num));
830 o = sizeof (num) - 1;
841 vt102_change_attr (v, &num[o]);
842 memset (num, 0, sizeof (num));
843 o = sizeof (num) - 1;
857 vt102_change_attr (v, &num[o]);
861 vt102_save_state (VT102 * v)
863 v->saved.pos = v->pos;
864 v->saved.attr = v->attr;
865 v->saved.color = v->color;
866 v->saved.origin_mode = v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
870 vt102_restore_state (VT102 * v)
872 v->pos = v->saved.pos;
873 v->attr = v->saved.attr;
874 v->color = v->saved.color;
875 v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE] = v->saved.origin_mode;
876 vt102_cursor_normalize (v);
881 vt102_regular_char (Context * c, VT102 * v, char ch)
884 vt102_do_pending_wrap (c);
886 if (v->modes[VT102_MODE_INSERT])
887 vt102_insert_into_line (v, v->pos);
889 v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
890 v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
891 v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
892 vt102_cursor_advance (c);
894 v->last_reg_char = ch;
898 vt102_scs (Context * c, int g, int s)
900 /*Ignoring charsets*/
904 vt102_parse_esc (Context * c, int ch)
910 if (v->pos.y == v->bottom_margin.y)
912 vt102_log_line (c, v->pos.y);
913 vt102_history (c, v->top_margin, v->bottom_margin);
914 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
918 vt102_cursor_relative (v, 0, 1);
925 if (v->pos.y == v->top_margin.y)
927 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1);
931 vt102_cursor_relative (v, 0, -1);
935 vt102_save_state (v);
938 vt102_restore_state (v);
941 v->application_keypad_mode = 1;
944 v->application_keypad_mode = 0;
947 log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__,__LINE__,ch,safe_ch(ch));
953 vt102_parse_csi (Context * c, char *buf, int len)
985 vt102_insert_into_line (v, v->pos);
988 vt102_cursor_relative (v, 0, -narg);
992 vt102_cursor_relative (v, 0, narg);
996 vt102_cursor_relative (v, narg, 0);
999 vt102_cursor_relative (v, -narg, 0);
1002 vt102_cursor_relative (v, 0, narg);
1003 vt102_cursor_carriage_return (v);
1006 vt102_cursor_relative (v, 0, -narg);
1007 vt102_cursor_carriage_return (v);
1010 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1019 ptr = index (arg, ';');
1021 x = atoi (ptr + 1) - 1;
1025 vt102_cursor_absolute (v, x, y);
1030 vt102_cursor_advance_tab (c->v);
1034 narg = 0; /*Different default */
1038 crt_erase (&v->crt, v->pos, v->screen_end, 1);
1041 crt_erase (&v->crt, v->screen_start, v->pos, 1);
1044 crt_erase (&v->crt, v->screen_start, v->screen_end, 1);
1050 CRT_Pos ls = { 0, v->pos.y };
1051 CRT_Pos le = { VT102_COLS - 1, v->pos.y };
1053 narg = 0; /*Different default */
1058 crt_erase (&v->crt, v->pos, le, 1);
1061 crt_erase (&v->crt, ls, v->pos, 1);
1064 crt_erase (&v->crt, ls, le, 1);
1071 if ((v->pos.y >= v->top_margin.y)
1072 && (v->pos.y <= v->bottom_margin.y))
1075 crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1);
1080 if ((v->pos.y >= v->top_margin.y)
1081 && (v->pos.y <= v->bottom_margin.y))
1085 vt102_history (c, v->pos, v->bottom_margin);
1086 crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1);
1092 vt102_delete_from_line (v, v->pos);
1095 //FIXME: cursor position report - does anything use that?
1100 vt102_history (c, v->top_margin, v->bottom_margin);
1101 crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
1106 crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1);
1110 CRT_Pos end = v->pos;
1114 if (end.x > v->bottom_margin.x)
1115 end.x = v->bottom_margin.x;
1117 crt_erase (&v->crt, v->pos, end, 1);
1122 vt102_cursor_retard_tab (c->v);
1125 vt102_cursor_absolute (v, narg - 1, v->pos.y);
1129 vt102_regular_char (c, v, v->last_reg_char);
1135 vt102_cursor_absolute (v, v->pos.x, narg - 1);
1139 narg = 0; /*Different default */
1144 v->tabs[v->pos.x] = 0;
1146 case 2: //FIXME: - LA120 says current line only WTF?
1148 memset (v->tabs, 0, sizeof (v->tabs));
1153 case 'i': //4,5 Turn printer on and off WTF?
1158 vt102_parse_mode_string (v, &buf[1], len - 1);
1163 vt102_parse_attr_string (v, &buf[1], len - 1);
1165 case 'n': // 6 request cursor position
1169 v->top_margin = v->screen_start;
1170 v->bottom_margin = v->screen_end;
1172 if ((len > 2) && (ptr = index (arg, ';')))
1175 v->top_margin.y = narg - 1;
1176 v->bottom_margin.y = atoi (ptr) - 1;
1179 if (v->top_margin.y < v->screen_start.y)
1180 v->top_margin.y = v->screen_start.y;
1181 if (v->top_margin.y > v->screen_end.y)
1182 v->top_margin.y = v->screen_end.y;
1183 if (v->bottom_margin.y < v->screen_start.y)
1184 v->bottom_margin.y = v->screen_start.y;
1185 if (v->bottom_margin.y > v->screen_end.y)
1186 v->bottom_margin.y = v->screen_end.y;
1188 vt102_cursor_home (v);
1191 v->saved.pos = v->pos;
1194 v->pos = v->saved.pos;
1195 vt102_cursor_normalize (v);
1196 v->pending_wrap = 0;
1200 log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__,__LINE__,buf);
1206 log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__,__LINE__,buf);
1215 vt102_status_line (VT102 * v, char *str)
1218 CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
1222 ca->attr = CRT_ATTR_REVERSE;
1223 ca->color = CRT_COLOR_NORMAL;
1234 vt102_parse_char (Context * c, int ch)
1237 VT102_parser *p = &v->parser;
1240 log_f (c->l, "char %3d %c pc %d %d %2d %2d %d",ch,safe_ch(ch),
1241 p->in_csi, p->in_escape, v->pos.x, v->pos.y,v->pending_wrap);
1245 p->csi_buf[p->csi_ptr++] = ch;
1246 if (csi_ender (ch) || (p->csi_ptr == VT102_CSI_LEN))
1248 if (csi_starter (p->csi_buf[0]))
1250 vt102_parse_csi (c, p->csi_buf, p->csi_ptr);
1252 else if (scs_starter (p->csi_buf[0]))
1254 vt102_scs (c, p->csi_buf[0], p->csi_buf[1]);
1258 log_f (c->l, "<%s:%d no dispatcher for sequence starting \\033 \\%03o (ESC %c)>", __FILE__,__LINE__,p->csi_buf[0],safe_ch(p->csi_buf[0]));
1263 else if (p->in_escape)
1265 if (csi_starter (ch) || scs_starter (ch))
1268 p->csi_buf[p->csi_ptr++] = ch;
1275 vt102_parse_esc (c, ch);
1291 c->t->xmit (c->t, "vt102", 5);
1297 vt102_cursor_retard (c->v);
1300 vt102_cursor_advance_tab (c->v);
1305 vt102_cursor_advance_line (c);
1306 if (!v->modes[VT102_MODE_NEWLINE_MODE])
1309 vt102_cursor_carriage_return (v);
1313 /*Ignoring charsets */
1317 /*Ignoring charsets */
1340 /*regular character */ default:
1341 vt102_regular_char (c, v, ch);
1345 v->crt.pos = v->pos;
1346 v->crt.hide_cursor =
1347 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1;
1349 if (v->current_line.y != v->pos.y)
1351 vt102_log_line (c, v->current_line.y);
1352 v->current_line = v->pos;
1356 cmd_show_status (c->d, c);
1359 vt102_parse (Context * c, char *buf, int len)
1362 vt102_parse_char (c, *(buf++));
1367 vt102_parser_reset (VT102_parser * p)
1376 vt102_send (Context * c, uint8_t key)
1384 fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
1386 if ((key > 31) && (key < 127))
1388 c->t->xmit (c->t, &key, 1);
1407 c->t->xmit (c->t, &key, 1);
1410 c->t->xmit (c->t, &key, 1);
1411 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1414 c->t->xmit (c->t, &ch, 1);
1430 c->t->xmit (c->t, &key, 1);
1438 c->t->xmit (c->t, &key, 1);
1449 if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
1451 uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) };
1452 c->t->xmit (c->t, &buf, sizeof (buf));
1456 uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
1457 c->t->xmit (c->t, &buf, sizeof (buf));
1475 if (c->v->application_keypad_mode)
1477 uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) };
1478 c->t->xmit (c->t, &buf, sizeof (buf));
1482 static char kpoff[KEY_NUM] = {
1501 c->t->xmit (c->t, &kpoff[key], 1);
1505 if (c->v->application_keypad_mode)
1507 uint8_t buf[] = { 033, 'O', 'M' };
1508 c->t->xmit (c->t, &buf, sizeof (buf));
1513 c->t->xmit (c->t, &ch, 1);
1514 if (c->v->modes[VT102_MODE_NEWLINE_MODE])
1517 c->t->xmit (c->t, &ch, 1);
1526 uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
1527 c->t->xmit (c->t, &buf, sizeof (buf));
1535 uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' };
1536 c->t->xmit (c->t, &buf, sizeof (buf));
1544 vt102_reset (VT102 * v)
1546 VT102_parser *p = &v->parser;
1548 vt102_parser_reset (p);
1551 v->attr = CRT_ATTR_NORMAL;
1552 v->color = CRT_COLOR_NORMAL;
1554 v->application_keypad_mode = 0;
1556 v->current_line = v->pos;
1557 v->pending_wrap = 0;
1559 v->screen_start.x = 0;
1560 v->screen_start.y = 0;
1561 v->screen_end.x = VT102_COLS - 1;
1562 v->screen_end.y = VT102_ROWS - 1;
1564 v->top_margin = v->screen_start;
1565 v->bottom_margin = v->screen_end;
1567 memset (v->modes, 0, VT102_NMODES);
1568 memset (v->private_modes, 0, VT102_NMODES);
1570 v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP] = 1;
1571 v->private_modes[VT102_PRIVATE_MODE_AUTO_REPEAT] = 1;
1572 v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] = 1;
1573 v->modes[VT102_MODE_LOCAL_ECHO_OFF] = 1;
1575 vt102_cursor_home (v);
1576 vt102_reset_tabs (v);
1577 v->current_line = v->pos;
1579 vt102_save_state (v);
1581 vt102_status_line (v, "");
1583 v->last_reg_char = ' ';
1590 vt102_dispatch (Context * c)
1595 red = c->t->recv (c->t, buf, sizeof (buf));
1603 vt102_parse (c, buf, red);
1610 vt102_dispatch_one (Context * c)
1615 red = c->t->recv (c->t, &buf, sizeof (buf));
1622 vt102_parse_char (c, buf);
1632 v = (VT102 *) malloc (sizeof (VT102));
1641 vt102_free (VT102 * v)