chiark / gitweb /
::
[sympathy.git] / src / libsympathy.c
1 /*
2  * libsympathy.c:
3  *
4  * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
5  * All rights reserved.
6  *
7  */
8
9 static char rcsid[] =
10   "$Id$";
11
12 /*
13  * $Log$
14  * Revision 1.3  2008/02/04 05:45:55  james
15  * ::
16  *
17  * Revision 1.2  2008/02/04 02:05:06  james
18  * *** empty log message ***
19  *
20  * Revision 1.1  2008/02/03 16:20:24  james
21  * *** empty log message ***
22  *
23  *
24  */
25
26 #include "project.h"
27
28 struct termios old={0};
29
30 static void foo(int not)
31 {
32   tcsetattr(0,TCSANOW,&old);
33   exit(1);
34 }
35
36
37 void
38 testy (void)
39 {
40   struct termios raw={0};
41   VT102 v = { 0 };
42   ANSI a = { 0 };
43   fd_set rfd;
44   int fd;
45   char c;
46  
47
48   signal(SIGINT,foo);
49
50   tcgetattr(0,&old);
51   tcgetattr(0,&raw);
52   cfmakeraw(&raw);
53   tcsetattr(0,TCSANOW,&raw);
54
55   a.fd = 1;
56
57 //vt102_reset(&v);
58   ansi_reset (&a);
59
60
61   fd = open_fd_to_bash ();
62
63   FD_ZERO (&rfd);
64
65
66   for (;;)
67     {
68       FD_SET (fd, &rfd);
69       FD_SET (0, &rfd);
70       if (select (fd + 1, &rfd, NULL, NULL, NULL) <= 0)
71         continue;
72       if (FD_ISSET (0, &rfd))
73         {
74           read (0, &c, 1);
75           if (c==3) {
76   tcsetattr(0,TCSANOW,&old);
77           exit(1);
78         }
79                         
80           write (fd, &c, 1);
81         }
82       if (FD_ISSET (fd, &rfd))
83         {
84           read (fd, &c, 1);
85           //write (1, &c, 1);
86           vt102_parse_char (&v, c);
87           ansi_draw (&a, &v.crt);
88         }
89     }
90 }