shithub: gemnine

Download patch

ref: 3987505e1b20d271b2838211dc2631d380dcf68c
parent: 1fe76cb758c2be655ff778499e002b66d756e4dc
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun May 17 09:25:10 EDT 2020

faster output, support basic plumbing

--- a/README.md
+++ b/README.md
@@ -9,3 +9,14 @@
 As of now some basics are implemented to handle errors and print the
 body to stdout, the plan is to add a separate GUI program to display
 the pages in a better way.
+
+## Installation
+
+Clone the repo, `mk install`. Add a plumb rule to `$home/lib/plumbing`:
+
+```
+type	is	text
+data	matches	'gemini://[^ ]+'
+plumb	to	gemini
+plumb	client	window gemnine -w $0
+```
--- a/main.c
+++ b/main.c
@@ -166,16 +166,25 @@
 {
 	Response *r;
 	char *s, *t, *u;
-	int len;
+	int len, wait;
+	Biobuf out;
 
-	if(argc < 2){
-		fprint(2, "usage: gemnine URL\n");
+	wait = 0;
+	ARGBEGIN{
+	case 'w':
+		wait = 1;
+		break;
+	}ARGEND;
+
+	if(argc < 1){
+		fprint(2, "usage: gemnine [-w] URL\n");
 		exits("usage");
 	}
 
 	quotefmtinstall();
+	Binit(&out, 1, OWRITE);
 
-	if((r = request(argv[1])) != nil){
+	if((r = request(argv[0])) != nil){
 		if(r->mime != nil && strncmp(r->mime, "text/", 5) != 0){
 			/* FIXME handle in a better way */
 			if(r->mime != nil)
@@ -193,11 +202,11 @@
 						t++;
 					u = t;
 					if((t = strpbrk(t, " :/")) == nil || t[0] != ':' || t[1] != '/' || t[2] != '/') /* relative URL */
-						print("=> gemini://%s:%s/%s\n", r->url->server, r->url->port, u);
+						Bprint(&out, "=> gemini://%s:%s/%s\n", r->url->server, r->url->port, u);
 					else
-						print("%s\n", s);
+						Bprint(&out, "%s\n", s);
 				}else{
-					print("%s\n", s);
+					Bprint(&out, "%s\n", s);
 				}
 				free(s);
 			}
@@ -205,8 +214,14 @@
 		freeresponse(r);
 	}else{
 		fprint(2, "%s: %r\n", argv[1]);
+		if(wait)
+			read(0, &wait, 4);
 		exits("failed");
 	}
+
+	Bflush(&out);
+	if(wait)
+		read(0, &wait, 4);
 
 	exits(nil);
 }