summaryrefslogtreecommitdiff
path: root/sys/src/cmd/vt
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2020-04-11 11:56:04 -0700
committerOri Bernstein <ori@eigenstate.org>2020-04-11 11:56:04 -0700
commitebb3e31118724ff3a655815abc333992ac7287ed (patch)
treecba603a3a8d52fcbecd4034abb50f62772277120 /sys/src/cmd/vt
parenta7dab2728bde8eea68ddfdfadfad08a00b1f7c68 (diff)
vt plumbing: don't require selection
Plumbing text in vt requires selecting the text that you want to plumb precisely. This patch makes plumbing behave the same way that it does in rio.
Diffstat (limited to 'sys/src/cmd/vt')
-rw-r--r--sys/src/cmd/vt/main.c45
1 files changed, 41 insertions, 4 deletions
diff --git a/sys/src/cmd/vt/main.c b/sys/src/cmd/vt/main.c
index aa074d6db..3dc8de5c7 100644
--- a/sys/src/cmd/vt/main.c
+++ b/sys/src/cmd/vt/main.c
@@ -170,7 +170,7 @@ int alnum(int);
void escapedump(int,uchar *,int);
void paste(void);
void snarfsel(void);
-void plumbsel(void);
+void plumbsel(Point);
static Channel *pidchan;
@@ -982,13 +982,47 @@ snarfsel(void)
free(s);
}
+/*
+ * Grabs the non-whitespace text around a character
+ * cell, matching the behavior in rio for plumbing.
+ * Does not modify the selection.
+ */
+char*
+surrounding(Point p)
+{
+ int c, x0, x1;
+ char *s, *e;
+
+ for(x0 = p.x; x0 > 0; x0--){
+ c = *onscreenr(x0 - 1, p.y);
+ if(c == 0 || c == ' ' || c == '\t' || c == '\n')
+ break;
+ }
+ for(x1 = p.x; x1 <= xmax; x1++){
+ c = *onscreenr(x1, p.y);
+ if(c == 0 || c == ' ' || c == '\t' || c == '\n')
+ break;
+ }
+ if(x0 == x1)
+ return nil;
+ s = malloc((x1 - x0 + 1)*UTFmax);
+ if(s == nil)
+ return nil;
+ e = selrange(s, x0, p.y, x1, p.y);
+ *e = 0;
+ return s;
+}
+
void
-plumbsel(void)
+plumbsel(Point p)
{
char *s, wdir[1024];
int plumb;
- if((s = selection()) == nil)
+ s = selection();
+ if(s == nil || *s == 0)
+ s = surrounding(p);
+ if(s == nil)
return;
if(getwd(wdir, sizeof wdir) == nil){
free(s);
@@ -1116,6 +1150,9 @@ selected(int x, int y)
void
readmenu(void)
{
+ Point p;
+
+ p = pos(mc->xy);
if(button3()) {
menu3.item[1] = ttystate[cs->raw].crnl ? "cr" : "crnl";
menu3.item[2] = ttystate[cs->raw].nlcr ? "nl" : "nlcr";
@@ -1173,7 +1210,7 @@ readmenu(void)
return;
case Mplumb:
- plumbsel();
+ plumbsel(p);
return;
case Mpage: /* pause and clear at end of screen */