shithub: vshot

Download patch

ref: 7d6dc788b95b32904f2252e4687993b50fa5db10
parent: e8826c996c2f3a7d587369490cf83245845c9285
author: phil9 <telephil9@gmail.com>
date: Thu Feb 4 02:57:31 EST 2021

add -c flag to dump screenshot to stdout

	this option allows for piping vshot to format converters like topng.
	when used the screenshot menu option will dump the image to stdout and exit vshot.

	also added Return key shortcut to take screenshot

--- a/vshot.c
+++ b/vshot.c
@@ -46,6 +46,7 @@
 int		nwins;
 int		nload;
 int		cur;
+int		dump;
 
 void*
 emalloc(ulong size)
@@ -73,6 +74,10 @@
 	char buf[256] = {0};
 	int fd;
 	
+	if(dump){
+		writememimage(1, wins[cur]->image);
+		threadexitsall(nil);
+	}
 	if(enter("Save as", buf, sizeof buf, mctl, kctl, nil)<=0)
 		return;
 	fd = create(buf, OWRITE, 0644);
@@ -299,9 +304,19 @@
 		{ nil, nil, CHANEND },
 	};
 
+	dump  = 0;
 	nload = 0;
 	nwins = 0;
-	cur = 0;
+	cur   = 0;
+	ARGBEGIN{
+	case 'c':
+		dump = 1;
+		break;
+	default:
+		fprint(2, "usage: %s [-c]\n", argv0);
+		threadexitsall("usage");
+	}ARGEND
+
 	if(initdraw(nil, nil, "vshot")<0)
 		sysfatal("initdraw: %r");
 	unlockdisplay(display);
@@ -355,6 +370,9 @@
 				if(cur<0)
 					cur = nwins - 1;
 				redraw();
+				break;
+			case '\n':
+				screenshot();
 				break;
 			}
 			break;