shithub: view

Download patch

ref: 032d83f1b0e022c09886d0a57815615332fce7c2
parent: f1547b9353c2276936f35a9c75f4eb3974ad87fa
author: phil9 <telephil9@gmail.com>
date: Thu Nov 25 00:57:48 EST 2021

add generic pipe menu option

	this new option allows to pipe the image to any external command.
	The external command is obviously expected to output an image in
	9 format.

--- a/view.c
+++ b/view.c
@@ -30,6 +30,7 @@
 	Mvflip,
 	Mrotleft,
 	Mrotright,
+	Mpipeto,
 };
 char *menu2str[] =
 {
@@ -37,6 +38,7 @@
 	"flip vert.",
 	"rotate left",
 	"rotate right",
+	"pipe to...",
 	nil,
 };
 Menu menu2 = { menu2str };
@@ -257,15 +259,35 @@
 {
 	Image *i;
 	int n;
+	char buf[255];
 
+	i = nil;
 	n = menuhit(2, mctl, &menu2, nil);
-	if(n >= 0){
+	switch(n){
+	case Mhflip:
+	case Mvflip:
+	case Mrotleft:
+	case Mrotright:
 		i = rotate(n);
-		freeimage(img);
-		img = i;
-		pos = subpt(ZP, img->r.min);
-		redraw();
+		if(i == nil){
+			fprint(2, "unable to rotate image: %r\n");
+			return;
+		}
+		break;
+	case Mpipeto:
+		if(enter("command:", buf, sizeof buf, mctl, kctl, nil) > 0){
+			i = ipipeto(img, buf);
+			if(i == nil){
+				fprint(2, "unable to pipe image: %r\n");
+				return;
+			}
+		}
+		break;
 	}
+	freeimage(img);
+	img = i;
+	pos = subpt(ZP, img->r.min);
+	redraw();
 }
 
 void