JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
merged tscroll() with tscrollup().
[st.git] / st.c
diff --git a/st.c b/st.c
index 623ca29..eabc0c5 100644 (file)
--- a/st.c
+++ b/st.c
 #include <X11/keysym.h>
 #include <X11/Xutil.h>
 
+#if   defined(LINUX)
+ #include <pty.h>
+#elif defined(OPENBSD)
+ #include <util.h>
+#elif defined(FREEBSD)
+ #include <libutil.h>
+#endif
+
 /* Arbitrary sizes */
 #define ESC_TITLE_SIZ 256
 #define ESC_BUF_SIZ   256
@@ -141,7 +149,6 @@ static void tputc(char);
 static void tputs(char*, int);
 static void treset(void);
 static void tresize(int, int);
-static void tscroll(void);
 static void tscrollup(int);
 static void tscrolldown(int);
 static void tsetattr(int*, int);
@@ -242,19 +249,12 @@ sigchld(int a) {
 void
 ttynew(void) {
        int m, s;
-       char *pts;
-
-       if((m = posix_openpt(O_RDWR | O_NOCTTY)) < 0)
-               die("openpt failed: %s\n", SERRNO);
-       if(grantpt(m) < 0)
-               die("grantpt failed: %s\n", SERRNO);
-       if(unlockpt(m) < 0)
-               die("unlockpt failed: %s\n", SERRNO);
-       if(!(pts = ptsname(m)))
-               die("ptsname failed: %s\n", SERRNO);
-       if((s = open(pts, O_RDWR | O_NOCTTY)) < 0)
-               die("Couldn't open slave: %s\n", SERRNO);
-       fcntl(s, F_SETFL, O_NDELAY);
+       
+       /* seems to work fine on linux, openbsd and freebsd */
+       struct winsize w = {term.row, term.col, 0, 0};
+       if(openpty(&m, &s, NULL, NULL, &w) < 0)
+               die("openpty failed: %s\n", SERRNO);
+
        switch(pid = fork()) {
        case -1:
                die("fork failed\n");
@@ -354,18 +354,6 @@ tnew(int col, int row) {
                term.line[row] = calloc(term.col, sizeof(Glyph));
 }
 
-/* TODO: Replace with scrollup/scolldown */
-void
-tscroll(void) {
-       Line temp = term.line[term.top];
-       int i;
-
-       for(i = term.top; i < term.bot; i++)
-               term.line[i] = term.line[i+1];
-       memset(temp, 0, sizeof(Glyph) * term.col);
-       term.line[term.bot] = temp;
-}
-
 void
 tscrolldown (int n) {
        int i;
@@ -403,7 +391,7 @@ void
 tnewline(void) {
        int y = term.c.y + 1;
        if(y > term.bot)
-               tscroll(), y = term.bot;
+               tscrollup(1), y = term.bot;
        tmoveto(0, y);
 }