Fix extra bracketed paste markers when pasting >8kb
[st.git] / st.c
diff --git a/st.c b/st.c
index d49804b..9de30ec 100644 (file)
--- a/st.c
+++ b/st.c
@@ -17,6 +17,7 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <termios.h>
 #include <time.h>
 #include <unistd.h>
 #include <libgen.h>
@@ -333,6 +334,7 @@ static void xzoomreset(const Arg *);
 static void printsel(const Arg *);
 static void printscreen(const Arg *) ;
 static void toggleprinter(const Arg *);
+static void sendbreak(const Arg *);
 
 /* Config.h for applying patches and the configuration. */
 #include "config.h"
@@ -1002,7 +1004,10 @@ getsel(void)
 
        /* append every set & selected glyph to the selection */
        for (y = sel.nb.y; y <= sel.ne.y; y++) {
-               linelen = tlinelen(y);
+               if ((linelen = tlinelen(y)) == 0) {
+                       *ptr++ = '\n';
+                       continue;
+               }
 
                if (sel.type == SEL_RECTANGULAR) {
                        gp = &term.line[y][sel.nb.x];
@@ -1130,10 +1135,10 @@ selnotify(XEvent *e)
                        *repl++ = '\r';
                }
 
-               if (IS_SET(MODE_BRCKTPASTE))
+               if (IS_SET(MODE_BRCKTPASTE) && ofs == 0)
                        ttywrite("\033[200~", 6);
                ttysend((char *)data, nitems * format / 8);
-               if (IS_SET(MODE_BRCKTPASTE))
+               if (IS_SET(MODE_BRCKTPASTE) && rem == 0)
                        ttywrite("\033[201~", 6);
                XFree(data);
                /* number of 32-bit chunks returned */
@@ -1425,8 +1430,7 @@ ttynew(void)
        if (opt_line) {
                if ((cmdfd = open(opt_line, O_RDWR)) < 0)
                        die("open line failed: %s\n", strerror(errno));
-               close(0);
-               dup(cmdfd);
+               dup2(cmdfd, 0);
                stty();
                return;
        }
@@ -2578,6 +2582,13 @@ strreset(void)
        memset(&strescseq, 0, sizeof(strescseq));
 }
 
+void
+sendbreak(const Arg *arg)
+{
+       if (tcsendbreak(cmdfd, 0))
+               perror("Error sending break");
+}
+
 void
 tprinter(char *s, size_t len)
 {
@@ -4294,7 +4305,7 @@ usage(void)
        "          [-i] [-t title] [-T title] [-w windowid] [-e command ...]"
        " [command ...]\n"
        "       st [-a] [-v] [-c class] [-f font] [-g geometry] [-o file]\n"
-       "          [-i] [-t title] [-T title] [-w windowid] [-l line]"
+       "          [-i] [-t title] [-T title] [-w windowid] -l line"
        " [stty_args ...]\n",
        argv0);
 }
@@ -4306,7 +4317,7 @@ main(int argc, char *argv[])
 
        xw.l = xw.t = 0;
        xw.isfixed = False;
-       xw.cursor = 0;
+       xw.cursor = cursorshape;
 
        ARGBEGIN {
        case 'a':