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"
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);
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);
static int cmdfd;
static pid_t pid;
static Selection sel;
-static int iofd;
+static int iofd = STDOUT_FILENO;
static char **opt_cmd = NULL;
static char *opt_io = NULL;
static char *opt_title = NULL;
}
}
-void
-selcopy(void) {
+char *
+getsel(void) {
char *str, *ptr;
int x, y, bufsize, size, i, ex;
Glyph *gp, *last;
}
*ptr = 0;
}
- xsetsel(str);
+ return str;
+}
+
+void
+selcopy(void) {
+ xsetsel(getsel());
}
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;
memset(&strescseq, 0, sizeof(strescseq));
}
+void
+tprinter(char *s, size_t len) {
+ if(iofd != -1 && xwrite(iofd, s, len) < 0) {
+ fprintf(stderr, "Error writing in %s:%s\n",
+ opt_io, strerror(errno));
+ close(iofd);
+ iofd = -1;
+ }
+}
+
+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;
+
+ bp = &term.line[n][0];
+ end = &bp[term.col-1];
+ while(end > bp && !strcmp(" ", end->c))
+ --end;
+ if(bp != end || strcmp(bp->c, " ")) {
+ for( ;bp <= end; ++bp)
+ tprinter(bp->c, strlen(bp->c));
+ }
+ 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;
width = wcwidth(u8char);
}
- if(IS_SET(MODE_PRINT) && iofd != -1) {
- if(xwrite(iofd, c, len) < 0) {
- fprintf(stderr, "Error writing in %s:%s\n",
- opt_io, strerror(errno));
- close(iofd);
- iofd = -1;
- }
- }
+ if(IS_SET(MODE_PRINT))
+ tprinter(c, len);
/*
* STR sequences must be checked before anything else