chiark / gitweb /
::
authorjames <james>
Mon, 4 Feb 2008 05:45:55 +0000 (05:45 +0000)
committerjames <james>
Mon, 4 Feb 2008 05:45:55 +0000 (05:45 +0000)
src/ansi.c
src/libsympathy.c
src/project.h
src/vt102.c

index 49a7bc9b331e8d9db9229ea9e295c0ef77df7f36..e7cd93445b21611854f35d8c74443a434c251a7e 100644 (file)
@@ -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;
index d43bbc558c55d88a2aef42591774a08697ac3858..013afc7f7361a7576321ff37e18ba8bb28892c97 100644 (file)
@@ -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);
+        }
+    }
+}
index 9ce651fdf33eb0c35b277d13432e311194e323e5..f8be4ca1bcf14a51a792f60f52c2b8dcc7330aa8 100644 (file)
@@ -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 ***
  *
 
 #include <termio.h>
 #include <termios.h>
+#include <signal.h>
+
+#include <utmp.h>
+#include <pty.h>
 
 #include "crt.h"
 #include "ansi.h"
index 8a7dc56ebae2ca4abeda216007afb5af0e58ca58..d29e708754e91b1068bf5cd36370548a77c06eb8 100644 (file)
@@ -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;
 }