From 9a3dd4b46f33152193a66494495b5ba64f294840 Mon Sep 17 00:00:00 2001 From: james Date: Mon, 4 Feb 2008 05:45:55 +0000 Subject: [PATCH 1/1] :: --- src/ansi.c | 28 ++++++++++++++++---- src/libsympathy.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ src/project.h | 7 +++++ src/vt102.c | 22 +++++++++++++++- 4 files changed, 118 insertions(+), 6 deletions(-) diff --git a/src/ansi.c b/src/ansi.c index 49a7bc9..e7cd934 100644 --- a/src/ansi.c +++ b/src/ansi.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.3 2008/02/04 05:45:55 james + * :: + * * Revision 1.2 2008/02/04 02:05:06 james * *** empty log message *** * @@ -25,6 +28,19 @@ ansi_write (ANSI * a, char *buf, int n) write (a->fd, buf, n); } +void +ansi_getsize(ANSI *a) +{ +struct winsize sz={0}; +if (ioctl(a->fd,TIOCGWINSZ,&sz)) { + a->size.x=CRT_COLS; + a->size.y=CRT_ROWS; +} else { + a->size.x=sz.ws_col; + a->size.y=sz.ws_row; +} + +} void @@ -102,13 +118,13 @@ ansi_move (ANSI * a, CRT_Pos p) } else { - n = snprintf (buf, sizeof (buf), "\033[%d;%dHF", p.y + 1, p.x + 1); + n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1); ansi_write (a, buf, n); } } else { - n = snprintf (buf, sizeof (buf), "\033[%d;%dHF", p.y + 1, p.x + 1); + n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1); ansi_write (a, buf, n); } @@ -124,11 +140,11 @@ ansi_showhide_cursor (ANSI * a, int hide) if (hide) { - ansi_write (a, "\033[?25h", 6); + ansi_write (a, "\033[?25l", 6); } else { - ansi_write (a, "\033[?25l", 6); + ansi_write (a, "\033[?25h", 6); } a->hide_cursor = hide; @@ -269,7 +285,9 @@ ansi_draw (ANSI * a, CRT * c) void ansi_reset (ANSI * a) { - ansi_write (a, "\033[c", 3); +// FIXME: -- echos back crap? +// ansi_write (a, "\033[c", 3); + ansi_getsize(a); a->pos.x = ANSI_INVAL; a->hide_cursor = ANSI_INVAL; diff --git a/src/libsympathy.c b/src/libsympathy.c index d43bbc5..013afc7 100644 --- a/src/libsympathy.c +++ b/src/libsympathy.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $Log$ + * Revision 1.3 2008/02/04 05:45:55 james + * :: + * * Revision 1.2 2008/02/04 02:05:06 james * *** empty log message *** * @@ -21,3 +24,67 @@ static char rcsid[] = */ #include "project.h" + +struct termios old={0}; + +static void foo(int not) +{ + tcsetattr(0,TCSANOW,&old); + exit(1); +} + + +void +testy (void) +{ + struct termios raw={0}; + VT102 v = { 0 }; + ANSI a = { 0 }; + fd_set rfd; + int fd; + char c; + + + signal(SIGINT,foo); + + tcgetattr(0,&old); + tcgetattr(0,&raw); + cfmakeraw(&raw); + tcsetattr(0,TCSANOW,&raw); + + a.fd = 1; + +//vt102_reset(&v); + ansi_reset (&a); + + + fd = open_fd_to_bash (); + + FD_ZERO (&rfd); + + + for (;;) + { + FD_SET (fd, &rfd); + FD_SET (0, &rfd); + if (select (fd + 1, &rfd, NULL, NULL, NULL) <= 0) + continue; + if (FD_ISSET (0, &rfd)) + { + read (0, &c, 1); + if (c==3) { + tcsetattr(0,TCSANOW,&old); + exit(1); + } + + write (fd, &c, 1); + } + if (FD_ISSET (fd, &rfd)) + { + read (fd, &c, 1); + //write (1, &c, 1); + vt102_parse_char (&v, c); + ansi_draw (&a, &v.crt); + } + } +} diff --git a/src/project.h b/src/project.h index 9ce651f..f8be4ca 100644 --- a/src/project.h +++ b/src/project.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.3 2008/02/04 05:45:55 james + * :: + * * Revision 1.2 2008/02/04 02:05:06 james * *** empty log message *** * @@ -65,6 +68,10 @@ #include #include +#include + +#include +#include #include "crt.h" #include "ansi.h" diff --git a/src/vt102.c b/src/vt102.c index 8a7dc56..d29e708 100644 --- a/src/vt102.c +++ b/src/vt102.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.4 2008/02/04 05:45:55 james + * :: + * * Revision 1.3 2008/02/04 02:05:06 james * *** empty log message *** * @@ -133,6 +136,11 @@ csi_starter (int c) return 0; } +void vt102_scroll(VT102 *v,int start,int end) +{ + +} + void vt102_cursor_normalize (VT102 * v, int wrap, int scroll) { @@ -196,13 +204,23 @@ vt102_cursor_motion (VT102 * v, int x, int y, int wrap, int scroll) } } +void vt102_parse_esc(VT102 *v,int c) +{ +fprintf(stderr, "ESC %d(%c)\n",c,c); +} + +void vt102_parse_csi(VT102 *v,char *buf,int len) +{ +buf[len]=0; +fprintf(stderr, "CSI %s\n",buf); +} void vt102_parse_char (VT102 * v, int c) { VT102_parser *p = &v->parser; - + fprintf(stderr,"%c pc %d %d %d %d %d\n",c,c,p->in_csi,p->in_escape,v->pos.x,v->pos.y); if (p->in_csi) { p->csi_buf[p->csi_ptr++] = c; @@ -284,4 +302,6 @@ vt102_parse_char (VT102 * v, int c) vt102_cursor_motion (v, 1, 0, 1, 1); } } + + v->crt.pos=v->pos; } -- 2.30.2