From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 27235 invoked from network); 25 Jul 2021 11:49:19 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 25 Jul 2021 11:49:19 -0000 Received: from mx.sdf.org ([205.166.94.24]) by 1ess; Sun Jul 25 07:43:34 -0400 2021 Received: from sdf.org (IDENT:nicolagi@rie.sdf.org [205.166.94.4]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 16PBbh9v022401 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for <9front@9front.org>; Sun, 25 Jul 2021 11:37:44 GMT Received: (from nicolagi@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 16PBbhFF016649 for 9front@9front.org; Sun, 25 Jul 2021 11:37:43 GMT Message-ID: <3A0D4B499E5045016D1455C2B65344F4@sdf.org> To: 9front@9front.org Date: Sun, 25 Jul 2021 12:37:41 +0100 From: nicolagi@sdf.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: extension XMPP blockchain general-purpose base database Subject: [9front] [PATCH] vdiff: assorted changes to share Reply-To: 9front@9front.org Precedence: bulk Hi, yesterday I discovered telephil9's vdiff program on shithub and love it. I made a few changes which may perhaps be useful to others: * Add scroll via scrollbar (acme/sam like behavior). * Quit by pressing 'q' besides ESC. (I usually keep left hand on keyboard, right hand on mouse, so it's handy.) * Make it compile and work in plan9port too (I will most often use vdiff on Linux...) * Make it detect the file name to plumb when the diff is in Linux git form (a/file b/file) (the heuristic can certainly be improved... but I doubt there are many repos with a "b" subdirectory). * Scrollwheel scroll by 1 instead of 10 -- personal preference here I guess. But I finally found out why I can't use the scrollwheel on 9front haha, I just have to change the scroll step in the programs I use. :-) Thanks to telephil9 for vdiff. Before finding it, I used a small program of mine to add plumbable addresses next to each diff hunk so e.g. @@ -36,7 +45,7 @@ becomes @@ -36,7 +45,7 @@ dp.go:45 but vdiff is much better! Cheers, Nicola --- diff d7a39b5d1ab703d248085130253db071f610795f 231f8ac5b833a88d4b25b8584ad940cfb28abb21 --- a/vdiff.c Tue Feb 9 08:16:49 2021 +++ b/vdiff.c Sun Jul 25 12:19:50 2021 @@ -47,7 +47,7 @@ Line **lines; int lsize; int lcount; -const char ellipsis[] = "..."; +char ellipsis[] = "..."; void drawline(Rectangle r, Line *l) @@ -226,9 +226,10 @@ if(s==nil) break; l = parseline(f, n, s); - if(l->t == Lfile && l->s[0] == '+') + if(l->t == Lfile && l->s[0] == '+'){ f = l->s+4; - else if(l->t == Lsep) + if(strncmp(f, "b/", 2)==0) f += 2; + }else if(l->t == Lsep) n = lineno(l->s); else if(l->t == Ladd || l->t == Lnone) ++n; @@ -245,7 +246,29 @@ void plumb(char *f, int l) { - USED(l); +#ifdef unix + /* + In plan9port libplumb depends on lib9pclient which depends on libthread. + Just invoke plumb(1) on plan9port instead of migrating vdiff to libthread. + */ + pid_t pid = fork(); + if(pid==-1) + fprint(2, "fork failed"); + else if(pid>0) + free(wait()); + else{ + char addr[300]={0}; + char *argv[7]; + int i = 0; + snprint(addr, sizeof addr, "%s:%d", f, l); + argv[i++] = "plumb"; + argv[i++] = "-s"; argv[i++] = "vdiff"; + argv[i++] = "-d"; argv[i++] = "edit"; + argv[i++] = addr; + argv[i++] = nil; + exec("plumb", argv); + } +#else int fd; char wd[256], addr[300]={0}; @@ -256,6 +279,7 @@ snprint(addr, sizeof addr, "%s:%d", f, l); plumbsendtext(fd, "vdiff", "edit", wd, addr); close(fd); +#endif } void @@ -274,17 +298,39 @@ e = event(&ev); switch(e){ case Emouse: + if(ev.mouse.buttons&4 && ptinrect(ev.mouse.xy, scrollr)){ + n = (ev.mouse.xy.y - scrollr.min.y) / lineh; + if(n=0 && lines[n+offset]->f != nil) plumb(lines[n+offset]->f, lines[n+offset]->l); }else if(ev.mouse.buttons&8) - scroll(-10); + scroll(-1); else if(ev.mouse.buttons&16) - scroll(10); + scroll(1); break; case Ekeyboard: switch(ev.kbdc){ + case 'q': + goto End; + break; case Kdel: goto End; break;