chiark / gitweb /
*** empty log message ***
[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.5  2008/02/06 17:53:28  james
15  * *** empty log message ***
16  *
17  * Revision 1.4  2008/02/04 20:23:55  james
18  * *** empty log message ***
19  *
20  * Revision 1.3  2008/02/04 05:45:55  james
21  * ::
22  *
23  * Revision 1.2  2008/02/04 02:05:06  james
24  * *** empty log message ***
25  *
26  * Revision 1.1  2008/02/03 16:20:24  james
27  * *** empty log message ***
28  *
29  *
30  */
31
32 #include "project.h"
33
34 struct termios old = { 0 };
35 static int had_winch=0;
36
37 static void quit (int not)
38 {
39   tcsetattr (0, TCSANOW, &old);
40   exit (1);
41 }
42
43 static void winch (int not)
44 {
45   had_winch++;
46 }
47
48
49 void
50 testy (void)
51 {
52   struct termios raw = { 0 };
53   VT102 v = { 0 };
54   ANSI a = { 0 };
55   fd_set rfd;
56   int fd;
57   char c;
58
59
60   signal (SIGINT, quit);
61 {
62 struct sigaction sa={0};
63
64 sa.sa_handler=winch;
65 sa.sa_flags=SA_RESTART;
66 sigaction(SIGWINCH,&sa,NULL);
67 }
68   
69
70   tcgetattr (0, &old);
71   tcgetattr (0, &raw);
72   cfmakeraw (&raw);
73   tcsetattr (0, TCSANOW, &raw);
74
75   a.fd = 1;
76
77   vt102_reset (&v);
78   ansi_reset (&a);
79
80
81   fd = open_fd_to_bash ();
82
83   FD_ZERO (&rfd);
84
85
86   for (;;)
87     {
88         struct timeval tv={0,100000};
89
90       FD_SET (fd, &rfd);
91       FD_SET (0, &rfd);
92       if (select (fd + 1, &rfd, NULL, NULL, &tv)<0) continue; 
93
94       if (FD_ISSET (0, &rfd))
95         {
96           if ((read (0, &c, 1) <= 0) || (c == 3))
97             break;
98
99           write (fd, &c, 1);
100         }
101       if (FD_ISSET (fd, &rfd))
102         {
103           if ((read (fd, &c, 1) <= 0))
104             break;
105           //write (1, &c, 1);
106           vt102_parse_char (&v, c);
107           ansi_draw (&a, &v.crt);
108         }
109         if (had_winch) {
110                 had_winch=0;
111                 ansi_getsize(&a);
112                 ansi_reset(&a);
113                 ansi_draw (&a, &v.crt);
114         }
115     }
116   tcsetattr (0, TCSANOW, &old);
117   printf ("QUAT\n");
118 }