* vt plumbing: empty selection
@ 2020-04-09 4:14 ori
2020-04-09 6:58 ` [9front] " Iruatã Souza
0 siblings, 1 reply; 8+ messages in thread
From: ori @ 2020-04-09 4:14 UTC (permalink / raw)
To: 9front
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, though cwd isn't updated
whenever we change directories. That'll take further thought
to get right.
There's an escape code (OSC 7) for programs to advertise
their current working directory to the terminal emulator,
and I'm willing to implement it -- but nothing on 9front
generates it, and it's not clear that we want to start.
The programs that do generate it are likely to be on the
other end of an ssh connection, which means that their cwd
is unlikely to make sense to plumb. Is there anything that
is useful to do here?
diff -r 3bcb5998f222 sys/src/cmd/vt/main.c
--- a/sys/src/cmd/vt/main.c Wed Apr 08 23:48:09 2020 +0200
+++ b/sys/src/cmd/vt/main.c Wed Apr 08 21:07:46 2020 -0700
@@ -170,7 +170,7 @@
void escapedump(int,uchar *,int);
void paste(void);
void snarfsel(void);
-void plumbsel(void);
+void plumbsel(Point);
static Channel *pidchan;
@@ -982,13 +982,47 @@
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 + 1, p.y);
+ if(c == 0 || c == ' ' || c == '\t' || c == '\n')
+ break;
+ }
+ s = malloc((x1 - x0 + 1)*UTFmax);
+ if(s == nil || x0 == x1)
+ return nil;
+ e = selrange(s, x0, p.y, x1, p.y);
+ *e = 0;
+ for(e = s; *e; e++)
+ print("%c(%d)\n", *e, *e);
+ 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 @@
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 @@
return;
case Mplumb:
- plumbsel();
+ plumbsel(p);
return;
case Mpage: /* pause and clear at end of screen */
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9front] vt plumbing: empty selection
2020-04-09 4:14 vt plumbing: empty selection ori
@ 2020-04-09 6:58 ` Iruatã Souza
2020-04-09 6:59 ` Iruatã Souza
0 siblings, 1 reply; 8+ messages in thread
From: Iruatã Souza @ 2020-04-09 6:58 UTC (permalink / raw)
To: 9front
Ori,
It seems that in surrounding, if x0 == x1 you allocate a one byte
buffer but return nil, effectively leaking that buffer.
On Thu, Apr 9, 2020 at 6:15 AM <ori@eigenstate.org> wrote:
>
> 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, though cwd isn't updated
> whenever we change directories. That'll take further thought
> to get right.
>
> There's an escape code (OSC 7) for programs to advertise
> their current working directory to the terminal emulator,
> and I'm willing to implement it -- but nothing on 9front
> generates it, and it's not clear that we want to start.
> The programs that do generate it are likely to be on the
> other end of an ssh connection, which means that their cwd
> is unlikely to make sense to plumb. Is there anything that
> is useful to do here?
>
> diff -r 3bcb5998f222 sys/src/cmd/vt/main.c
> --- a/sys/src/cmd/vt/main.c Wed Apr 08 23:48:09 2020 +0200
> +++ b/sys/src/cmd/vt/main.c Wed Apr 08 21:07:46 2020 -0700
> @@ -170,7 +170,7 @@
> void escapedump(int,uchar *,int);
> void paste(void);
> void snarfsel(void);
> -void plumbsel(void);
> +void plumbsel(Point);
>
> static Channel *pidchan;
>
> @@ -982,13 +982,47 @@
> 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 + 1, p.y);
> + if(c == 0 || c == ' ' || c == '\t' || c == '\n')
> + break;
> + }
> + s = malloc((x1 - x0 + 1)*UTFmax);
> + if(s == nil || x0 == x1)
> + return nil;
> + e = selrange(s, x0, p.y, x1, p.y);
> + *e = 0;
> + for(e = s; *e; e++)
> + print("%c(%d)\n", *e, *e);
> + 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 @@
> 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 @@
> return;
>
> case Mplumb:
> - plumbsel();
> + plumbsel(p);
> return;
>
> case Mpage: /* pause and clear at end of screen */
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9front] vt plumbing: empty selection
2020-04-09 6:58 ` [9front] " Iruatã Souza
@ 2020-04-09 6:59 ` Iruatã Souza
2020-04-09 13:06 ` ori
0 siblings, 1 reply; 8+ messages in thread
From: Iruatã Souza @ 2020-04-09 6:59 UTC (permalink / raw)
To: 9front
sorry 1 * UTFmax
On Thu, Apr 9, 2020 at 8:58 AM Iruatã Souza <iru.muzgo@gmail.com> wrote:
>
> Ori,
>
> It seems that in surrounding, if x0 == x1 you allocate a one byte
> buffer but return nil, effectively leaking that buffer.
>
> On Thu, Apr 9, 2020 at 6:15 AM <ori@eigenstate.org> wrote:
> >
> > 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, though cwd isn't updated
> > whenever we change directories. That'll take further thought
> > to get right.
> >
> > There's an escape code (OSC 7) for programs to advertise
> > their current working directory to the terminal emulator,
> > and I'm willing to implement it -- but nothing on 9front
> > generates it, and it's not clear that we want to start.
> > The programs that do generate it are likely to be on the
> > other end of an ssh connection, which means that their cwd
> > is unlikely to make sense to plumb. Is there anything that
> > is useful to do here?
> >
> > diff -r 3bcb5998f222 sys/src/cmd/vt/main.c
> > --- a/sys/src/cmd/vt/main.c Wed Apr 08 23:48:09 2020 +0200
> > +++ b/sys/src/cmd/vt/main.c Wed Apr 08 21:07:46 2020 -0700
> > @@ -170,7 +170,7 @@
> > void escapedump(int,uchar *,int);
> > void paste(void);
> > void snarfsel(void);
> > -void plumbsel(void);
> > +void plumbsel(Point);
> >
> > static Channel *pidchan;
> >
> > @@ -982,13 +982,47 @@
> > 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 + 1, p.y);
> > + if(c == 0 || c == ' ' || c == '\t' || c == '\n')
> > + break;
> > + }
> > + s = malloc((x1 - x0 + 1)*UTFmax);
> > + if(s == nil || x0 == x1)
> > + return nil;
> > + e = selrange(s, x0, p.y, x1, p.y);
> > + *e = 0;
> > + for(e = s; *e; e++)
> > + print("%c(%d)\n", *e, *e);
> > + 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 @@
> > 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 @@
> > return;
> >
> > case Mplumb:
> > - plumbsel();
> > + plumbsel(p);
> > return;
> >
> > case Mpage: /* pause and clear at end of screen */
> >
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9front] vt plumbing: empty selection
2020-04-09 6:59 ` Iruatã Souza
@ 2020-04-09 13:06 ` ori
2020-04-09 13:17 ` Iruatã Souza
0 siblings, 1 reply; 8+ messages in thread
From: ori @ 2020-04-09 13:06 UTC (permalink / raw)
To: iru.muzgo, 9front
> sorry 1 * UTFmax
>
That, plus some debug printing.
Updated:
diff -r 3bcb5998f222 sys/src/cmd/vt/main.c
--- a/sys/src/cmd/vt/main.c Wed Apr 08 23:48:09 2020 +0200
+++ b/sys/src/cmd/vt/main.c Thu Apr 09 06:06:11 2020 -0700
@@ -170,7 +170,7 @@
void escapedump(int,uchar *,int);
void paste(void);
void snarfsel(void);
-void plumbsel(void);
+void plumbsel(Point);
static Channel *pidchan;
@@ -982,13 +982,44 @@
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 + 1, p.y);
+ if(c == 0 || c == ' ' || c == '\t' || c == '\n')
+ break;
+ }
+ if(s == nil || x0 == x1)
+ return nil;
+ s = malloc((x1 - x0 + 1)*UTFmax);
+ e = selrange(s, x0, p.y, x1, p.y);
+ 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 +1147,9 @@
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 +1207,7 @@
return;
case Mplumb:
- plumbsel();
+ plumbsel(p);
return;
case Mpage: /* pause and clear at end of screen */
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9front] vt plumbing: empty selection
2020-04-09 13:06 ` ori
@ 2020-04-09 13:17 ` Iruatã Souza
2020-04-09 13:23 ` ori
0 siblings, 1 reply; 8+ messages in thread
From: Iruatã Souza @ 2020-04-09 13:17 UTC (permalink / raw)
To: ori; +Cc: 9front
why not
if (x0 == x1)
return nil;
s = malloc((x1 - x0 + 1)*UTFmax);
if (s == nil)
return nil;
On Thu, Apr 9, 2020 at 3:06 PM <ori@eigenstate.org> wrote:
>
> > sorry 1 * UTFmax
> >
>
> That, plus some debug printing.
>
> Updated:
>
> diff -r 3bcb5998f222 sys/src/cmd/vt/main.c
> --- a/sys/src/cmd/vt/main.c Wed Apr 08 23:48:09 2020 +0200
> +++ b/sys/src/cmd/vt/main.c Thu Apr 09 06:06:11 2020 -0700
> @@ -170,7 +170,7 @@
> void escapedump(int,uchar *,int);
> void paste(void);
> void snarfsel(void);
> -void plumbsel(void);
> +void plumbsel(Point);
>
> static Channel *pidchan;
>
> @@ -982,13 +982,44 @@
> 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 + 1, p.y);
> + if(c == 0 || c == ' ' || c == '\t' || c == '\n')
> + break;
> + }
> + if(s == nil || x0 == x1)
> + return nil;
> + s = malloc((x1 - x0 + 1)*UTFmax);
> + e = selrange(s, x0, p.y, x1, p.y);
> + 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 +1147,9 @@
> 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 +1207,7 @@
> return;
>
> case Mplumb:
> - plumbsel();
> + plumbsel(p);
> return;
>
> case Mpage: /* pause and clear at end of screen */
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9front] vt plumbing: empty selection
2020-04-09 13:17 ` Iruatã Souza
@ 2020-04-09 13:23 ` ori
2020-04-09 15:12 ` Iruatã Souza
0 siblings, 1 reply; 8+ messages in thread
From: ori @ 2020-04-09 13:23 UTC (permalink / raw)
To: iru.muzgo, ori; +Cc: 9front
> why not
>
> if (x0 == x1)
> return nil;
>
> s = malloc((x1 - x0 + 1)*UTFmax);
> if (s == nil)
> return nil;
>
Mostly because my coffee hasn't metabolized. Done.
diff -r 3bcb5998f222 sys/src/cmd/vt/main.c
--- a/sys/src/cmd/vt/main.c Wed Apr 08 23:48:09 2020 +0200
+++ b/sys/src/cmd/vt/main.c Thu Apr 09 06:22:30 2020 -0700
@@ -170,7 +170,7 @@
void escapedump(int,uchar *,int);
void paste(void);
void snarfsel(void);
-void plumbsel(void);
+void plumbsel(Point);
static Channel *pidchan;
@@ -982,13 +982,47 @@
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 + 1, 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 @@
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 @@
return;
case Mplumb:
- plumbsel();
+ plumbsel(p);
return;
case Mpage: /* pause and clear at end of screen */
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [9front] vt plumbing: empty selection
2020-04-09 13:23 ` ori
@ 2020-04-09 15:12 ` Iruatã Souza
2020-04-10 16:01 ` cinap_lenrek
0 siblings, 1 reply; 8+ messages in thread
From: Iruatã Souza @ 2020-04-09 15:12 UTC (permalink / raw)
To: ori; +Cc: 9front
Looks good to me!
On Thu, Apr 9, 2020 at 3:23 PM <ori@eigenstate.org> wrote:
>
> > why not
> >
> > if (x0 == x1)
> > return nil;
> >
> > s = malloc((x1 - x0 + 1)*UTFmax);
> > if (s == nil)
> > return nil;
> >
>
> Mostly because my coffee hasn't metabolized. Done.
>
> diff -r 3bcb5998f222 sys/src/cmd/vt/main.c
> --- a/sys/src/cmd/vt/main.c Wed Apr 08 23:48:09 2020 +0200
> +++ b/sys/src/cmd/vt/main.c Thu Apr 09 06:22:30 2020 -0700
> @@ -170,7 +170,7 @@
> void escapedump(int,uchar *,int);
> void paste(void);
> void snarfsel(void);
> -void plumbsel(void);
> +void plumbsel(Point);
>
> static Channel *pidchan;
>
> @@ -982,13 +982,47 @@
> 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 + 1, 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 @@
> 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 @@
> return;
>
> case Mplumb:
> - plumbsel();
> + plumbsel(p);
> return;
>
> case Mpage: /* pause and clear at end of screen */
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-04-10 16:01 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-09 4:14 vt plumbing: empty selection ori
2020-04-09 6:58 ` [9front] " Iruatã Souza
2020-04-09 6:59 ` Iruatã Souza
2020-04-09 13:06 ` ori
2020-04-09 13:17 ` Iruatã Souza
2020-04-09 13:23 ` ori
2020-04-09 15:12 ` Iruatã Souza
2020-04-10 16:01 ` cinap_lenrek
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).