support REP (repeat) escape sequence
[st.git] / st.c
diff --git a/st.c b/st.c
index 1414f98..54af098 100644 (file)
--- a/st.c
+++ b/st.c
@@ -129,6 +129,7 @@ typedef struct {
        int charset;  /* current charset */
        int icharset; /* selected charset for sequence */
        int *tabs;
+       Rune lastc;   /* last printed char outside of sequence, 0 if control */
 } Term;
 
 /* CSI Escape sequence structs */
@@ -634,7 +635,8 @@ getsel(void)
                 * st.
                 * FIXME: Fix the computer world.
                 */
-               if ((y < sel.ne.y || lastx >= linelen) && !(last->mode & ATTR_WRAP))
+               if ((y < sel.ne.y || lastx >= linelen) &&
+                   (!(last->mode & ATTR_WRAP) || sel.type == SEL_RECTANGULAR))
                        *ptr++ = '\n';
        }
        *ptr = 0;
@@ -1105,27 +1107,17 @@ selscroll(int orig, int n)
        if (sel.ob.x == -1)
                return;
 
-       if (BETWEEN(sel.ob.y, orig, term.bot) || BETWEEN(sel.oe.y, orig, term.bot)) {
-               if ((sel.ob.y += n) > term.bot || (sel.oe.y += n) < term.top) {
+       if (BETWEEN(sel.nb.y, orig, term.bot) != BETWEEN(sel.ne.y, orig, term.bot)) {
+               selclear();
+       } else if (BETWEEN(sel.nb.y, orig, term.bot)) {
+               sel.ob.y += n;
+               sel.oe.y += n;
+               if (sel.ob.y < term.top || sel.ob.y > term.bot ||
+                   sel.oe.y < term.top || sel.oe.y > term.bot) {
                        selclear();
-                       return;
-               }
-               if (sel.type == SEL_RECTANGULAR) {
-                       if (sel.ob.y < term.top)
-                               sel.ob.y = term.top;
-                       if (sel.oe.y > term.bot)
-                               sel.oe.y = term.bot;
                } else {
-                       if (sel.ob.y < term.top) {
-                               sel.ob.y = term.top;
-                               sel.ob.x = 0;
-                       }
-                       if (sel.oe.y > term.bot) {
-                               sel.oe.y = term.bot;
-                               sel.oe.x = term.col;
-                       }
+                       selnormalize();
                }
-               selnormalize();
        }
 }
 
@@ -1657,6 +1649,12 @@ csihandle(void)
                if (csiescseq.arg[0] == 0)
                        ttywrite(vtiden, strlen(vtiden), 0);
                break;
+       case 'b': /* REP -- if last char is printable print it <n> more times */
+               DEFAULT(csiescseq.arg[0], 1);
+               if (term.lastc)
+                       while (csiescseq.arg[0]-- > 0)
+                               tputc(term.lastc);
+               break;
        case 'C': /* CUF -- Cursor <n> Forward */
        case 'a': /* HPR -- Cursor <n> Forward */
                DEFAULT(csiescseq.arg[0], 1);
@@ -2153,6 +2151,7 @@ tcontrolcode(uchar ascii)
                return;
        case '\032': /* SUB */
                tsetchar('?', &term.c.attr, term.c.x, term.c.y);
+               /* FALLTHROUGH */
        case '\030': /* CAN */
                csireset();
                break;
@@ -2381,6 +2380,8 @@ check_control_code:
                /*
                 * control codes are not shown ever
                 */
+               if (!term.esc)
+                       term.lastc = 0;
                return;
        } else if (term.esc & ESC_START) {
                if (term.esc & ESC_CSI) {
@@ -2411,7 +2412,7 @@ check_control_code:
                 */
                return;
        }
-       if (sel.ob.x != -1 && BETWEEN(term.c.y, sel.ob.y, sel.oe.y))
+       if (selected(term.c.x, term.c.y))
                selclear();
 
        gp = &term.line[term.c.y][term.c.x];
@@ -2430,6 +2431,7 @@ check_control_code:
        }
 
        tsetchar(u, &term.c.attr, term.c.x, term.c.y);
+       term.lastc = u;
 
        if (width == 2) {
                gp->mode |= ATTR_WIDE;