Force redisplay of all lines in DECSCNM
[st.git] / st.c
diff --git a/st.c b/st.c
index 8e1afe2..193db5e 100644 (file)
--- a/st.c
+++ b/st.c
@@ -36,7 +36,7 @@
 
 #define USAGE \
        "st " VERSION " (c) 2010-2012 st engineers\n" \
-       "usage: st [-t title] [-c class] [-w windowid] [-v] [-e command...]\n"
+       "usage: st [-t title] [-c class] [-w windowid] [-v] [-f file] [-e command...]\n"
 
 /* XEMBED messages */
 #define XEMBED_FOCUS_IN  4
@@ -54,6 +54,7 @@
 
 #define SELECT_TIMEOUT (20*1000) /* 20 ms */
 #define DRAW_TIMEOUT  (20*1000) /* 20 ms */
+#define REDRAW_TIMEOUT (80*1000) /* 80 ms */
 
 #define SERRNO strerror(errno)
 #define MIN(a, b)  ((a) < (b) ? (a) : (b))
@@ -238,6 +239,7 @@ typedef struct {
 
 static void die(const char*, ...);
 static void draw(void);
+static void redraw(void);
 static void drawregion(int, int, int, int);
 static void execsh(void);
 static void sigchld(int);
@@ -342,7 +344,9 @@ static STREscape strescseq;
 static int cmdfd;
 static pid_t pid;
 static Selection sel;
+static FILE *fileio;
 static char **opt_cmd  = NULL;
+static char *opt_io    = NULL;
 static char *opt_title = NULL;
 static char *opt_embed = NULL;
 static char *opt_class = NULL;
@@ -776,6 +780,10 @@ ttynew(void) {
                close(s);
                cmdfd = m;
                signal(SIGCHLD, sigchld);
+               if (opt_io && !(fileio = fopen(opt_io, "w"))) {
+                       fprintf(stderr, "Error opening %s:%s",
+                               opt_io, strerror(errno));
+               }
        }
 }
 
@@ -1104,6 +1112,9 @@ tsetattr(int *attr, int l) {
                case 1:
                        term.c.attr.mode |= ATTR_BOLD;
                        break;
+               case 3: /* enter standout (highlight) mode TODO: make it italic */
+                       term.c.attr.mode |= ATTR_REVERSE;
+                       break;
                case 4:
                        term.c.attr.mode |= ATTR_UNDERLINE;
                        break;
@@ -1113,6 +1124,9 @@ tsetattr(int *attr, int l) {
                case 22:
                        term.c.attr.mode &= ~ATTR_BOLD;
                        break;
+               case 23: /* leave standout (highlight) mode TODO: make it italic */
+                       term.c.attr.mode &= ~ATTR_REVERSE;
+                       break;
                case 24:
                        term.c.attr.mode &= ~ATTR_UNDERLINE;
                        break;
@@ -1194,7 +1208,7 @@ tsetmode(bool priv, bool set, int *args, int narg) {
                                mode = term.mode;
                                MODBIT(term.mode,set, MODE_REVERSE);
                                if (mode != term.mode)
-                                       draw();
+                                       redraw();
                                break;
                        case 7:
                                MODBIT(term.mode, set, MODE_WRAP);
@@ -1441,7 +1455,7 @@ strhandle(void) {
         */
        strparse();
 
-       p = strescseq.buf; 
+       p = strescseq.buf;
 
        switch(strescseq.type) {
        case ']': /* OSC -- Operating System Command */
@@ -1528,6 +1542,9 @@ tputtab(bool forward) {
 void
 tputc(char *c) {
        char ascii = *c;
+
+       if (fileio)
+               putc(ascii, fileio);
        if(term.esc & ESC_START) {
                if(term.esc & ESC_CSI) {
                        csiescseq.buf[csiescseq.len++] = ascii;
@@ -2014,6 +2031,14 @@ xdrawcursor(void) {
        xcopy(term.c.x, term.c.y, 1, 1);
 }
 
+void
+redraw(void) {
+       struct timespec tv = {0, REDRAW_TIMEOUT * 1000};
+       tfulldirt();
+       draw();
+       nanosleep(&tv, NULL);
+}
+
 void
 draw() {
        drawregion(0, 0, term.col, term.row);
@@ -2263,6 +2288,9 @@ main(int argc, char *argv[]) {
                case 'w':
                        if(++i < argc) opt_embed = argv[i];
                        break;
+               case 'f':
+                       if (++i < argc) opt_io = argv[i];
+                       break;
                case 'e':
                        /* eat every remaining arguments */
                        if(++i < argc) opt_cmd = &argv[i];