diff options
| -rw-r--r-- | config.def.h | 3 | ||||
| -rw-r--r-- | st.c | 110 | ||||
| -rw-r--r-- | st.info | 3 |
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 | ||
| 108 | static Shortcut shortcuts[] = { | 108 | static 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} }, |
| @@ -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 *); | |||
| 313 | static void numlock(const Arg *); | 314 | static void numlock(const Arg *); |
| 314 | static void selpaste(const Arg *); | 315 | static void selpaste(const Arg *); |
| 315 | static void xzoom(const Arg *); | 316 | static void xzoom(const Arg *); |
| 317 | static void printsel(const Arg *); | ||
| 318 | static void printscreen(const Arg *) ; | ||
| 319 | static 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); | |||
| 355 | static void strreset(void); | 359 | static void strreset(void); |
| 356 | 360 | ||
| 357 | static int tattrset(int); | 361 | static int tattrset(int); |
| 362 | static void tprinter(char *s, size_t len); | ||
| 363 | static void tdumpsel(void); | ||
| 364 | static void tdumpline(int); | ||
| 365 | static void tdump(void); | ||
| 358 | static void tclearregion(int, int, int, int); | 366 | static void tclearregion(int, int, int, int); |
| 359 | static void tcursor(int); | 367 | static void tcursor(int); |
| 360 | static void tdeletechar(int); | 368 | static void tdeletechar(int); |
| @@ -429,6 +437,7 @@ static void selrequest(XEvent *); | |||
| 429 | static void selinit(void); | 437 | static void selinit(void); |
| 430 | static void selsort(void); | 438 | static void selsort(void); |
| 431 | static inline bool selected(int, int); | 439 | static inline bool selected(int, int); |
| 440 | static char *getsel(void); | ||
| 432 | static void selcopy(void); | 441 | static void selcopy(void); |
| 433 | static void selscroll(int, int); | 442 | static void selscroll(int, int); |
| 434 | static void selsnap(int, int *, int *, int); | 443 | static void selsnap(int, int *, int *, int); |
| @@ -469,7 +478,7 @@ static STREscape strescseq; | |||
| 469 | static int cmdfd; | 478 | static int cmdfd; |
| 470 | static pid_t pid; | 479 | static pid_t pid; |
| 471 | static Selection sel; | 480 | static Selection sel; |
| 472 | static int iofd = -1; | 481 | static int iofd = STDOUT_FILENO; |
| 473 | static char **opt_cmd = NULL; | 482 | static char **opt_cmd = NULL; |
| 474 | static char *opt_io = NULL; | 483 | static char *opt_io = NULL; |
| 475 | static char *opt_title = NULL; | 484 | static char *opt_title = NULL; |
| @@ -949,8 +958,8 @@ bpress(XEvent *e) { | |||
| 949 | } | 958 | } |
| 950 | } | 959 | } |
| 951 | 960 | ||
| 952 | void | 961 | char * |
| 953 | selcopy(void) { | 962 | getsel(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 | |||
| 1024 | void | ||
| 1025 | selcopy(void) { | ||
| 1026 | xsetsel(getsel()); | ||
| 1013 | } | 1027 | } |
| 1014 | 1028 | ||
| 1015 | void | 1029 | void |
| @@ -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 | ||
| 2254 | void | 2288 | void |
| 2289 | tprinter(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 | |||
| 2298 | void | ||
| 2299 | toggleprinter(const Arg *arg) { | ||
| 2300 | term.mode ^= MODE_PRINT; | ||
| 2301 | } | ||
| 2302 | |||
| 2303 | void | ||
| 2304 | printscreen(const Arg *arg) { | ||
| 2305 | tdump(); | ||
| 2306 | } | ||
| 2307 | |||
| 2308 | void | ||
| 2309 | printsel(const Arg *arg) { | ||
| 2310 | tdumpsel(); | ||
| 2311 | } | ||
| 2312 | |||
| 2313 | void | ||
| 2314 | tdumpsel(void) | ||
| 2315 | { | ||
| 2316 | char *ptr; | ||
| 2317 | |||
| 2318 | ptr = getsel(); | ||
| 2319 | tprinter(ptr, strlen(ptr)); | ||
| 2320 | free(ptr); | ||
| 2321 | } | ||
| 2322 | |||
| 2323 | void | ||
| 2324 | tdumpline(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 | |||
| 2338 | void | ||
| 2339 | tdump(void) { | ||
| 2340 | int i; | ||
| 2341 | |||
| 2342 | for(i = 0; i < term.row; ++i) | ||
| 2343 | tdumpline(i); | ||
| 2344 | } | ||
| 2345 | |||
| 2346 | void | ||
| 2255 | tputtab(bool forward) { | 2347 | tputtab(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 |
| @@ -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, |
