X-Git-Url: https://git.xinqibao.xyz/st.git/blobdiff_plain/017af76f5c89fa1acf9b54ceaad2101dcfd880a0..121d9109e8202aaa8df836f2d23922008bdf2c72:/st.c

diff --git a/st.c b/st.c
index 8e31a73..5e8cf02 100644
--- a/st.c
+++ b/st.c
@@ -77,6 +77,7 @@ enum glyph_attribute {
 	ATTR_BOLD      = 4,
 	ATTR_GFX       = 8,
 	ATTR_ITALIC    = 16,
+	ATTR_BLINK     = 32,
 };
 
 enum cursor_movement {
@@ -311,6 +312,7 @@ static void brelease(XEvent *);
 static void bpress(XEvent *);
 static void bmotion(XEvent *);
 static void selnotify(XEvent *);
+static void selclear(XEvent *);
 static void selrequest(XEvent *);
 
 static void selinit(void);
@@ -336,6 +338,7 @@ static void (*handler[LASTEvent])(XEvent *) = {
 	[MotionNotify] = bmotion,
 	[ButtonPress] = bpress,
 	[ButtonRelease] = brelease,
+	[SelectionClear] = selclear,
 	[SelectionNotify] = selnotify,
 	[SelectionRequest] = selrequest,
 };
@@ -612,6 +615,14 @@ selpaste() {
 	XConvertSelection(xw.dpy, XA_PRIMARY, sel.xtarget, XA_PRIMARY, xw.win, CurrentTime);
 }
 
+void selclear(XEvent *e) {
+	if(sel.bx == -1)
+		return;
+	sel.bx = -1;
+	tsetdirt(sel.b.y, sel.e.y);
+	draw();
+}
+
 void
 selrequest(XEvent *e) {
 	XSelectionRequestEvent *xsre;
@@ -790,9 +801,15 @@ ttynew(void) {
 		close(s);
 		cmdfd = m;
 		signal(SIGCHLD, sigchld);
-		if(opt_io && !(fileio = fopen(opt_io, "w"))) {
-			fprintf(stderr, "Error opening %s:%s\n",
-				opt_io, strerror(errno));
+		if(opt_io) {
+			if(!strcmp(opt_io, "-")) {
+				fileio = stdout;
+			} else {
+				if(!(fileio = fopen(opt_io, "w"))) {
+					fprintf(stderr, "Error opening %s:%s\n",
+						opt_io, strerror(errno));
+				}
+			}
 		}
 	}
 }
@@ -1116,7 +1133,8 @@ tsetattr(int *attr, int l) {
 	for(i = 0; i < l; i++) {
 		switch(attr[i]) {
 		case 0:
-			term.c.attr.mode &= ~(ATTR_REVERSE | ATTR_UNDERLINE | ATTR_BOLD);
+			term.c.attr.mode &= ~(ATTR_REVERSE | ATTR_UNDERLINE | ATTR_BOLD \
+					| ATTR_ITALIC | ATTR_BLINK);
 			term.c.attr.fg = DefaultFG;
 			term.c.attr.bg = DefaultBG;
 			break;
@@ -1129,6 +1147,9 @@ tsetattr(int *attr, int l) {
 		case 4:
 			term.c.attr.mode |= ATTR_UNDERLINE;
 			break;
+		case 5:
+			term.c.attr.mode |= ATTR_BLINK;
+			break;
 		case 7:
 			term.c.attr.mode |= ATTR_REVERSE;
 			break;
@@ -1141,6 +1162,9 @@ tsetattr(int *attr, int l) {
 		case 24:
 			term.c.attr.mode &= ~ATTR_UNDERLINE;
 			break;
+		case 25:
+			term.c.attr.mode &= ~ATTR_BLINK;
+			break;
 		case 27:
 			term.c.attr.mode &= ~ATTR_REVERSE;
 			break;
@@ -1492,6 +1516,9 @@ strhandle(void) {
 			break;
 		}
 		break;
+	case 'k': /* old title set compatibility */
+		XStoreName(xw.dpy, xw.win, strescseq.buf);
+		break;
 	case 'P': /* DSC -- Device Control String */
 	case '_': /* APC -- Application Program Command */
 	case '^': /* PM -- Privacy Message */
@@ -1554,8 +1581,10 @@ void
 tputc(char *c) {
 	char ascii = *c;
 
-	if(fileio)
+	if(fileio) {
 		putc(ascii, fileio);
+		fflush(fileio);
+	}
 
 	if(term.esc & ESC_START) {
 		if(term.esc & ESC_CSI) {
@@ -1605,6 +1634,7 @@ tputc(char *c) {
 			case '_': /* APC -- Application Program Command */
 			case '^': /* PM -- Privacy Message */
 			case ']': /* OSC -- Operating System Command */
+			case 'k': /* old title set compatibility */
 				strreset();
 				strescseq.type = ascii;
 				term.esc |= ESC_STR;
@@ -1914,6 +1944,17 @@ xinit(void) {
 		die("Can't open display\n");
 	xw.scr = XDefaultScreen(xw.dpy);
 
+	/* font */
+	initfonts(FONT, BOLDFONT, ITALICFONT);
+
+	/* XXX: Assuming same size for bold font */
+	xw.cw = dc.font.rbearing - dc.font.lbearing;
+	xw.ch = dc.font.ascent + dc.font.descent;
+
+	/* colors */
+	xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
+	xloadcols();
+
 	/* adjust fixed window geometry */
 	if(xw.isfixed) {
 		sw = DisplayWidth(xw.dpy, xw.scr);
@@ -1933,24 +1974,12 @@ xinit(void) {
 		xw.fy = 0;
 	}
 
-	/* font */
-	initfonts(FONT, BOLDFONT, ITALICFONT);
-
-	/* XXX: Assuming same size for bold font */
-	xw.cw = dc.font.rbearing - dc.font.lbearing;
-	xw.ch = dc.font.ascent + dc.font.descent;
-
-	/* colors */
-	xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
-	xloadcols();
-
 	attrs.background_pixel = dc.col[DefaultBG];
 	attrs.border_pixel = dc.col[DefaultBG];
 	attrs.bit_gravity = NorthWestGravity;
 	attrs.event_mask = FocusChangeMask | KeyPressMask
 		| ExposureMask | VisibilityChangeMask | StructureNotifyMask
-		| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask
-		| EnterWindowMask | LeaveWindowMask;
+		| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
 	attrs.colormap = xw.cmap;
 
 	parent = opt_embed ? strtol(opt_embed, NULL, 0) : XRootWindow(xw.dpy, xw.scr);
@@ -2036,7 +2065,6 @@ void
 xcopy() {
 	XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}};
 	XdbeSwapBuffers(xw.dpy, swpinfo, 1);
-
 }
 
 void