From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f51.google.com ([209.85.167.51]) by ewsd; Thu Apr 9 02:58:28 EDT 2020 Received: by mail-lf1-f51.google.com with SMTP id m19so5050727lfq.13 for <9front@9front.org>; Wed, 08 Apr 2020 23:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=NgjfcraNQmH/Jad86JUjWEdtBm/XIBg4BnXKmSBl5D4=; b=JuLRRSkLhl1WNR5Fj2JxYkwYLSf+aQH54lacyksZYRG+OiOrgeEObqhRD/TWKuMiXV MXQfSwlobdd7AdbF+yxxRDKZIoK1exiXNUXmwqS6i8xD4LfaxWdegp44zd2P++XqPbKV 3wAdHypQTm3Q8WoIzdhK202drdQ+kTky2nGi24KS/HD3CaQWOVGFDNJtNjKjXn9kvpnd Jomr/l70mXpLz3NoCeqKxQqWACzQXws0kzhfGQHwnbMzWgJoF2svtQNLIa68yogIUyjC 44nNcwUPEdPhnTiCrlFrmlYBlYmD/B1Nq6fTmPqOYcsbXpYUGFLt/tYuRWT2K/yNK7tE ZFdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=NgjfcraNQmH/Jad86JUjWEdtBm/XIBg4BnXKmSBl5D4=; b=K/v44Xou6O9oo2zoLYAh89UsX1uUICKZB4u/RejEF1TWzsk/BCuGPBI/3v6c7FscPI K2MfZ5oGUjtLw1nXnjqL0uJc9mfrgkW/NMix5Sp4oubW2xu415hwUfuHAHsuiEGKDk/I 4J3LPZbCeEC+ntuUADIsPFz/ARpAHACK+kqazYf3WYn7v1EIiE/gopYi7/J/ZyCuzQMi TgEjMrW/qCjO06fJWktZeWMFYN4GtU0zNFFKm4AsRxXHB/NDarGMshHN602213sNFzYW wRs6Le16+fYYPaM30LjG+HpKPH/jYFASJQWN0zOb8F4sFn4B1tz1b+iDQ5Hv43umBSQp ZpSQ== X-Gm-Message-State: AGi0PubUApmFo+pGBcUh3qShGxfn08CSAEpOsM+NbgMttULzkMq0Gg+v V9QHoPHKWEsH91e6cywQtHR9sQ0+k0LETW7NlUJwPFhM X-Google-Smtp-Source: APiQypLP1PLieWpQK5gwHXhP89yY1o77BTA2aEmG5v4IKTtScGiNt5Twe2z3MoI47iiUQt2N88GByPzek+dJ2NMYePM= X-Received: by 2002:ac2:5f92:: with SMTP id r18mr2909022lfe.154.1586415501646; Wed, 08 Apr 2020 23:58:21 -0700 (PDT) MIME-Version: 1.0 References: <618C497B56559996D5CB5F02EF37BD27@eigenstate.org> In-Reply-To: <618C497B56559996D5CB5F02EF37BD27@eigenstate.org> From: =?UTF-8?Q?Iruat=C3=A3_Souza?= Date: Thu, 9 Apr 2020 08:58:10 +0200 Message-ID: Subject: Re: [9front] vt plumbing: empty selection To: 9front@9front.org Content-Type: text/plain; charset="UTF-8" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: compliant session-oriented layer 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 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 */ >