9front - general discussion about 9front
 help / color / mirror / Atom feed
* [Patch] Plumbing in vt
@ 2018-05-20 18:02 ori
  0 siblings, 0 replies; only message in thread
From: ori @ 2018-05-20 18:02 UTC (permalink / raw)
  To: 9front

I've wanted plumbing in vt for a while.  This patch adds it.  It keeps
the first 512 runes of a selection around, and plumbs them when you
hit the 'plumb' menu entry.

I'm a little iffy about the limited size buffer, but I think it's good
enough -- most things that get plumbed will be small.

Does this look good to commit?

diff -r bf754277ec0e sys/src/cmd/vt/main.c
--- a/sys/src/cmd/vt/main.c	Fri May 18 21:39:19 2018 -0400
+++ b/sys/src/cmd/vt/main.c	Sun May 20 02:34:16 2018 -0700
@@ -1,6 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <draw.h>
+#include <plumb.h>
 
 #include "cons.h"
 
@@ -18,6 +19,7 @@
 	"reset",
 	"clear",
 	"paste",
+	"plumb",
 	"page",
 	0
 };
@@ -36,6 +38,7 @@
 
 int	x, y;	/* character positions */
 Rune	*backp;
+Rune	lastsel[512];
 int	backc;
 int	atend;
 int	nbacklines;
@@ -884,12 +887,33 @@
 }
 
 void
+sendplumb(void)
+{
+	char buf[512], wdir[512];
+	int plumb;
+
+	plumb = plumbopen("send", OWRITE);
+	if(plumb == -1)
+		goto cleanup;
+	if (getwd(wdir, sizeof wdir) == 0)
+		goto cleanup;
+	snprint(buf, sizeof buf, "%S", lastsel);
+	plumbsendtext(plumb, "vt", nil, wdir, buf);
+
+cleanup:
+	close(plumb);
+}
+
+void
 seputrunes(Biobuf *b, Rune *s, Rune *e)
 {
 	int z, p;
+	Rune *psel, *esel;
 
 	if(s >= e)
 		return;
+	psel = lastsel;
+	esel = lastsel + sizeof(lastsel) - 1;
 	for(z = p = 0; s < e; s++){
 		if(*s){
 			if(*s == '\n')
@@ -897,11 +921,14 @@
 			else if(p++ == 0){
 				while(z-- > 0) Bputc(b, ' ');
 			}
+			if (psel != esel)
+				*psel++ = *s;
 			Bputrune(b, *s);
 		} else {
 			z++;
 		}
 	}
+	*psel = 0;
 }
 
 int
@@ -1011,7 +1038,7 @@
 		return;
 	}
 
-	menu2.item[5] = pagemode? "scroll": "page";
+	menu2.item[6] = pagemode? "scroll": "page";
 
 	switch(menuhit(2, mc, &menu2, nil)) {
 
@@ -1042,8 +1069,10 @@
 	case 4:		/* send the snarf buffer */
 		sendsnarf();
 		return;
-
-	case 5:		/* pause and clear at end of screen */
+	case 5:
+		sendplumb();
+		return;
+	case 6:		/* pause and clear at end of screen */
 		pagemode = 1-pagemode;
 		if(blocked && !pagemode) {
 			resize_flag = 1;



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-05-20 18:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-20 18:02 [Patch] Plumbing in vt ori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).