X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=sympathy.git;a=blobdiff_plain;f=src%2Fterminal.c;h=22415f4a6257a3990e78960c979d7fd1f691ad95;hp=d0cde9916e2c2cc4a13cf83ce5ac8452533b6292;hb=d3a389bb8820859175314ef2f329d863d31d2b3f;hpb=475b8d78f7920a0b9d1e35aaefc89fa162ba226a diff --git a/src/terminal.c b/src/terminal.c index d0cde99..22415f4 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -1,4 +1,4 @@ -/* +/* * terminal.c: * * Copyright (c) 2008 James McKenzie , @@ -6,10 +6,53 @@ * */ -static char rcsid[] = "$Id$"; +static char rcsid[] = + "$Id: terminal.c,v 1.24 2008/03/12 10:47:26 james Exp $"; -/* - * $Log$ +/* + * $Log: terminal.c,v $ + * Revision 1.24 2008/03/12 10:47:26 james + * @@ + * + * Revision 1.23 2008/03/12 01:30:23 james + * *** empty log message *** + * + * Revision 1.22 2008/03/11 17:56:50 james + * *** empty log message *** + * + * Revision 1.21 2008/03/11 17:56:04 james + * *** empty log message *** + * + * Revision 1.20 2008/03/10 11:49:33 james + * *** empty log message *** + * + * Revision 1.19 2008/03/07 14:16:44 james + * *** empty log message *** + * + * Revision 1.18 2008/03/07 14:13:40 james + * *** empty log message *** + * + * Revision 1.17 2008/03/07 13:16:02 james + * *** empty log message *** + * + * Revision 1.16 2008/03/07 12:42:08 james + * *** empty log message *** + * + * Revision 1.15 2008/03/07 12:37:04 james + * *** empty log message *** + * + * Revision 1.14 2008/03/03 06:04:42 james + * *** empty log message *** + * + * Revision 1.13 2008/03/02 10:37:56 james + * *** empty log message *** + * + * Revision 1.12 2008/02/28 16:57:52 james + * *** empty log message *** + * + * 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 *** * @@ -63,8 +106,7 @@ static char rcsid[] = "$Id$"; #include "project.h" -typedef struct TERMINAL_struct -{ +typedef struct TERMINAL_struct { TTY_SIGNATURE; struct termios orig_termios; struct TERMINAL_struct *next; @@ -100,15 +142,17 @@ terminal_close (TTY * _t) 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, "\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[?25h", 6); // Show cursor + t->xmit (_t, "\033[r", 3); // No margins + t->xmit (_t, "\033[0m", 4); // Default attributes + i = sprintf (buf, "\033[%d;%dH", t->displayed_length ? (t->displayed_length + 1) : (CRT_ROWS + 1), 1); + // Cursor to bottom t->xmit (_t, buf, i); - t->xmit (_t, "\033[J", 3); //erase rest of screen + t->xmit (_t, "\033[J", 3); // erase rest of screen set_blocking (t->rfd); set_blocking (t->wfd); @@ -147,16 +191,13 @@ terminal_getsize (TTY * _t) if (!t) return; - if (ioctl (t->wfd, TIOCGWINSZ, &sz)) - { - t->size.x = CRT_COLS; - t->size.y = CRT_ROWS; - } - else - { - t->size.x = sz.ws_col; - t->size.y = sz.ws_row; - } + if (ioctl (t->wfd, TIOCGWINSZ, &sz)) { + t->size.x = CRT_COLS; + t->size.y = CRT_ROWS; + } else { + t->size.x = sz.ws_col; + t->size.y = sz.ws_row; + } } @@ -186,19 +227,18 @@ terminal_read (TTY * _t, void *buf, int len) terminal_dispatch (); set_nonblocking (t->rfd); - do - { + do { - red = wrap_read (t->rfd, buf, len); - if (red < 0) - return -1; - if (!red) - return done; + red = wrap_read (t->rfd, buf, len); + if (red < 0) + return -1; + if (!red) + return done; - buf += red; - len -= red; - done += red; - } + buf += red; + len -= red; + done += red; + } while (len); @@ -216,20 +256,19 @@ terminal_write (TTY * _t, void *buf, int len) set_blocking (t->wfd); - do - { + do { - writ = wrap_write (t->wfd, buf, len); - if (writ < 0) - return -1; + writ = wrap_write (t->wfd, buf, len); + if (writ < 0) + return -1; - if (!writ) - usleep (1000); + if (!writ) + usleep (1000); - buf += writ; - len -= writ; - done += writ; - } + buf += writ; + len -= writ; + done += writ; + } while (len); @@ -259,7 +298,7 @@ terminal_open (int rfd, int wfd) pid_t child; struct termios termios; - t = (TERMINAL *) malloc (sizeof (TERMINAL)); + t = (TERMINAL *) xmalloc (sizeof (TERMINAL)); strcpy (t->name, "terminal"); t->rfd = rfd; @@ -277,7 +316,7 @@ terminal_open (int rfd, int wfd) cfmakeraw (&termios); - //raw_termios (&termios); + // raw_termios (&termios); tcsetattr (wfd, TCSANOW, &termios);