chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / ansi.c
1 /*
2  * ansi.c:
3  *
4  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
5  * All rights reserved.
6  *
7  */
8
9 static char rcsid[] = "$Id$";
10
11 /*
12  * $Log$
13  * Revision 1.30  2008/02/24 00:42:53  james
14  * *** empty log message ***
15  *
16  * Revision 1.29  2008/02/23 11:48:37  james
17  * *** empty log message ***
18  *
19  * Revision 1.28  2008/02/22 17:07:00  james
20  * *** empty log message ***
21  *
22  * Revision 1.27  2008/02/20 22:54:22  staffcvs
23  * *** empty log message ***
24  *
25  * Revision 1.26  2008/02/20 20:16:07  james
26  * *** empty log message ***
27  *
28  * Revision 1.25  2008/02/20 19:44:37  james
29  * @@
30  *
31  * Revision 1.24  2008/02/20 19:36:06  james
32  * @@
33  *
34  * Revision 1.23  2008/02/20 19:25:09  james
35  * *** empty log message ***
36  *
37  * Revision 1.22  2008/02/15 03:32:07  james
38  * *** empty log message ***
39  *
40  * Revision 1.21  2008/02/14 02:46:44  james
41  * *** empty log message ***
42  *
43  * Revision 1.20  2008/02/14 01:55:57  james
44  * *** empty log message ***
45  *
46  * Revision 1.19  2008/02/13 16:57:29  james
47  * *** empty log message ***
48  *
49  * Revision 1.18  2008/02/13 09:12:21  james
50  * *** empty log message ***
51  *
52  * Revision 1.17  2008/02/13 01:08:18  james
53  * *** empty log message ***
54  *
55  * Revision 1.16  2008/02/07 13:22:51  james
56  * *** empty log message ***
57  *
58  * Revision 1.15  2008/02/07 13:19:48  james
59  * *** empty log message ***
60  *
61  * Revision 1.14  2008/02/07 12:21:16  james
62  * *** empty log message ***
63  *
64  * Revision 1.13  2008/02/07 12:16:04  james
65  * *** empty log message ***
66  *
67  * Revision 1.12  2008/02/07 11:32:41  james
68  * *** empty log message ***
69  *
70  * Revision 1.11  2008/02/07 11:11:14  staffcvs
71  * *** empty log message ***
72  *
73  * Revision 1.10  2008/02/07 01:02:52  james
74  * *** empty log message ***
75  *
76  * Revision 1.9  2008/02/07 00:43:27  james
77  * *** empty log message ***
78  *
79  * Revision 1.8  2008/02/07 00:39:13  james
80  * *** empty log message ***
81  *
82  * Revision 1.7  2008/02/06 20:26:57  james
83  * *** empty log message ***
84  *
85  * Revision 1.6  2008/02/06 17:53:28  james
86  * *** empty log message ***
87  *
88  * Revision 1.5  2008/02/06 15:53:22  james
89  * *** empty log message ***
90  *
91  * Revision 1.4  2008/02/04 20:23:55  james
92  * *** empty log message ***
93  *
94  * Revision 1.3  2008/02/04 05:45:55  james
95  * ::
96  *
97  * Revision 1.2  2008/02/04 02:05:06  james
98  * *** empty log message ***
99  *
100  * Revision 1.1  2008/02/03 23:31:25  james
101  * *** empty log message ***
102  *
103  */
104 #include "project.h"
105
106
107 static void
108 ansi_move (ANSI * a, CRT_Pos p)
109 {
110   char buf[16];
111   int n;
112   int dx = p.x - a->pos.x;
113   int dy = p.y - a->pos.y;
114
115 //  a->pos.x = ANSI_INVAL;
116
117   if (a->pos.x != ANSI_INVAL)
118     {
119
120       if ((!dx) && (!dy))
121         return;
122
123       if (!dy)
124         {
125           if (dx == 1)
126             {
127               a->terminal->xmit (a->terminal, "\033[C", 3);
128             }
129           else if (dx == -1)
130             {
131               a->terminal->xmit (a->terminal, "\033[D", 3);
132             }
133           else
134             {
135               n = snprintf (buf, sizeof (buf), "\033[%dG", p.x + 1);
136               a->terminal->xmit (a->terminal, buf, n);
137             }
138         }
139       else if (!dx)
140         {
141           if (dy == -1)
142             {
143               a->terminal->xmit (a->terminal, "\033[A", 3);
144             }
145           else if (dy == 1)
146             {
147               a->terminal->xmit (a->terminal, "\033[B", 3);
148             }
149           else if (dy < 0)
150             {
151               n = snprintf (buf, sizeof (buf), "\033[%dA", -dy);
152               a->terminal->xmit (a->terminal, buf, n);
153             }
154           else
155             {
156               n = snprintf (buf, sizeof (buf), "\033[%dB", dy);
157               a->terminal->xmit (a->terminal, buf, n);
158             }
159         }
160       else if (!p.x)
161         {
162           if (dy == 1)
163             {
164               a->terminal->xmit (a->terminal, "\033[E", 3);
165             }
166           else if (dy == -1)
167             {
168               a->terminal->xmit (a->terminal, "\033[F", 3);
169             }
170           else if (dy > 0)
171             {
172               n = snprintf (buf, sizeof (buf), "\033[%dE", dy);
173               a->terminal->xmit (a->terminal, buf, n);
174             }
175           else
176             {
177               n = snprintf (buf, sizeof (buf), "\033[%dF", -dy);
178               a->terminal->xmit (a->terminal, buf, n);
179             }
180         }
181       else
182         {
183           n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1);
184           a->terminal->xmit (a->terminal, buf, n);
185         }
186     }
187   else
188     {
189       n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1);
190       a->terminal->xmit (a->terminal, buf, n);
191     }
192
193   a->pos = p;
194 }
195
196
197 static void
198 ansi_showhide_cursor (ANSI * a, int hide)
199 {
200   if (a->hide_cursor == hide)
201     return;
202
203   if (hide)
204     {
205       a->terminal->xmit (a->terminal, "\033[?25l", 6);
206     }
207   else
208     {
209       a->terminal->xmit (a->terminal, "\033[?25h", 6);
210     }
211
212   a->hide_cursor = hide;
213 }
214
215
216 static void
217 ansi_force_attr_normal (ANSI * a)
218 {
219   a->terminal->xmit (a->terminal, "\033[0m", 4);
220   a->attr = CRT_ATTR_NORMAL;
221   a->color = ANSI_INVAL;
222 }
223
224 static void
225 ansi_set_color (ANSI * a, int color)
226 {
227   int dif;
228   char buf[16];
229   int i;
230   int fg, bg;
231
232   if ((a->color == ANSI_INVAL) || (color != a->color))
233     {
234       fg = CRT_COLOR_FG (color);
235       bg = CRT_COLOR_BG (color);
236
237       if (fg & CRT_COLOR_INTENSITY)
238         {
239           fg += 90;
240         }
241       else
242         {
243           fg += 30;
244         }
245
246       if (bg & CRT_COLOR_INTENSITY)
247         {
248           bg += 100;
249         }
250       else
251         {
252           bg += 40;
253         }
254
255       i = sprintf (buf, "\033[%d;%dm", fg, bg);
256 #if 0
257       fprintf (stderr, "Color set to %d %d %x\n", fg, bg, color);
258 #endif
259
260       a->terminal->xmit (a->terminal, buf, i);
261       a->color = color;
262     }
263 }
264
265 static void
266 ansi_set_attr (ANSI * a, int attr)
267 {
268   int dif;
269
270   dif = attr ^ a->attr;
271
272   if (!dif)
273     return;
274
275   a->attr = attr;
276
277 #if 0
278   if (attr == CRT_ATTR_NORMAL)
279     {
280       ansi_force_attr_normal (a);
281       return;
282     }
283 #endif
284
285   if (dif & CRT_ATTR_UNDERLINE)
286     {
287       if (attr & CRT_ATTR_UNDERLINE)
288         {
289           a->terminal->xmit (a->terminal, "\033[4m", 4);
290         }
291       else
292         {
293           a->terminal->xmit (a->terminal, "\033[24m", 5);
294         }
295     }
296   if (dif & CRT_ATTR_REVERSE)
297     {
298       if (attr & CRT_ATTR_REVERSE)
299         {
300           a->terminal->xmit (a->terminal, "\033[7m", 4);
301         }
302       else
303         {
304           a->terminal->xmit (a->terminal, "\033[27m", 5);
305         }
306     }
307   if (dif & CRT_ATTR_BOLD)
308     {
309       if (attr & CRT_ATTR_BOLD)
310         {
311           a->terminal->xmit (a->terminal, "\033[1m", 4);
312         }
313       else
314         {
315           a->terminal->xmit (a->terminal, "\033[21m", 5);
316           a->terminal->xmit (a->terminal, "\033[22m", 5);
317         }
318     }
319
320 }
321
322 static void
323 ansi_emit_noutf8 (TTY * t, uint32_t ch)
324 {
325   uint8_t c = (ch > 0x7f) ? '?' : ch;
326   t->xmit (t, &c, 1);
327 }
328
329 static void
330 ansi_render (ANSI * a, CRT_CA ca)
331 {
332   int dif;
333
334   if (ca.chr < 0x20)
335     ca.chr = ' ';
336   if ((ca.chr > 0x7e) && (ca.chr < 0xa0))
337     ca.chr = ' ';
338
339   ansi_set_attr (a, ca.attr);
340   ansi_set_color (a, ca.color);
341
342   if (a->utf8)
343     utf8_emit (a->terminal, ca.chr);
344   else
345     ansi_emit_noutf8 (a->terminal, ca.chr);
346
347   a->pos.x++;
348
349 /*Can't easily wrap round here as don't know size of destination screen*/
350 /*so invalidate the cached cursor position*/
351
352   if (a->pos.x >= a->size.x)
353     a->pos.x = ANSI_INVAL;
354
355 }
356
357 static void
358 ansi_cls (ANSI * a)
359 {
360   CRT_Pos p = { 0 };
361
362   crt_cls (&a->crt);
363
364   ansi_set_attr (a, CRT_ATTR_NORMAL);
365   ansi_set_color (a, CRT_COLOR_NORMAL);
366   ansi_move (a, p);
367   a->terminal->xmit (a->terminal, "\033[2J", 4);
368 /*different emulators leave cursor in different places after cls differently*/
369   a->pos.x = ANSI_INVAL;
370 }
371
372 #if 0
373 int
374 ansi_scroll_up (ANSI * a, CRT_Pos s, CRT_Pos e)
375 {
376   char buf[16];
377   int i;
378   if (s.x)
379     return -1;
380   if (e.x != (CRT_COLS - 1))
381     return -1;
382   if (s.y)
383     return -1;
384   if (s.y >= a->size.y)
385     return -1;
386
387   ansi_showhide_cursor (a, 1);
388   i = sprintf (buf, "\033[%d;%dr", s.y + 1, e.y + 1);
389   a->terminal->xmit (a->terminal, buf, i);
390   i = sprintf (buf, "\033[%d;%dH", e.y + 1, 0);
391   a->terminal->xmit (a->terminal, buf, i);
392   a->terminal->xmit (a->terminal, "\033D", 2);
393   a->terminal->xmit (a->terminal, "\033[r", 3);
394
395   s.y = e.y;
396   crt_erase (&a->crt, s, e, 1);
397
398   a->pos.x = ANSI_INVAL;
399
400   return 0;
401 }
402
403
404 static void
405 ansi_spot_scroll_up (ANSI * a, CRT * c)
406 {
407   int l, n, p;
408
409   l = c->sh.e.x - c->sh.s.x;
410   l++;
411   l *= sizeof (CRT_CA);
412
413   n = c->sh.e.y - c->sh.s.y;
414   p = CRT_ADDR_POS (&c->sh.s);
415
416   while (n--)
417     {
418       if (memcmp (&c->screen[p], &a->crt.screen[p + CRT_COLS], l))
419         return;
420       p += CRT_COLS;
421     }
422
423   if (ansi_scroll_up (a, c->sh.s, c->sh.e))
424     return;
425
426   n = c->sh.e.y - c->sh.s.y;
427   p = CRT_ADDR_POS (&c->sh.s);
428
429   while (n--)
430     {
431       memcpy (&a->crt.screen[p], &a->crt.screen[p + CRT_COLS], l);
432       p += CRT_COLS;
433     }
434
435   c->sh.dir = 0;                //FIXME: horrid hack
436
437 }
438
439 static void
440 ansi_spot_scroll (ANSI * a, CRT * c)
441 {
442
443   switch (c->sh.dir)
444     {
445     case -1:
446 /*we only care about up for the moment */
447       ansi_spot_scroll_up (a, c);
448       break;
449     }
450
451   return;
452 }
453
454 #endif
455
456
457 static void
458 ansi_draw_line (ANSI * a, CRT_CA * cap, int y)
459 {
460   CRT_Pos p = { 0, y };
461   CRT_CA *acap = &a->crt.screen[CRT_ADDR_POS (&p)];
462
463   for (p.x = 0; p.x < CRT_COLS; ++p.x)
464     {
465       if (p.x >= a->size.x)
466         continue;
467
468       if (crt_ca_cmp (*acap, *cap))
469         {
470           ansi_showhide_cursor (a, 1);
471           *acap = *cap;
472
473           ansi_move (a, p);
474           ansi_render (a, *acap);
475         }
476
477       acap++;
478       cap++;
479     }
480 }
481
482 static void
483 ansi_resize_check (ANSI * a)
484 {
485
486   if (!crt_pos_cmp (a->terminal->size, a->size))
487     return;
488
489   terminal_getsize (a->terminal);
490
491   a->size = a->terminal->size;
492
493   a->pos.x = ANSI_INVAL;
494   a->hide_cursor = ANSI_INVAL;
495
496   crt_reset (&a->crt);
497
498 // FIXME: -- echos back crap?
499 //  a->terminal->xmit (a->terminal, "\033[c", 3);
500
501   ansi_cls (a);
502   a->terminal->xmit (a->terminal, "\033=", 2);
503   a->terminal->xmit (a->terminal, "\033[?6l", 5);
504   a->terminal->xmit (a->terminal, "\033[r", 3);
505
506 }
507
508 #define HISTORY_GUESS_SCROLL 24 /*guess all 24 lines usually scroll */
509 /*if they haven't then ansi_draw will patch it up*/
510
511 static void
512 ansi_history (ANSI * a, History * h)
513 {
514   char buf[32];
515   int i;
516 /*Do we need to catch up on history?*/
517
518   if (a->history_ptr == h->wptr)
519     return;
520   ansi_resize_check (a);
521
522   if ((a->size.x < CRT_COLS) || (a->size.y < CRT_ROWS))
523     return;
524
525   ansi_force_attr_normal (a);
526   ansi_set_color (a, CRT_COLOR_NORMAL);
527
528   i = sprintf (buf, "\033[%d;%dr", 1, HISTORY_GUESS_SCROLL);
529   a->terminal->xmit (a->terminal, buf, i);
530
531
532   while (a->history_ptr != h->wptr)
533     {
534
535       History_ent *e = &h->lines[a->history_ptr];
536
537       HISTORY_INC (h, a->history_ptr);
538
539       if (!e->valid)
540         continue;
541
542       /*If so write the line ot the top of the screen */
543       ansi_draw_line (a, e->line, 0);
544
545
546       /*Roll HISTORY_GUESS_SCROLL lines up putting the top line into the xterm's history */
547
548
549       /*Make extra lines a predictable colour */
550       ansi_set_color (a, CRT_COLOR_NORMAL);
551
552       ansi_showhide_cursor (a, 1);
553       i = sprintf (buf, "\033[%d;%dH", HISTORY_GUESS_SCROLL, 1);
554       a->terminal->xmit (a->terminal, buf, i);
555       a->terminal->xmit (a->terminal, "\033D", 2);
556       a->pos.x = ANSI_INVAL;
557
558       /*now do the same in our image of the screen */
559
560       {
561         CRT_Pos s = { 0 }
562         , e =
563         {
564         0};
565
566         /*scroll lines up */
567         for (s.y++; s.y < HISTORY_GUESS_SCROLL; s.y++, e.y++)
568           {
569             memcpy (&a->crt.screen[CRT_ADDR_POS (&e)],
570                     &a->crt.screen[CRT_ADDR_POS (&s)],
571                     sizeof (CRT_CA) * CRT_COLS);
572           }
573
574         /* erase new line */
575         s.y = e.y;
576         e.x = CRT_COLS - 1;
577         crt_erase (&a->crt, s, e, 1, CRT_COLOR_NORMAL);
578       }
579
580     }
581 /*reset margins*/
582   a->terminal->xmit (a->terminal, "\033[r", 3);
583   a->pos.x = ANSI_INVAL;
584
585 }
586
587
588
589
590 static void
591 ansi_draw (ANSI * a, CRT * c)
592 {
593   CRT_Pos p;
594   int o;
595   int hidden_cursor = 0;
596
597   ansi_resize_check (a);
598
599
600
601   for (p.y = 0; p.y < CRT_ROWS; ++p.y)
602     {
603       if (p.y >= a->size.y)
604         continue;
605
606       ansi_draw_line (a, &c->screen[CRT_ADDR (p.y, 0)], p.y);
607
608     }
609
610
611   if ((CRT_COLS > a->size.x) || (CRT_ROWS > a->size.y))
612     {
613       char msg[1024];           // = "Window is too small";
614       int i;
615       p.x = 0;
616       p.y = 0;
617
618       i =
619         sprintf (msg, "Window too small (%dx%d need %dx%d)", a->size.x,
620                  a->size.y, CRT_COLS, CRT_ROWS);
621
622       ansi_showhide_cursor (a, 1);
623       ansi_set_attr (a, CRT_ATTR_REVERSE);
624       ansi_set_color (a, CRT_MAKE_COLOR (CRT_COLOR_WHITE, CRT_COLOR_RED));
625       ansi_move (a, p);
626
627       a->terminal->xmit (a->terminal, msg, i);
628       a->pos.x = ANSI_INVAL;
629     }
630
631
632   if ((c->pos.x >= a->size.x) || (c->pos.y >= a->size.y))
633     {
634       ansi_showhide_cursor (a, 1);
635       return;
636     }
637
638   a->crt.pos = c->pos;
639   ansi_move (a, a->crt.pos);
640
641   a->crt.hide_cursor = c->hide_cursor;
642   ansi_showhide_cursor (a, a->crt.hide_cursor);
643 }
644
645 static void
646 ansi_reset (ANSI * a, CRT * c)
647 {
648   a->size.x = -1;
649   ansi_draw (a, c ? c : &a->crt);
650 }
651
652 static void
653 ansi_terminal_reset (ANSI * a)
654 {
655   CRT_Pos p = { 0, CRT_ROWS };
656   ansi_force_attr_normal (a);
657
658   ansi_move (a, p);
659 }
660
661 static void
662 ansi_flush_escape (ANSI * a, Context * c)
663 {
664   ANSI_Parser *p = &a->parser;
665   int i;
666
667   for (i = 0; i < p->escape_ptr; ++i)
668     {
669       keydis_key (c->k, c, p->escape_buf[i]);
670     }
671
672   p->escape_ptr = 0;
673   p->in_escape = 0;
674 }
675
676 static void
677 ansi_parse_deckey (ANSI * a, Context * c)
678 {
679   ANSI_Parser *p = &a->parser;
680   if ((p->escape_buf[1] != '[') && (p->escape_buf[1] != 'O'))
681     {
682       ansi_flush_escape (a, c);
683       return;
684     }
685
686   if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z'))
687     {
688       keydis_key (c->k, c, KEY_UP + (p->escape_buf[2] - 'A'));
689     }
690   else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z'))
691     {
692       keydis_key (c->k, c, KEY_154 + (p->escape_buf[2] - 'a'));
693     }
694   else
695     {
696       ansi_flush_escape (a, c);
697       return;
698     }
699   p->in_escape = 0;
700   p->escape_ptr = 0;
701 }
702
703 static void
704 ansi_parse_ansikey (ANSI * a, Context * c)
705 {
706   ANSI_Parser *p = &a->parser;
707
708   if ((p->escape_buf[1] != '[') || (p->escape_buf[3] != '~'))
709     {
710       ansi_flush_escape (a, c);
711       return;
712     }
713   if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9'))
714     {
715       keydis_key (c->k, c, KEY_180 + (p->escape_buf[2] - '0'));
716     }
717   else
718     {
719       ansi_flush_escape (a, c);
720       return;
721     }
722
723   p->in_escape = 0;
724   p->escape_ptr = 0;
725 }
726
727
728
729 static void
730 ansi_parse_escape (ANSI * a, Context * c)
731 {
732   ANSI_Parser *p = &a->parser;
733   switch (p->escape_ptr)
734     {
735     case 0:
736     case 1:
737       return;
738     case 2:
739       switch (p->escape_buf[1])
740         {
741         case '[':
742         case 'O':
743           break;
744         default:
745           ansi_flush_escape (a, c);
746         }
747       break;
748     case 3:
749       switch (p->escape_buf[1])
750         {
751         case 'O':
752           ansi_parse_deckey (a, c);
753           break;
754         case '[':
755           if ((p->escape_buf[2] >= 'A') && (p->escape_buf[2] <= 'Z'))
756             ansi_parse_deckey (a, c);
757           break;
758         default:
759           ansi_flush_escape (a, c);
760         }
761       break;
762     case 4:
763       switch (p->escape_buf[1])
764         {
765         case '[':
766           ansi_parse_ansikey (a, c);
767           break;
768         default:
769           ansi_flush_escape (a, c);
770         }
771       break;
772     case 5:
773       ansi_flush_escape (a, c);
774     }
775 }
776
777
778 static void
779 ansi_check_escape (ANSI * a, Context * c)
780 {
781   ANSI_Parser *p = &a->parser;
782   struct timeval now, diff;
783   gettimeofday (&now, NULL);
784   timersub (&now, &p->last_escape, &diff);
785
786 #if 0
787   fprintf (stderr, "ie %d tl %d.%06d eb %d\n",
788            p->in_escape, diff.tv_sec, diff.tv_usec, p->escape_ptr);
789 #endif
790
791   if (!p->in_escape)
792     return;
793
794
795   /*Time up? */
796   if (diff.tv_sec || (diff.tv_usec > ANSI_ESCAPE_TIMEOUT))
797     ansi_flush_escape (a, c);
798
799 }
800
801
802 static void
803 ansi_parse_char (ANSI * a, Context * c, int ch)
804 {
805   ANSI_Parser *p = &a->parser;
806
807
808 /*See if it's time to flush the escape*/
809   ansi_check_escape (a, c);
810
811   if (ch == 033)
812     {
813       if (p->in_escape)
814         ansi_flush_escape (a, c);
815
816       p->in_escape++;
817       p->escape_ptr = 0;
818       gettimeofday (&p->last_escape, NULL);
819     }
820
821   if (p->in_escape)
822     {
823       p->escape_buf[p->escape_ptr++] = ch;
824       ansi_parse_escape (a, c);
825     }
826   else
827     {
828       keydis_key (c->k, c, ch);
829     }
830
831 }
832
833 static void
834 ansi_parse (ANSI * a, Context * c, char *buf, int len)
835 {
836   while (len--)
837     ansi_parse_char (a, c, *(buf++));
838 }
839
840 int
841 ansi_dispatch (ANSI * a, Context * c)
842 {
843   char buf[1024];
844   int red;
845
846   ansi_check_escape (a, c);
847
848
849   if (!a->terminal)
850     return 0;
851
852   red = a->terminal->recv (a->terminal, buf, sizeof (buf));
853   if (red <= 0)
854     return red;
855
856 #if 0
857   if (*buf == 3)
858     return -1;
859 #endif
860
861 #if 0
862   if (*buf == 2)
863     {
864 #if  0
865       a->history_ptr = c->h->wptr;
866       HISTORY_INC (c->h, a->history_ptr);
867 #endif
868       return -1;
869     }
870 #endif
871
872
873   ansi_parse (a, c, buf, red);
874
875   return 0;
876 }
877
878
879 static void
880 ansi_update (ANSI * a, Context * c)
881 {
882   ansi_history (a, c->h);
883   ansi_draw (a, &c->v->crt);
884 }
885
886 static void
887 ansi_free (ANSI * a)
888 {
889   a->terminal_reset (a);
890   if (a->terminal)
891     a->terminal->close (a->terminal);
892
893   free (a);
894
895 }
896
897 ANSI *
898 ansi_new_from_terminal (TTY * t, int utf8)
899 {
900   ANSI *ret;
901
902   ret = malloc (sizeof (ANSI));
903   memset (ret, 0, sizeof (ANSI));
904
905   ret->terminal = t;
906
907   ret->utf8 = utf8;
908   ret->update = ansi_update;
909   ret->reset = ansi_reset;
910   ret->terminal_reset = ansi_terminal_reset;
911   ret->close = ansi_free;
912   ret->dispatch = ansi_dispatch;
913
914   return ret;
915 }