]> git.armaanb.net Git - st.git/blobdiff - st.c
Add sequence for printing the current selection
[st.git] / st.c
diff --git a/st.c b/st.c
index e60643c85cad9aeed391d4a528a7c6c382327ea2..c97712c3e8e115c126d840954edeec1ce0c06661 100644 (file)
--- a/st.c
+++ b/st.c
@@ -314,6 +314,9 @@ static void clippaste(const Arg *);
 static void numlock(const Arg *);
 static void selpaste(const Arg *);
 static void xzoom(const Arg *);
+static void printsel(const Arg *);
+static void printscreen(const Arg *) ;
+static void toggleprinter(const Arg *);
 
 /* Config.h for applying patches and the configuration. */
 #include "config.h"
@@ -357,7 +360,9 @@ static void strreset(void);
 
 static int tattrset(int);
 static void tprinter(char *s, size_t len);
+static void tdumpsel(void);
 static void tdumpline(int);
+static void tdump(void);
 static void tclearregion(int, int, int, int);
 static void tcursor(int);
 static void tdeletechar(int);
@@ -432,6 +437,7 @@ static void selrequest(XEvent *);
 static void selinit(void);
 static void selsort(void);
 static inline bool selected(int, int);
+static char *getsel(void);
 static void selcopy(void);
 static void selscroll(int, int);
 static void selsnap(int, int *, int *, int);
@@ -952,8 +958,8 @@ bpress(XEvent *e) {
        }
 }
 
-void
-selcopy(void) {
+char *
+getsel(void) {
        char *str, *ptr;
        int x, y, bufsize, size, i, ex;
        Glyph *gp, *last;
@@ -1012,7 +1018,12 @@ selcopy(void) {
                }
                *ptr = 0;
        }
-       xsetsel(str);
+       return str;
+}
+
+void
+selcopy(void) {
+       xsetsel(getsel());
 }
 
 void
@@ -1986,9 +1997,14 @@ csihandle(void) {
        case 'i': /* MC -- Media Copy */
                switch(csiescseq.arg[0]) {
                case 0:
+                       tdump();
+                       break;
                case 1:
                        tdumpline(term.c.y);
                        break;
+               case 2:
+                       tdumpsel();
+                       break;
                case 4:
                        term.mode &= ~MODE_PRINT;
                        break;
@@ -2279,6 +2295,31 @@ tprinter(char *s, size_t len) {
        }
 }
 
+void
+toggleprinter(const Arg *arg) {
+       term.mode ^= MODE_PRINT;
+}
+
+void
+printscreen(const Arg *arg) {
+       tdump();
+}
+
+void
+printsel(const Arg *arg) {
+       tdumpsel();
+}
+
+void
+tdumpsel(void)
+{
+       char *ptr;
+
+       ptr = getsel();
+       tprinter(ptr, strlen(ptr));
+       free(ptr);
+}
+
 void
 tdumpline(int n) {
        Glyph *bp, *end;
@@ -2294,6 +2335,14 @@ tdumpline(int n) {
        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;