chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / terminal.c
index 1223c0f0b677d610edca450c99e9ec83baac20af..72a7764d3b80163a706ce7d9b65c5c855ce1fa13 100644 (file)
@@ -6,10 +6,35 @@
  *
  */
 
-static char rcsid[] = "$Id$";
+static char rcsid[] =
+  "$Id$";
 
 /*
  * $Log$
+ * Revision 1.11  2008/02/26 23:56:12  james
+ * *** empty log message ***
+ *
+ * Revision 1.10  2008/02/26 23:23:17  james
+ * *** empty log message ***
+ *
+ * Revision 1.9  2008/02/15 03:32:07  james
+ * *** empty log message ***
+ *
+ * Revision 1.8  2008/02/14 10:39:14  james
+ * *** empty log message ***
+ *
+ * Revision 1.7  2008/02/14 01:55:57  james
+ * *** empty log message ***
+ *
+ * Revision 1.6  2008/02/14 00:57:58  james
+ * *** empty log message ***
+ *
+ * Revision 1.5  2008/02/13 18:05:06  james
+ * *** empty log message ***
+ *
+ * Revision 1.4  2008/02/13 16:57:29  james
+ * *** empty log message ***
+ *
  * Revision 1.3  2008/02/13 09:12:21  james
  * *** empty log message ***
  *
@@ -58,6 +83,9 @@ int terminal_winches;
 static void
 terminal_close (TTY * _t)
 {
+  char buf[32];
+  int i;
+
   TERMINAL *t = (TERMINAL *) _t;
   TERMINAL **ptr = &terminal_list;
 
@@ -73,6 +101,19 @@ terminal_close (TTY * _t)
 
   tcsetattr (t->wfd, TCSANOW, &t->orig_termios);
 
+  set_nonblocking (t->wfd);
+
+
+  t->xmit (_t, "\033%@", 3);    //Leave UTF-8
+  t->xmit (_t, "\033(B", 3);    //US-ASCII in G0
+  t->xmit (_t, "\033)B", 3);    //US-ASCII in G1
+  t->xmit (_t, "\017", 1);      //Select G0
+  t->xmit (_t, "\033[r", 3);    //No margins
+  t->xmit (_t, "\033[0m", 4);   //Default attributes
+  i = sprintf (buf, "\033[%d;%dH", CRT_ROWS + 1, 1); //Cursor to bottom
+  t->xmit (_t, buf, i);
+  t->xmit (_t, "\033[J", 3);    //erase rest of screen
+
   set_blocking (t->rfd);
   set_blocking (t->wfd);
 
@@ -135,7 +176,7 @@ terminal_dispatch (void)
   terminal_winches = 0;
 
   for (t = terminal_list; t; t = t->next)
-    terminal_getsize (t);
+    terminal_getsize ((TTY *) t);
 
 }
 
@@ -147,6 +188,7 @@ terminal_read (TTY * _t, void *buf, int len)
   int red, done = 0;
 
   terminal_dispatch ();
+  set_nonblocking (t->rfd);
 
   do
     {
@@ -176,14 +218,17 @@ terminal_write (TTY * _t, void *buf, int len)
 
   terminal_dispatch ();
 
+  set_blocking (t->wfd);
+
   do
     {
 
       writ = wrap_write (t->wfd, buf, len);
       if (writ < 0)
         return -1;
+
       if (!writ)
-        sleep (1);
+        usleep (1000);
 
       buf += writ;
       len -= writ;
@@ -210,16 +255,17 @@ terminal_register_handlers (void)
   sigaction (SIGINT, &sa, NULL);
 }
 
+
 TTY *
 terminal_open (int rfd, int wfd)
 {
   TERMINAL *t;
   pid_t child;
-  char name[1024];
   struct termios termios;
 
   t = (TERMINAL *) malloc (sizeof (TERMINAL));
 
+  strcpy (t->name, "terminal");
   t->rfd = rfd;
   t->wfd = wfd;
 
@@ -234,13 +280,15 @@ terminal_open (int rfd, int wfd)
   set_nonblocking (wfd);
 
 
-  raw_termios (&termios);
+  cfmakeraw (&termios);
+  //raw_termios (&termios);
 
   tcsetattr (wfd, TCSANOW, &termios);
 
   t->recv = terminal_read;
   t->xmit = terminal_write;
   t->close = terminal_close;
+  t->blocked = 0;
 
 
   terminal_getsize ((TTY *) t);