JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Add MC for the full screen
[st.git] / st.c
diff --git a/st.c b/st.c
index 314bf3f..1711842 100644 (file)
--- a/st.c
+++ b/st.c
@@ -356,6 +356,9 @@ static void strparse(void);
 static void strreset(void);
 
 static int tattrset(int);
+static void tprinter(char *s, size_t len);
+static void tdumpline(int);
+static void tdump(void);
 static void tclearregion(int, int, int, int);
 static void tcursor(int);
 static void tdeletechar(int);
@@ -470,7 +473,7 @@ static STREscape strescseq;
 static int cmdfd;
 static pid_t pid;
 static Selection sel;
-static int iofd;
+static int iofd = STDOUT_FILENO;
 static char **opt_cmd = NULL;
 static char *opt_io = NULL;
 static char *opt_title = NULL;
@@ -1984,7 +1987,11 @@ csihandle(void) {
        case 'i': /* MC -- Media Copy */
                switch(csiescseq.arg[0]) {
                case 0:
+                       tdump();
+                       break;
                case 1:
+                       tdumpline(term.c.y);
+                       break;
                case 4:
                        term.mode &= ~MODE_PRINT;
                        break;
@@ -2266,6 +2273,39 @@ strreset(void) {
 }
 
 void
+tprinter(char *s, size_t len) {
+       if(iofd != -1 && xwrite(iofd, s, len) < 0) {
+               fprintf(stderr, "Error writing in %s:%s\n",
+                       opt_io, strerror(errno));
+               close(iofd);
+               iofd = -1;
+       }
+}
+
+void
+tdumpline(int n) {
+       Glyph *bp, *end;
+
+       bp = &term.line[n][0];
+       end = &bp[term.col-1];
+       while(end > bp && !strcmp(" ", end->c))
+               --end;
+       if(bp != end || strcmp(bp->c, " ")) {
+               for( ;bp <= end; ++bp)
+                       tprinter(bp->c, strlen(bp->c));
+       }
+       tprinter("\n", 1);
+}
+
+void
+tdump(void) {
+       int i;
+
+       for(i = 0; i < term.row; ++i)
+               tdumpline(i);
+}
+
+void
 tputtab(bool forward) {
        uint x = term.c.x;
 
@@ -2346,14 +2386,8 @@ tputc(char *c, int len) {
                width = wcwidth(u8char);
        }
 
-       if(IS_SET(MODE_PRINT) && iofd != -1) {
-               if(xwrite(iofd, c, len) < 0) {
-                       fprintf(stderr, "Error writing in %s:%s\n",
-                               opt_io, strerror(errno));
-                       close(iofd);
-                       iofd = -1;
-               }
-       }
+       if(IS_SET(MODE_PRINT))
+               tprinter(c, len);
 
        /*
         * STR sequences must be checked before anything else