aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h3
-rw-r--r--st.c110
-rw-r--r--st.info3
3 files changed, 104 insertions, 12 deletions
diff --git a/config.def.h b/config.def.h
index b31d7d6..58b470e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -107,6 +107,9 @@ static Mousekey mshortcuts[] = {
107 107
108static Shortcut shortcuts[] = { 108static Shortcut shortcuts[] = {
109 /* mask keysym function argument */ 109 /* mask keysym function argument */
110 { ControlMask, XK_Print, toggleprinter, {.i = 0} },
111 { ShiftMask, XK_Print, printscreen, {.i = 0} },
112 { XK_ANY_MOD, XK_Print, printsel, {.i = 0} },
110 { MODKEY|ShiftMask, XK_Prior, xzoom, {.i = +1} }, 113 { MODKEY|ShiftMask, XK_Prior, xzoom, {.i = +1} },
111 { MODKEY|ShiftMask, XK_Next, xzoom, {.i = -1} }, 114 { MODKEY|ShiftMask, XK_Next, xzoom, {.i = -1} },
112 { ShiftMask, XK_Insert, selpaste, {.i = 0} }, 115 { ShiftMask, XK_Insert, selpaste, {.i = 0} },
diff --git a/st.c b/st.c
index c16e45d..69b2491 100644
--- a/st.c
+++ b/st.c
@@ -134,6 +134,7 @@ enum term_mode {
134 MODE_MOUSEX10 = 131072, 134 MODE_MOUSEX10 = 131072,
135 MODE_MOUSEMANY = 262144, 135 MODE_MOUSEMANY = 262144,
136 MODE_BRCKTPASTE = 524288, 136 MODE_BRCKTPASTE = 524288,
137 MODE_PRINT = 1048576,
137 MODE_MOUSE = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\ 138 MODE_MOUSE = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\
138 |MODE_MOUSEMANY, 139 |MODE_MOUSEMANY,
139}; 140};
@@ -313,6 +314,9 @@ static void clippaste(const Arg *);
313static void numlock(const Arg *); 314static void numlock(const Arg *);
314static void selpaste(const Arg *); 315static void selpaste(const Arg *);
315static void xzoom(const Arg *); 316static void xzoom(const Arg *);
317static void printsel(const Arg *);
318static void printscreen(const Arg *) ;
319static void toggleprinter(const Arg *);
316 320
317/* Config.h for applying patches and the configuration. */ 321/* Config.h for applying patches and the configuration. */
318#include "config.h" 322#include "config.h"
@@ -355,6 +359,10 @@ static void strparse(void);
355static void strreset(void); 359static void strreset(void);
356 360
357static int tattrset(int); 361static int tattrset(int);
362static void tprinter(char *s, size_t len);
363static void tdumpsel(void);
364static void tdumpline(int);
365static void tdump(void);
358static void tclearregion(int, int, int, int); 366static void tclearregion(int, int, int, int);
359static void tcursor(int); 367static void tcursor(int);
360static void tdeletechar(int); 368static void tdeletechar(int);
@@ -429,6 +437,7 @@ static void selrequest(XEvent *);
429static void selinit(void); 437static void selinit(void);
430static void selsort(void); 438static void selsort(void);
431static inline bool selected(int, int); 439static inline bool selected(int, int);
440static char *getsel(void);
432static void selcopy(void); 441static void selcopy(void);
433static void selscroll(int, int); 442static void selscroll(int, int);
434static void selsnap(int, int *, int *, int); 443static void selsnap(int, int *, int *, int);
@@ -469,7 +478,7 @@ static STREscape strescseq;
469static int cmdfd; 478static int cmdfd;
470static pid_t pid; 479static pid_t pid;
471static Selection sel; 480static Selection sel;
472static int iofd = -1; 481static int iofd = STDOUT_FILENO;
473static char **opt_cmd = NULL; 482static char **opt_cmd = NULL;
474static char *opt_io = NULL; 483static char *opt_io = NULL;
475static char *opt_title = NULL; 484static char *opt_title = NULL;
@@ -949,8 +958,8 @@ bpress(XEvent *e) {
949 } 958 }
950} 959}
951 960
952void 961char *
953selcopy(void) { 962getsel(void) {
954 char *str, *ptr; 963 char *str, *ptr;
955 int x, y, bufsize, size, i, ex; 964 int x, y, bufsize, size, i, ex;
956 Glyph *gp, *last; 965 Glyph *gp, *last;
@@ -1009,7 +1018,12 @@ selcopy(void) {
1009 } 1018 }
1010 *ptr = 0; 1019 *ptr = 0;
1011 } 1020 }
1012 xsetsel(str); 1021 return str;
1022}
1023
1024void
1025selcopy(void) {
1026 xsetsel(getsel());
1013} 1027}
1014 1028
1015void 1029void
@@ -1256,6 +1270,7 @@ ttynew(void) {
1256 cmdfd = m; 1270 cmdfd = m;
1257 signal(SIGCHLD, sigchld); 1271 signal(SIGCHLD, sigchld);
1258 if(opt_io) { 1272 if(opt_io) {
1273 term.mode |= MODE_PRINT;
1259 iofd = (!strcmp(opt_io, "-")) ? 1274 iofd = (!strcmp(opt_io, "-")) ?
1260 STDOUT_FILENO : 1275 STDOUT_FILENO :
1261 open(opt_io, O_WRONLY | O_CREAT, 0666); 1276 open(opt_io, O_WRONLY | O_CREAT, 0666);
@@ -1979,6 +1994,25 @@ csihandle(void) {
1979 DEFAULT(csiescseq.arg[0], 1); 1994 DEFAULT(csiescseq.arg[0], 1);
1980 tmoveto(term.c.x, term.c.y+csiescseq.arg[0]); 1995 tmoveto(term.c.x, term.c.y+csiescseq.arg[0]);
1981 break; 1996 break;
1997 case 'i': /* MC -- Media Copy */
1998 switch(csiescseq.arg[0]) {
1999 case 0:
2000 tdump();
2001 break;
2002 case 1:
2003 tdumpline(term.c.y);
2004 break;
2005 case 2:
2006 tdumpsel();
2007 break;
2008 case 4:
2009 term.mode &= ~MODE_PRINT;
2010 break;
2011 case 5:
2012 term.mode |= MODE_PRINT;
2013 break;
2014 }
2015 break;
1982 case 'c': /* DA -- Device Attributes */ 2016 case 'c': /* DA -- Device Attributes */
1983 if(csiescseq.arg[0] == 0) 2017 if(csiescseq.arg[0] == 0)
1984 ttywrite(VT102ID, sizeof(VT102ID) - 1); 2018 ttywrite(VT102ID, sizeof(VT102ID) - 1);
@@ -2252,6 +2286,64 @@ strreset(void) {
2252} 2286}
2253 2287
2254void 2288void
2289tprinter(char *s, size_t len) {
2290 if(iofd != -1 && xwrite(iofd, s, len) < 0) {
2291 fprintf(stderr, "Error writing in %s:%s\n",
2292 opt_io, strerror(errno));
2293 close(iofd);
2294 iofd = -1;
2295 }
2296}
2297
2298void
2299toggleprinter(const Arg *arg) {
2300 term.mode ^= MODE_PRINT;
2301}
2302
2303void
2304printscreen(const Arg *arg) {
2305 tdump();
2306}
2307
2308void
2309printsel(const Arg *arg) {
2310 tdumpsel();
2311}
2312
2313void
2314tdumpsel(void)
2315{
2316 char *ptr;
2317
2318 ptr = getsel();
2319 tprinter(ptr, strlen(ptr));
2320 free(ptr);
2321}
2322
2323void
2324tdumpline(int n) {
2325 Glyph *bp, *end;
2326
2327 bp = &term.line[n][0];
2328 end = &bp[term.col-1];
2329 while(end > bp && !strcmp(" ", end->c))
2330 --end;
2331 if(bp != end || strcmp(bp->c, " ")) {
2332 for( ;bp <= end; ++bp)
2333 tprinter(bp->c, strlen(bp->c));
2334 }
2335 tprinter("\n", 1);
2336}
2337
2338void
2339tdump(void) {
2340 int i;
2341
2342 for(i = 0; i < term.row; ++i)
2343 tdumpline(i);
2344}
2345
2346void
2255tputtab(bool forward) { 2347tputtab(bool forward) {
2256 uint x = term.c.x; 2348 uint x = term.c.x;
2257 2349
@@ -2332,14 +2424,8 @@ tputc(char *c, int len) {
2332 width = wcwidth(u8char); 2424 width = wcwidth(u8char);
2333 } 2425 }
2334 2426
2335 if(iofd != -1) { 2427 if(IS_SET(MODE_PRINT))
2336 if(xwrite(iofd, c, len) < 0) { 2428 tprinter(c, len);
2337 fprintf(stderr, "Error writing in %s:%s\n",
2338 opt_io, strerror(errno));
2339 close(iofd);
2340 iofd = -1;
2341 }
2342 }
2343 2429
2344 /* 2430 /*
2345 * STR sequences must be checked before anything else 2431 * STR sequences must be checked before anything else
diff --git a/st.info b/st.info
index 7526141..4e60a89 100644
--- a/st.info
+++ b/st.info
@@ -152,6 +152,9 @@ st| simpleterm,
152 ncv#3, 152 ncv#3,
153 op=\E[39;49m, 153 op=\E[39;49m,
154 pairs#64, 154 pairs#64,
155 mc0=\E[i,
156 mc4=\E[4i,
157 mc5=\E[5i,
155 rc=\E8, 158 rc=\E8,
156 rev=\E[7m, 159 rev=\E[7m,
157 ri=\EM, 160 ri=\EM,